Class: OmniAuth::Strategies::TradeMe
- Defined in:
- lib/omniauth/strategies/oauth/trade_me.rb
Overview
Authenticate to TradeMe via OAuth and retrieve basic user information. Usage: use OmniAuth::Strategies::TradeMe, 'consumerkey', 'consumersecret'
Instance Attribute Summary
Attributes inherited from OAuth
#consumer_key, #consumer_options, #consumer_secret, #name
Instance Method Summary collapse
- #auth_hash ⇒ Object
-
#initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block) ⇒ TradeMe
constructor
A new instance of TradeMe.
-
#user_hash ⇒ Object
info as supplied by TradeMe user summary.
-
#user_info ⇒ Object
user info according to schema.
Methods inherited from OAuth
#callback_phase, #consumer, #request_phase, #unique_id
Constructor Details
#initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block) ⇒ TradeMe
Returns a new instance of TradeMe.
12 13 14 15 16 17 18 19 20 |
# File 'lib/omniauth/strategies/oauth/trade_me.rb', line 12 def initialize(app, consumer_key=nil, consumer_secret=nil, ={}, &block) = { :access_token_path => '/Oauth/AccessToken', :authorize_path => '/Oauth/Authorize', :request_token_path => '/Oauth/RequestToken', :site => 'https://secure.trademe.co.nz', } super(app, :trademe, consumer_key, consumer_secret, , , &block) end |
Instance Method Details
#auth_hash ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/omniauth/strategies/oauth/trade_me.rb', line 22 def auth_hash OmniAuth::Utils.deep_merge( super, { 'uid' => user_hash['MemberId'], 'user_info' => user_info, 'extra' => { 'user_hash' => user_hash, }, } ) end |
#user_hash ⇒ Object
info as supplied by TradeMe user summary
45 46 47 |
# File 'lib/omniauth/strategies/oauth/trade_me.rb', line 45 def user_hash @user_hash ||= MultiJson.decode(@access_token.get('https://api.trademe.co.nz/v1/MyTradeMe/Summary.json').body) end |
#user_info ⇒ Object
user info according to schema
35 36 37 38 39 40 41 42 |
# File 'lib/omniauth/strategies/oauth/trade_me.rb', line 35 def user_info { 'nickname' => user_hash['Nickname'], 'first_name' => user_hash['FirstName'], 'last_name' => user_hash['LastName'], 'name' => [user_hash['FirstName'], user_hash['LastName']].reject{|n| n.nil? || n.empty?}.join(' '), } end |