Sha256: fe6dd9bc401015538e8442e7c1b66ee09044a0c6054a404a57f2e8a36f4a7e9b
Contents?: true
Size: 1.7 KB
Versions: 1
Compression:
Stored size: 1.7 KB
Contents
class Tumblr class Request # a GET request to http://[YOURUSERNAME].tumblr.com/api/read # override this behavior by setting Tumblr.blog_url, # GET request will then direct to http://[YOURURL]/api/read def self.read(options = {}) response = HTTParty.get("http://#{Tumblr::blog_url ||= (Tumblr::blog ||= 'staff')+'.tumblr.com'}/api/read", options) return response unless raise_errors(response) end # a POST request to http://www.tumblr.com/api/write def self.write(options = {}) response = HTTParty.post('http://www.tumblr.com/api/write', :query => options) return(response) unless raise_errors(response) end # a POST request to http://www.tumblr.com/api/delete def self.delete(options = {}) response = HTTParty.post('http://www.tumblr.com/api/delete', :query => options) return(response) unless raise_errors(response) end # a POST request to http://www.tumblr.com/api/authenticate def self.authenticate(email, password) HTTParty.post('http://www.tumblr.com/api/authenticate', :query => {:email => email, :password => password}) end # raise tumblr response errors. def self.raise_errors(response) if(response.is_a?(Hash)) message = "#{response[:code]}: #{response[:body]}" code = response[:code].to_i else message = "#{response.code}: #{response.body}" code = response.code.to_i end case code when 403 raise(Forbidden.new, message) when 400 raise(BadRequest.new, message) when 404 raise(NotFound.new, message) when 201 return false end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
gisikw-tumblr-0.1.4 | lib/tumblr/request.rb |