Class: OmniAuth::Strategies::TradeMe

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

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

Instance Method Details

#auth_hashObject



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

#user_hashObject

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_infoObject

user info according to schema



30
31
32
33
34
35
36
37
# File 'lib/omniauth/strategies/trade_me.rb', line 30

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