Class: Tumblr::Request
- Inherits:
-
Object
- Object
- Tumblr::Request
- Defined in:
- lib/tumblr/request.rb
Class Method Summary collapse
-
.authenticate(email, password) ⇒ Object
a POST request to www.tumblr.com/api/authenticate.
-
.delete(options = {}) ⇒ Object
a POST request to www.tumblr.com/api/delete.
-
.raise_errors(response) ⇒ Object
raise tumblr response errors.
-
.read(options = {}) ⇒ Object
a GET request to [YOURUSERNAME].tumblr.com/api/read override this behavior by setting Tumblr.blog_url, GET request will then direct to [YOURURL]/api/read.
-
.write(options = {}) ⇒ Object
a POST request to www.tumblr.com/api/write.
Class Method Details
.authenticate(email, password) ⇒ Object
a POST request to www.tumblr.com/api/authenticate
25 26 27 |
# File 'lib/tumblr/request.rb', line 25 def self.authenticate(email, password) HTTParty.post('http://www.tumblr.com/api/authenticate', :query => {:email => email, :password => password}) end |
.delete(options = {}) ⇒ Object
a POST request to www.tumblr.com/api/delete
19 20 21 22 |
# File 'lib/tumblr/request.rb', line 19 def self.delete( = {}) response = HTTParty.post('http://www.tumblr.com/api/delete', :query => ) return(response) unless raise_errors(response) end |
.raise_errors(response) ⇒ Object
raise tumblr response errors.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/tumblr/request.rb', line 30 def self.raise_errors(response) if(response.is_a?(Hash)) = "#{response[:code]}: #{response[:body]}" code = response[:code].to_i else = "#{response.code}: #{response.body}" code = response.code.to_i end case code when 403 raise(Forbidden.new, ) when 400 raise(BadRequest.new, ) when 404 raise(NotFound.new, ) when 201 return false end end |
.read(options = {}) ⇒ Object
a GET request to [YOURUSERNAME].tumblr.com/api/read override this behavior by setting Tumblr.blog_url, GET request will then direct to [YOURURL]/api/read
7 8 9 10 |
# File 'lib/tumblr/request.rb', line 7 def self.read( = {}) response = HTTParty.get("http://#{Tumblr::blog_url ||= (Tumblr::blog ||= 'staff')+'.tumblr.com'}/api/read", ) return response unless raise_errors(response) end |
.write(options = {}) ⇒ Object
a POST request to www.tumblr.com/api/write
13 14 15 16 |
# File 'lib/tumblr/request.rb', line 13 def self.write( = {}) response = HTTParty.post('http://www.tumblr.com/api/write', :query => ) return(response) unless raise_errors(response) end |