peddler 3.0.0.beta1 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +108 -110
- data/lib/peddler/api.rb +56 -18
- data/lib/peddler/{api → apis}/amazon_warehousing_and_distribution_2024_05_09.rb +38 -26
- data/lib/peddler/{api → apis}/aplus_content_2020_11_01.rb +97 -59
- data/lib/peddler/apis/application_integrations_2024_04_01.rb +56 -0
- data/lib/peddler/{api → apis}/application_management_2023_11_30.rb +14 -4
- data/lib/peddler/{api → apis}/catalog_items_2020_12_01.rb +34 -23
- data/lib/peddler/{api → apis}/catalog_items_2022_04_01.rb +39 -29
- data/lib/peddler/{api → apis}/catalog_items_v0.rb +43 -30
- data/lib/peddler/{api → apis}/data_kiosk_2023_11_15.rb +47 -31
- data/lib/peddler/apis/easy_ship_2022_03_23.rb +126 -0
- data/lib/peddler/{api → apis}/fba_inbound_eligibility_v1.rb +15 -7
- data/lib/peddler/{api → apis}/fba_inventory_v1.rb +45 -29
- data/lib/peddler/{api → apis}/feeds_2021_06_30.rb +54 -33
- data/lib/peddler/apis/finances_2024_06_19.rb +50 -0
- data/lib/peddler/{api → apis}/finances_v0.rb +50 -36
- data/lib/peddler/{api → apis}/fulfillment_inbound_2024_03_20.rb +384 -255
- data/lib/peddler/{api → apis}/fulfillment_inbound_v0.rb +138 -93
- data/lib/peddler/{api → apis}/fulfillment_outbound_2020_07_01.rb +105 -68
- data/lib/peddler/apis/invoices_2024_06_19.rb +180 -0
- data/lib/peddler/apis/listings_items_2020_09_01.rb +95 -0
- data/lib/peddler/apis/listings_items_2021_08_01.rb +136 -0
- data/lib/peddler/{api → apis}/listings_restrictions_2021_08_01.rb +21 -11
- data/lib/peddler/apis/merchant_fulfillment_v0.rb +80 -0
- data/lib/peddler/{api → apis}/messaging_v1.rb +107 -75
- data/lib/peddler/{api → apis}/notifications_v1.rb +63 -32
- data/lib/peddler/{api → apis}/orders_v0.rb +99 -84
- data/lib/peddler/apis/product_fees_v0.rb +77 -0
- data/lib/peddler/{api → apis}/product_pricing_2022_05_01.rb +24 -13
- data/lib/peddler/{api → apis}/product_pricing_v0.rb +70 -52
- data/lib/peddler/{api → apis}/product_type_definitions_2020_09_01.rb +32 -21
- data/lib/peddler/{api → apis}/replenishment_2022_11_07.rb +25 -13
- data/lib/peddler/{api → apis}/reports_2021_06_30.rb +71 -47
- data/lib/peddler/{api → apis}/sales_v1.rb +22 -14
- data/lib/peddler/{api → apis}/sellers_v1.rb +19 -7
- data/lib/peddler/{api → apis}/services_v1.rb +156 -116
- data/lib/peddler/apis/shipment_invoicing_v0.rb +59 -0
- data/lib/peddler/apis/shipping_v1.rb +132 -0
- data/lib/peddler/{api → apis}/shipping_v2.rb +150 -98
- data/lib/peddler/{api → apis}/solicitations_v1.rb +21 -11
- data/lib/peddler/apis/supply_sources_2020_07_01.rb +100 -0
- data/lib/peddler/{api → apis}/tokens_2021_03_01.rb +15 -7
- data/lib/peddler/{api → apis}/uploads_2020_11_01.rb +18 -8
- data/lib/peddler/{api → apis}/vendor_direct_fulfillment_inventory_v1.rb +14 -6
- data/lib/peddler/{api → apis}/vendor_direct_fulfillment_orders_2021_12_28.rb +33 -21
- data/lib/peddler/{api → apis}/vendor_direct_fulfillment_orders_v1.rb +33 -21
- data/lib/peddler/{api → apis}/vendor_direct_fulfillment_payments_v1.rb +13 -5
- data/lib/peddler/apis/vendor_direct_fulfillment_sandbox_test_data_2021_10_28.rb +45 -0
- data/lib/peddler/{api → apis}/vendor_direct_fulfillment_shipping_2021_12_28.rb +86 -60
- data/lib/peddler/apis/vendor_direct_fulfillment_shipping_v1.rb +189 -0
- data/lib/peddler/{api → apis}/vendor_direct_fulfillment_transactions_2021_12_28.rb +14 -6
- data/lib/peddler/{api → apis}/vendor_direct_fulfillment_transactions_v1.rb +14 -6
- data/lib/peddler/apis/vendor_invoices_v1.rb +30 -0
- data/lib/peddler/{api → apis}/vendor_orders_v1.rb +59 -48
- data/lib/peddler/apis/vendor_shipments_v1.rb +132 -0
- data/lib/peddler/{api → apis}/vendor_transaction_status_v1.rb +14 -5
- data/lib/peddler/endpoint.rb +51 -0
- data/lib/peddler/error.rb +21 -11
- data/lib/peddler/helpers/feeds_2021_06_30.rb +26 -0
- data/lib/peddler/json_feed_document.rb +31 -0
- data/lib/peddler/marketplace.rb +93 -0
- data/lib/peddler/response.rb +46 -0
- data/lib/peddler/token.rb +70 -0
- data/lib/peddler/version.rb +1 -1
- data/lib/peddler.rb +55 -52
- metadata +64 -57
- data/lib/peddler/access_token.rb +0 -76
- data/lib/peddler/api/easy_ship_2022_03_23.rb +0 -108
- data/lib/peddler/api/listings_items_2020_09_01.rb +0 -84
- data/lib/peddler/api/listings_items_2021_08_01.rb +0 -154
- data/lib/peddler/api/merchant_fulfillment_v0.rb +0 -64
- data/lib/peddler/api/product_fees_v0.rb +0 -69
- data/lib/peddler/api/shipment_invoicing_v0.rb +0 -46
- data/lib/peddler/api/shipping_v1.rb +0 -107
- data/lib/peddler/api/supply_sources_2020_07_01.rb +0 -82
- data/lib/peddler/api/vendor_direct_fulfillment_sandbox_test_data_2021_10_28.rb +0 -35
- data/lib/peddler/api/vendor_direct_fulfillment_shipping_v1.rb +0 -165
- data/lib/peddler/api/vendor_invoices_v1.rb +0 -22
- data/lib/peddler/api/vendor_shipments_v1.rb +0 -120
- data/lib/peddler/region.rb +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 989f5bec7dce426405b687e65c4677fe8b359b355d815df799a048ef1907809f
|
4
|
+
data.tar.gz: eec2f1236bf285bf00c7d32e1482ae2fadaadeb2db9f0bc0a9beb64cf3ec7072
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 361ce5ea21116bbc09efb9590d080db5275f35dbc6717ccd318c291eb32e4b122b24d06ad4f78c9c693298d8e6e70fc81f3d7a128b843b7949579a601683bf91
|
7
|
+
data.tar.gz: 956ad0c6b2b7d1a490dffbf846a4c4415e1323510ac52c0eebdb2b42835f5a2f14354f2e0d16fa19099d0823ed47f09218255e98973735e7ccfa1579f08ccefa
|
data/README.md
CHANGED
@@ -4,9 +4,16 @@
|
|
4
4
|
[][maintainability]
|
5
5
|
[][test-coverage]
|
6
6
|
|
7
|
+
> **_NOTE:_** This README explains the main branch, which may contain unreleased code. For the README of the latest release, please refer to [this link][latest-release-readme].
|
8
|
+
|
7
9
|
**Peddler** is a Ruby interface to the [Amazon Selling Partner API (SP-API)][docs-overview]. The SP-API enables Amazon sellers and vendors to programmatically access their data on orders, shipments, payments, and more.
|
8
10
|
|
9
|
-
|
11
|
+
Peddler is automatically generated from the Open API models provided by Amazon.
|
12
|
+
|
13
|
+
To begin using the Amazon SP-API, you must [register as a developer][register-as-developer] and [register your application][register-application]. Once registered, [obtain your Login with Amazon (LWA) credentials][view-credentials] to access your own or other selling partners' data.
|
14
|
+
|
15
|
+
- [API models][api-models]
|
16
|
+
- [API samples][api-samples]
|
10
17
|
|
11
18
|

|
12
19
|
|
@@ -15,7 +22,7 @@ To begin using the Amazon SP-API, you must [register as a developer][register-as
|
|
15
22
|
Add this line to your Gemfile.
|
16
23
|
|
17
24
|
```ruby
|
18
|
-
gem "peddler", "3.0
|
25
|
+
gem "peddler", "~> 3.0"
|
19
26
|
```
|
20
27
|
|
21
28
|
And then execute:
|
@@ -39,53 +46,65 @@ Require the library.
|
|
39
46
|
require "peddler"
|
40
47
|
```
|
41
48
|
|
42
|
-
###
|
49
|
+
### Authorization
|
43
50
|
|
44
|
-
A seller or vendor
|
51
|
+
A seller or vendor [provides you a refresh token][authorization] to access their data on Amazon.
|
45
52
|
|
46
53
|
```ruby
|
47
|
-
|
54
|
+
refresh_token = Peddled::Token.request(
|
55
|
+
code: "<AUTHORIZATION_CODE>"
|
56
|
+
).parse["refresh_token"]
|
57
|
+
```
|
58
|
+
|
59
|
+
You use this to generate a temporary access token to authenticate individual API requests.
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
access_token = Peddler::Token.request(
|
48
63
|
refresh_token: "<REFRESH_TOKEN>",
|
49
|
-
)
|
64
|
+
).parse["access_token"]
|
50
65
|
```
|
51
66
|
|
52
|
-
|
67
|
+
Similarly, you can request a token for grantless operations.
|
53
68
|
|
54
69
|
```ruby
|
55
|
-
access_token = Peddler::
|
70
|
+
access_token = Peddler::Token.request(
|
56
71
|
scope: "sellingpartnerapi::notifications",
|
57
|
-
)
|
72
|
+
).parse["access_token"]
|
58
73
|
```
|
59
74
|
|
60
|
-
|
61
|
-
|
62
|
-
If you haven’t set your LWA credentials as environment variables, you can pass them directly when requesting an access token:
|
75
|
+
If you haven’t set your LWA credentials as environment variables, pass them directly when requesting the token.
|
63
76
|
|
64
77
|
```ruby
|
65
|
-
access_token = Peddler::
|
78
|
+
access_token = Peddler::Token.request(
|
66
79
|
client_id: "<YOUR_CLIENT_ID>",
|
67
80
|
client_secret: "<YOUR_CLIENT_SECRET>",
|
68
81
|
refresh_token: "<REFRESH_TOKEN>",
|
69
|
-
)
|
82
|
+
).parse["access_token"]
|
70
83
|
```
|
71
84
|
|
72
|
-
|
85
|
+
Access tokens are valid for one hour. To optimize performance, cache the token and reuse across calls.
|
73
86
|
|
74
|
-
|
75
|
-
|
76
|
-
**Note:** This functionality requires version 6 of the underlying [HTTP library][httprb]. As of writing, this is not released yet. To use rate limiting, point to the main branch of their GitHub repo:
|
87
|
+
In Rails, if you're storing a refresh token in a model representing a selling partner, implement a method there to retrieve and cache access tokens:
|
77
88
|
|
78
89
|
```ruby
|
79
|
-
|
90
|
+
class Seller
|
91
|
+
"..."
|
92
|
+
|
93
|
+
def access_token
|
94
|
+
Rails.cache.fetch("#{cache_key}/access_key", expires_in: 1.hour) do
|
95
|
+
Peddler::Token.request(
|
96
|
+
refresh_token:,
|
97
|
+
).parse["access_token"]
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
80
101
|
```
|
81
102
|
|
82
|
-
|
103
|
+
### Rate limiting
|
83
104
|
|
84
|
-
|
85
|
-
@api.rate_limit(5).get_item_offers_batch(...)
|
86
|
-
```
|
105
|
+
Amazon’s Selling Partner API (SP-API) imposes [rate limits][rate-limits] on most operations. Peddler respects these limits and automatically backs off when throttled. To override the default rate limit, pass a `:rate_limit` argument when running an operation.
|
87
106
|
|
88
|
-
This
|
107
|
+
**Note:** This functionality requires version 6 of the underlying [HTTP library][httprb]. As of writing, this is not released yet. To use rate limiting, point to their main branch on GitHub.
|
89
108
|
|
90
109
|
### The APIs
|
91
110
|
|
@@ -95,42 +114,37 @@ Peddler provides a class for each API version under an eponymous namespace. Belo
|
|
95
114
|
|
96
115
|
Provides programmatic access to Amazon's catalog data, such as item titles, descriptions, and other product details.
|
97
116
|
|
98
|
-
**Example:**
|
99
|
-
|
100
117
|
```ruby
|
101
|
-
|
102
|
-
response =
|
118
|
+
api = Peddler.catalog_items_2022_04_01(aws_region, access_token)
|
119
|
+
response = api.get_catalog_item(
|
103
120
|
marketplaceIds: ["ATVPDKIKX0DER"],
|
104
121
|
asin: "B08N5WRWNW"
|
105
122
|
)
|
106
|
-
items = response.
|
123
|
+
items = response.dig("items")
|
107
124
|
```
|
108
125
|
|
109
126
|
#### Orders API (v0)
|
110
127
|
|
111
128
|
Allows you to retrieve order information, including order details, buyer information, and order items.
|
112
129
|
|
113
|
-
**Example:**
|
114
|
-
|
115
130
|
```ruby
|
116
|
-
|
117
|
-
response =
|
131
|
+
api = Peddler.orders_v0(aws_region, access_token)
|
132
|
+
response = api.get_orders(
|
118
133
|
marketplaceIds: ["ATVPDKIKX0DER"],
|
119
134
|
createdAfter: "2023-01-01T00:00:00Z"
|
120
135
|
)
|
121
|
-
|
136
|
+
response.dig("orders")
|
122
137
|
```
|
123
138
|
|
124
139
|
#### Feeds API (2021-06-30)
|
125
140
|
|
126
141
|
Enables you to upload data to Amazon for updating listings, prices, inventory, and more.
|
127
142
|
|
128
|
-
**Example:**
|
129
|
-
|
130
143
|
```ruby
|
131
|
-
|
144
|
+
api = Peddler.feeds_2021_06_30(aws_region, access_token)
|
145
|
+
|
132
146
|
# Create a feed document to get an upload URL
|
133
|
-
response =
|
147
|
+
response = api.create_feed_document(
|
134
148
|
contentType: "text/xml; charset=UTF-8"
|
135
149
|
)
|
136
150
|
feed_document_id = response.parse["feedDocumentId"]
|
@@ -138,41 +152,37 @@ upload_url = response.parse["url"]
|
|
138
152
|
|
139
153
|
# Upload the feed content to the provided URL
|
140
154
|
feed_content = File.read("inventory_update.xml")
|
141
|
-
|
155
|
+
api.upload_feed_document(upload_url, feed_content, "text/xml; charset=UTF-8")
|
142
156
|
|
143
157
|
# Create the feed
|
144
|
-
response =
|
158
|
+
response = api.create_feed(
|
145
159
|
feedType: "POST_INVENTORY_AVAILABILITY_DATA",
|
146
160
|
marketplaceIds: ["ATVPDKIKX0DER"],
|
147
161
|
inputFeedDocumentId: feed_document_id
|
148
162
|
)
|
149
|
-
|
163
|
+
response.parse["feedId"]
|
150
164
|
```
|
151
165
|
|
152
166
|
#### Reports API (2021-06-30)
|
153
167
|
|
154
168
|
Allows you to request and download various reports, such as order and inventory reports.
|
155
169
|
|
156
|
-
**Example:**
|
157
|
-
|
158
170
|
```ruby
|
159
|
-
|
160
|
-
response =
|
171
|
+
api = Peddler.reports_2021_06_30(aws_region, access_token)
|
172
|
+
response = api.create_report(
|
161
173
|
reportType: "GET_FLAT_FILE_OPEN_LISTINGS_DATA",
|
162
174
|
marketplaceIds: ["ATVPDKIKX0DER"]
|
163
175
|
)
|
164
|
-
|
176
|
+
response.parse["reportId"]
|
165
177
|
```
|
166
178
|
|
167
179
|
#### Listings Items API (2021-08-01)
|
168
180
|
|
169
181
|
Enables you to manage your product listings on Amazon, including creating, updating, and deleting listings.
|
170
182
|
|
171
|
-
**Example:**
|
172
|
-
|
173
183
|
```ruby
|
174
|
-
|
175
|
-
response =
|
184
|
+
api = Peddler.listings_items_2021_08_01(aws_region, access_token)
|
185
|
+
response = api.put_listings_item(
|
176
186
|
"<SELLER_ID>",
|
177
187
|
"SKU123",
|
178
188
|
"ATVPDKIKX0DER",
|
@@ -187,19 +197,17 @@ response = client.put_listings_item(
|
|
187
197
|
}
|
188
198
|
}
|
189
199
|
)
|
190
|
-
|
200
|
+
response.parse
|
191
201
|
```
|
192
202
|
|
193
203
|
#### Notifications API (v1)
|
194
204
|
|
195
205
|
Allows you to subscribe to notifications for specific events like order status updates or feed processing statuses.
|
196
206
|
|
197
|
-
**Example:**
|
198
|
-
|
199
207
|
```ruby
|
200
|
-
|
208
|
+
api = Peddler.notifications_v1(aws_region, access_token)
|
201
209
|
# Create a destination
|
202
|
-
response =
|
210
|
+
response = api.create_destination(
|
203
211
|
name: "MySQSQueue",
|
204
212
|
resourceSpecification: {
|
205
213
|
sqs: {
|
@@ -210,7 +218,7 @@ response = client.create_destination(
|
|
210
218
|
destination_id = response.parse["destinationId"]
|
211
219
|
|
212
220
|
# Create a subscription
|
213
|
-
response =
|
221
|
+
response = api.create_subscription(
|
214
222
|
notificationType: "ANY_OFFER_CHANGED",
|
215
223
|
destinationId: destination_id
|
216
224
|
)
|
@@ -221,11 +229,9 @@ subscription = response.parse
|
|
221
229
|
|
222
230
|
Provides information about fees that may be charged for selling products on Amazon.
|
223
231
|
|
224
|
-
**Example:**
|
225
|
-
|
226
232
|
```ruby
|
227
|
-
|
228
|
-
response =
|
233
|
+
api = Peddler.product_fees_v0(aws_region, access_token)
|
234
|
+
response = api.get_my_fees_estimate_for_sku(
|
229
235
|
sellerId: "<YOUR_SELLER_ID>",
|
230
236
|
sku: "SKU123",
|
231
237
|
body: {
|
@@ -248,11 +254,9 @@ fees_estimate = response.parse
|
|
248
254
|
|
249
255
|
Allows you to create and manage fulfillment orders using Amazon's fulfillment network.
|
250
256
|
|
251
|
-
**Example:**
|
252
|
-
|
253
257
|
```ruby
|
254
|
-
|
255
|
-
response =
|
258
|
+
api = Peddler.fulfillment_outbound_2020_07_01(aws_region, access_token)
|
259
|
+
response = api.create_fulfillment_order(
|
256
260
|
body: {
|
257
261
|
sellerFulfillmentOrderId: "ORDER123",
|
258
262
|
displayableOrderId: "ORDER123",
|
@@ -276,18 +280,16 @@ response = client.create_fulfillment_order(
|
|
276
280
|
]
|
277
281
|
}
|
278
282
|
)
|
279
|
-
|
283
|
+
response.parse
|
280
284
|
```
|
281
285
|
|
282
286
|
#### Merchant Fulfillment API (v0)
|
283
287
|
|
284
288
|
Allows you to create shipping labels for orders using Amazon's negotiated shipping rates.
|
285
289
|
|
286
|
-
**Example:**
|
287
|
-
|
288
290
|
```ruby
|
289
|
-
|
290
|
-
response =
|
291
|
+
api = Peddler.merchant_fulfillment_v0(aws_region, access_token)
|
292
|
+
response = api.get_eligible_shipping_services(
|
291
293
|
body: {
|
292
294
|
shipmentRequestDetails: {
|
293
295
|
amazonOrderId: "ORDER123",
|
@@ -329,11 +331,9 @@ shipping_services = response.parse["shippingServiceList"]
|
|
329
331
|
|
330
332
|
Allows vendors to retrieve purchase orders and order details from Amazon.
|
331
333
|
|
332
|
-
**Example:**
|
333
|
-
|
334
334
|
```ruby
|
335
|
-
|
336
|
-
response =
|
335
|
+
api = Peddler.vendor_orders_2021_12_28(aws_region, access_token)
|
336
|
+
response = api.get_purchase_orders(
|
337
337
|
shipToPartyId: "<PARTY_ID>",
|
338
338
|
limit: 10,
|
339
339
|
createdAfter: "2023-01-01T00:00:00Z"
|
@@ -345,40 +345,34 @@ purchase_orders = response.parse["purchaseOrders"]
|
|
345
345
|
|
346
346
|
Enables vendors to manage shipping labels and shipping information for direct fulfillment orders.
|
347
347
|
|
348
|
-
**Example:**
|
349
|
-
|
350
348
|
```ruby
|
351
|
-
|
352
|
-
response =
|
349
|
+
api = Peddler.vendor_direct_fulfillment_shipping_2021_12_28(aws_region, access_token)
|
350
|
+
response = api.get_packing_slip(
|
353
351
|
purchaseOrderNumber: "PO123456789"
|
354
352
|
)
|
355
|
-
|
353
|
+
response.parse
|
356
354
|
```
|
357
355
|
|
358
356
|
#### Vendor Direct Fulfillment Orders API (2021-12-28)
|
359
357
|
|
360
358
|
Allows vendors to receive orders for direct fulfillment and provide shipment confirmations.
|
361
359
|
|
362
|
-
**Example:**
|
363
|
-
|
364
360
|
```ruby
|
365
|
-
|
366
|
-
response =
|
361
|
+
api = Peddler.vendor_direct_fulfillment_orders_2021_12_28(aws_region, access_token)
|
362
|
+
response = api.get_orders(
|
367
363
|
createdAfter: "2023-01-01T00:00:00Z",
|
368
364
|
limit: 10
|
369
365
|
)
|
370
|
-
|
366
|
+
response.parse["orders"]
|
371
367
|
```
|
372
368
|
|
373
369
|
#### Vendor Direct Fulfillment Inventory API (2021-12-28)
|
374
370
|
|
375
371
|
Enables vendors to update inventory levels for direct fulfillment items.
|
376
372
|
|
377
|
-
**Example:**
|
378
|
-
|
379
373
|
```ruby
|
380
|
-
|
381
|
-
response =
|
374
|
+
api = Peddler.vendor_direct_fulfillment_inventory_2021_12_28(aws_region, access_token)
|
375
|
+
response = api.submit_inventory_update(
|
382
376
|
body: {
|
383
377
|
inventory: [
|
384
378
|
{
|
@@ -399,18 +393,16 @@ response = client.submit_inventory_update(
|
|
399
393
|
]
|
400
394
|
}
|
401
395
|
)
|
402
|
-
|
396
|
+
response.parse
|
403
397
|
```
|
404
398
|
|
405
399
|
#### Shipping API (v2)
|
406
400
|
|
407
401
|
Provides functionalities for purchasing shipping labels and tracking shipments.
|
408
402
|
|
409
|
-
**Example:**
|
410
|
-
|
411
403
|
```ruby
|
412
|
-
|
413
|
-
response =
|
404
|
+
api = Peddler.shipping_v2(aws_region, access_token)
|
405
|
+
response = api.purchase_shipment(
|
414
406
|
body: {
|
415
407
|
clientReferenceId: "CLIENT_REF_123",
|
416
408
|
shipTo: {
|
@@ -446,18 +438,16 @@ response = client.purchase_shipment(
|
|
446
438
|
serviceType: "Standard"
|
447
439
|
}
|
448
440
|
)
|
449
|
-
|
441
|
+
response.parse
|
450
442
|
```
|
451
443
|
|
452
444
|
#### Token API (2021-03-01)
|
453
445
|
|
454
446
|
Allows you to create restricted data tokens to access personally identifiable information (PII) in specific API calls.
|
455
447
|
|
456
|
-
**Example:**
|
457
|
-
|
458
448
|
```ruby
|
459
|
-
|
460
|
-
response =
|
449
|
+
api = Peddler.tokens_2021_03_01(aws_region, access_token)
|
450
|
+
response = api.create_restricted_data_token(
|
461
451
|
body: {
|
462
452
|
restrictedResources: [
|
463
453
|
{
|
@@ -471,46 +461,54 @@ response = client.create_restricted_data_token(
|
|
471
461
|
restricted_data_token = response.parse["restrictedDataToken"]
|
472
462
|
|
473
463
|
# Use the token in subsequent API calls
|
474
|
-
|
475
|
-
response =
|
464
|
+
orders_api = Peddler.orders_2021_12_01("<AWS_REGION>", restricted_data_token)
|
465
|
+
response = orders_api.get_order(
|
476
466
|
orderId: "123-1234567-1234567"
|
477
467
|
)
|
478
|
-
|
468
|
+
response.parse
|
479
469
|
```
|
480
470
|
|
481
471
|
#### Finances API (v0)
|
482
472
|
|
483
473
|
Provides information about financial events for your seller account, such as order payments, refunds, and fees.
|
484
474
|
|
485
|
-
**Example:**
|
486
|
-
|
487
475
|
```ruby
|
488
|
-
|
489
|
-
response =
|
476
|
+
api = Peddler.finances_v0(aws_region, access_token)
|
477
|
+
response = api.list_financial_events(
|
490
478
|
postedAfter: "2023-01-01T00:00:00Z",
|
491
479
|
maxResultsPerPage: 100
|
492
480
|
)
|
493
|
-
|
481
|
+
response.parse
|
494
482
|
```
|
495
483
|
|
496
484
|
#### Sellers API (V1)
|
497
485
|
|
498
486
|
Provides information about seller's marketplaces and participation status.
|
499
487
|
|
500
|
-
**Example:**
|
501
|
-
|
502
488
|
```ruby
|
503
|
-
|
504
|
-
response =
|
505
|
-
|
489
|
+
api = Peddler.sellers_v1(aws_region, access_token)
|
490
|
+
response = api.get_marketplace_participations
|
491
|
+
response.parse
|
506
492
|
```
|
507
493
|
|
494
|
+
## TODO
|
495
|
+
|
496
|
+
- Code generate models to parse payload. Consider using `dry-struct`.
|
497
|
+
- Code generate the APIs section—descriptions and code examples—in this README here.
|
498
|
+
- Schedule code generation with GitHub Actions. Push new gem when models change.
|
499
|
+
- Review and consider applying [these patches][patches].
|
500
|
+
|
508
501
|
[build]: https://github.com/hakanensari/peddler/actions
|
509
502
|
[maintainability]: https://codeclimate.com/github/hakanensari/peddler/maintainability
|
510
503
|
[test-coverage]: https://codeclimate.com/github/hakanensari/peddler/test_coverage
|
504
|
+
[latest-release-readme]: https://github.com/lineofflight/peddler/tree/v3.0.0
|
511
505
|
[docs-overview]: https://developer.amazonservices.com/sp-api-docs/overview
|
512
506
|
[register-as-developer]: https://developer-docs.amazon.com/sp-api/docs/registering-as-a-developer
|
513
507
|
[register-application]: https://developer-docs.amazon.com/sp-api/docs/registering-your-application
|
508
|
+
[api-models]: https://github.com/amzn/selling-partner-api-models
|
509
|
+
[api-samples]: https://github.com/amzn/selling-partner-api-samples
|
514
510
|
[view-credentials]: https://developer-docs.amazon.com/sp-api/docs/viewing-your-application-information-and-credentials
|
515
511
|
[authorization]: https://developer-docs.amazon.com/sp-api/docs/authorizing-selling-partner-api-applications
|
512
|
+
[rate-limits]: https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits
|
516
513
|
[httprb]: https://github.com/httprb/http
|
514
|
+
[patches]: https://github.com/bizon/selling-partner-api-sdk/tree/master/codegen/patches
|
data/lib/peddler/api.rb
CHANGED
@@ -2,14 +2,25 @@
|
|
2
2
|
|
3
3
|
require "http"
|
4
4
|
|
5
|
+
require "peddler/endpoint"
|
5
6
|
require "peddler/error"
|
6
|
-
require "peddler/
|
7
|
+
require "peddler/marketplace"
|
8
|
+
require "peddler/response"
|
9
|
+
require "peddler/version"
|
7
10
|
|
8
11
|
module Peddler
|
9
12
|
# Wraps an Amazon Selling Partner API (SP-API)
|
10
13
|
class API
|
11
|
-
|
12
|
-
|
14
|
+
class CannotSandbox < StandardError; end
|
15
|
+
class MustSandbox < StandardError; end
|
16
|
+
|
17
|
+
class << self
|
18
|
+
# @return [#call]
|
19
|
+
attr_accessor :parser
|
20
|
+
end
|
21
|
+
|
22
|
+
# @return [Peddler::Endpoint]
|
23
|
+
attr_reader :endpoint
|
13
24
|
|
14
25
|
# @return [String]
|
15
26
|
attr_reader :access_token
|
@@ -17,41 +28,52 @@ module Peddler
|
|
17
28
|
# @param [String] aws_region
|
18
29
|
# @param [String] access_token
|
19
30
|
def initialize(aws_region, access_token)
|
20
|
-
@
|
31
|
+
@endpoint = Endpoint.find(aws_region)
|
21
32
|
@access_token = access_token
|
33
|
+
@sandbox = false
|
22
34
|
end
|
23
35
|
|
24
|
-
|
25
|
-
|
36
|
+
# @return [URI::HTTPS]
|
37
|
+
def endpoint_uri
|
38
|
+
sandbox? ? endpoint.sandbox : endpoint.production
|
26
39
|
end
|
27
40
|
|
41
|
+
# Switches to the SP-API sandbox to make test calls
|
42
|
+
#
|
28
43
|
# @see https://developer-docs.amazon.com/sp-api/docs/the-selling-partner-api-sandbox
|
29
44
|
# @return [self]
|
30
45
|
def sandbox
|
31
|
-
@
|
46
|
+
@sandbox = true
|
32
47
|
self
|
33
48
|
end
|
34
49
|
|
50
|
+
# @return [Boolean]
|
51
|
+
def sandbox?
|
52
|
+
@sandbox
|
53
|
+
end
|
54
|
+
|
35
55
|
# @see https://developer-docs.amazon.com/sp-api/docs/include-a-user-agent-header-in-all-requests
|
36
56
|
# @see https://developer-docs.amazon.com/amazon-shipping/docs/connecting-to-the-selling-partner-api#step-3-add-headers-to-the-uri
|
37
57
|
# @return [HTTP::Client]
|
38
58
|
def http
|
39
59
|
@http ||= HTTP.headers(
|
40
|
-
"Host" =>
|
60
|
+
"Host" => endpoint_uri.host,
|
41
61
|
"User-Agent" => user_agent,
|
42
62
|
"X-Amz-Access-Token" => access_token,
|
43
63
|
"X-Amz-Date" => timestamp,
|
44
64
|
)
|
45
65
|
end
|
46
66
|
|
47
|
-
#
|
67
|
+
# Throttles with a rate limit and retries when the API returns a 429
|
48
68
|
#
|
49
|
-
# @param [Float]
|
69
|
+
# @param [Float] rate_limit The delay in seconds before retrying
|
50
70
|
# @return [self]
|
51
|
-
def rate_limit
|
52
|
-
# HTTP v6.0 will implement retriable
|
71
|
+
def meter(rate_limit)
|
72
|
+
# HTTP v6.0 will implement retriable. Until then, point to their GitHub repo, or it's a no-op.
|
53
73
|
# https://github.com/httprb/http/pull/790
|
54
|
-
|
74
|
+
delay = sandbox? ? 0.2 : 1.0 / rate_limit
|
75
|
+
retriable(delay: delay, retry_statuses: [429])
|
76
|
+
|
55
77
|
self
|
56
78
|
end
|
57
79
|
|
@@ -75,7 +97,7 @@ module Peddler
|
|
75
97
|
# @return [self]
|
76
98
|
[:via, :use, :retriable].each do |method|
|
77
99
|
define_method(method) do |*args, &block|
|
78
|
-
@http = http.send(method, *args, &block)
|
100
|
+
@http = http.send(method, *args, &block) if http.respond_to?(method)
|
79
101
|
self
|
80
102
|
end
|
81
103
|
end
|
@@ -87,21 +109,37 @@ module Peddler
|
|
87
109
|
options[:json] = options.delete(:body)
|
88
110
|
end
|
89
111
|
|
90
|
-
|
112
|
+
uri = endpoint_uri.tap do |uri|
|
113
|
+
uri.path = path
|
114
|
+
end
|
115
|
+
|
116
|
+
response = http.send(method, uri, **options)
|
91
117
|
|
92
118
|
if response.status.client_error?
|
93
119
|
error = Error.build(response)
|
94
120
|
raise error if error
|
95
121
|
end
|
96
122
|
|
97
|
-
response
|
123
|
+
Response.decorate(response, parser:)
|
98
124
|
end
|
99
125
|
end
|
100
126
|
|
127
|
+
attr_writer :parser
|
128
|
+
|
129
|
+
# @!attribute parser
|
130
|
+
# @return [#call]
|
131
|
+
def parser
|
132
|
+
@parser || self.class.parser
|
133
|
+
end
|
134
|
+
|
101
135
|
private
|
102
136
|
|
103
|
-
def
|
104
|
-
|
137
|
+
def cannot_sandbox!
|
138
|
+
raise CannotSandbox, "cannot run in a sandbox" if sandbox?
|
139
|
+
end
|
140
|
+
|
141
|
+
def must_sandbox!
|
142
|
+
raise MustSandbox, "must run in a sandbox" unless sandbox?
|
105
143
|
end
|
106
144
|
|
107
145
|
def user_agent
|