Class: Ppds::Tumblr
- Inherits:
-
Object
- Object
- Ppds::Tumblr
- Defined in:
- lib/ppds/tumblr.rb
Constant Summary collapse
- MANDATORY_FIELDS =
{ 'text' => ['body'], 'link' => ['url'], 'chat' => ['conversation'], 'quote' => ['quote'], 'photo' => [], 'video' => [], 'audio' => ['data'] }
- CONCURENT_FIELDS =
{ 'text' => [], 'link' => [], 'chat' => [], 'quote' => [], 'photo' => ['source', 'data'], 'video' => ['embed', 'data'], 'audio' => [] }
- OPTIONAL_FIELDS =
{ 'text' => ['title'], 'link' => ['name', 'description'], 'chat' => ['title'], 'quote' => ['source'], 'photo' => ['caption','click-through-url'], 'video' => ['caption'], # 'title' 'audio' => ['caption'] }
- API_URL =
'http://www.tumblr.com/api/'
Instance Attribute Summary collapse
-
#blogs ⇒ Object
Returns the value of attribute blogs.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
- #authenticate(email, password) ⇒ Object
-
#initialize ⇒ Tumblr
constructor
A new instance of Tumblr.
- #query(action, data) ⇒ Object
Constructor Details
#initialize ⇒ Tumblr
Returns a new instance of Tumblr.
51 52 53 54 |
# File 'lib/ppds/tumblr.rb', line 51 def initialize self.user = nil self.blogs = [] end |
Instance Attribute Details
#blogs ⇒ Object
Returns the value of attribute blogs.
17 18 19 |
# File 'lib/ppds/tumblr.rb', line 17 def blogs @blogs end |
#user ⇒ Object
Returns the value of attribute user.
17 18 19 |
# File 'lib/ppds/tumblr.rb', line 17 def user @user end |
Instance Method Details
#authenticate(email, password) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/ppds/tumblr.rb', line 66 def authenticate(email, password) data = { :email => email, :password => password } xml = query('authenticate', data) @xml = XML::Parser.string(xml).parse self.user = User.new(@xml.find_first('//tumblr/user').attributes) if @xml self.blogs = @xml.find('//tumblr/tumblelog').map do |node| Blog.new(node.attributes) end true rescue Exception false end |
#query(action, data) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/ppds/tumblr.rb', line 56 def query(action, data) RestClient.post(API_URL + action, data) rescue RestClient::RequestFailed raise 'Query failed: %s' % $! rescue RestClient::RequestTimeout raise 'Timeout occured' rescue Exception raise $! end |