ebay-ruby 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ebay/browse.rb +13 -14
- data/lib/ebay/finding.rb +4 -8
- data/lib/ebay/merchandising.rb +4 -8
- data/lib/ebay/oauth/client_credentials_grant.rb +4 -11
- data/lib/ebay/requestable.rb +41 -0
- data/lib/ebay/shopping.rb +4 -8
- data/lib/ebay/version.rb +1 -1
- metadata +2 -2
- data/lib/ebay/sandboxable.rb +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9fbfdf33fe78c10cfdeee697936f0f9eb31a8541a3f0b993d37058539227ac3
|
4
|
+
data.tar.gz: 1fee63caeec5e67ec429050c970bb4717089d5a6f3c150342e7babb9c735a787
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cbea01c20e390702353ef7970d08c43fc067efb26a760f89e0884f91b29310795c7bc3bdcd2495e0638d588332a5ed4b927863a2394cac8fe8fa75d287960dcb
|
7
|
+
data.tar.gz: d759fdf30c035ab2d9934ececd8228d05d2ad9a7eadbfb2128c287af4b5db10b063e4d1b8f8f6198b39a68bda2fb370271ea6bb657ba13722f1a0f5a9bbe74b7
|
data/lib/ebay/browse.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'base64'
|
4
4
|
|
5
5
|
require 'ebay/config'
|
6
|
-
require 'ebay/
|
6
|
+
require 'ebay/requestable'
|
7
7
|
|
8
8
|
module Ebay
|
9
9
|
# Using the Browse API, you can create a rich selection of items for your
|
@@ -13,10 +13,9 @@ module Ebay
|
|
13
13
|
#
|
14
14
|
# @see https://developer.ebay.com/api-docs/buy/browse/overview.html
|
15
15
|
class Browse
|
16
|
-
include
|
16
|
+
include Requestable
|
17
17
|
|
18
|
-
|
19
|
-
PRODUCTION_ENDPOINT = 'https://api.ebay.com/buy/browse/v1'
|
18
|
+
self.endpoint = 'https://api.ebay.com/buy/browse/v1'
|
20
19
|
|
21
20
|
# @return [String]
|
22
21
|
attr_reader :campaign_id
|
@@ -56,20 +55,21 @@ module Ebay
|
|
56
55
|
# @return [HTTP::Response]
|
57
56
|
def search(**params)
|
58
57
|
url = build_url('item_summary', 'search')
|
59
|
-
|
58
|
+
http.headers(build_headers).get(url, params: params)
|
60
59
|
end
|
61
60
|
|
62
61
|
# Searches for eBay items based on a image and retrieves their summaries
|
63
62
|
#
|
64
|
-
# @param [
|
63
|
+
# @param [File] image
|
65
64
|
# @param [Hash] params
|
66
65
|
# @return [HTTP::Response]
|
67
66
|
def search_by_image(image, **params)
|
68
67
|
url = build_url('item_summary', 'search_by_image')
|
69
68
|
headers = build_headers.update('CONTENT-TYPE' => 'application/json')
|
70
|
-
|
69
|
+
encoded_string = Base64.encode64(image.read)
|
70
|
+
body = JSON.dump(image: encoded_string)
|
71
71
|
|
72
|
-
|
72
|
+
http.headers(headers).post(url, params: params, body: body)
|
73
73
|
end
|
74
74
|
|
75
75
|
# Retrieves the details of a specific item
|
@@ -81,7 +81,7 @@ module Ebay
|
|
81
81
|
url = build_url('item', item_id)
|
82
82
|
params.update(item_id: item_id)
|
83
83
|
|
84
|
-
|
84
|
+
http.headers(build_headers).get(url, params: params)
|
85
85
|
end
|
86
86
|
|
87
87
|
# Retrieves the details of a specific item using its legacy item ID
|
@@ -93,7 +93,7 @@ module Ebay
|
|
93
93
|
url = build_url('item', 'get_item_by_legacy_id')
|
94
94
|
params.update(legacy_item_id: legacy_item_id)
|
95
95
|
|
96
|
-
|
96
|
+
http.headers(build_headers).get(url, params: params)
|
97
97
|
end
|
98
98
|
|
99
99
|
# Retrieves the details of the individual items in an item group
|
@@ -104,7 +104,7 @@ module Ebay
|
|
104
104
|
url = build_url('item', 'get_items_by_item_group')
|
105
105
|
params = { item_group_id: item_group_id }
|
106
106
|
|
107
|
-
|
107
|
+
http.headers(build_headers).get(url, params: params)
|
108
108
|
end
|
109
109
|
|
110
110
|
# Retrieves the details of the individual items in an item group
|
@@ -119,7 +119,7 @@ module Ebay
|
|
119
119
|
'CONTENT-TYPE' => 'application/json')
|
120
120
|
body = JSON.dump('compatibilityProperties' => compatibility_properties)
|
121
121
|
|
122
|
-
|
122
|
+
http.headers(headers).post(url, body: body)
|
123
123
|
end
|
124
124
|
|
125
125
|
def add_item
|
@@ -141,7 +141,6 @@ module Ebay
|
|
141
141
|
private
|
142
142
|
|
143
143
|
def build_url(*resources, operation)
|
144
|
-
endpoint = sandbox? ? SANDBOX_ENDPOINT : PRODUCTION_ENDPOINT
|
145
144
|
[endpoint, *resources, operation].join('/')
|
146
145
|
end
|
147
146
|
|
data/lib/ebay/finding.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'http'
|
4
|
-
|
5
3
|
require 'ebay/config'
|
6
|
-
require 'ebay/
|
4
|
+
require 'ebay/requestable'
|
7
5
|
|
8
6
|
module Ebay
|
9
7
|
# The Finding API lets you search for and browse items listed on eBay and
|
@@ -12,10 +10,9 @@ module Ebay
|
|
12
10
|
# @see https://developer.ebay.com/Devzone/finding/Concepts/MakingACall.html
|
13
11
|
# @see https://developer.ebay.com/Devzone/finding/CallRef/index.html
|
14
12
|
class Finding
|
15
|
-
include
|
13
|
+
include Requestable
|
16
14
|
|
17
|
-
|
18
|
-
PRODUCTION_ENDPOINT = 'https://svcs.ebay.com/services/search/FindingService/v1'
|
15
|
+
self.endpoint = 'https://svcs.ebay.com/services/search/FindingService/v1'
|
19
16
|
|
20
17
|
# @return [String, nil]
|
21
18
|
attr_reader :global_id
|
@@ -133,7 +130,6 @@ module Ebay
|
|
133
130
|
private
|
134
131
|
|
135
132
|
def request(operation, payload = {})
|
136
|
-
url = sandbox? ? SANDBOX_ENDPOINT : PRODUCTION_ENDPOINT
|
137
133
|
params = { 'GLOBAL-ID' => global_id,
|
138
134
|
'MESSAGE-ENCODING' => message_encoding,
|
139
135
|
'OPERATION-NAME' => operation,
|
@@ -142,7 +138,7 @@ module Ebay
|
|
142
138
|
'SECURITY-APPNAME' => security_appname,
|
143
139
|
'SERVICE-VERSION' => service_version }.compact
|
144
140
|
|
145
|
-
|
141
|
+
http.post(endpoint, params: params, body: JSON.dump(payload))
|
146
142
|
end
|
147
143
|
end
|
148
144
|
end
|
data/lib/ebay/merchandising.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'http'
|
4
|
-
|
5
3
|
require 'ebay/config'
|
6
|
-
require 'ebay/
|
4
|
+
require 'ebay/requestable'
|
7
5
|
|
8
6
|
module Ebay
|
9
7
|
# Retrieves information about products or item listings on eBay to help you
|
@@ -12,10 +10,9 @@ module Ebay
|
|
12
10
|
# @see https://developer.ebay.com/Devzone/merchandising/docs/Concepts/MerchandisingAPI_FormatOverview.html
|
13
11
|
# @see https://developer.ebay.com/Devzone/merchandising/docs/CallRef/index.html
|
14
12
|
class Merchandising
|
15
|
-
include
|
13
|
+
include Requestable
|
16
14
|
|
17
|
-
|
18
|
-
PRODUCTION_ENDPOINT = 'https://svcs.ebay.com/MerchandisingService'
|
15
|
+
self.endpoint = 'https://svcs.ebay.com/MerchandisingService'
|
19
16
|
|
20
17
|
# @return [String]
|
21
18
|
attr_reader :consumer_id
|
@@ -80,7 +77,6 @@ module Ebay
|
|
80
77
|
private
|
81
78
|
|
82
79
|
def request(operation, payload = {})
|
83
|
-
endpoint = sandbox? ? SANDBOX_ENDPOINT : PRODUCTION_ENDPOINT
|
84
80
|
params = { 'CONSUMER-ID' => consumer_id,
|
85
81
|
'GLOBAL-ID' => global_id,
|
86
82
|
'OPERATION-NAME' => operation,
|
@@ -88,7 +84,7 @@ module Ebay
|
|
88
84
|
'RESPONSE-DATA-FORMAT' => response_data_format,
|
89
85
|
'SERVICE-VERSION' => service_version }.compact
|
90
86
|
|
91
|
-
|
87
|
+
http.post(endpoint, params: params, body: JSON.dump(payload))
|
92
88
|
end
|
93
89
|
end
|
94
90
|
end
|
@@ -1,9 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'http'
|
4
|
-
|
5
3
|
require 'ebay/config'
|
6
|
-
require 'ebay/
|
4
|
+
require 'ebay/requestable'
|
7
5
|
|
8
6
|
module Ebay
|
9
7
|
module Oauth
|
@@ -11,10 +9,9 @@ module Ebay
|
|
11
9
|
#
|
12
10
|
# @see https://developer.ebay.com/api-docs/static/oauth-client-credentials-grant.html
|
13
11
|
class ClientCredentialsGrant
|
14
|
-
include
|
12
|
+
include Requestable
|
15
13
|
|
16
|
-
|
17
|
-
PRODUCTION_ENDPOINT = 'https://api.ebay.com/identity/v1/oauth2/token'
|
14
|
+
self.endpoint = 'https://api.ebay.com/identity/v1/oauth2/token'
|
18
15
|
|
19
16
|
# @return [String]
|
20
17
|
attr_reader :app_id
|
@@ -41,15 +38,11 @@ module Ebay
|
|
41
38
|
# @return [HTTP::Response]
|
42
39
|
def request
|
43
40
|
HTTP.basic_auth(user: app_id, pass: cert_id)
|
44
|
-
.post(
|
41
|
+
.post(endpoint, form: payload)
|
45
42
|
end
|
46
43
|
|
47
44
|
private
|
48
45
|
|
49
|
-
def url
|
50
|
-
sandbox? ? SANDBOX_ENDPOINT : PRODUCTION_ENDPOINT
|
51
|
-
end
|
52
|
-
|
53
46
|
def payload
|
54
47
|
{ grant_type: 'client_credentials',
|
55
48
|
scope: 'https://api.ebay.com/oauth/api_scope' }
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'http'
|
4
|
+
|
5
|
+
module Ebay
|
6
|
+
# Adds an HTTP client and ability to switch to the eBay Sandbox environment
|
7
|
+
module Requestable
|
8
|
+
class << self
|
9
|
+
private
|
10
|
+
|
11
|
+
def included(base)
|
12
|
+
class << base
|
13
|
+
attr_accessor :endpoint
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# @return [HTTP::Client]
|
19
|
+
attr_writer :http
|
20
|
+
|
21
|
+
# @!attribute [r] http
|
22
|
+
# @return [HTTP::Client]
|
23
|
+
def http
|
24
|
+
@http ||= HTTP::Client.new
|
25
|
+
end
|
26
|
+
|
27
|
+
# @!attribute [r] endpoint
|
28
|
+
# @return [String]
|
29
|
+
def endpoint
|
30
|
+
@endpoint ||= self.class.endpoint
|
31
|
+
end
|
32
|
+
|
33
|
+
# Switches to the eBay Sandbox environment
|
34
|
+
#
|
35
|
+
# @return [self]
|
36
|
+
def sandbox
|
37
|
+
@endpoint = endpoint.sub('ebay', 'sandbox.ebay')
|
38
|
+
self
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/ebay/shopping.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'http'
|
4
|
-
|
5
3
|
require 'ebay/config'
|
6
|
-
require 'ebay/
|
4
|
+
require 'ebay/requestable'
|
7
5
|
|
8
6
|
module Ebay
|
9
7
|
# The eBay Shopping API makes it easy to search for things on eBay.
|
@@ -11,10 +9,9 @@ module Ebay
|
|
11
9
|
# @see https://developer.ebay.com/Devzone/shopping/docs/Concepts/ShoppingAPI_FormatOverview.html
|
12
10
|
# @see https://developer.ebay.com/Devzone/shopping/docs/CallRef/index.html
|
13
11
|
class Shopping
|
14
|
-
include
|
12
|
+
include Requestable
|
15
13
|
|
16
|
-
|
17
|
-
PRODUCTION_ENDPOINT = 'https://open.api.ebay.com/shopping'
|
14
|
+
self.endpoint = 'https://open.api.ebay.com/shopping'
|
18
15
|
|
19
16
|
# @return [String]
|
20
17
|
attr_reader :app_id
|
@@ -149,7 +146,6 @@ module Ebay
|
|
149
146
|
private
|
150
147
|
|
151
148
|
def request(operation, payload = {})
|
152
|
-
endpoint = sandbox? ? SANDBOX_ENDPOINT : PRODUCTION_ENDPOINT
|
153
149
|
params = { 'appid' => app_id,
|
154
150
|
'callname' => operation,
|
155
151
|
'requestencoding' => 'JSON',
|
@@ -161,7 +157,7 @@ module Ebay
|
|
161
157
|
'trackingid' => tracking_id,
|
162
158
|
'trackingpartnercode' => tracking_partner_code }.compact
|
163
159
|
|
164
|
-
|
160
|
+
http.post(endpoint, params: params, body: JSON.dump(payload))
|
165
161
|
end
|
166
162
|
end
|
167
163
|
end
|
data/lib/ebay/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ebay-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hakan Ensari
|
@@ -138,7 +138,7 @@ files:
|
|
138
138
|
- lib/ebay/finding.rb
|
139
139
|
- lib/ebay/merchandising.rb
|
140
140
|
- lib/ebay/oauth/client_credentials_grant.rb
|
141
|
-
- lib/ebay/
|
141
|
+
- lib/ebay/requestable.rb
|
142
142
|
- lib/ebay/shopping.rb
|
143
143
|
- lib/ebay/version.rb
|
144
144
|
homepage: https://github.com/hakanensari/ebay-ruby
|
data/lib/ebay/sandboxable.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'ebay/config'
|
4
|
-
|
5
|
-
module Ebay
|
6
|
-
# Allows running requests in the eBay Sandbox
|
7
|
-
module Sandboxable
|
8
|
-
# Runs requests in the eBay Sandbox
|
9
|
-
#
|
10
|
-
# @return [self]
|
11
|
-
def sandbox
|
12
|
-
@sandbox = true
|
13
|
-
self
|
14
|
-
end
|
15
|
-
|
16
|
-
# @!attribute [r] sandbox?
|
17
|
-
# Returns whether requests run in the eBay Sandbox
|
18
|
-
#
|
19
|
-
# @return [Boolean]
|
20
|
-
def sandbox?
|
21
|
-
@sandbox ||= false
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|