class Sorcery::Providers::Instagram
This class adds support for OAuth with Instagram.com.
Attributes
access_permissions[RW]
scope[RW]
token_url[RW]
user_info_fields[RW]
user_info_path[RW]
Public Class Methods
included(base)
click to toggle source
# File lib/sorcery/providers/instagram.rb, line 21 def self.included(base) base.extend Sorcery::Providers end
new()
click to toggle source
Calls superclass method
Sorcery::Providers::Base::new
# 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
Public Instance Methods
get_user_hash(access_token)
click to toggle source
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
# 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)
click to toggle source
provider implements method to build Oauth client
# File lib/sorcery/providers/instagram.rb, line 26 def login_url(_params, _session) authorize_url(token_url: @token_url) end
process_callback(params, _session)
click to toggle source
pass oauth2 param `code` provided by instgrm server
# 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