Skip to content

Commit

Permalink
Adding the simplified GET requests for the tumblr api and an Updated …
Browse files Browse the repository at this point in the history
…readme.
  • Loading branch information
codingjester committed Jul 15, 2011
1 parent 332610b commit f55df7a
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
6 changes: 6 additions & 0 deletions 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.
17 changes: 17 additions & 0 deletions 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
Expand All @@ -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)
Expand All @@ -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
14 changes: 14 additions & 0 deletions 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
11 changes: 11 additions & 0 deletions 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

0 comments on commit f55df7a

Please sign in to comment.