Class: Sorcery::Providers::Instagram
- Includes:
- Sorcery::Protocols::Oauth2
- Defined in:
- lib/sorcery/providers/instagram.rb
Overview
This class adds support for OAuth with Instagram.com.
Instance Attribute Summary collapse
-
#access_permissions ⇒ Object
Returns the value of attribute access_permissions.
-
#authorization_path ⇒ Object
Returns the value of attribute authorization_path.
-
#scope ⇒ Object
Returns the value of attribute scope.
-
#token_url ⇒ Object
Returns the value of attribute token_url.
-
#user_info_fields ⇒ Object
Returns the value of attribute user_info_fields.
-
#user_info_path ⇒ Object
Returns the value of attribute user_info_path.
Attributes inherited from Base
#access_token, #callback_url, #key, #original_callback_url, #secret, #site, #state, #user_info_mapping
Class Method Summary collapse
Instance Method Summary collapse
-
#authorize_url(opts = {}) ⇒ Object
overrides oauth2#authorize_url to allow customized scope.
-
#get_user_hash(access_token) ⇒ Object
see ‘user_info_mapping` in config/initializer, given `user_info_mapping` to specify => ’instagram_attr_name’ so that Sorcery can build AR model from attr names.
-
#initialize ⇒ Instagram
constructor
A new instance of Instagram.
-
#login_url(_params, _session) ⇒ Object
provider implements method to build Oauth client.
-
#process_callback(params, _session) ⇒ Object
pass oauth2 param ‘code` provided by instgrm server.
Methods included from Sorcery::Protocols::Oauth2
#build_client, #get_access_token, #oauth_version
Methods inherited from Base
#auth_hash, descendants, #has_callback?, name
Constructor Details
#initialize ⇒ Instagram
Returns a new instance of Instagram.
11 12 13 14 15 16 17 18 19 |
# File 'lib/sorcery/providers/instagram.rb', line 11 def initialize super @site = 'https://api.instagram.com' @token_url = '/oauth/access_token' @authorization_path = '/oauth/authorize/' @user_info_path = '/v1/users/self' @scope = 'basic' end |
Instance Attribute Details
#access_permissions ⇒ Object
Returns the value of attribute access_permissions.
7 8 9 |
# File 'lib/sorcery/providers/instagram.rb', line 7 def @access_permissions end |
#authorization_path ⇒ Object
Returns the value of attribute authorization_path.
7 8 9 |
# File 'lib/sorcery/providers/instagram.rb', line 7 def @authorization_path end |
#scope ⇒ Object
Returns the value of attribute scope.
7 8 9 |
# File 'lib/sorcery/providers/instagram.rb', line 7 def scope @scope end |
#token_url ⇒ Object
Returns the value of attribute token_url.
7 8 9 |
# File 'lib/sorcery/providers/instagram.rb', line 7 def token_url @token_url end |
#user_info_fields ⇒ Object
Returns the value of attribute user_info_fields.
7 8 9 |
# File 'lib/sorcery/providers/instagram.rb', line 7 def user_info_fields @user_info_fields end |
#user_info_path ⇒ Object
Returns the value of attribute user_info_path.
7 8 9 |
# File 'lib/sorcery/providers/instagram.rb', line 7 def user_info_path @user_info_path end |
Class Method Details
Instance Method Details
#authorize_url(opts = {}) ⇒ Object
overrides oauth2#authorize_url to allow customized scope.
31 32 33 34 |
# File 'lib/sorcery/providers/instagram.rb', line 31 def (opts = {}) @scope = .present? ? .join(' ') : scope super(opts.merge(token_url: @token_url)) end |
#get_user_hash(access_token) ⇒ Object
see ‘user_info_mapping` in config/initializer, given `user_info_mapping` to specify
{:db_attribute_name => 'instagram_attr_name'}
so that Sorcery can build AR model from attr names
NOTE: instead of just getting the user info from the access_token (which already returns them), testing strategy relies on querying user_info_path
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/sorcery/providers/instagram.rb', line 57 def get_user_hash(access_token) call_api_params = { access_token: access_token.token, client_id: access_token[:client_id] } response = access_token.get( "#{user_info_path}?#{call_api_params.to_param}" ) user_attrs = {} user_attrs[:user_info] = JSON.parse(response.body)['data'] user_attrs[:uid] = user_attrs[:user_info]['id'] user_attrs end |
#login_url(_params, _session) ⇒ Object
provider implements method to build Oauth client
26 27 28 |
# File 'lib/sorcery/providers/instagram.rb', line 26 def login_url(_params, _session) (token_url: @token_url) end |
#process_callback(params, _session) ⇒ Object
pass oauth2 param ‘code` provided by instgrm server
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/sorcery/providers/instagram.rb', line 37 def process_callback(params, _session) args = {}.tap do |a| a[:code] = params[:code] if params[:code] end get_access_token( args, token_url: @token_url, client_id: @key, client_secret: @secret ) end |