Class: OmniAuth::Strategies::TradeMe
- Defined in:
- lib/omniauth/strategies/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 |
# File 'lib/omniauth/strategies/trade_me.rb', line 12 def initialize(app, consumer_key = nil, consumer_secret = nil, = {}, &block) super(app, :trademe, consumer_key, consumer_secret, {:site => 'https://secure.trademe.co.nz', :request_token_path => "/Oauth/RequestToken", :access_token_path => "/Oauth/AccessToken", :authorize_path => "/Oauth/Authorize", }, , &block) end |
Instance Method Details
#auth_hash ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/omniauth/strategies/trade_me.rb', line 21 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
40 41 42 |
# File 'lib/omniauth/strategies/trade_me.rb', line 40 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
30 31 32 33 34 35 36 37 |
# File 'lib/omniauth/strategies/trade_me.rb', line 30 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 |