Permalink
Browse files

Update oauth gem and fix code

  • Loading branch information...
1 parent fc3132d commit c5299a43332df6ef6a06289213f9ce32af048f74 @philnash committed Jan 8, 2012
Showing with 15 additions and 10 deletions.
  1. +1 −1 Rakefile
  2. +14 −9 lib/bitly/v3/oauth.rb
View
@@ -8,6 +8,6 @@ Echoe.new('bitly', Bitly::VERSION) do |p|
p.url = "http://github.com/philnash/bitly"
p.author = "Phil Nash"
p.email = "philnash@gmail.com"
- p.extra_deps = [['crack', '>= 0.1.4'], ['httparty', '>= 0.7.6'], ['oauth2', '>= 0.1.1']]
+ p.extra_deps = [['crack', '>= 0.1.4'], ['httparty', '>= 0.7.6'], ['oauth2', '~> 0.5.0']]
p.development_dependencies = []
end
View
@@ -1,33 +1,38 @@
module Bitly
- module V3
+ module V3
# OAuth consumer for authentication
class OAuth
attr_reader :access_token
def initialize(consumer_token, consumer_secret)
@consumer_token, @consumer_secret = consumer_token, consumer_secret
end
-
+
# Get the OAuth 2 client
def client
- @client ||= ::OAuth2::Client.new(@consumer_token, @consumer_secret, :site => 'https://api-ssl.bit.ly')
+ @client ||= ::OAuth2::Client.new(
+ @consumer_token,
+ @consumer_secret,
+ :site => 'https://api-ssl.bit.ly',
+ :token_url => '/oauth/access_token'
+ )
end
-
+
# Get the url to redirect a user to, pass the url you want the user
# to be redirected back to.
def authorize_url(redirect_url)
- client.web_server.authorize_url(:redirect_uri => redirect_url).gsub(/api-ssl\./,'')
+ client.auth_code.authorize_url(:redirect_uri => redirect_url).gsub(/api-ssl\./,'')
end
-
+
# Get the access token. You must pass the exact same redirect_url passed
# to the authorize_url method
def get_access_token_from_code(code,redirect_url)
- @access_token ||= client.web_server.get_access_token(code, :redirect_uri => redirect_url)
+ @access_token ||= client.auth_code.get_token(code, :redirect_uri => redirect_url, :parse => :query)
end
-
+
# If you already have a user token, this method gets the access token
def get_access_token_from_token(token, params={})
params = params.inject({}) { |options, (key, value)| options[key.to_s] = value; options }
- @access_token ||= ::OAuth2::AccessToken.new(client, token, nil, nil, params)
+ @access_token ||= ::OAuth2::AccessToken.new(client, token, params)
end
end
end

0 comments on commit c5299a4

Please sign in to comment.