Class: Bitlyr::Strategy::OAuth
- Extended by:
- Forwardable
- Defined in:
- lib/bitlyr/strategy/oauth.rb
Constant Summary collapse
- BASE_URL =
'https://api-ssl.bit.ly/v3/'
Instance Method Summary collapse
-
#authorize_url(redirect_url) ⇒ Object
Get the url to redirect a user to, pass the url you want the user to be redirected back to.
-
#get_access_token_from_code(code, redirect_url) ⇒ Object
Get the access token.
-
#get_access_token_from_token(token, params = {}) ⇒ Object
If you already have a user token, this method gets the access token.
-
#initialize(consumer_token, consumer_secret) ⇒ OAuth
constructor
A new instance of OAuth.
-
#set_access_token_from_token!(token, params = {}) ⇒ Object
If you already have a user token, this method sets the access token.
Methods inherited from Base
Constructor Details
#initialize(consumer_token, consumer_secret) ⇒ OAuth
Returns a new instance of OAuth.
9 10 11 12 |
# File 'lib/bitlyr/strategy/oauth.rb', line 9 def initialize(consumer_token, consumer_secret) @consumer_token = consumer_token @consumer_secret = consumer_secret end |
Instance Method Details
#authorize_url(redirect_url) ⇒ Object
Get the url to redirect a user to, pass the url you want the user to be redirected back to.
16 17 18 |
# File 'lib/bitlyr/strategy/oauth.rb', line 16 def (redirect_url) client.auth_code.(:redirect_uri => redirect_url).gsub(/api-ssl.bit.ly/,'bitly.com') end |
#get_access_token_from_code(code, redirect_url) ⇒ Object
Get the access token. You must pass the exact same redirect_url passed to the authorize_url method
22 23 24 25 |
# File 'lib/bitlyr/strategy/oauth.rb', line 22 def get_access_token_from_code(code, redirect_url) access_token = client.auth_code.get_token(code, :redirect_uri => redirect_url, :parse => :query) Bitlyr::Strategy::AccessToken.new(access_token) end |
#get_access_token_from_token(token, params = {}) ⇒ Object
If you already have a user token, this method gets the access token
28 29 30 31 32 |
# File 'lib/bitlyr/strategy/oauth.rb', line 28 def get_access_token_from_token(token, params={}) params.stringify_keys! access_token = ::OAuth2::AccessToken.new(client, token, params) Bitlyr::Strategy::AccessToken.new(access_token) end |
#set_access_token_from_token!(token, params = {}) ⇒ Object
If you already have a user token, this method sets the access token
35 36 37 |
# File 'lib/bitlyr/strategy/oauth.rb', line 35 def set_access_token_from_token!(token, params={}) @access_token ||= get_access_token_from_token(token, params) end |