ebay_request 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.rubocop.yml +23 -0
- data/.travis.yml +4 -0
- data/Gemfile +5 -0
- data/README.md +124 -0
- data/Rakefile +7 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/config/sites.yml +321 -0
- data/ebay_request.gemspec +46 -0
- data/lib/ebay_request.rb +77 -0
- data/lib/ebay_request/auth.rb +35 -0
- data/lib/ebay_request/base.rb +115 -0
- data/lib/ebay_request/business_policies.rb +39 -0
- data/lib/ebay_request/config.rb +59 -0
- data/lib/ebay_request/error.rb +9 -0
- data/lib/ebay_request/finding.rb +36 -0
- data/lib/ebay_request/response.rb +40 -0
- data/lib/ebay_request/shopping.rb +36 -0
- data/lib/ebay_request/site.rb +30 -0
- data/lib/ebay_request/trading.rb +83 -0
- data/lib/ebay_request/version.rb +4 -0
- data/lib/omniauth/strategies/ebay.rb +80 -0
- metadata +208 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
class EbayRequest::Shopping < EbayRequest::Base
|
3
|
+
private
|
4
|
+
|
5
|
+
def payload(callname, request)
|
6
|
+
request = Gyoku.xml(request)
|
7
|
+
|
8
|
+
%(<?xml version="1.0" encoding="utf-8"?>\
|
9
|
+
<#{callname}Request xmlns="urn:ebay:apis:eBLBaseComponents">\
|
10
|
+
#{request}</#{callname}Request>)
|
11
|
+
end
|
12
|
+
|
13
|
+
def endpoint
|
14
|
+
"http://open.api%{sandbox}.ebay.com/shopping"
|
15
|
+
end
|
16
|
+
|
17
|
+
def headers(callname)
|
18
|
+
super.merge(
|
19
|
+
"Content-Type" => "text/xml",
|
20
|
+
"X-EBAY-API-APP-ID" => config.appid,
|
21
|
+
"X-EBAY-API-VERSION" => config.version.to_s,
|
22
|
+
"X-EBAY-API-CALL-NAME" => callname,
|
23
|
+
"X-EBAY-API-REQUEST-ENCODING" => "XML",
|
24
|
+
"X-EBAY-API-SITE-ID" => siteid.to_s
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
def errors_for(r)
|
29
|
+
[r["Errors"]]
|
30
|
+
.flatten
|
31
|
+
.compact
|
32
|
+
.map { |e| [e["SeverityCode"], e["ErrorCode"], e["LongMessage"]] }
|
33
|
+
end
|
34
|
+
|
35
|
+
FATAL_ERRORS = {}.freeze
|
36
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
class EbayRequest::Site
|
3
|
+
KEYS = %w(
|
4
|
+
globalid id name currency language domain code metric country gtc_available
|
5
|
+
free_placement max_insertion_fee free_pictures subtitle_fee quantity_limits
|
6
|
+
min_fixed_price
|
7
|
+
).freeze
|
8
|
+
|
9
|
+
attr_reader(*KEYS)
|
10
|
+
|
11
|
+
def initialize(hash)
|
12
|
+
@hash = hash
|
13
|
+
KEYS.each { |key| instance_variable_set(:"@#{key}", hash[key]) }
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_hash
|
17
|
+
@hash
|
18
|
+
end
|
19
|
+
alias to_h to_hash
|
20
|
+
|
21
|
+
def gtc_available?
|
22
|
+
return @gtc_available if [true, false].include? @gtc_available
|
23
|
+
|
24
|
+
raise <<-MESSAGE.gsub(/^ +\|/, "")
|
25
|
+
|We haven't checked whether GTC duration is available on the site #{@id}.
|
26
|
+
|You should explore if GTC is supported by at least one of its categories (see https://developer.ebay.com/devzone/xml/docs/reference/ebay/GetCategoryFeatures.html)
|
27
|
+
|Then you're welcome to make a PR with a resulting value (true|false) added to `config/sites.yml`
|
28
|
+
MESSAGE
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
class EbayRequest::Trading < EbayRequest::Base
|
3
|
+
class IllegalItemStateError < EbayRequest::Error; end
|
4
|
+
class ItemLimitReachedError < EbayRequest::Error; end
|
5
|
+
class DailyItemCallLimitReachedError < EbayRequest::Error; end
|
6
|
+
class TokenValidationFailed < EbayRequest::Error; end
|
7
|
+
class IAFTokenExpired < TokenValidationFailed; end
|
8
|
+
class AccountSuspended < EbayRequest::Error; end
|
9
|
+
class ApplicationInvalid < EbayRequest::Error; end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
def payload(callname, request)
|
14
|
+
request = Gyoku.xml(request, key_converter: :camelcase)
|
15
|
+
|
16
|
+
%(<?xml version="1.0" encoding="utf-8"?>\
|
17
|
+
<#{callname}Request xmlns="urn:ebay:apis:eBLBaseComponents">\
|
18
|
+
#{creds}#{request}</#{callname}Request>)
|
19
|
+
end
|
20
|
+
|
21
|
+
def creds
|
22
|
+
return if options[:token].nil? || options[:iaf_token_manager].present?
|
23
|
+
%(<RequesterCredentials>\
|
24
|
+
<eBayAuthToken>#{options[:token]}</eBayAuthToken>\
|
25
|
+
</RequesterCredentials>)
|
26
|
+
end
|
27
|
+
|
28
|
+
def endpoint
|
29
|
+
"https://api%{sandbox}.ebay.com/ws/api.dll"
|
30
|
+
end
|
31
|
+
|
32
|
+
def headers(callname)
|
33
|
+
authorized_headers = {
|
34
|
+
"Content-Type" => "text/xml",
|
35
|
+
"X-EBAY-API-APP-NAME" => config.appid,
|
36
|
+
"X-EBAY-API-DEV-NAME" => config.devid,
|
37
|
+
"X-EBAY-API-CERT-NAME" => config.certid,
|
38
|
+
"X-EBAY-API-COMPATIBILITY-LEVEL" => config.version.to_s,
|
39
|
+
"X-EBAY-API-CALL-NAME" => callname,
|
40
|
+
"X-EBAY-API-SITEID" => siteid.to_s,
|
41
|
+
}
|
42
|
+
if options[:iaf_token_manager]
|
43
|
+
authorized_headers["X-EBAY-API-IAF-TOKEN"] =
|
44
|
+
options[:iaf_token_manager].access_token
|
45
|
+
end
|
46
|
+
super.merge(authorized_headers)
|
47
|
+
end
|
48
|
+
|
49
|
+
def errors_for(r)
|
50
|
+
[r["Errors"]]
|
51
|
+
.flatten
|
52
|
+
.compact
|
53
|
+
.map { |e| [e["SeverityCode"], e["ErrorCode"], e["LongMessage"]] }
|
54
|
+
end
|
55
|
+
|
56
|
+
def request(*)
|
57
|
+
retried ||= false
|
58
|
+
super.tap do |response|
|
59
|
+
next if retried || options[:iaf_token_manager].nil?
|
60
|
+
next if response.success? || response.error_class > IAFTokenExpired
|
61
|
+
raise response.error
|
62
|
+
end
|
63
|
+
rescue IAFTokenExpired
|
64
|
+
options[:iaf_token_manager].refresh!
|
65
|
+
retried = true
|
66
|
+
retry
|
67
|
+
end
|
68
|
+
|
69
|
+
# http://developer.ebay.com/devzone/xml/docs/reference/ebay/errors/errormessages.htm
|
70
|
+
FATAL_ERRORS = {
|
71
|
+
291 => IllegalItemStateError,
|
72
|
+
1047 => IllegalItemStateError,
|
73
|
+
21_919_188 => ItemLimitReachedError,
|
74
|
+
21_919_165 => DailyItemCallLimitReachedError,
|
75
|
+
931 => TokenValidationFailed,
|
76
|
+
17_470 => TokenValidationFailed,
|
77
|
+
16_110 => TokenValidationFailed,
|
78
|
+
21_916_984 => TokenValidationFailed,
|
79
|
+
21_917_053 => IAFTokenExpired,
|
80
|
+
841 => AccountSuspended,
|
81
|
+
127 => ApplicationInvalid
|
82
|
+
}.freeze
|
83
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
class OmniAuth::Strategies::Ebay
|
3
|
+
include OmniAuth::Strategy
|
4
|
+
|
5
|
+
args [:runame, :devid, :appid, :certid]
|
6
|
+
|
7
|
+
option :runame, nil
|
8
|
+
option :devid, nil
|
9
|
+
option :appid, nil
|
10
|
+
option :certid, nil
|
11
|
+
option :site_id, "0"
|
12
|
+
option :sandbox, true
|
13
|
+
option :env, nil
|
14
|
+
|
15
|
+
uid { raw_info["EIASToken"] }
|
16
|
+
credentials { { token: @auth_token, expires_at: @expires_at } }
|
17
|
+
extra { { raw_info: raw_info } }
|
18
|
+
|
19
|
+
info do
|
20
|
+
{
|
21
|
+
user_id: raw_info["UserID"],
|
22
|
+
auth_token: @auth_token,
|
23
|
+
email: raw_info["Email"],
|
24
|
+
full_name: full_name,
|
25
|
+
first_name: parsed_name[0],
|
26
|
+
last_name: parsed_name[1],
|
27
|
+
eias_token: raw_info["EIASToken"]
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def request_phase
|
32
|
+
configure unless EbayRequest.configured?
|
33
|
+
session["omniauth.ebay.session_id"] = fetch_session_id
|
34
|
+
redirect ebay.ebay_login_url(session["omniauth.ebay.session_id"])
|
35
|
+
end
|
36
|
+
|
37
|
+
def callback_phase
|
38
|
+
response = fetch_token
|
39
|
+
|
40
|
+
@auth_token = response["eBayAuthToken"]
|
41
|
+
@expires_at = Time.parse(response["HardExpirationTime"]).to_i
|
42
|
+
@user_info = ebay.user(@auth_token)
|
43
|
+
|
44
|
+
super
|
45
|
+
end
|
46
|
+
|
47
|
+
def configure
|
48
|
+
EbayRequest.configure(options.env) do |config|
|
49
|
+
config.runame = options.runame
|
50
|
+
config.devid = options.devid
|
51
|
+
config.appid = options.appid
|
52
|
+
config.certid = options.certid
|
53
|
+
config.sandbox = options.sandbox
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def raw_info
|
58
|
+
@user_info["User"]
|
59
|
+
end
|
60
|
+
|
61
|
+
def full_name
|
62
|
+
@full_name ||= raw_info["RegistrationAddress"].try(:[], "Name")
|
63
|
+
end
|
64
|
+
|
65
|
+
def parsed_name
|
66
|
+
@parsed_name ||= (full_name || "").split(" ", 2)
|
67
|
+
end
|
68
|
+
|
69
|
+
def ebay
|
70
|
+
@ebay ||= EbayRequest::Auth.new(site_id: options.site_id, env: options.env)
|
71
|
+
end
|
72
|
+
|
73
|
+
def fetch_token
|
74
|
+
ebay.token(session["omniauth.ebay.session_id"])
|
75
|
+
end
|
76
|
+
|
77
|
+
def fetch_session_id
|
78
|
+
ebay.session_id["SessionID"]
|
79
|
+
end
|
80
|
+
end
|
metadata
ADDED
@@ -0,0 +1,208 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ebay_request
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Victor Sokolov
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-06-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: multi_xml
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: gyoku
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: omniauth
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: dry-initializer
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :runtime
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
description:
|
154
|
+
email:
|
155
|
+
- gzigzigzeo@evilmartians.com
|
156
|
+
executables: []
|
157
|
+
extensions: []
|
158
|
+
extra_rdoc_files: []
|
159
|
+
files:
|
160
|
+
- ".gitignore"
|
161
|
+
- ".rspec"
|
162
|
+
- ".rubocop.yml"
|
163
|
+
- ".travis.yml"
|
164
|
+
- Gemfile
|
165
|
+
- README.md
|
166
|
+
- Rakefile
|
167
|
+
- bin/console
|
168
|
+
- bin/setup
|
169
|
+
- config/sites.yml
|
170
|
+
- ebay_request.gemspec
|
171
|
+
- lib/ebay_request.rb
|
172
|
+
- lib/ebay_request/auth.rb
|
173
|
+
- lib/ebay_request/base.rb
|
174
|
+
- lib/ebay_request/business_policies.rb
|
175
|
+
- lib/ebay_request/config.rb
|
176
|
+
- lib/ebay_request/error.rb
|
177
|
+
- lib/ebay_request/finding.rb
|
178
|
+
- lib/ebay_request/response.rb
|
179
|
+
- lib/ebay_request/shopping.rb
|
180
|
+
- lib/ebay_request/site.rb
|
181
|
+
- lib/ebay_request/trading.rb
|
182
|
+
- lib/ebay_request/version.rb
|
183
|
+
- lib/omniauth/strategies/ebay.rb
|
184
|
+
homepage: https://github.com/gzigzigzeo/ebay_request
|
185
|
+
licenses: []
|
186
|
+
metadata:
|
187
|
+
allowed_push_host: https://rubygems.org
|
188
|
+
post_install_message:
|
189
|
+
rdoc_options: []
|
190
|
+
require_paths:
|
191
|
+
- lib
|
192
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
193
|
+
requirements:
|
194
|
+
- - ">="
|
195
|
+
- !ruby/object:Gem::Version
|
196
|
+
version: '0'
|
197
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
requirements: []
|
203
|
+
rubyforge_project:
|
204
|
+
rubygems_version: 2.7.6
|
205
|
+
signing_key:
|
206
|
+
specification_version: 4
|
207
|
+
summary: eBay API request interface
|
208
|
+
test_files: []
|