ebay-ruby 0.2.0 → 0.3.0

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