ebay-ruby 0.2.0 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,96 @@
1
- require 'ebay/request'
1
+ # frozen_string_literal: true
2
2
 
3
+ require 'ebay/config'
4
+ require 'ebay/requestable'
5
+
6
+ # Ruby wrapper to the eBay APIs
3
7
  module Ebay
4
- class Merchandising < Request
5
- host 'svcs.ebay.com'
6
- path '/MerchandisingService'
7
- headers 'EBAY-SOA-CONSUMER-ID' => Config.app_id
8
+ # Returns a {Ebay::Merchandising#initialize Merchandising API} instance
9
+ def self.merchandising(**params)
10
+ Merchandising.new(**params)
11
+ end
12
+
13
+ # Retrieves information about products or item listings on eBay to help you
14
+ # sell more merchandise to eBay buyers
15
+ #
16
+ # @see https://developer.ebay.com/Devzone/merchandising/docs/Concepts/MerchandisingAPI_FormatOverview.html
17
+ # @see https://developer.ebay.com/Devzone/merchandising/docs/CallRef/index.html
18
+ class Merchandising
19
+ include Requestable
20
+
21
+ self.endpoint = 'https://svcs.ebay.com/MerchandisingService'
22
+
23
+ # @return [String]
24
+ attr_reader :consumer_id
25
+
26
+ # @return [String]
27
+ attr_reader :global_id
28
+
29
+ # @return [String]
30
+ attr_reader :response_data_format
31
+
32
+ # @return [String]
33
+ attr_reader :service_version
34
+
35
+ # Returns a Finding API request instance
36
+ #
37
+ # @param [String] consumer_id
38
+ # @param [String] global_id
39
+ # @param [String] response_data_format
40
+ # @param [String] service_version
41
+ def initialize(consumer_id: Config.app_id, global_id: nil,
42
+ response_data_format: nil, service_version: nil)
43
+ @consumer_id = consumer_id
44
+ @global_id = global_id
45
+ @response_data_format = response_data_format
46
+ @service_version = service_version
47
+ end
48
+
49
+ # Retrieves data for items with the highest watch count
50
+ #
51
+ # @param [Hash] payload
52
+ # @return [HTTP::Response]
53
+ def get_most_watched_items(payload = {})
54
+ request('getMostWatchedItems', payload)
55
+ end
56
+
57
+ # Retrieves recommended items from categories related to a specified
58
+ # category or item
59
+ #
60
+ # @param [Hash] payload
61
+ # @return [HTTP::Response]
62
+ def get_related_category_items(payload = {})
63
+ request('getRelatedCategoryItems', payload)
64
+ end
65
+
66
+ # Retrieves items that are similar to the specified item
67
+ #
68
+ # @param [String] item_id
69
+ # @param [Hash] payload
70
+ # @return [HTTP::Response]
71
+ def get_similar_items(item_id, payload = {})
72
+ payload = payload.merge('itemId' => item_id)
73
+ request('getSimilarItems', payload)
74
+ end
75
+
76
+ # Returns the current service version
77
+ #
78
+ # @return [HTTP::Response]
79
+ def get_version
80
+ request('getVersion')
81
+ end
82
+
83
+ private
84
+
85
+ def request(operation, payload = {})
86
+ params = { 'CONSUMER-ID' => consumer_id,
87
+ 'GLOBAL-ID' => global_id,
88
+ 'OPERATION-NAME' => operation,
89
+ 'REQUEST-DATA-FORMAT' => 'JSON',
90
+ 'RESPONSE-DATA-FORMAT' => response_data_format,
91
+ 'SERVICE-VERSION' => service_version }.compact
92
+
93
+ http.post(endpoint, params: params, body: JSON.dump(payload))
94
+ end
8
95
  end
9
96
  end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ebay/config'
4
+ require 'ebay/requestable'
5
+
6
+ module Ebay
7
+ module Oauth
8
+ # Mints an access token to use in API requests
9
+ #
10
+ # @see https://developer.ebay.com/api-docs/static/oauth-client-credentials-grant.html
11
+ class ClientCredentialsGrant
12
+ include Requestable
13
+
14
+ self.endpoint = 'https://api.ebay.com/identity/v1/oauth2/token'
15
+
16
+ # @return [String]
17
+ attr_reader :app_id
18
+
19
+ # @return [String]
20
+ attr_reader :cert_id
21
+
22
+ # @param [String] app_id
23
+ # @param [String] cert_id
24
+ def initialize(app_id: Config.app_id, cert_id: Config.cert_id)
25
+ @app_id = app_id
26
+ @cert_id = cert_id
27
+ end
28
+
29
+ # Mints a new access token
30
+ #
31
+ # @return [String]
32
+ def mint_access_token
33
+ JSON.parse(request).fetch('access_token')
34
+ end
35
+
36
+ # Requests a client credentials grant
37
+ #
38
+ # @return [HTTP::Response]
39
+ def request
40
+ http.basic_auth(user: app_id, pass: cert_id)
41
+ .post(endpoint, form: payload)
42
+ end
43
+
44
+ private
45
+
46
+ def payload
47
+ { grant_type: 'client_credentials',
48
+ scope: 'https://api.ebay.com/oauth/api_scope' }
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,69 @@
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
+
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
68
+ end
69
+ end
data/lib/ebay/shopping.rb CHANGED
@@ -1,10 +1,169 @@
1
- require 'ebay/request'
1
+ # frozen_string_literal: true
2
2
 
3
+ require 'ebay/config'
4
+ require 'ebay/requestable'
5
+
6
+ # Ruby wrapper to the eBay APIs
3
7
  module Ebay
4
- class Shopping < Request
5
- host 'open.api.ebay.com'
6
- path '/shopping'
7
- headers 'X-EBAY-API-APP-ID' => Config.app_id,
8
- 'X-EBAY-API-VERSION' => 799
8
+ # Returns a {Ebay::Shopping#initialize Shopping API} instance
9
+ def self.shopping(**params)
10
+ Shopping.new(**params)
11
+ end
12
+
13
+ # The eBay Shopping API makes it easy to search for things on eBay.
14
+ #
15
+ # @see https://developer.ebay.com/Devzone/shopping/docs/Concepts/ShoppingAPI_FormatOverview.html
16
+ # @see https://developer.ebay.com/Devzone/shopping/docs/CallRef/index.html
17
+ class Shopping
18
+ include Requestable
19
+
20
+ self.endpoint = 'https://open.api.ebay.com/shopping'
21
+
22
+ # @return [String]
23
+ attr_reader :app_id
24
+
25
+ # @return [String]
26
+ attr_reader :response_encoding
27
+
28
+ # @return [String]
29
+ attr_reader :site_id
30
+
31
+ # @return [String]
32
+ attr_reader :version
33
+
34
+ # @return [String]
35
+ attr_reader :version_handling
36
+
37
+ # @return [String]
38
+ attr_reader :tracking_id
39
+
40
+ # @return [String]
41
+ attr_reader :tracking_partner_code
42
+
43
+ # @return [String]
44
+ attr_reader :affiliate_user_id
45
+
46
+ # Returns a Finding API request instance
47
+ #
48
+ # @param [String] app_id
49
+ # @param [String] response_encoding
50
+ # @param [String] site_id
51
+ # @param [String] version
52
+ # @param [String] version_handling
53
+ # @param [String] tracking_id
54
+ # @param [String] tracking_partner_code
55
+ # @param [String] affiliate_user_id
56
+ def initialize(app_id: Config.app_id, response_encoding: nil,
57
+ site_id: nil, version: '1119',
58
+ version_handling: nil, tracking_id: nil,
59
+ tracking_partner_code: nil, affiliate_user_id: nil)
60
+ @app_id = app_id
61
+ @response_encoding = response_encoding
62
+ @site_id = site_id
63
+ @version = version
64
+ @version_handling = version_handling
65
+ @tracking_id = tracking_id
66
+ @tracking_partner_code = tracking_partner_code
67
+ @affiliate_user_id = affiliate_user_id
68
+ end
69
+
70
+ # Returns one or more eBay catalog products based on a query string or
71
+ # product ID value
72
+ #
73
+ # @param [Hash] payload
74
+ # @return [HTTP::Response]
75
+ def find_products(payload = {})
76
+ request('FindProducts', payload)
77
+ end
78
+
79
+ # Retrieves high-level data for a specified eBay category
80
+ #
81
+ # @param [String] category_id
82
+ # @param [Hash] payload
83
+ # @return [HTTP::Response]
84
+ def get_category_info(category_id, payload = {})
85
+ payload = payload.merge('CategoryID' => category_id)
86
+ request('GetCategoryInfo', payload)
87
+ end
88
+
89
+ # Gets the official eBay system time in GMT
90
+ #
91
+ # @param [Hash] payload
92
+ # @return [HTTP::Response]
93
+ def get_ebay_time(payload = {})
94
+ request('GeteBayTime', payload)
95
+ end
96
+
97
+ # Retrieves the current status of up to 20 eBay listings
98
+ #
99
+ # @overload get_item_status(*item_ids, payload = {})
100
+ # @param [String] item_ids
101
+ # @param [Hash] payload
102
+ # @return [HTTP::Response]
103
+ def get_item_status(*item_ids)
104
+ payload = item_ids.last.is_a?(Hash) ? item_ids.pop : {}
105
+ payload = payload.merge('ItemID' => item_ids.map(&:to_s))
106
+ request('GetItemStatus', payload)
107
+ end
108
+
109
+ # Retrieves publicly available data for one or more listings
110
+ #
111
+ # @overload get_multiple_items(*item_ids, payload = {})
112
+ # @param [String] item_ids
113
+ # @param [Hash] payload
114
+ # @return [HTTP::Response]
115
+ def get_multiple_items(*item_ids)
116
+ payload = item_ids.last.is_a?(Hash) ? item_ids.pop : {}
117
+ payload = payload.merge('ItemID' => item_ids.map(&:to_s))
118
+
119
+ request('GetMultipleItems', payload)
120
+ end
121
+
122
+ # Gets shipping costs for a listing
123
+ #
124
+ # @param [String] item_id
125
+ # @param [Hash] payload
126
+ # @return [HTTP::Response]
127
+ def get_shipping_costs(item_id, payload = {})
128
+ payload = payload.merge('ItemID' => item_id)
129
+ request('GetShippingCosts', payload)
130
+ end
131
+
132
+ # Gets publicly visible details about one listing
133
+ #
134
+ # @param [String] item_id
135
+ # @param [Hash] payload
136
+ # @return [HTTP::Response]
137
+ def get_single_item(item_id, payload = {})
138
+ payload = payload.merge('ItemID' => item_id)
139
+ request('GetSingleItem', payload)
140
+ end
141
+
142
+ # Retrieves user information
143
+ #
144
+ # @param [String] user_id
145
+ # @param [Hash] payload
146
+ # @return [HTTP::Response]
147
+ def get_user_profile(user_id, payload = {})
148
+ payload = payload.merge('UserID' => user_id)
149
+ request('GetUserProfile', payload)
150
+ end
151
+
152
+ private
153
+
154
+ def request(operation, payload = {})
155
+ params = { 'appid' => app_id,
156
+ 'callname' => operation,
157
+ 'requestencoding' => 'JSON',
158
+ 'responseencoding' => response_encoding,
159
+ 'siteid' => site_id,
160
+ 'version' => version,
161
+ 'versionhandling' => version_handling,
162
+ 'affiliateuserid' => affiliate_user_id,
163
+ 'trackingid' => tracking_id,
164
+ 'trackingpartnercode' => tracking_partner_code }.compact
165
+
166
+ http.post(endpoint, params: params, body: JSON.dump(payload))
167
+ end
9
168
  end
10
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.2.0'
4
+ VERSION = '0.3.4'
5
5
  end
metadata CHANGED
@@ -1,125 +1,179 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ebay-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
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-01-15 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
- name: excon
14
+ name: http
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.33'
19
+ version: '4.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.33'
26
+ version: '4.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: multi_xml
28
+ name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.5.5
34
- type: :runtime
33
+ version: '0'
34
+ type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 0.5.5
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '10.3'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '10.3'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: minitest
56
+ name: redcarpet
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '5.3'
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
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: 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
+ - - ">="
67
109
  - !ruby/object:Gem::Version
68
- version: '5.3'
110
+ version: '0'
69
111
  - !ruby/object:Gem::Dependency
70
112
  name: vcr
71
113
  requirement: !ruby/object:Gem::Requirement
72
114
  requirements:
73
- - - "~>"
115
+ - - ">="
74
116
  - !ruby/object:Gem::Version
75
- version: '2.9'
117
+ version: '0'
76
118
  type: :development
77
119
  prerelease: false
78
120
  version_requirements: !ruby/object:Gem::Requirement
79
121
  requirements:
80
- - - "~>"
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: webmock
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
81
130
  - !ruby/object:Gem::Version
82
- version: '2.9'
83
- description:
131
+ version: '0'
132
+ type: :development
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: yard
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description:
84
154
  email:
85
155
  - me@hakanensari.com
86
156
  executables: []
87
157
  extensions: []
88
158
  extra_rdoc_files: []
89
159
  files:
90
- - ".gitignore"
91
- - ".travis.yml"
92
- - Gemfile
160
+ - LICENSE
93
161
  - README.md
94
- - Rakefile
95
- - ebay-ruby.gemspec
96
162
  - lib/ebay-ruby.rb
97
163
  - lib/ebay.rb
164
+ - lib/ebay/browse.rb
98
165
  - lib/ebay/config.rb
99
166
  - lib/ebay/finding.rb
100
167
  - lib/ebay/merchandising.rb
101
- - lib/ebay/parser.rb
102
- - lib/ebay/product.rb
103
- - lib/ebay/product_metadata.rb
104
- - lib/ebay/request.rb
168
+ - lib/ebay/oauth/client_credentials_grant.rb
169
+ - lib/ebay/requestable.rb
105
170
  - lib/ebay/shopping.rb
106
171
  - lib/ebay/version.rb
107
- - test/cassettes/finding.yml
108
- - test/cassettes/merchandising.yml
109
- - test/cassettes/product.yml
110
- - test/cassettes/product_metadata.yml
111
- - test/cassettes/shopping.yml
112
- - test/helper.rb
113
- - test/test_finding.rb
114
- - test/test_merchandising.rb
115
- - test/test_parser.rb
116
- - test/test_product.rb
117
- - test/test_product_metadata.rb
118
- - test/test_shopping.rb
119
172
  homepage: https://github.com/hakanensari/ebay-ruby
120
- licenses: []
173
+ licenses:
174
+ - MIT
121
175
  metadata: {}
122
- post_install_message:
176
+ post_install_message:
123
177
  rdoc_options: []
124
178
  require_paths:
125
179
  - lib
@@ -127,27 +181,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
127
181
  requirements:
128
182
  - - ">="
129
183
  - !ruby/object:Gem::Version
130
- version: '0'
184
+ version: '2.5'
131
185
  required_rubygems_version: !ruby/object:Gem::Requirement
132
186
  requirements:
133
187
  - - ">="
134
188
  - !ruby/object:Gem::Version
135
189
  version: '0'
136
190
  requirements: []
137
- rubygems_version: 3.1.2
138
- signing_key:
191
+ rubygems_version: 3.2.3
192
+ signing_key:
139
193
  specification_version: 4
140
- summary: A Ruby wrapper to the eBay Web Services API
141
- test_files:
142
- - test/cassettes/finding.yml
143
- - test/cassettes/merchandising.yml
144
- - test/cassettes/product.yml
145
- - test/cassettes/product_metadata.yml
146
- - test/cassettes/shopping.yml
147
- - test/helper.rb
148
- - test/test_finding.rb
149
- - test/test_merchandising.rb
150
- - test/test_parser.rb
151
- - test/test_product.rb
152
- - test/test_product_metadata.rb
153
- - test/test_shopping.rb
194
+ summary: Ruby wrapper to the eBay APIs
195
+ test_files: []