Sha256: 03a297ab1194841d96386f5382614858b77e0c0e404e2115a82b16bbcfdeddd0
Contents?: true
Size: 1.58 KB
Versions: 3
Compression:
Stored size: 1.58 KB
Contents
module Tumblr class Request # a GET request to http://[YOURUSERNAME].tumblr.com/api/read def self.read(options = {}) Tumblr::blog ||= 'staff' response = HTTParty.get("http://#{Tumblr::blog}.tumblr.com/api/read/", :query => 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
3 entries across 3 versions & 2 rubygems
Version | Path |
---|---|
jeffkreeftmeijer-tumblr-0.0.10 | lib/tumblr/request.rb |
zapnap-tumblr-0.0.10 | lib/tumblr/request.rb |
zapnap-tumblr-0.0.9 | lib/tumblr/request.rb |