ebay-ruby 0.3.3 → 0.3.4

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: bbadae6120cf8748d6f33d847c9746199717facc4734db1d81719a37393886bc
4
+ data.tar.gz: d457466d75675c9fb698d9fa8feac2bb773d4a89be43f698ab22598bada96839
5
5
  SHA512:
6
- metadata.gz: 197bc765789a721d8f678dbe0f5ed931c01743cff6699957d02a122ce6c61d73bab3046c6a15c5eb4c8ff4ebde04bd3690183fd41be8c512264393583121423b
7
- data.tar.gz: 29bb107067f9802f8988eb4c08f991715c7de01b699694e3b38f762f61d65a562ca8c88fe9083c63e8668e6ab960e81de1b880427f582102fa3df2ca5174f3eb
6
+ metadata.gz: 98aea0105ee22960dece81289809e60048afbc5a68bd17bbf3ef2d54c6f0c139b5551b0f0e04293d49d471a2bd7d244d285f8fcc76a8f8b35eb5eaef05b6900c
7
+ data.tar.gz: 769e216aa765b9850aa3192e82668bc9a79bc69e47b34e54799ecb897b4bbbb38a3750d237a841ce3f3abc2556b9b0f77017801ea97229bb3521053f52354d7e
data/README.md CHANGED
@@ -2,81 +2,120 @@
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
51
58
 
52
- #### [Shopping API]
59
+ ### [Browse API]
53
60
 
54
- The eBay Shopping API makes it easy to search for things on eBay.
61
+ 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.
55
62
 
56
63
  ```ruby
57
- require 'ebay/shopping'
64
+ require 'ebay/browse'
65
+ require 'ebay/oauth/client_credentials_grant'
58
66
 
59
- request = Ebay::Shopping.new(response_encoding: 'JSON')
60
- response = request.find_products('QueryKeywords' => 'tolkien')
67
+ access_token = Oauth::ClientCredentialsGrant.new.mint_access_token
68
+ request = Ebay.browse(campaign_id: '123', country: 'US', zip: '19406',
69
+ access_token: access_token)
70
+ response = request.search(q: 'iphone')
71
+ ```
61
72
 
62
- JSON.parse(response)
73
+ ### [Finding API]
74
+
75
+ The Finding API lets you search and browse for items listed on eBay and provides useful metadata to refine searches.
76
+
77
+ ```ruby
78
+ require 'ebay/finding'
79
+
80
+ request = Ebay.finding
81
+ response = request.find_items_by_keywords('iphone')
63
82
  ```
64
83
 
65
- #### [Merchandising API]
84
+ ### [Merchandising API]
66
85
 
67
- The Merchandising API provides item and product recommendations that can be used to cross-sell and up-sell eBay items to buyers.
86
+ The Merchandising API retrieves information about products or item listings on eBay to help you sell more merchandise to eBay buyers.
68
87
 
69
88
  ```ruby
70
89
  require 'ebay/merchandising'
71
90
 
72
- request = Ebay::Merchandising.new(response_data_format: 'JSON')
91
+ request = Ebay::Merchandising.new
73
92
  response = request.get_most_watched_items
93
+ ```
74
94
 
75
- JSON.parse(response)
95
+ ### [Shopping API]
96
+
97
+ The eBay Shopping API makes it easy to search for things on eBay.
98
+
99
+ ```ruby
100
+ require 'ebay/shopping'
101
+
102
+ request = Ebay::Shopping.new
103
+ response = request.find_products('QueryKeywords' => 'tolkien')
104
+ ```
105
+
106
+ ## Development
107
+
108
+ To write requests and responses to a logger, use the logging feature:
109
+
110
+ ```ruby
111
+ require 'logger'
112
+
113
+ request = request.use(logging: {logger: Logger.new(STDOUT)})
76
114
  ```
77
115
 
78
116
  [eBay APIs]: https://developer.ebay.com/docs
117
+ [developer keys]: https://developer.ebay.com/my/keys
79
118
  [Browse API]: https://developer.ebay.com/api-docs/buy/browse/static/overview.html
80
119
  [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
120
  [Merchandising API]: https://developer.ebay.com/Devzone/merchandising/docs/Concepts/merchandisingAPIGuide.html
121
+ [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
@@ -39,8 +43,7 @@ module Ebay
39
43
  # @param [String] campaign_id
40
44
  # @param [String] reference_id
41
45
  # @param [String] access_token
42
- def initialize(campaign_id:, reference_id: nil, country: nil, zip: nil,
43
- access_token: nil)
46
+ def initialize(campaign_id:, reference_id: nil, country: nil, zip: nil, access_token: nil)
44
47
  @campaign_id = campaign_id
45
48
  @reference_id = reference_id
46
49
  @country = country
@@ -48,8 +51,7 @@ module Ebay
48
51
  @access_token = access_token
49
52
  end
50
53
 
51
- # Searches for eBay items by various query parameters and retrieves
52
- # summaries of the item
54
+ # Searches for eBay items by various query parameters and retrieves summaries of the item
53
55
  #
54
56
  # @param [Hash] params
55
57
  # @return [HTTP::Response]
@@ -115,8 +117,7 @@ module Ebay
115
117
  def check_compatibility(item_id, marketplace_id, compatibility_properties)
116
118
  url = build_url('item', item_id, 'check_compatibility')
117
119
  headers = build_headers
118
- headers.update('X-EBAY-C-MARKETPLACE-ID' => marketplace_id,
119
- 'CONTENT-TYPE' => 'application/json')
120
+ headers.update('X-EBAY-C-MARKETPLACE-ID' => marketplace_id, 'CONTENT-TYPE' => 'application/json')
120
121
  body = JSON.dump('compatibilityProperties' => compatibility_properties)
121
122
 
122
123
  http.headers(headers).post(url, body: body)
@@ -152,14 +153,11 @@ module Ebay
152
153
  def build_ebay_enduser_context
153
154
  { 'affiliateCampaignId' => campaign_id,
154
155
  'affiliateReferenceId' => reference_id,
155
- 'contextualLocation' => build_contextual_location }
156
- .compact.map { |kv| kv.join('=') }.join(',')
156
+ 'contextualLocation' => build_contextual_location }.compact.map { |kv| kv.join('=') }.join(',')
157
157
  end
158
158
 
159
159
  def build_contextual_location
160
- string = { 'country' => country, 'zip' => zip }
161
- .compact.map { |kv| kv.join('=') }.join(',')
162
-
160
+ string = { 'country' => country, 'zip' => zip }.compact.map { |kv| kv.join('=') }.join(',')
163
161
  CGI.escape(string) if string
164
162
  end
165
163
  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
@@ -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
  #
@@ -37,5 +37,33 @@ module Ebay
37
37
  @endpoint = endpoint.sub('ebay', 'sandbox.ebay')
38
38
  self
39
39
  end
40
+
41
+ # Flags request as persistent
42
+ #
43
+ # @param [Integer] timeout
44
+ # @return [self]
45
+ def persistent(timeout: 5)
46
+ self.http = http.persistent(endpoint, timeout: timeout)
47
+ self
48
+ end
49
+
50
+ # @!method use(*features)
51
+ # Turns on {https://github.com/httprb/http HTTP} features
52
+ #
53
+ # @param features
54
+ # @return [self]
55
+ #
56
+ # @!method via(*proxy)
57
+ # Makes a request through an HTTP proxy
58
+ #
59
+ # @param [Array] proxy
60
+ # @raise [HTTP::Request::Error] if HTTP proxy is invalid
61
+ # @return [self]
62
+ %i[timeout via through headers use].each do |method_name|
63
+ define_method(method_name) do |*args, &block|
64
+ self.http = http.send(method_name, *args, &block)
65
+ self
66
+ end
67
+ end
40
68
  end
41
69
  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
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.3.4'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
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.3.4
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-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http
@@ -80,6 +80,34 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop-minitest
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: rubocop-rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
83
111
  - !ruby/object:Gem::Dependency
84
112
  name: vcr
85
113
  requirement: !ruby/object:Gem::Requirement
@@ -122,7 +150,7 @@ dependencies:
122
150
  - - ">="
123
151
  - !ruby/object:Gem::Version
124
152
  version: '0'
125
- description:
153
+ description:
126
154
  email:
127
155
  - me@hakanensari.com
128
156
  executables: []
@@ -145,7 +173,7 @@ homepage: https://github.com/hakanensari/ebay-ruby
145
173
  licenses:
146
174
  - MIT
147
175
  metadata: {}
148
- post_install_message:
176
+ post_install_message:
149
177
  rdoc_options: []
150
178
  require_paths:
151
179
  - lib
@@ -153,15 +181,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
153
181
  requirements:
154
182
  - - ">="
155
183
  - !ruby/object:Gem::Version
156
- version: '2.4'
184
+ version: '2.5'
157
185
  required_rubygems_version: !ruby/object:Gem::Requirement
158
186
  requirements:
159
187
  - - ">="
160
188
  - !ruby/object:Gem::Version
161
189
  version: '0'
162
190
  requirements: []
163
- rubygems_version: 3.1.2
164
- signing_key:
191
+ rubygems_version: 3.2.3
192
+ signing_key:
165
193
  specification_version: 4
166
194
  summary: Ruby wrapper to the eBay APIs
167
195
  test_files: []