Class: OmniAuth::Strategies::TradeMe

Inherits:
OAuth
  • Object
show all
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

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, options={}, &block)
  client_options = {
    :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, client_options, options, &block)
end

Instance Method Details

#auth_hashObject



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' => ,
      'extra' => {
        'user_hash' => user_hash,
      },
    }
  )
end

#user_hashObject

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_infoObject

user info according to schema



35
36
37
38
39
40
41
42
# File 'lib/omniauth/strategies/oauth/trade_me.rb', line 35

def 
  {
    '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