peddler 2.3.0 → 2.4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -15
- data/lib/mws/orders/client.rb +1 -3
- data/lib/mws/subscriptions/client.rb +2 -2
- data/lib/peddler/client.rb +7 -4
- data/lib/peddler/errors/class_generator.rb +8 -3
- data/lib/peddler/flat_file_parser.rb +1 -1
- data/lib/peddler/headers.rb +6 -1
- data/lib/peddler/marketplace.rb +4 -1
- data/lib/peddler/operation.rb +1 -1
- data/lib/peddler/version.rb +1 -1
- data/lib/peddler/xml_response_parser.rb +2 -1
- metadata +8 -10
- data/lib/peddler/content.rb +0 -69
- data/lib/peddler/mws.rb +0 -58
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6d04cca2ae15bfa1b30a6cc0d12c2635144395a3981ef0f81fbade475433a1e
|
4
|
+
data.tar.gz: 5572b66b7ac592fe3ac9beea26d89068699c33116b91c80e422a5e699638711c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0293f38c3193aa0f9a8258c2620cf27f7fbc206a4240ccf4b483e51c312db71bcbc10d42ad829174ab1aa83c8017b3b08bc2c082a669e9040c503bf71747fab
|
7
|
+
data.tar.gz: ec5af682f45f8c6c7fcf2be530549bc0aeff921d7b8ba6a27ba9a977f26a31734fba3055901c3f1269759a92619a55cf0bd02e6f447f6bd9f0b4c386d641d4e2
|
data/README.md
CHANGED
@@ -4,13 +4,15 @@
|
|
4
4
|
[![Maintainability](https://api.codeclimate.com/v1/badges/281e6176048f3c0a1ed3/maintainability)](https://codeclimate.com/github/hakanensari/peddler/maintainability)
|
5
5
|
[![Test Coverage](https://api.codeclimate.com/v1/badges/281e6176048f3c0a1ed3/test_coverage)](https://codeclimate.com/github/hakanensari/peddler/test_coverage)
|
6
6
|
|
7
|
+
> :boom: Amazon is migrating to the newly-launched Selling Partner API (SP-API) and is no longer granting new users access to the MWS APIs. I hope to add support in Peddler in due course.
|
8
|
+
|
7
9
|
**Peddler** is a Ruby interface to the [Amazon MWS API](https://developer.amazonservices.com/), a collection of web services that help Amazon sellers programmatically exchange data on their listings, orders, payments, reports, and more.
|
8
10
|
|
9
11
|
To use Amazon MWS, you must have an eligible seller account and [register as a developer](https://docs.developer.amazonservices.com/en_US/dev_guide/DG_Registering.html#DG_Registering__RegisteringAsADeveloper). You can then access your own selling account using its merchant ID—note that Amazon also refers to this as seller ID or merchant token in different places.
|
10
12
|
|
11
13
|
Amazon has [multiple regions](https://docs.developer.amazonservices.com/en_US/dev_guide/DG_Endpoints.html). Each region requires application developers to register individually. Some MWS API sections may require additional authorisation from Amazon.
|
12
14
|
|
13
|
-
![Peddler](
|
15
|
+
![Peddler](https://github.com/hakanensari/peddler/blob/main/images/peddler.jpg?raw=true)
|
14
16
|
|
15
17
|
## Usage
|
16
18
|
|
@@ -143,14 +145,14 @@ You can access the same attributes on `error.response`. See <a href="#throttling
|
|
143
145
|
With the Easy Ship API, you can build applications that help sellers in India manage and ship their Amazon Easy Ship orders. Your Amazon Easy Ship applications can get available pickup slots; schedule, reschedule, and cancel pickups; and print labels, invoices, and warranties.
|
144
146
|
|
145
147
|
- [Amazon references](https://docs.developer.amazonservices.com/en_US/easy_ship/EasyShip_Overview.html)
|
146
|
-
- [Peddler API docs](https://www.rubydoc.info/
|
148
|
+
- [Peddler API docs](https://www.rubydoc.info/github/hakanensari/peddler/MWS/EasyShip/Client)
|
147
149
|
|
148
150
|
### Feeds
|
149
151
|
|
150
152
|
The MWS Feeds API lets you upload inventory and order data to Amazon. You can also use this API to get information about the processing of feeds.
|
151
153
|
|
152
154
|
- [Amazon references](https://docs.developer.amazonservices.com/en_US/feeds/Feeds_Overview.html)
|
153
|
-
- [Peddler API docs](https://www.rubydoc.info/
|
155
|
+
- [Peddler API docs](https://www.rubydoc.info/github/hakanensari/peddler/MWS/Feeds/Client)
|
154
156
|
- [XML schema docs](https://sellercentral.amazon.com/gp/help/help-page.html?itemID=1611)
|
155
157
|
|
156
158
|
### Finances
|
@@ -158,21 +160,21 @@ The MWS Feeds API lets you upload inventory and order data to Amazon. You can al
|
|
158
160
|
The MWS Finances API enables you to obtain financial information relevant to your business with Amazon. You can obtain financial events for a given order, financial event group, or date range without having to wait until a statement period closes. You can also obtain financial event groups for a given date range.
|
159
161
|
|
160
162
|
- [Amazon references](https://docs.developer.amazonservices.com/en_US/finances/Finances_Overview.html)
|
161
|
-
- [Peddler API docs](https://www.rubydoc.info/
|
163
|
+
- [Peddler API docs](https://www.rubydoc.info/github/hakanensari/peddler/MWS/Finances/Client)
|
162
164
|
|
163
165
|
### Fulfillment Inbound Shipment
|
164
166
|
|
165
167
|
With the MWS Fulfillment Inbound Shipment API, you can create and update inbound shipments of inventory in the Amazon Fulfillment Network. You can also also request lists of inbound shipments or inbound shipment items based on criteria that you specify.
|
166
168
|
|
167
169
|
- [Amazon references](https://docs.developer.amazonservices.com/en_US/fba_inbound/FBAInbound_Overview.html)
|
168
|
-
- [Peddler API docs](https://www.rubydoc.info/
|
170
|
+
- [Peddler API docs](https://www.rubydoc.info/github/hakanensari/peddler/MWS/FulfillmentInboundShipment/Client)
|
169
171
|
|
170
172
|
### Fulfillment Inventory
|
171
173
|
|
172
174
|
The MWS Fulfillment Inventory API can help you stay up-to-date on the availability of your inventory in the Amazon Fulfillment Network. The Fulfillment Inventory API reports real-time availability information for your Amazon Fulfillment Network inventory regardless of whether you are selling your inventory on Amazon's retail web site or through other retail channels.
|
173
175
|
|
174
176
|
- [Amazon references](https://docs.developer.amazonservices.com/en_US/fba_inventory/FBAInventory_Overview.html)
|
175
|
-
- [Peddler API docs](https://www.rubydoc.info/
|
177
|
+
- [Peddler API docs](https://www.rubydoc.info/github/hakanensari/peddler/MWS/FulfillmentInventory/Client)
|
176
178
|
|
177
179
|
### Fulfillment Outbound Shipment
|
178
180
|
|
@@ -181,49 +183,49 @@ The MWS Fulfillment Outbound Shipment API enables you to fulfill orders placed t
|
|
181
183
|
Support for creating and cancelling fulfillment orders has been implemented, but the rest of the API is not supported yet.
|
182
184
|
|
183
185
|
- [Amazon references](https://docs.developer.amazonservices.com/en_US/fba_outbound/FBAOutbound_Overview.html)
|
184
|
-
- [Peddler API docs](https://www.rubydoc.info/
|
186
|
+
- [Peddler API docs](https://www.rubydoc.info/github/hakanensari/peddler/MWS/FulfillmentOutboundShipment/Client)
|
185
187
|
|
186
188
|
### Merchant Fulfillment
|
187
189
|
|
188
190
|
The Merchant Fulfillment API provides programmatic access to Amazon’s fulfillment shipping services for sellers, including competitive rates with Amazon-partnered carriers. Sellers can find out what shipping services are available by submitting information about a proposed fulfillment shipment, such as package size and weight; shipment origin and destination; and delivery date requirements. Sellers can choose from the shipping service options returned by Amazon, and then receive shipping labels for fulfilling their orders.
|
189
191
|
|
190
192
|
- [Amazon references](https://docs.developer.amazonservices.com/en_US/merch_fulfill/MerchFulfill_Overview.html)
|
191
|
-
- [Peddler API docs](https://www.rubydoc.info/
|
193
|
+
- [Peddler API docs](https://www.rubydoc.info/github/hakanensari/peddler/MWS/MerchantFulfillment/Client)
|
192
194
|
|
193
195
|
### Orders
|
194
196
|
|
195
197
|
With the MWS Orders API, you can list orders created or updated during a time frame you specify or retrieve information about specific orders.
|
196
198
|
|
197
199
|
- [Amazon references](https://docs.developer.amazonservices.com/en_US/orders-2013-09-01/Orders_Overview.html)
|
198
|
-
- [Peddler API docs](https://www.rubydoc.info/
|
200
|
+
- [Peddler API docs](https://www.rubydoc.info/github/hakanensari/peddler/MWS/Orders/Client)
|
199
201
|
|
200
202
|
### Products
|
201
203
|
|
202
204
|
The MWS Products API helps you get information to match your products to existing product listings on Amazon Marketplace websites and to make sourcing and pricing decisions for listing those products on Amazon Marketplace websites.
|
203
205
|
|
204
206
|
- [Amazon references](https://docs.developer.amazonservices.com/en_US/products/Products_Overview.html)
|
205
|
-
- [Peddler API docs](https://www.rubydoc.info/
|
207
|
+
- [Peddler API docs](https://www.rubydoc.info/github/hakanensari/peddler/MWS/Products/Client)
|
206
208
|
|
207
209
|
### Recommendations
|
208
210
|
|
209
211
|
The Recommendations API enables you to programmatically retrieve Amazon Selling Coach recommendations by recommendation category. A recommendation is an actionable, timely, and personalized opportunity to increase your sales and performance.
|
210
212
|
|
211
213
|
- [Amazon references](https://docs.developer.amazonservices.com/en_US/recommendations/Recommendations_Overview.html)
|
212
|
-
- [Peddler API docs](https://www.rubydoc.info/
|
214
|
+
- [Peddler API docs](https://www.rubydoc.info/github/hakanensari/peddler/MWS/Recommendations/Client)
|
213
215
|
|
214
216
|
### Reports
|
215
217
|
|
216
218
|
The Reports API lets you request reports about your inventory and orders.
|
217
219
|
|
218
220
|
- [Amazon references](https://docs.developer.amazonservices.com/en_US/reports/Reports_Overview.html)
|
219
|
-
- [Peddler API docs](https://www.rubydoc.info/
|
221
|
+
- [Peddler API docs](https://www.rubydoc.info/github/hakanensari/peddler/MWS/Reports/Client)
|
220
222
|
|
221
223
|
### Sellers
|
222
224
|
|
223
225
|
The Sellers API lets sellers retrieve information about their seller account, such as the marketplaces they participate in.
|
224
226
|
|
225
227
|
- [Amazon references](https://docs.developer.amazonservices.com/en_US/subscriptions/Subscriptions_Overview.html)
|
226
|
-
- [Peddler API docs](https://www.rubydoc.info/
|
228
|
+
- [Peddler API docs](https://www.rubydoc.info/github/hakanensari/peddler/MWS/Sellers/Client)
|
227
229
|
|
228
230
|
### Shipment Invoicing
|
229
231
|
|
@@ -232,11 +234,11 @@ With the Shipment Invoicing API section (in conjunction with the FBAOutboundShip
|
|
232
234
|
This functionality is available only in the Brazil marketplace.
|
233
235
|
|
234
236
|
- [Amazon references](https://docs.developer.amazonservices.com/en_US/shipment_invoicing/ShipmentInvoicing_Overview.html)
|
235
|
-
- [Peddler API docs](https://www.rubydoc.info/
|
237
|
+
- [Peddler API docs](https://www.rubydoc.info/github/hakanensari/peddler/MWS/ShipmentInvoicing/Client)
|
236
238
|
|
237
239
|
### Subscriptions
|
238
240
|
|
239
241
|
The Amazon MWS Subscriptions API section enables you to subscribe to receive notifications that are relevant to your business with Amazon. With the operations in the Subscriptions API section, you can register to receive important information from Amazon without having to poll the Amazon MWS service. Instead, the information is sent directly to you when an event occurs to which you are subscribed.
|
240
242
|
|
241
243
|
- [Amazon references](https://docs.developer.amazonservices.com/en_US/subscriptions/Subscriptions_Overview.html)
|
242
|
-
- [Peddler API docs](https://www.rubydoc.info/
|
244
|
+
- [Peddler API docs](https://www.rubydoc.info/github/hakanensari/peddler/MWS/Subscriptions/Client)
|
data/lib/mws/orders/client.rb
CHANGED
@@ -34,9 +34,7 @@ module MWS
|
|
34
34
|
def list_orders(*marketplace_id)
|
35
35
|
marketplace_id = marketplace_id.dup
|
36
36
|
opts = extract_options(marketplace_id)
|
37
|
-
if opts.key?(:tfm_shipment_status)
|
38
|
-
opts['TFMShipmentStatus'] = opts.delete(:tfm_shipment_status)
|
39
|
-
end
|
37
|
+
opts['TFMShipmentStatus'] = opts.delete(:tfm_shipment_status) if opts.key?(:tfm_shipment_status)
|
40
38
|
|
41
39
|
operation('ListOrders')
|
42
40
|
.add(opts)
|
@@ -139,7 +139,7 @@ module MWS
|
|
139
139
|
marketplace_id)
|
140
140
|
operation('UpdateSubscription')
|
141
141
|
.add('MarketplaceId' => marketplace_id)
|
142
|
-
.add(build_subscription(notification_type, sqs_queue_url, enabled))
|
142
|
+
.add(build_subscription(notification_type, sqs_queue_url, enabled: enabled))
|
143
143
|
|
144
144
|
run
|
145
145
|
end
|
@@ -163,7 +163,7 @@ module MWS
|
|
163
163
|
}
|
164
164
|
end
|
165
165
|
|
166
|
-
def build_subscription(notification_type, sqs_queue_url, enabled
|
166
|
+
def build_subscription(notification_type, sqs_queue_url, enabled: true)
|
167
167
|
{
|
168
168
|
'Subscription.IsEnabled' => enabled,
|
169
169
|
'Subscription.NotificationType' => notification_type,
|
data/lib/peddler/client.rb
CHANGED
@@ -22,6 +22,7 @@ module Peddler
|
|
22
22
|
private
|
23
23
|
|
24
24
|
def inherited(base)
|
25
|
+
super
|
25
26
|
base.parser = parser
|
26
27
|
base.params params
|
27
28
|
end
|
@@ -112,7 +113,7 @@ module Peddler
|
|
112
113
|
# @!visibility private
|
113
114
|
def run(&block)
|
114
115
|
opts = build_options
|
115
|
-
opts.store(:response_block, block) if
|
116
|
+
opts.store(:response_block, block) if block
|
116
117
|
res = post(opts)
|
117
118
|
self.body = nil if res.status == 200
|
118
119
|
|
@@ -129,13 +130,15 @@ module Peddler
|
|
129
130
|
end
|
130
131
|
|
131
132
|
def add_content(content)
|
132
|
-
|
133
|
+
@body = content
|
134
|
+
if content.encoding.names.include?('BINARY')
|
135
|
+
headers['Content-Type'] = 'application/octet-stream'
|
136
|
+
elsif content.start_with?('<?xml')
|
133
137
|
headers['Content-Type'] = 'text/xml'
|
134
|
-
@body = content
|
135
138
|
else
|
136
139
|
headers['Content-Type'] =
|
137
140
|
"text/tab-separated-values; charset=#{encoding}"
|
138
|
-
@body =
|
141
|
+
@body = @body.encode(encoding)
|
139
142
|
end
|
140
143
|
end
|
141
144
|
|
@@ -19,7 +19,12 @@ module Peddler
|
|
19
19
|
|
20
20
|
def generate(name)
|
21
21
|
with_mutex do
|
22
|
-
|
22
|
+
if Errors.const_defined?(name)
|
23
|
+
error = Errors.const_get(name)
|
24
|
+
return error if error <= Error
|
25
|
+
|
26
|
+
raise TypeError, "#{name} must be a Peddler::Errors::Error"
|
27
|
+
end
|
23
28
|
|
24
29
|
Errors.const_set(name, Class.new(Error))
|
25
30
|
end
|
@@ -27,8 +32,8 @@ module Peddler
|
|
27
32
|
|
28
33
|
private
|
29
34
|
|
30
|
-
def with_mutex
|
31
|
-
@mutex.synchronize
|
35
|
+
def with_mutex(&block)
|
36
|
+
@mutex.synchronize(&block)
|
32
37
|
end
|
33
38
|
end
|
34
39
|
end
|
data/lib/peddler/headers.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'time'
|
4
|
+
|
3
5
|
module Peddler
|
4
6
|
# Parses useful metadata returned in response headers
|
5
7
|
module Headers
|
@@ -47,7 +49,10 @@ module Peddler
|
|
47
49
|
match_data = headers['Content-Type']&.match(/charset=(.*);?/)
|
48
50
|
return unless match_data
|
49
51
|
|
50
|
-
|
52
|
+
string = match_data[1].upcase
|
53
|
+
string = 'UTF-8' if string == 'UTF8'
|
54
|
+
|
55
|
+
Encoding.find(string)
|
51
56
|
end
|
52
57
|
|
53
58
|
# The max hourly request quota for the requested operation
|
data/lib/peddler/marketplace.rb
CHANGED
@@ -64,11 +64,14 @@ module Peddler
|
|
64
64
|
['A1F83G8C2ARO7P', 'GB', 'mws-eu.amazonservices.com'],
|
65
65
|
['A21TJRUUN4KGV', 'IN', 'mws.amazonservices.in'],
|
66
66
|
['APJ6JRA9NG5V4', 'IT', 'mws-eu.amazonservices.com'],
|
67
|
+
['A1805IZSGTT6HS', 'NL', 'mws-eu.amazonservices.com'],
|
67
68
|
['A17E79C6D8DWNP', 'SA', 'mws-eu.amazonservices.com'],
|
68
69
|
['A33AVAJ2PDY3EV', 'TR', 'mws-eu.amazonservices.com'],
|
70
|
+
['A2NODRKZP88ZB9', 'SE', 'mws-eu.amazonservices.com'],
|
69
71
|
['A19VAU5U5O7RUS', 'SG', 'mws-fe.amazonservices.com'],
|
70
72
|
['A39IBJ37TRP1C6', 'AU', 'mws.amazonservices.com.au'],
|
71
|
-
['A1VC38T7YXB528', 'JP', 'mws.amazonservices.jp']
|
73
|
+
['A1VC38T7YXB528', 'JP', 'mws.amazonservices.jp'],
|
74
|
+
['A1C3SOZRARQ6R3', 'PL', 'mws-eu.amazonservices.com']
|
72
75
|
].map do |values|
|
73
76
|
new(*values)
|
74
77
|
end
|
data/lib/peddler/operation.rb
CHANGED
data/lib/peddler/version.rb
CHANGED
@@ -5,7 +5,7 @@ require 'peddler/xml_parser'
|
|
5
5
|
module Peddler
|
6
6
|
# @!visibility private
|
7
7
|
class XMLResponseParser < XMLParser
|
8
|
-
MATCHER = /^Message$|Report|Result/.freeze
|
8
|
+
MATCHER = /^Message$|^Node$|Report|Result/.freeze
|
9
9
|
private_constant :MATCHER
|
10
10
|
|
11
11
|
def next_token
|
@@ -14,6 +14,7 @@ module Peddler
|
|
14
14
|
|
15
15
|
private
|
16
16
|
|
17
|
+
# FIXME: In next major version bump, stop assuming we know report internals.
|
17
18
|
def find_data
|
18
19
|
payload = xml.values.first
|
19
20
|
found = payload.find { |k, _| k.match(MATCHER) }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: peddler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.5
|
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-04-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: excon
|
@@ -52,7 +52,7 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 0.5.0
|
55
|
-
description:
|
55
|
+
description:
|
56
56
|
email:
|
57
57
|
- me@hakanensari.com
|
58
58
|
executables: []
|
@@ -93,7 +93,6 @@ files:
|
|
93
93
|
- lib/mws/subscriptions/client.rb
|
94
94
|
- lib/peddler.rb
|
95
95
|
- lib/peddler/client.rb
|
96
|
-
- lib/peddler/content.rb
|
97
96
|
- lib/peddler/errors/builder.rb
|
98
97
|
- lib/peddler/errors/class_generator.rb
|
99
98
|
- lib/peddler/errors/error.rb
|
@@ -101,7 +100,6 @@ files:
|
|
101
100
|
- lib/peddler/flat_file_parser.rb
|
102
101
|
- lib/peddler/headers.rb
|
103
102
|
- lib/peddler/marketplace.rb
|
104
|
-
- lib/peddler/mws.rb
|
105
103
|
- lib/peddler/operation.rb
|
106
104
|
- lib/peddler/parser.rb
|
107
105
|
- lib/peddler/structured_list.rb
|
@@ -113,7 +111,7 @@ homepage: https://github.com/hakanensari/peddler
|
|
113
111
|
licenses:
|
114
112
|
- MIT
|
115
113
|
metadata: {}
|
116
|
-
post_install_message:
|
114
|
+
post_install_message:
|
117
115
|
rdoc_options: []
|
118
116
|
require_paths:
|
119
117
|
- lib
|
@@ -121,15 +119,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
121
119
|
requirements:
|
122
120
|
- - ">="
|
123
121
|
- !ruby/object:Gem::Version
|
124
|
-
version: '2.
|
122
|
+
version: '2.5'
|
125
123
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
124
|
requirements:
|
127
125
|
- - ">="
|
128
126
|
- !ruby/object:Gem::Version
|
129
127
|
version: '0'
|
130
128
|
requirements: []
|
131
|
-
rubygems_version: 3.
|
132
|
-
signing_key:
|
129
|
+
rubygems_version: 3.2.3
|
130
|
+
signing_key:
|
133
131
|
specification_version: 4
|
134
132
|
summary: A Ruby wrapper to the Amazon MWS API
|
135
133
|
test_files: []
|
data/lib/peddler/content.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Peddler
|
4
|
-
# Parses content metadata provided in the headers of a response
|
5
|
-
class Content
|
6
|
-
# @!visibility private
|
7
|
-
attr_reader :headers
|
8
|
-
|
9
|
-
# @!visibility private
|
10
|
-
def initialize(headers)
|
11
|
-
@headers = headers.select { |key| key.start_with?('Content') }
|
12
|
-
end
|
13
|
-
|
14
|
-
# The size of the response body in bytes
|
15
|
-
# @return [String, nil]
|
16
|
-
def length
|
17
|
-
return unless headers['Content-Length']
|
18
|
-
|
19
|
-
headers['Content-Length'].to_i
|
20
|
-
end
|
21
|
-
|
22
|
-
# The MD5 digest of the response body
|
23
|
-
# @return [String, nil]
|
24
|
-
def md5
|
25
|
-
headers['Content-MD5']
|
26
|
-
end
|
27
|
-
|
28
|
-
# The MIME type of the response
|
29
|
-
# @return [String, nil]
|
30
|
-
def media_type
|
31
|
-
return unless headers['Content-Type']
|
32
|
-
|
33
|
-
headers['Content-Type'].split(';').first
|
34
|
-
end
|
35
|
-
|
36
|
-
# The general category into which the MIME type falls
|
37
|
-
# @return [String, nil]
|
38
|
-
def type
|
39
|
-
return unless media_type
|
40
|
-
|
41
|
-
media_type.split('/').first
|
42
|
-
end
|
43
|
-
|
44
|
-
# The exact kind of data of the specified type the MIME type represents
|
45
|
-
# @return [String, nil]
|
46
|
-
def subtype
|
47
|
-
return unless media_type
|
48
|
-
|
49
|
-
media_type.split('/').last
|
50
|
-
end
|
51
|
-
|
52
|
-
# The character encoding of the response
|
53
|
-
# @return [Encoding, nil]
|
54
|
-
def charset
|
55
|
-
match_data = headers['Content-Type']&.match(/charset=(.*);?/)
|
56
|
-
return unless match_data
|
57
|
-
|
58
|
-
Encoding.find(match_data[1])
|
59
|
-
end
|
60
|
-
|
61
|
-
# Whether the response is an XML document
|
62
|
-
# @return [Boolean, nil]
|
63
|
-
def xml?
|
64
|
-
return unless subtype
|
65
|
-
|
66
|
-
subtype == 'xml'
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
data/lib/peddler/mws.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Peddler
|
4
|
-
# Parses MWS metadata provided in the headers of a response
|
5
|
-
class MWS
|
6
|
-
# @!visibility private
|
7
|
-
attr_reader :headers
|
8
|
-
|
9
|
-
# @!visibility private
|
10
|
-
def initialize(headers)
|
11
|
-
@headers = headers.select { |key| key.start_with?('x-mws') }
|
12
|
-
end
|
13
|
-
|
14
|
-
# The max hourly request quota for the requested operation
|
15
|
-
# @return [Integer, nil]
|
16
|
-
def quota_max
|
17
|
-
return unless headers['x-mws-quota-max']
|
18
|
-
|
19
|
-
headers['x-mws-quota-max'].to_i
|
20
|
-
end
|
21
|
-
|
22
|
-
# The remaining hourly request quota for the requested operation
|
23
|
-
# @return [Integer, nil]
|
24
|
-
def quota_remaining
|
25
|
-
return unless headers['x-mws-quota-remaining']
|
26
|
-
|
27
|
-
headers['x-mws-quota-remaining'].to_i
|
28
|
-
end
|
29
|
-
|
30
|
-
# When the hourly request quota for the requested operation resets
|
31
|
-
# @return [Time, nil]
|
32
|
-
def quota_resets_on
|
33
|
-
return unless headers['x-mws-quota-resetsOn']
|
34
|
-
|
35
|
-
Time.parse(headers['x-mws-quota-resetsOn'])
|
36
|
-
end
|
37
|
-
|
38
|
-
# The ID of the request
|
39
|
-
# @return [String, nil]
|
40
|
-
def request_id
|
41
|
-
headers['x-mws-request-id']
|
42
|
-
end
|
43
|
-
|
44
|
-
# The timestamp of the request
|
45
|
-
# @return [Time, nil]
|
46
|
-
def timestamp
|
47
|
-
return unless headers['x-mws-timestamp']
|
48
|
-
|
49
|
-
Time.parse(headers['x-mws-timestamp'])
|
50
|
-
end
|
51
|
-
|
52
|
-
# The context of the response
|
53
|
-
# @return [String, nil]
|
54
|
-
def response_context
|
55
|
-
headers['x-mws-response-context']
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|