From f55df7ace28c158eb81fda53bc47147b8142a0f9 Mon Sep 17 00:00:00 2001 From: John Bunting Date: Fri, 15 Jul 2011 14:54:30 -0400 Subject: [PATCH] Adding the simplified GET requests for the tumblr api and an Updated readme. --- README | 6 ++++++ lib/tumblr_oauth/client.rb | 17 +++++++++++++++++ lib/tumblr_oauth/posts.rb | 14 ++++++++++++++ lib/tumblr_oauth/user.rb | 11 +++++++++++ 4 files changed, 48 insertions(+) create mode 100644 lib/tumblr_oauth/posts.rb create mode 100644 lib/tumblr_oauth/user.rb diff --git a/README b/README index b2a2c1d..e8c5caa 100644 --- a/README +++ b/README @@ -1 +1,7 @@ A Ruby client for restful interaction with Tumblr + +This isn't ready for primetime but if you'd like to contribute send me a pull. + +Design of the gem is borrowed heavily from: https://github.com/moomerman/twitter_oauth + +He's awesome. diff --git a/lib/tumblr_oauth/client.rb b/lib/tumblr_oauth/client.rb index bd6434a..9ad3a30 100644 --- a/lib/tumblr_oauth/client.rb +++ b/lib/tumblr_oauth/client.rb @@ -1,12 +1,15 @@ module TumblrOAuth class Client + def initalize(options={}) @consumer_key = options[:consumer_key] @consumer_secret = options[:consumer_secret] @token = options[:token] @secret = options[:secret] @proxy = options[:proxy] + @api_url = "http://api.tumblr.com/v2" end + def authorize(token, secret, options={}) request_token = OAuth::RequestToken.new( consumer, token, secret @@ -16,9 +19,11 @@ def authorize(token, secret, options={}) @secret = @access_token.secret @access_token end + def request_token(options={}) consumer.get_request_token(options) end + def authentication_request_token(options={}) consumer.options[:authorize_path] = '/oauth/authenticate' request_token(options) @@ -36,5 +41,17 @@ def access_token @access_token ||= OAuth::AccessToken.new(consumer, @token, @secret) end + def get path, body='', headers={} + headers.merge!("User-Agent" => "tumblr oauth gem v#{TumblrOAuth::VERSION}") + oauth_response = access_token.get("#{@api_url}/#{path}", headers) + JSON.parse(oauth_response.body) + end + + def post path, body='', headers={} + headers.merge!("User-Agent" => "tumblr oauth gem v#{TumblrOAuth::VERSION}") + oauth_response = access_token.post("#{@api_url}/#{path}", headers) + JSON.parse(oauth_response.body) + end + end end diff --git a/lib/tumblr_oauth/posts.rb b/lib/tumblr_oauth/posts.rb new file mode 100644 index 0000000..86f9e28 --- /dev/null +++ b/lib/tumblr_oauth/posts.rb @@ -0,0 +1,14 @@ +module TumblrOAuth + #Allow for different blogs + def queued_posts + get("/posts/queue") + end + def draft_posts + get("/posts/draf") + end + + def posts(options={}) + #accept those optional parameters + get("/posts") + end +end diff --git a/lib/tumblr_oauth/user.rb b/lib/tumblr_oauth/user.rb new file mode 100644 index 0000000..cb39e2d --- /dev/null +++ b/lib/tumblr_oauth/user.rb @@ -0,0 +1,11 @@ +module TumblrOAuth + def followers + return get("/followers") + end + def likes + return get("/user/likes") + end + def following + return get("/user/following") + end +end