ebay-ruby 0.3.3 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f75e5710d5dc86f3f0a83ec943b90ec3b5aa318be568163accba7ce326adb2a2
4
- data.tar.gz: 223f627ad8321defd29a21fce8e1083eecb3b8447b5962d448ad51152d9b0dc1
3
+ metadata.gz: 0fd16f623556b875afb1ecb939fbd296ce5b476ba452dd6180fa52bac6085bc4
4
+ data.tar.gz: b4d55cba32a9a53878f649c3dbcd2d8ee0649fa381a312d809ab5c11b68a19ce
5
5
  SHA512:
6
- metadata.gz: 197bc765789a721d8f678dbe0f5ed931c01743cff6699957d02a122ce6c61d73bab3046c6a15c5eb4c8ff4ebde04bd3690183fd41be8c512264393583121423b
7
- data.tar.gz: 29bb107067f9802f8988eb4c08f991715c7de01b699694e3b38f762f61d65a562ca8c88fe9083c63e8668e6ab960e81de1b880427f582102fa3df2ca5174f3eb
6
+ metadata.gz: f672edffb9231c9a573adf8c1291bf267793c62be549b47b52c3457fac118218d10b1e1d3bc7a733dab0eb7ee3c7dd50beb59e2c331ca3fd2e98f177a784b498
7
+ data.tar.gz: f32cfa29cf7ec5fdc79683140debd33ee7830e5968e8aea489dbdb6dc34bb274859812a1a1f49a7e9557ccc6b1841b435172843948a8932d8d327c1a1f948a9f
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
- A Ruby wrapper to the [eBay APIs]
5
+ This library provides a wrapper to the [eBay APIs].
6
6
 
7
- ## Usage
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
- ### Buy APIs
15
+ ### Keys
10
16
 
11
- Retrieve purchasable items, check out, then track orders without visiting the eBay site.
17
+ eBay APIs require [developer keys].
12
18
 
13
- #### [Browse API]
19
+ You can provide these globally with the environment variables `EBAY_APP_ID`, `EBAY_DEV_ID`, and `EBAY_CERT_ID`.
14
20
 
15
- Using the Browse API, you can create a rich selection of items for your buyers to browse with keyword and category searches. You can also provides the ability to eBay members to add items and change the quantity of an item in their eBay shopping cart as well as view the contents of their eBay cart.
21
+ If you prefer not to use environment variables, you can provide your keys globally with:
16
22
 
17
23
  ```ruby
18
- require 'ebay/browse'
19
- require 'ebay/oauth/client_credentials_grant'
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
- access_token = Oauth::ClientCredentialsGrant.new.mint_access_token
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
- JSON.parse(response)
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
- ### Traditional Searching APIs
39
+ In the examples below, we will assume we are providing our keys with environment variables.
32
40
 
33
- Search eBay; build search and browse experiences.
41
+ ### Parsing a response
34
42
 
35
- #### [Finding API]
43
+ The eBay APIs return responses in XML or JSON format.
36
44
 
37
- The Finding API provides programmatic access to the next generation search capabilities on the eBay platform. It lets you search and browse for items listed on eBay and provides useful metadata to refine searches and enhance the search experience.
45
+ You can override the default format of an API when instantiating the request.
38
46
 
39
47
  ```ruby
40
- require 'ebay/finding'
48
+ require 'json'
41
49
 
42
- request = Ebay::Finding.new(response_data_format: 'JSON')
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
- ### Traditional Shopping/Buying APIs
49
-
50
- Retrieve public items and user data to create shopping and marketing applications.
57
+ ## Usage
58
+ ### [Browse API]
51
59
 
52
- #### [Shopping API]
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 eBay Shopping API makes it easy to search for things on eBay.
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/shopping'
65
+ require 'ebay/browse'
66
+ require 'ebay/oauth/client_credentials_grant'
58
67
 
59
- request = Ebay::Shopping.new(response_encoding: 'JSON')
60
- response = request.find_products('QueryKeywords' => 'tolkien')
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
- JSON.parse(response)
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
- #### [Merchandising API]
85
+ ### [Merchandising API]
66
86
 
67
- The Merchandising API provides item and product recommendations that can be used to cross-sell and up-sell eBay items to buyers.
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::Merchandising.new(response_data_format: 'JSON')
92
+ request = Ebay::Merchandising.new
73
93
  response = request.get_most_watched_items
94
+ ```
74
95
 
75
- JSON.parse(response)
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
- # Using the Browse API, you can create a rich selection of items for your
10
- # buyers to browse with keyword and category searches. It also provides the
11
- # ability to eBay members to add items and change the quantity of an item in
12
- # their eBay shopping cart as well as view the contents of their eBay cart.
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
@@ -17,6 +21,9 @@ module Ebay
17
21
 
18
22
  self.endpoint = 'https://api.ebay.com/buy/browse/v1'
19
23
 
24
+ # @return [String]
25
+ attr_reader :access_token
26
+
20
27
  # @return [String]
21
28
  attr_reader :campaign_id
22
29
 
@@ -29,27 +36,27 @@ module Ebay
29
36
  # @return [String,nil]
30
37
  attr_reader :zip
31
38
 
32
- # @return [String] the application access token
33
- def access_token
34
- @access_token ||= mint_access_token
35
- end
39
+ # @return [String,nil]
40
+ attr_reader :market_id
36
41
 
37
42
  # Returns a Browse API request instance
38
43
  #
44
+ # @param [String] access_token
39
45
  # @param [String] campaign_id
40
46
  # @param [String] reference_id
41
- # @param [String] access_token
42
- def initialize(campaign_id:, reference_id: nil, country: nil, zip: nil,
43
- access_token: nil)
47
+ # @param [String] country
48
+ # @param [String] zip
49
+ # @param [String] market_id
50
+ def initialize(access_token:, campaign_id:, reference_id: nil, country: nil, zip: nil, market_id: 'EBAY_US')
44
51
  @campaign_id = campaign_id
45
52
  @reference_id = reference_id
46
53
  @country = country
47
54
  @zip = zip
48
55
  @access_token = access_token
56
+ @market_id = market_id
49
57
  end
50
58
 
51
- # Searches for eBay items by various query parameters and retrieves
52
- # summaries of the item
59
+ # Searches for eBay items by various query parameters and retrieves summaries of the item
53
60
  #
54
61
  # @param [Hash] params
55
62
  # @return [HTTP::Response]
@@ -115,8 +122,7 @@ module Ebay
115
122
  def check_compatibility(item_id, marketplace_id, compatibility_properties)
116
123
  url = build_url('item', item_id, 'check_compatibility')
117
124
  headers = build_headers
118
- headers.update('X-EBAY-C-MARKETPLACE-ID' => marketplace_id,
119
- 'CONTENT-TYPE' => 'application/json')
125
+ headers.update('X-EBAY-C-MARKETPLACE-ID' => marketplace_id, 'CONTENT-TYPE' => 'application/json')
120
126
  body = JSON.dump('compatibilityProperties' => compatibility_properties)
121
127
 
122
128
  http.headers(headers).post(url, body: body)
@@ -146,20 +152,18 @@ module Ebay
146
152
 
147
153
  def build_headers
148
154
  { 'AUTHORIZATION' => "Bearer #{access_token}",
155
+ 'X-EBAY-C-MARKETPLACE-ID' => market_id,
149
156
  'X-EBAY-C-ENDUSERCTX' => build_ebay_enduser_context }
150
157
  end
151
158
 
152
159
  def build_ebay_enduser_context
153
160
  { 'affiliateCampaignId' => campaign_id,
154
161
  'affiliateReferenceId' => reference_id,
155
- 'contextualLocation' => build_contextual_location }
156
- .compact.map { |kv| kv.join('=') }.join(',')
162
+ 'contextualLocation' => build_contextual_location }.compact.map { |kv| kv.join('=') }.join(',')
157
163
  end
158
164
 
159
165
  def build_contextual_location
160
- string = { 'country' => country, 'zip' => zip }
161
- .compact.map { |kv| kv.join('=') }.join(',')
162
-
166
+ string = { 'country' => country, 'zip' => zip }.compact.map { |kv| kv.join('=') }.join(',')
163
167
  CGI.escape(string) if string
164
168
  end
165
169
  end
data/lib/ebay/config.rb CHANGED
@@ -8,7 +8,7 @@ module Ebay
8
8
  yield Config
9
9
  end
10
10
 
11
- # Stores credentials for accessing the eBay APIs
11
+ # Configures credentials for accessing the eBay APIs
12
12
  module Config
13
13
  class << self
14
14
  # @!attribute [rw] app_id
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
- # The Finding API lets you search for and browse items listed on eBay and
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
@@ -137,7 +143,7 @@ module Ebay
137
143
  'SECURITY-APPNAME' => security_appname,
138
144
  'SERVICE-VERSION' => service_version }.update(payload).compact
139
145
 
140
- http.get(endpoint, params: params)
146
+ http.headers(headers).get(endpoint, params: params)
141
147
  end
142
148
  end
143
149
  end
@@ -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
  #
@@ -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
@@ -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
@@ -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 = payload.merge('ItemID' => item_ids.join(','))
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 = payload.merge('ItemID' => item_ids.join(','))
117
+ payload = payload.merge('ItemID' => item_ids.map(&:to_s))
112
118
 
113
119
  request('GetMultipleItems', payload)
114
120
  end
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ebay
4
- VERSION = '0.3.3'
4
+ VERSION = '0.4.1'
5
5
  end
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.3.3
4
+ version: 0.4.1
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: 2020-03-18 00:00:00.000000000 Z
11
+ date: 2021-09-07 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.4'
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.1.2
164
- signing_key:
197
+ rubygems_version: 3.2.22
198
+ signing_key:
165
199
  specification_version: 4
166
200
  summary: Ruby wrapper to the eBay APIs
167
201
  test_files: []