Sha256: 23a76b6a76956f3eb632dd60ca23fd7c4aeff43bea4f287b0505c7f2d2b673cf
Contents?: true
Size: 1.54 KB
Versions: 5
Compression:
Stored size: 1.54 KB
Contents
require 'omniauth/oauth' require 'multi_json' module OmniAuth module Strategies # # Authenticate to TradeMe via OAuth and retrieve basic user information. # Usage: # use OmniAuth::Strategies::TradeMe, 'consumerkey', 'consumersecret' # class TradeMe < OmniAuth::Strategies::OAuth 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 def auth_hash OmniAuth::Utils.deep_merge(super, { 'uid' => user_hash['MemberId'], 'user_info' => user_info, 'extra' => { 'user_hash' => user_hash }, }) end # user info according to schema 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 # info as supplied by TradeMe user summary def user_hash @user_hash ||= MultiJson.decode(@access_token.get('https://api.trademe.co.nz/v1/MyTradeMe/Summary.json').body) end end end end
Version data entries
5 entries across 5 versions & 1 rubygems