ebay-ruby 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +80 -35
- data/lib/ebay/browse.rb +24 -21
- data/lib/ebay/config.rb +1 -1
- data/lib/ebay/finding.rb +17 -12
- data/lib/ebay/merchandising.rb +12 -6
- data/lib/ebay/oauth/client_credentials_grant.rb +1 -1
- data/lib/ebay/requestable.rb +40 -0
- data/lib/ebay/shopping.rb +20 -14
- data/lib/ebay/version.rb +1 -1
- metadata +44 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f9688f2d0adcae118335721df5184c0e2dcd2c5b6d02e9473df5fb677798196
|
4
|
+
data.tar.gz: 9914bf32f01ce3719667b0b34443ef4c1b7829bd40c8e69a497caccfa550ebe5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77451dd48c94af23957a9c9989bf99b8e0367ffd246c6f61856633e51250c389b9d9dbbcb91f3c7cab3ea5e529db53c69df0cb783aa5487a4dc6b3afe5299fa8
|
7
|
+
data.tar.gz: a2027027fc7f7904ddcfa5880a67b43245f2df3cee9d9420215e3fced3cee8e3aa399b9d53e8a6c055fb7c9cf7490b684f49b9f4069e1ded4863c2dbbb80f4cf
|
data/README.md
CHANGED
@@ -2,81 +2,126 @@
|
|
2
2
|
|
3
3
|
[![Build](https://github.com/hakanensari/ebay-ruby/workflows/build/badge.svg)](https://github.com/hakanensari/ebay-ruby/actions)
|
4
4
|
|
5
|
-
|
5
|
+
This library provides a wrapper to the [eBay APIs].
|
6
6
|
|
7
|
-
##
|
7
|
+
## Getting started
|
8
|
+
|
9
|
+
You can instantiate API requests using shorthand class methods defined on `Ebay`.
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
Ebay.finding # returns a new Ebay::Finding instance
|
13
|
+
```
|
8
14
|
|
9
|
-
###
|
15
|
+
### Keys
|
10
16
|
|
11
|
-
|
17
|
+
eBay APIs require [developer keys].
|
12
18
|
|
13
|
-
|
19
|
+
You can provide these globally with the environment variables `EBAY_APP_ID`, `EBAY_DEV_ID`, and `EBAY_CERT_ID`.
|
14
20
|
|
15
|
-
|
21
|
+
If you prefer not to use environment variables, you can provide your keys globally with:
|
16
22
|
|
17
23
|
```ruby
|
18
|
-
|
19
|
-
|
24
|
+
Ebay.configure do |config|
|
25
|
+
config.app_id = 'YOUR APP ID'
|
26
|
+
config.dev_id = 'YOUR DEV ID'
|
27
|
+
config.cert_id = 'YOUR CERT ID'
|
28
|
+
end
|
29
|
+
```
|
20
30
|
|
21
|
-
|
22
|
-
request = Ebay::Browse.new(campaign_id: '123',
|
23
|
-
country: 'US',
|
24
|
-
zip: '19406',
|
25
|
-
access_token: access_token)
|
26
|
-
response = @request.search(q: 'iphone')
|
31
|
+
Finally, you can provide your keys individually to the request when instantiating it. This is what you will want to do if you are using multiple sets of credentials.
|
27
32
|
|
28
|
-
|
33
|
+
Please note that each API names keys differently.
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
request = Ebay.finding(security_appname: 'YOUR APP ID')
|
29
37
|
```
|
30
38
|
|
31
|
-
|
39
|
+
In the examples below, we will assume we are providing our keys with environment variables.
|
32
40
|
|
33
|
-
|
41
|
+
### Parsing a response
|
34
42
|
|
35
|
-
|
43
|
+
The eBay APIs return responses in XML or JSON format.
|
36
44
|
|
37
|
-
|
45
|
+
You can override the default format of an API when instantiating the request.
|
38
46
|
|
39
47
|
```ruby
|
40
|
-
require '
|
48
|
+
require 'json'
|
41
49
|
|
42
|
-
|
50
|
+
### the Finding API returns XML by default
|
51
|
+
request = Ebay.finding(response_data_format: 'JSON')
|
43
52
|
response = request.find_items_by_keywords('iphone')
|
44
53
|
|
45
54
|
JSON.parse(response)
|
46
55
|
```
|
47
56
|
|
48
|
-
|
49
|
-
|
50
|
-
Retrieve public items and user data to create shopping and marketing applications.
|
57
|
+
## Usage
|
58
|
+
### [Browse API]
|
51
59
|
|
52
|
-
|
60
|
+
The Browse API allows your buyers to search eBay items by keyword and category. It also allows them to view and add items to their eBay shopping cart. The Browse API defaults to the eBay US marketplace but may be set during initialisation. The list of available marketplaces is [here](https://developer.ebay.com/api-docs/static/rest-request-components.html#marketpl).
|
53
61
|
|
54
|
-
The
|
62
|
+
**Note** The marketplace value needs to use an underscore between EBAY and the country code. The Finding and Merchandising APIs use a hyphen.
|
55
63
|
|
56
64
|
```ruby
|
57
|
-
require 'ebay/
|
65
|
+
require 'ebay/browse'
|
66
|
+
require 'ebay/oauth/client_credentials_grant'
|
58
67
|
|
59
|
-
|
60
|
-
|
68
|
+
access_token = Oauth::ClientCredentialsGrant.new.mint_access_token
|
69
|
+
request = Ebay.browse(campaign_id: '123', country: 'US', zip: '19406',
|
70
|
+
access_token: access_token, market_id: 'EBAY_US')
|
71
|
+
response = request.search(q: 'iphone')
|
72
|
+
```
|
61
73
|
|
62
|
-
|
74
|
+
### [Finding API]
|
75
|
+
|
76
|
+
The Finding API lets you search and browse for items listed on eBay and provides useful metadata to refine searches.
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
require 'ebay/finding'
|
80
|
+
|
81
|
+
request = Ebay.finding
|
82
|
+
response = request.find_items_by_keywords('iphone')
|
63
83
|
```
|
64
84
|
|
65
|
-
|
85
|
+
### [Merchandising API]
|
66
86
|
|
67
|
-
The Merchandising API
|
87
|
+
The Merchandising API retrieves information about products or item listings on eBay to help you sell more merchandise to eBay buyers.
|
68
88
|
|
69
89
|
```ruby
|
70
90
|
require 'ebay/merchandising'
|
71
91
|
|
72
|
-
request = Ebay::
|
92
|
+
request = Ebay::Merchandising.new
|
73
93
|
response = request.get_most_watched_items
|
94
|
+
```
|
74
95
|
|
75
|
-
|
96
|
+
### [Shopping API]
|
97
|
+
|
98
|
+
The eBay Shopping API makes it easy to search for things on eBay.
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
require 'ebay/shopping'
|
102
|
+
|
103
|
+
request = Ebay::Shopping.new
|
104
|
+
response = request.find_products('QueryKeywords' => 'tolkien')
|
105
|
+
```
|
106
|
+
|
107
|
+
### Market Place
|
108
|
+
eBay has country bsaed marketplaces ( listed [here](https://developer.ebay.com/api-docs/static/rest-request-components.html#marketpl) ). By default, the eBay gem queries the US Marketplace. To change the marketplace, set the marketplace on the request object.
|
109
|
+
|
110
|
+
**Note** For the Browse API, the marketplace value needs to use an underscore between EBAY and the country code (EBAY_AU). The Finding and Merchandising APIs require a hyphen between EBAY and the country code ( EBAY-AU )
|
111
|
+
|
112
|
+
## Development
|
113
|
+
|
114
|
+
To write requests and responses to a logger, use the logging feature:
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
require 'logger'
|
118
|
+
|
119
|
+
request = request.use(logging: {logger: Logger.new(STDOUT)})
|
76
120
|
```
|
77
121
|
|
78
122
|
[eBay APIs]: https://developer.ebay.com/docs
|
123
|
+
[developer keys]: https://developer.ebay.com/my/keys
|
79
124
|
[Browse API]: https://developer.ebay.com/api-docs/buy/browse/static/overview.html
|
80
125
|
[Finding API]: https://developer.ebay.com/Devzone/finding/Concepts/FindingAPIGuide.html
|
81
|
-
[Shopping API]: https://developer.ebay.com/Devzone/shopping/docs/Concepts/ShoppingAPIGuide.html
|
82
126
|
[Merchandising API]: https://developer.ebay.com/Devzone/merchandising/docs/Concepts/merchandisingAPIGuide.html
|
127
|
+
[Shopping API]: https://developer.ebay.com/Devzone/shopping/docs/Concepts/ShoppingAPIGuide.html
|
data/lib/ebay/browse.rb
CHANGED
@@ -5,11 +5,15 @@ require 'base64'
|
|
5
5
|
require 'ebay/config'
|
6
6
|
require 'ebay/requestable'
|
7
7
|
|
8
|
+
# Ruby wrapper to the eBay APIs
|
8
9
|
module Ebay
|
9
|
-
#
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
# Returns a {Ebay::Browse#initialize Browse API} instance
|
11
|
+
def self.browse(**params)
|
12
|
+
Browse.new(**params)
|
13
|
+
end
|
14
|
+
|
15
|
+
# The Browse API allows your buyers to search eBay items by keyword and category. It also allows them to view and add
|
16
|
+
# items to their eBay shopping cart.
|
13
17
|
#
|
14
18
|
# @see https://developer.ebay.com/api-docs/buy/browse/overview.html
|
15
19
|
class Browse
|
@@ -29,6 +33,9 @@ module Ebay
|
|
29
33
|
# @return [String,nil]
|
30
34
|
attr_reader :zip
|
31
35
|
|
36
|
+
# @return [String,nil]
|
37
|
+
attr_reader :market_id
|
38
|
+
|
32
39
|
# @return [String] the application access token
|
33
40
|
def access_token
|
34
41
|
@access_token ||= mint_access_token
|
@@ -39,21 +46,20 @@ module Ebay
|
|
39
46
|
# @param [String] campaign_id
|
40
47
|
# @param [String] reference_id
|
41
48
|
# @param [String] access_token
|
42
|
-
def initialize(campaign_id:, reference_id: nil, country: nil, zip: nil,
|
43
|
-
access_token: nil)
|
49
|
+
def initialize(campaign_id:, reference_id: nil, country: nil, zip: nil, access_token: nil, market_id: 'EBAY_US')
|
44
50
|
@campaign_id = campaign_id
|
45
51
|
@reference_id = reference_id
|
46
52
|
@country = country
|
47
53
|
@zip = zip
|
48
54
|
@access_token = access_token
|
55
|
+
@market_id = market_id
|
49
56
|
end
|
50
57
|
|
51
|
-
# Searches for eBay items by various query parameters and retrieves
|
52
|
-
# summaries of the item
|
58
|
+
# Searches for eBay items by various query parameters and retrieves summaries of the item
|
53
59
|
#
|
54
60
|
# @param [Hash] params
|
55
61
|
# @return [HTTP::Response]
|
56
|
-
def search(
|
62
|
+
def search(params = {})
|
57
63
|
url = build_url('item_summary', 'search')
|
58
64
|
http.headers(build_headers).get(url, params: params)
|
59
65
|
end
|
@@ -63,7 +69,7 @@ module Ebay
|
|
63
69
|
# @param [File] image
|
64
70
|
# @param [Hash] params
|
65
71
|
# @return [HTTP::Response]
|
66
|
-
def search_by_image(image,
|
72
|
+
def search_by_image(image, params = {})
|
67
73
|
url = build_url('item_summary', 'search_by_image')
|
68
74
|
headers = build_headers.update('CONTENT-TYPE' => 'application/json')
|
69
75
|
encoded_string = Base64.encode64(image.read)
|
@@ -77,9 +83,9 @@ module Ebay
|
|
77
83
|
# @param [String] item_id
|
78
84
|
# @param [Hash] params
|
79
85
|
# @return [HTTP::Response]
|
80
|
-
def get_item(item_id,
|
86
|
+
def get_item(item_id, params = {})
|
81
87
|
url = build_url('item', item_id)
|
82
|
-
params.
|
88
|
+
params = params.merge(item_id: item_id)
|
83
89
|
|
84
90
|
http.headers(build_headers).get(url, params: params)
|
85
91
|
end
|
@@ -89,9 +95,9 @@ module Ebay
|
|
89
95
|
# @param [String] legacy_item_id
|
90
96
|
# @param [Hash] params
|
91
97
|
# @return [HTTP::Response]
|
92
|
-
def get_item_by_legacy_id(legacy_item_id,
|
98
|
+
def get_item_by_legacy_id(legacy_item_id, params = {})
|
93
99
|
url = build_url('item', 'get_item_by_legacy_id')
|
94
|
-
params.
|
100
|
+
params = params.merge(legacy_item_id: legacy_item_id)
|
95
101
|
|
96
102
|
http.headers(build_headers).get(url, params: params)
|
97
103
|
end
|
@@ -115,8 +121,7 @@ module Ebay
|
|
115
121
|
def check_compatibility(item_id, marketplace_id, compatibility_properties)
|
116
122
|
url = build_url('item', item_id, 'check_compatibility')
|
117
123
|
headers = build_headers
|
118
|
-
headers.update('X-EBAY-C-MARKETPLACE-ID' => marketplace_id,
|
119
|
-
'CONTENT-TYPE' => 'application/json')
|
124
|
+
headers.update('X-EBAY-C-MARKETPLACE-ID' => marketplace_id, 'CONTENT-TYPE' => 'application/json')
|
120
125
|
body = JSON.dump('compatibilityProperties' => compatibility_properties)
|
121
126
|
|
122
127
|
http.headers(headers).post(url, body: body)
|
@@ -146,20 +151,18 @@ module Ebay
|
|
146
151
|
|
147
152
|
def build_headers
|
148
153
|
{ 'AUTHORIZATION' => "Bearer #{access_token}",
|
154
|
+
'X-EBAY-C-MARKETPLACE-ID' => market_id,
|
149
155
|
'X-EBAY-C-ENDUSERCTX' => build_ebay_enduser_context }
|
150
156
|
end
|
151
157
|
|
152
158
|
def build_ebay_enduser_context
|
153
159
|
{ 'affiliateCampaignId' => campaign_id,
|
154
160
|
'affiliateReferenceId' => reference_id,
|
155
|
-
'contextualLocation' => build_contextual_location }
|
156
|
-
.compact.map { |kv| kv.join('=') }.join(',')
|
161
|
+
'contextualLocation' => build_contextual_location }.compact.map { |kv| kv.join('=') }.join(',')
|
157
162
|
end
|
158
163
|
|
159
164
|
def build_contextual_location
|
160
|
-
string = { 'country' => country, 'zip' => zip }
|
161
|
-
.compact.map { |kv| kv.join('=') }.join(',')
|
162
|
-
|
165
|
+
string = { 'country' => country, 'zip' => zip }.compact.map { |kv| kv.join('=') }.join(',')
|
163
166
|
CGI.escape(string) if string
|
164
167
|
end
|
165
168
|
end
|
data/lib/ebay/config.rb
CHANGED
data/lib/ebay/finding.rb
CHANGED
@@ -3,8 +3,14 @@
|
|
3
3
|
require 'ebay/config'
|
4
4
|
require 'ebay/requestable'
|
5
5
|
|
6
|
+
# Ruby wrapper to the eBay APIs
|
6
7
|
module Ebay
|
7
|
-
#
|
8
|
+
# Returns a {Ebay::Finding#initialize Finding API} instance
|
9
|
+
def self.finding(**params)
|
10
|
+
Finding.new(**params)
|
11
|
+
end
|
12
|
+
|
13
|
+
# The Finding API lets you search and browse for items listed on eBay and
|
8
14
|
# provides useful metadata to refine searches.
|
9
15
|
#
|
10
16
|
# @see https://developer.ebay.com/Devzone/finding/Concepts/MakingACall.html
|
@@ -14,19 +20,19 @@ module Ebay
|
|
14
20
|
|
15
21
|
self.endpoint = 'https://svcs.ebay.com/services/search/FindingService/v1'
|
16
22
|
|
17
|
-
# @return [String
|
23
|
+
# @return [String]
|
18
24
|
attr_reader :global_id
|
19
25
|
|
20
|
-
# @return [String
|
26
|
+
# @return [String]
|
21
27
|
attr_reader :message_encoding
|
22
28
|
|
23
|
-
# @return [String
|
29
|
+
# @return [String]
|
24
30
|
attr_reader :response_data_format
|
25
31
|
|
26
32
|
# @return [String]
|
27
33
|
attr_reader :security_appname
|
28
34
|
|
29
|
-
# @return [String
|
35
|
+
# @return [String]
|
30
36
|
attr_reader :service_version
|
31
37
|
|
32
38
|
# Returns a Finding API request instance
|
@@ -38,7 +44,7 @@ module Ebay
|
|
38
44
|
# @param [String] security_appname
|
39
45
|
# @param [String] service_version
|
40
46
|
def initialize(global_id: nil, message_encoding: nil,
|
41
|
-
response_data_format:
|
47
|
+
response_data_format: nil,
|
42
48
|
security_appname: Config.app_id, service_version: nil)
|
43
49
|
@global_id = global_id
|
44
50
|
@message_encoding = message_encoding
|
@@ -77,7 +83,7 @@ module Ebay
|
|
77
83
|
# @param [Hash] payload
|
78
84
|
# @return [HTTP::Response]
|
79
85
|
def find_items_by_keywords(keywords, payload = {})
|
80
|
-
payload.
|
86
|
+
payload = payload.merge('keywords' => keywords)
|
81
87
|
request('findItemsByKeywords', payload)
|
82
88
|
end
|
83
89
|
|
@@ -88,8 +94,8 @@ module Ebay
|
|
88
94
|
# @param [Hash] payload
|
89
95
|
# @return [HTTP::Response]
|
90
96
|
def find_items_by_product(product_id, product_id_type, payload = {})
|
91
|
-
payload.
|
92
|
-
|
97
|
+
payload = payload.merge('productId' => product_id,
|
98
|
+
'productId.@type' => product_id_type)
|
93
99
|
|
94
100
|
request('findItemsByProduct', payload)
|
95
101
|
end
|
@@ -133,12 +139,11 @@ module Ebay
|
|
133
139
|
params = { 'GLOBAL-ID' => global_id,
|
134
140
|
'MESSAGE-ENCODING' => message_encoding,
|
135
141
|
'OPERATION-NAME' => operation,
|
136
|
-
'REQUEST-DATA-FORMAT' => 'JSON',
|
137
142
|
'RESPONSE-DATA-FORMAT' => response_data_format,
|
138
143
|
'SECURITY-APPNAME' => security_appname,
|
139
|
-
'SERVICE-VERSION' => service_version }.compact
|
144
|
+
'SERVICE-VERSION' => service_version }.update(payload).compact
|
140
145
|
|
141
|
-
http.
|
146
|
+
http.headers(headers).get(endpoint, params: params)
|
142
147
|
end
|
143
148
|
end
|
144
149
|
end
|
data/lib/ebay/merchandising.rb
CHANGED
@@ -3,7 +3,13 @@
|
|
3
3
|
require 'ebay/config'
|
4
4
|
require 'ebay/requestable'
|
5
5
|
|
6
|
+
# Ruby wrapper to the eBay APIs
|
6
7
|
module Ebay
|
8
|
+
# Returns a {Ebay::Merchandising#initialize Merchandising API} instance
|
9
|
+
def self.merchandising(**params)
|
10
|
+
Merchandising.new(**params)
|
11
|
+
end
|
12
|
+
|
7
13
|
# Retrieves information about products or item listings on eBay to help you
|
8
14
|
# sell more merchandise to eBay buyers
|
9
15
|
#
|
@@ -17,13 +23,13 @@ module Ebay
|
|
17
23
|
# @return [String]
|
18
24
|
attr_reader :consumer_id
|
19
25
|
|
20
|
-
# @return [String
|
26
|
+
# @return [String]
|
21
27
|
attr_reader :global_id
|
22
28
|
|
23
|
-
# @return [String
|
29
|
+
# @return [String]
|
24
30
|
attr_reader :response_data_format
|
25
31
|
|
26
|
-
# @return [String
|
32
|
+
# @return [String]
|
27
33
|
attr_reader :service_version
|
28
34
|
|
29
35
|
# Returns a Finding API request instance
|
@@ -33,7 +39,7 @@ module Ebay
|
|
33
39
|
# @param [String] response_data_format
|
34
40
|
# @param [String] service_version
|
35
41
|
def initialize(consumer_id: Config.app_id, global_id: nil,
|
36
|
-
response_data_format:
|
42
|
+
response_data_format: nil, service_version: nil)
|
37
43
|
@consumer_id = consumer_id
|
38
44
|
@global_id = global_id
|
39
45
|
@response_data_format = response_data_format
|
@@ -63,7 +69,7 @@ module Ebay
|
|
63
69
|
# @param [Hash] payload
|
64
70
|
# @return [HTTP::Response]
|
65
71
|
def get_similar_items(item_id, payload = {})
|
66
|
-
payload.
|
72
|
+
payload = payload.merge('itemId' => item_id)
|
67
73
|
request('getSimilarItems', payload)
|
68
74
|
end
|
69
75
|
|
@@ -84,7 +90,7 @@ module Ebay
|
|
84
90
|
'RESPONSE-DATA-FORMAT' => response_data_format,
|
85
91
|
'SERVICE-VERSION' => service_version }.compact
|
86
92
|
|
87
|
-
http.post(endpoint, params: params, body: JSON.dump(payload))
|
93
|
+
http.headers(headers).post(endpoint, params: params, body: JSON.dump(payload))
|
88
94
|
end
|
89
95
|
end
|
90
96
|
end
|
data/lib/ebay/requestable.rb
CHANGED
@@ -18,6 +18,18 @@ module Ebay
|
|
18
18
|
# @return [HTTP::Client]
|
19
19
|
attr_writer :http
|
20
20
|
|
21
|
+
# @!attribute [r] headers
|
22
|
+
# @return [Hash]
|
23
|
+
attr_accessor :headers
|
24
|
+
|
25
|
+
# Sets the eBay Market
|
26
|
+
#
|
27
|
+
# @param [String]
|
28
|
+
def market_id=(market_id)
|
29
|
+
@headers ||= {}
|
30
|
+
@headers['X-EBAY-SOA-GLOBAL-ID'] = market_id
|
31
|
+
end
|
32
|
+
|
21
33
|
# @!attribute [r] http
|
22
34
|
# @return [HTTP::Client]
|
23
35
|
def http
|
@@ -37,5 +49,33 @@ module Ebay
|
|
37
49
|
@endpoint = endpoint.sub('ebay', 'sandbox.ebay')
|
38
50
|
self
|
39
51
|
end
|
52
|
+
|
53
|
+
# Flags request as persistent
|
54
|
+
#
|
55
|
+
# @param [Integer] timeout
|
56
|
+
# @return [self]
|
57
|
+
def persistent(timeout: 5)
|
58
|
+
self.http = http.persistent(endpoint, timeout: timeout)
|
59
|
+
self
|
60
|
+
end
|
61
|
+
|
62
|
+
# @!method use(*features)
|
63
|
+
# Turns on {https://github.com/httprb/http HTTP} features
|
64
|
+
#
|
65
|
+
# @param features
|
66
|
+
# @return [self]
|
67
|
+
#
|
68
|
+
# @!method via(*proxy)
|
69
|
+
# Makes a request through an HTTP proxy
|
70
|
+
#
|
71
|
+
# @param [Array] proxy
|
72
|
+
# @raise [HTTP::Request::Error] if HTTP proxy is invalid
|
73
|
+
# @return [self]
|
74
|
+
%i[timeout via through use].each do |method_name|
|
75
|
+
define_method(method_name) do |*args, &block|
|
76
|
+
self.http = http.send(method_name, *args, &block)
|
77
|
+
self
|
78
|
+
end
|
79
|
+
end
|
40
80
|
end
|
41
81
|
end
|
data/lib/ebay/shopping.rb
CHANGED
@@ -3,7 +3,13 @@
|
|
3
3
|
require 'ebay/config'
|
4
4
|
require 'ebay/requestable'
|
5
5
|
|
6
|
+
# Ruby wrapper to the eBay APIs
|
6
7
|
module Ebay
|
8
|
+
# Returns a {Ebay::Shopping#initialize Shopping API} instance
|
9
|
+
def self.shopping(**params)
|
10
|
+
Shopping.new(**params)
|
11
|
+
end
|
12
|
+
|
7
13
|
# The eBay Shopping API makes it easy to search for things on eBay.
|
8
14
|
#
|
9
15
|
# @see https://developer.ebay.com/Devzone/shopping/docs/Concepts/ShoppingAPI_FormatOverview.html
|
@@ -16,25 +22,25 @@ module Ebay
|
|
16
22
|
# @return [String]
|
17
23
|
attr_reader :app_id
|
18
24
|
|
19
|
-
# @return [String
|
25
|
+
# @return [String]
|
20
26
|
attr_reader :response_encoding
|
21
27
|
|
22
|
-
# @return [String
|
28
|
+
# @return [String]
|
23
29
|
attr_reader :site_id
|
24
30
|
|
25
31
|
# @return [String]
|
26
32
|
attr_reader :version
|
27
33
|
|
28
|
-
# @return [String
|
34
|
+
# @return [String]
|
29
35
|
attr_reader :version_handling
|
30
36
|
|
31
|
-
# @return [String
|
37
|
+
# @return [String]
|
32
38
|
attr_reader :tracking_id
|
33
39
|
|
34
|
-
# @return [String
|
40
|
+
# @return [String]
|
35
41
|
attr_reader :tracking_partner_code
|
36
42
|
|
37
|
-
# @return [String
|
43
|
+
# @return [String]
|
38
44
|
attr_reader :affiliate_user_id
|
39
45
|
|
40
46
|
# Returns a Finding API request instance
|
@@ -47,7 +53,7 @@ module Ebay
|
|
47
53
|
# @param [String] tracking_id
|
48
54
|
# @param [String] tracking_partner_code
|
49
55
|
# @param [String] affiliate_user_id
|
50
|
-
def initialize(app_id: Config.app_id, response_encoding:
|
56
|
+
def initialize(app_id: Config.app_id, response_encoding: nil,
|
51
57
|
site_id: nil, version: '1119',
|
52
58
|
version_handling: nil, tracking_id: nil,
|
53
59
|
tracking_partner_code: nil, affiliate_user_id: nil)
|
@@ -76,7 +82,7 @@ module Ebay
|
|
76
82
|
# @param [Hash] payload
|
77
83
|
# @return [HTTP::Response]
|
78
84
|
def get_category_info(category_id, payload = {})
|
79
|
-
payload.
|
85
|
+
payload = payload.merge('CategoryID' => category_id)
|
80
86
|
request('GetCategoryInfo', payload)
|
81
87
|
end
|
82
88
|
|
@@ -96,7 +102,7 @@ module Ebay
|
|
96
102
|
# @return [HTTP::Response]
|
97
103
|
def get_item_status(*item_ids)
|
98
104
|
payload = item_ids.last.is_a?(Hash) ? item_ids.pop : {}
|
99
|
-
payload.
|
105
|
+
payload = payload.merge('ItemID' => item_ids.map(&:to_s))
|
100
106
|
request('GetItemStatus', payload)
|
101
107
|
end
|
102
108
|
|
@@ -108,7 +114,7 @@ module Ebay
|
|
108
114
|
# @return [HTTP::Response]
|
109
115
|
def get_multiple_items(*item_ids)
|
110
116
|
payload = item_ids.last.is_a?(Hash) ? item_ids.pop : {}
|
111
|
-
payload.
|
117
|
+
payload = payload.merge('ItemID' => item_ids.map(&:to_s))
|
112
118
|
|
113
119
|
request('GetMultipleItems', payload)
|
114
120
|
end
|
@@ -119,7 +125,7 @@ module Ebay
|
|
119
125
|
# @param [Hash] payload
|
120
126
|
# @return [HTTP::Response]
|
121
127
|
def get_shipping_costs(item_id, payload = {})
|
122
|
-
payload.
|
128
|
+
payload = payload.merge('ItemID' => item_id)
|
123
129
|
request('GetShippingCosts', payload)
|
124
130
|
end
|
125
131
|
|
@@ -129,7 +135,7 @@ module Ebay
|
|
129
135
|
# @param [Hash] payload
|
130
136
|
# @return [HTTP::Response]
|
131
137
|
def get_single_item(item_id, payload = {})
|
132
|
-
payload.
|
138
|
+
payload = payload.merge('ItemID' => item_id)
|
133
139
|
request('GetSingleItem', payload)
|
134
140
|
end
|
135
141
|
|
@@ -139,7 +145,7 @@ module Ebay
|
|
139
145
|
# @param [Hash] payload
|
140
146
|
# @return [HTTP::Response]
|
141
147
|
def get_user_profile(user_id, payload = {})
|
142
|
-
payload.
|
148
|
+
payload = payload.merge('UserID' => user_id)
|
143
149
|
request('GetUserProfile', payload)
|
144
150
|
end
|
145
151
|
|
@@ -157,7 +163,7 @@ module Ebay
|
|
157
163
|
'trackingid' => tracking_id,
|
158
164
|
'trackingpartnercode' => tracking_partner_code }.compact
|
159
165
|
|
160
|
-
http.post(endpoint, params: params, body: JSON.dump(payload))
|
166
|
+
http.headers(headers).post(endpoint, params: params, body: JSON.dump(payload))
|
161
167
|
end
|
162
168
|
end
|
163
169
|
end
|
data/lib/ebay/version.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ebay-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hakan Ensari
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '4.0'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '6.0'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '4.0'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '6.0'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: minitest
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +86,34 @@ dependencies:
|
|
80
86
|
- - ">="
|
81
87
|
- !ruby/object:Gem::Version
|
82
88
|
version: '0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: rubocop-minitest
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: rubocop-rake
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
83
117
|
- !ruby/object:Gem::Dependency
|
84
118
|
name: vcr
|
85
119
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,7 +156,7 @@ dependencies:
|
|
122
156
|
- - ">="
|
123
157
|
- !ruby/object:Gem::Version
|
124
158
|
version: '0'
|
125
|
-
description:
|
159
|
+
description:
|
126
160
|
email:
|
127
161
|
- me@hakanensari.com
|
128
162
|
executables: []
|
@@ -145,7 +179,7 @@ homepage: https://github.com/hakanensari/ebay-ruby
|
|
145
179
|
licenses:
|
146
180
|
- MIT
|
147
181
|
metadata: {}
|
148
|
-
post_install_message:
|
182
|
+
post_install_message:
|
149
183
|
rdoc_options: []
|
150
184
|
require_paths:
|
151
185
|
- lib
|
@@ -153,15 +187,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
153
187
|
requirements:
|
154
188
|
- - ">="
|
155
189
|
- !ruby/object:Gem::Version
|
156
|
-
version: '2.
|
190
|
+
version: '2.6'
|
157
191
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
192
|
requirements:
|
159
193
|
- - ">="
|
160
194
|
- !ruby/object:Gem::Version
|
161
195
|
version: '0'
|
162
196
|
requirements: []
|
163
|
-
rubygems_version: 3.
|
164
|
-
signing_key:
|
197
|
+
rubygems_version: 3.2.15
|
198
|
+
signing_key:
|
165
199
|
specification_version: 4
|
166
200
|
summary: Ruby wrapper to the eBay APIs
|
167
201
|
test_files: []
|