-
Notifications
You must be signed in to change notification settings - Fork 14
/
ebay.rb
81 lines (65 loc) · 1.81 KB
/
ebay.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# frozen_string_literal: true
class OmniAuth::Strategies::Ebay
include OmniAuth::Strategy
args %i[runame devid appid certid]
option :runame, nil
option :devid, nil
option :appid, nil
option :certid, nil
option :site_id, "0"
option :sandbox, true
option :env, nil
uid { raw_info["EIASToken"] }
credentials { { token: @auth_token, expires_at: @expires_at } }
extra { { raw_info: raw_info } }
info do
{
user_id: raw_info["UserID"],
auth_token: @auth_token,
email: raw_info["Email"],
full_name: full_name,
first_name: parsed_name[0],
last_name: parsed_name[1],
eias_token: raw_info["EIASToken"],
}
end
def request_phase
configure unless EbayRequest.configured?
session["omniauth.ebay.session_id"] = fetch_session_id
redirect ebay.ebay_login_url(session["omniauth.ebay.session_id"])
end
def callback_phase
response = fetch_token
@auth_token = response["eBayAuthToken"]
@expires_at = Time.parse(response["HardExpirationTime"]).to_i
@user_info = ebay.user(@auth_token)
super
end
def configure
EbayRequest.configure(options.env) do |config|
config.runame = options.runame
config.devid = options.devid
config.appid = options.appid
config.certid = options.certid
config.sandbox = options.sandbox
end
end
def raw_info
@user_info["User"]
end
def full_name
@full_name ||= raw_info["RegistrationAddress"].try(:[], "Name")
end
def parsed_name
@parsed_name ||= (full_name || "").split(" ", 2)
end
def ebay
@ebay ||= EbayRequest::Auth.new(site_id: options.site_id, env: options.env)
end
def fetch_token
ebay.token(session["omniauth.ebay.session_id"])
end
def fetch_session_id
ebay.session_id["SessionID"]
end
end