peddler 4.3.1 → 4.4.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.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +328 -109
  3. data/lib/peddler/api.rb +11 -0
  4. data/lib/peddler/apis/amazon_warehousing_and_distribution_2024_05_09.rb +7 -7
  5. data/lib/peddler/apis/aplus_content_2020_11_01.rb +10 -10
  6. data/lib/peddler/apis/application_integrations_2024_04_01.rb +1 -1
  7. data/lib/peddler/apis/catalog_items_2020_12_01.rb +8 -8
  8. data/lib/peddler/apis/catalog_items_2022_04_01.rb +9 -9
  9. data/lib/peddler/apis/data_kiosk_2023_11_15.rb +4 -4
  10. data/lib/peddler/apis/fba_inbound_eligibility_v1.rb +1 -1
  11. data/lib/peddler/apis/fba_inventory_v1.rb +3 -3
  12. data/lib/peddler/apis/feeds_2021_06_30.rb +6 -6
  13. data/lib/peddler/apis/finances_2024_06_01.rb +1 -1
  14. data/lib/peddler/apis/finances_v0.rb +2 -2
  15. data/lib/peddler/apis/fulfillment_inbound_2024_03_20.rb +40 -40
  16. data/lib/peddler/apis/fulfillment_inbound_v0.rb +8 -8
  17. data/lib/peddler/apis/fulfillment_outbound_2020_07_01.rb +7 -7
  18. data/lib/peddler/apis/invoices_2024_06_19.rb +4 -4
  19. data/lib/peddler/apis/listings_items_2020_09_01.rb +6 -6
  20. data/lib/peddler/apis/listings_items_2021_08_01.rb +20 -26
  21. data/lib/peddler/apis/listings_restrictions_2021_08_01.rb +1 -1
  22. data/lib/peddler/apis/merchant_fulfillment_v0.rb +2 -2
  23. data/lib/peddler/apis/messaging_v1.rb +26 -26
  24. data/lib/peddler/apis/notifications_v1.rb +6 -6
  25. data/lib/peddler/apis/orders_v0.rb +16 -16
  26. data/lib/peddler/apis/product_fees_v0.rb +2 -2
  27. data/lib/peddler/apis/product_pricing_v0.rb +6 -6
  28. data/lib/peddler/apis/product_type_definitions_2020_09_01.rb +4 -4
  29. data/lib/peddler/apis/reports_2021_06_30.rb +9 -9
  30. data/lib/peddler/apis/sales_v1.rb +7 -2
  31. data/lib/peddler/apis/seller_wallet_2024_03_01.rb +5 -5
  32. data/lib/peddler/apis/services_v1.rb +27 -27
  33. data/lib/peddler/apis/shipment_invoicing_v0.rb +3 -3
  34. data/lib/peddler/apis/shipping_v1.rb +5 -5
  35. data/lib/peddler/apis/shipping_v2.rb +6 -6
  36. data/lib/peddler/apis/solicitations_v1.rb +4 -4
  37. data/lib/peddler/apis/supply_sources_2020_07_01.rb +4 -4
  38. data/lib/peddler/apis/uploads_2020_11_01.rb +2 -2
  39. data/lib/peddler/apis/vendor_direct_fulfillment_inventory_v1.rb +1 -1
  40. data/lib/peddler/apis/vendor_direct_fulfillment_orders_2021_12_28.rb +1 -1
  41. data/lib/peddler/apis/vendor_direct_fulfillment_orders_v1.rb +1 -1
  42. data/lib/peddler/apis/vendor_direct_fulfillment_sandbox_test_data_2021_10_28.rb +1 -1
  43. data/lib/peddler/apis/vendor_direct_fulfillment_shipping_2021_12_28.rb +4 -4
  44. data/lib/peddler/apis/vendor_direct_fulfillment_shipping_v1.rb +3 -3
  45. data/lib/peddler/apis/vendor_direct_fulfillment_transactions_2021_12_28.rb +1 -1
  46. data/lib/peddler/apis/vendor_direct_fulfillment_transactions_v1.rb +1 -1
  47. data/lib/peddler/apis/vendor_orders_v1.rb +1 -1
  48. data/lib/peddler/apis/vendor_transaction_status_v1.rb +1 -1
  49. data/lib/peddler/error.rb +16 -4
  50. data/lib/peddler/token.rb +6 -11
  51. data/lib/peddler/version.rb +1 -1
  52. data/lib/peddler.rb +51 -0
  53. metadata +1 -3
  54. data/lib/peddler/parsers/openapi_parser_generator.rb +0 -550
  55. data/lib/peddler/parsers/smart_parser.rb +0 -199
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cfb5b2595fa619d422cd487a9c07a54659a5152d4e2168abf69af45ec98fff68
4
- data.tar.gz: 1c950c5f13fe1837c36d6035b4e36ffe9c28687a3425fb5db753cd5bf0b72edf
3
+ metadata.gz: 747dd42d445c711adc43f20e6a9c479bf795352512fecc67814f1a5f698c86a9
4
+ data.tar.gz: 134255293900b9c32086f2291a42498e1477f29df64cbe0aa8b3da1420dfe320
5
5
  SHA512:
6
- metadata.gz: 8cc66a461269368582b15cef95c2209d9fe1c969cad00a58ab6d7d7a7771540686baa919b8067aa447de6b47f1543206929a7e47a403f74d3efbdc8cfe9a0cc5
7
- data.tar.gz: c93c7d80ebbc031cdf8c4a02e58f10878745e461b129260b442cc5eaf3de36c219cd56756573aec55976824aa4d7ed243e044b5ef5d89af7039a4cade3fec187
6
+ metadata.gz: 5880a513c77e79ae8523ca96c69d65697c179ede0febc18f2b4a10d932e7de9ed32cdf74c82ff13bc68ca7c15ae6df9d84ec92150d7bc018da6778e104dcb889
7
+ data.tar.gz: 60b00292980fdac6da6acccac237b0ce677f7e49cb001f72584426aa70d54deac3c84d9e89abc5e380cf94aecda6db0d695d39868644380acb8c86603245e30d
data/README.md CHANGED
@@ -11,7 +11,7 @@ To begin using the Amazon SP-API, you must [register as a developer][register-as
11
11
  - [API models][api-models]
12
12
  - [API samples][api-samples]
13
13
 
14
- ![Peddler](https://github.com/hakanensari/peddler/blob/main/images/peddler.jpg?raw=true)
14
+ <img src="https://github.com/hakanensari/peddler/blob/main/images/peddler.jpg?raw=true" alt="Peddler" style="max-width: 830px" />
15
15
 
16
16
  ## Installation
17
17
 
@@ -120,124 +120,89 @@ Peddler provides Ruby interfaces to all Amazon SP-API endpoints. Each API is ava
120
120
  api = Peddler.<api_name>_<version>(aws_region, access_token, options)
121
121
  ```
122
122
 
123
- Below are key APIs with examples of their usage:
124
-
125
- #### Orders API (v0)
126
-
127
- Retrieve order information and manage orders.
123
+ You can also simply initialize the latest version:
128
124
 
129
125
  ```ruby
130
- api = Peddler.orders_v0(aws_region, access_token)
131
- response = api.get_orders(
132
- marketplaceIds: ["ATVPDKIKX0DER"],
133
- createdAfter: "2023-01-01T00:00:00Z"
134
- )
135
- orders = response.parse["orders"]
126
+ api = Peddler.<api_name>(aws_region, access_token, options)
136
127
  ```
137
128
 
138
- #### Catalog Items API (2022-04-01, 2020-12-01, v0)
139
-
140
- Access Amazon's catalog data including product details, offers, and competitive pricing.
141
-
142
- ```ruby
143
- api = Peddler.catalog_items_2022_04_01(aws_region, access_token)
144
- response = api.get_catalog_item(
145
- marketplaceIds: ["ATVPDKIKX0DER"],
146
- asin: "B08N5WRWNW"
147
- )
148
- item_details = response.parse["payload"]
149
- ```
129
+ Below is a comprehensive list of all available APIs organized by category:
150
130
 
151
- #### Feeds API (2021-06-30)
131
+ #### Orders and Financial APIs
152
132
 
153
- Upload data to Amazon to update listings, prices, inventory, and more.
133
+ - **Orders API (v0)**: Retrieve and manage orders
134
+ - **Finances API (2024-06-19, 2024-06-01, v0)**: Get financial data including transaction details, payments, and refunds
135
+ - **Invoices API (2024-06-19)**: Manage billing invoices
136
+ - **Sales API (v1)**: Get order metrics and sales data
154
137
 
155
138
  ```ruby
156
- api = Peddler.feeds_2021_06_30(aws_region, access_token)
157
-
158
- # Create feed document
159
- document_response = api.create_feed_document(
160
- contentType: "text/xml; charset=UTF-8"
161
- )
162
- feed_document_id = document_response.parse["feedDocumentId"]
163
- upload_url = document_response.parse["url"]
164
-
165
- # Upload feed content
166
- feed_content = File.read("inventory_update.xml")
167
- api.upload_feed_document(upload_url, feed_content, "text/xml; charset=UTF-8")
168
-
169
- # Create feed
170
- feed_response = api.create_feed(
171
- feedType: "POST_INVENTORY_AVAILABILITY_DATA",
139
+ api = Peddler.orders(aws_region, access_token)
140
+ response = api.get_orders(
172
141
  marketplaceIds: ["ATVPDKIKX0DER"],
173
- inputFeedDocumentId: feed_document_id
142
+ createdAfter: "2023-01-01T00:00:00Z"
174
143
  )
175
- feed_id = feed_response.parse["feedId"]
176
- ```
177
144
 
178
- #### Reports API (2021-06-30)
145
+ # Use the `dig` method to safely navigate through nested response data
146
+ # This returns nil instead of raising an error if any key in the path doesn't exist
147
+ orders = response.dig("payload", "orders")
179
148
 
180
- Request and download reports about orders, inventory, fulfillment, and more.
149
+ # You can chain multiple keys to access deeply nested data
150
+ first_order_id = response.dig("payload", "orders", 0, "amazonOrderId")
181
151
 
182
- ```ruby
183
- api = Peddler.reports_2021_06_30(aws_region, access_token)
152
+ # This is safer than using chain indexing which would raise an error if any part is missing:
153
+ # response.parse["payload"]["orders"][0]["amazonOrderId"] # Error prone!
184
154
 
185
- # Request a report
186
- create_response = api.create_report(
187
- reportType: "GET_FLAT_FILE_OPEN_LISTINGS_DATA",
188
- marketplaceIds: ["ATVPDKIKX0DER"]
155
+ # For sandbox testing
156
+ api.sandbox.get_orders(
157
+ marketplaceIds: ["ATVPDKIKX0DER"],
158
+ createdAfter: "TEST_CASE_200"
189
159
  )
190
- report_id = create_response.parse["reportId"]
191
-
192
- # Check report status
193
- report = api.get_report(report_id).parse
194
-
195
- # Once processed, get the document
196
- if report["processingStatus"] == "DONE"
197
- doc_id = report["reportDocumentId"]
198
- document = api.get_report_document(doc_id).parse
199
- download_url = document["url"]
200
- # Download report from URL
201
- end
202
160
  ```
203
161
 
204
- #### Listings APIs
205
-
206
- Manage product listings with multiple APIs:
162
+ #### Catalog and Listing APIs
207
163
 
164
+ - **Catalog Items API (2022-04-01, 2020-12-01, v0)**: Access Amazon's catalog data
208
165
  - **Listings Items API (2021-08-01, 2020-09-01)**: Create and update listings
209
166
  - **Listings Restrictions API (2021-08-01)**: Check listing eligibility
210
167
  - **Product Type Definitions API (2020-09-01)**: Get schema requirements for listings
168
+ - **A+ Content API (2020-11-01)**: Create and manage enhanced marketing content
169
+ - **Product Pricing API (2022-05-01, v0)**: Get pricing information
170
+ - **Product Fees API (v0)**: Retrieve fee estimates for products
211
171
 
212
172
  ```ruby
213
- api = Peddler.listings_items_2021_08_01(aws_region, access_token)
214
- api.put_listings_item(
215
- seller_id,
216
- "SKU123",
217
- "ATVPDKIKX0DER",
218
- body: {
219
- productType: "LUGGAGE",
220
- requirements: "LISTING",
221
- attributes: {
222
- title: [{ value: "Travel Backpack" }],
223
- manufacturer: [{ value: "Brand Name" }]
224
- }
225
- }
173
+ api = Peddler.catalog_items(aws_region, access_token)
174
+ response = api.get_catalog_item(
175
+ marketplaceIds: ["ATVPDKIKX0DER"],
176
+ asin: "B08N5WRWNW"
226
177
  )
227
- ```
178
+ item_details = response.dig("payload")
228
179
 
229
- #### Fulfillment APIs
180
+ # Search catalog items by identifier
181
+ response = api.search_catalog_items(
182
+ ["ATVPDKIKX0DER"],
183
+ identifiers: "B08N5WRWNW",
184
+ identifiers_type: "ASIN"
185
+ )
186
+ search_results = response.parse
187
+ ```
230
188
 
231
- Manage inventory and fulfillment through FBA and merchant fulfillment:
189
+ #### Fulfillment and Inventory APIs
232
190
 
233
191
  - **Fulfillment Inbound API (2024-03-20, v0)**: Send inventory to FBA
234
192
  - **Fulfillment Outbound API (2020-07-01)**: Create and track FBA orders
235
193
  - **FBA Inventory API (v1)**: Manage FBA inventory quantities
194
+ - **FBA Inbound Eligibility API (v1)**: Check product eligibility for FBA
236
195
  - **Merchant Fulfillment API (v0)**: Create shipping labels for self-fulfilled orders
196
+ - **Easy Ship API (2022-03-23)**: Manage Amazon's carrier service for deliveries
197
+ - **Shipping APIs (v1, v2)**: Create shipments and purchase shipping labels
198
+ - **Replenishment API (2022-11-07)**: Manage inventory replenishment
199
+ - **Amazon Warehousing and Distribution API (2024-05-09)**: Manage fulfillment warehousing
200
+ - **Supply Sources API (2020-07-01)**: Manage supply/inventory sources
201
+ - **Shipment Invoicing API (v0)**: Manage shipment-related invoices
237
202
 
238
203
  ```ruby
239
204
  # FBA outbound example
240
- api = Peddler.fulfillment_outbound_2020_07_01(aws_region, access_token)
205
+ api = Peddler.fulfillment_outbound(aws_region, access_token)
241
206
  api.create_fulfillment_order(
242
207
  body: {
243
208
  sellerFulfillmentOrderId: "ORDER123",
@@ -263,24 +228,94 @@ api.create_fulfillment_order(
263
228
  )
264
229
  ```
265
230
 
266
- #### Financial APIs (2024-06-19, 2024-06-01, v0)
231
+ #### Data Management APIs
267
232
 
268
- Get financial data including transaction details, payments, and refunds.
233
+ - **Feeds API (2021-06-30)**: Upload data to Amazon to update listings, prices, inventory, and more
234
+ - **Reports API (2021-06-30)**: Request and download reports about orders, inventory, fulfillment, and more
235
+ - **Uploads API (2020-11-01)**: Upload files for various SP-API operations
236
+ - **Data Kiosk API (2023-11-15)**: Access and manage analytical data
269
237
 
270
238
  ```ruby
271
- api = Peddler.finances_v0(aws_region, access_token)
272
- response = api.list_financial_events(
273
- posted_after: "2023-01-01T00:00:00Z"
239
+ api = Peddler.feeds(aws_region, access_token)
240
+
241
+ # Create feed document
242
+ document_response = api.create_feed_document(
243
+ contentType: "text/xml; charset=UTF-8"
244
+ )
245
+
246
+ # The `dig` method safely navigates the response hash
247
+ # If the response structure is:
248
+ # {
249
+ # "feedDocumentId": "amzn1.tortuga.3.abc123...",
250
+ # "url": "https://s3.amazonaws.com/bucket/key...",
251
+ # "encryptionDetails": {
252
+ # "standard": "AES",
253
+ # "key": "encryption-key",
254
+ # "initializationVector": "vector-value"
255
+ # }
256
+ # }
257
+
258
+ # Access top-level keys with dig
259
+ feed_document_id = document_response.dig("feedDocumentId")
260
+ upload_url = document_response.dig("url")
261
+
262
+ # Access nested keys - returns nil if any key in the path is missing
263
+ encryption_key = document_response.dig("encryptionDetails", "key")
264
+
265
+ # Upload feed content
266
+ feed_content = File.read("inventory_update.xml")
267
+ api.upload_feed_document(upload_url, feed_content, "text/xml; charset=UTF-8")
268
+
269
+ # Create feed
270
+ feed_response = api.create_feed(
271
+ feedType: "POST_INVENTORY_AVAILABILITY_DATA",
272
+ marketplaceIds: ["ATVPDKIKX0DER"],
273
+ inputFeedDocumentId: feed_document_id
274
+ )
275
+ feed_id = feed_response.dig("feedId")
276
+
277
+ # Upload JSON feed
278
+ json_document = api.create_feed_document(
279
+ { "contentType" => "application/json; charset=UTF-8" }
274
280
  )
275
- financial_events = response.parse["FinancialEvents"]
281
+ json_feed_content = JSON.generate({
282
+ "header": {
283
+ "sellerId": "SELLER_ID",
284
+ "version": "2.0",
285
+ "issueLocale": "en_US"
286
+ },
287
+ "messages": [
288
+ {
289
+ "messageId": 1,
290
+ "sku": "SKU123",
291
+ "operationType": "UPDATE",
292
+ "productType": "PRODUCT",
293
+ "attributes": {
294
+ # Your product attributes here
295
+ }
296
+ }
297
+ ]
298
+ })
299
+ api.upload_feed_document(json_document.dig("url"), json_feed_content, "application/json; charset=UTF-8")
300
+
301
+ # Get feed status
302
+ api.get_feed(feed_id)
303
+
304
+ # Get feed document content
305
+ document = api.get_feed_document(feed_document_id)
306
+ download_url = document.dig("url")
307
+ response = HTTP.get(download_url)
308
+ content = Zlib::GzipReader.new(response).read if document.dig("compressionAlgorithm") == "GZIP"
276
309
  ```
277
310
 
278
- #### Notifications API (v1)
311
+ #### Communication and Customer Management APIs
279
312
 
280
- Subscribe to notifications for various events like order updates and report processing.
313
+ - **Notifications API (v1)**: Subscribe to notifications for events like order updates
314
+ - **Messaging API (v1)**: Send messages to customers
315
+ - **Solicitations API (v1)**: Request customer reviews
281
316
 
282
317
  ```ruby
283
- api = Peddler.notifications_v1(aws_region, access_token)
318
+ api = Peddler.notifications(aws_region, access_token)
284
319
  # Create destination
285
320
  destination = api.create_destination(
286
321
  name: "MyEventQueue",
@@ -288,7 +323,7 @@ destination = api.create_destination(
288
323
  sqs: { arn: "arn:aws:sqs:us-east-1:123456789012:MyQueue" }
289
324
  }
290
325
  )
291
- destination_id = destination.parse["payload"]["destinationId"]
326
+ destination_id = destination.dig("payload", "destinationId")
292
327
 
293
328
  # Create subscription
294
329
  api.create_subscription(
@@ -296,6 +331,14 @@ api.create_subscription(
296
331
  destinationId: destination_id,
297
332
  payloadVersion: "1"
298
333
  )
334
+
335
+ # For sandbox testing (requires grantless token)
336
+ sandbox_api = Peddler.notifications(aws_region, grantless_access_token).sandbox
337
+ # Get all destinations
338
+ destinations = sandbox_api.get_destinations
339
+
340
+ # Get specific subscription
341
+ subscription = sandbox_api.get_subscription("LISTINGS_ITEM_ISSUES_CHANGE")
299
342
  ```
300
343
 
301
344
  #### Vendor APIs
@@ -303,36 +346,212 @@ api.create_subscription(
303
346
  APIs for vendors selling to Amazon:
304
347
 
305
348
  - **Vendor Orders API (v1)**: Retrieve purchase orders
306
- - **Vendor Direct Fulfillment APIs**: Manage orders, shipping, payments, and inventory
349
+ - **Vendor Direct Fulfillment Orders API (2021-12-28, v1)**: Manage direct fulfillment orders
350
+ - **Vendor Direct Fulfillment Shipping API (2021-12-28, v1)**: Manage shipping for direct fulfillment
351
+ - **Vendor Direct Fulfillment Payments API (v1)**: Process payments for direct fulfillment
352
+ - **Vendor Direct Fulfillment Inventory API (v1)**: Manage inventory for direct fulfillment
353
+ - **Vendor Direct Fulfillment Transactions API (2021-12-28, v1)**: Track transaction status
354
+ - **Vendor Direct Fulfillment Sandbox Test Data API (2021-10-28)**: Generate test data in sandbox
307
355
  - **Vendor Shipments API (v1)**: Track vendor shipments
308
356
  - **Vendor Invoices API (v1)**: Submit and track invoices
357
+ - **Vendor Transaction Status API (v1)**: Check transaction status
309
358
 
310
359
  ```ruby
311
- api = Peddler.vendor_orders_v1(aws_region, access_token)
360
+ api = Peddler.vendor_orders(aws_region, access_token)
312
361
  orders = api.get_purchase_orders(
313
362
  limit: 10,
314
363
  createdAfter: "2023-01-01T00:00:00Z"
315
364
  ).parse
316
365
  ```
317
366
 
318
- #### Additional APIs
367
+ #### Authorization and Account Management APIs
319
368
 
320
- - **A+ Content API (2020-11-01)**: Create and manage enhanced marketing content
321
- - **Authorization API (2023-11-30)**: Manage app authorization
322
- - **Messaging API (v1)**: Send messages to customers
323
- - **Product Fees API (v0)**: Retrieve fee estimates for products
324
- - **Product Pricing API (2022-05-01, v0)**: Get pricing information
325
- - **Sellers API (v1)**: Get seller account information and marketplace participation
326
- - **Shipping APIs (v1, v2)**: Create shipments and purchase shipping labels
327
- - **Solicitations API (v1)**: Request customer reviews
369
+ - **Application Management API (2023-11-30)**: Manage application authorization
328
370
  - **Tokens API (2021-03-01)**: Generate restricted data tokens for accessing PII
329
- - **Uploads API (2020-11-01)**: Upload files for various SP-API operations
371
+ - **Sellers API (v1)**: Get seller account information and marketplace participation
372
+ - **Services API (v1)**: Manage seller services and subscriptions
373
+ - **Seller Wallet API (2024-03-01)**: Manage seller financial accounts
374
+ - **Application Integrations API (2024-04-01)**: Manage app integrations
375
+ - **Vehicles API (2024-11-01)**: Manage vehicle data for automotive products
376
+
377
+ ### Additional API Examples
378
+
379
+ #### Product Pricing API
380
+
381
+ ```ruby
382
+ # Using Product Pricing v0
383
+ api = Peddler.product_pricing_v0(aws_region, access_token)
384
+
385
+ # Get pricing information for an ASIN
386
+ pricing = api.get_pricing(
387
+ Marketplace.id("US"),
388
+ "Asin",
389
+ asins: ["B08N5WRWNW"]
390
+ )
391
+
392
+ # Get competitive pricing for an ASIN
393
+ competitive = api.get_competitive_pricing(
394
+ Marketplace.id("US"),
395
+ "Asin",
396
+ asins: ["B08N5WRWNW"]
397
+ )
398
+
399
+ # Get offers for a specific item
400
+ offers = api.get_item_offers(
401
+ Marketplace.id("US"),
402
+ "New",
403
+ "B08N5WRWNW"
404
+ )
405
+
406
+ # Batch request for multiple items (2022-05-01 API)
407
+ api = Peddler.product_pricing_2022_05_01(aws_region, access_token)
408
+ batch_request = {
409
+ requests: [
410
+ {
411
+ uri: "/products/pricing/2022-05-01/items/competitiveSummary",
412
+ method: "GET",
413
+ asin: "B08N5WRWNW",
414
+ marketplaceId: Marketplace.id("US"),
415
+ includedData: ["featuredBuyingOptions", "referencePrices", "lowestPricedOffers"]
416
+ },
417
+ # Additional items...
418
+ ]
419
+ }
420
+ results = api.get_competitive_summary(batch_request)
421
+ ```
422
+
423
+ #### Listings Items API
424
+
425
+ ```ruby
426
+ api = Peddler.listings_items(aws_region, access_token)
427
+
428
+ # Create or update a listing
429
+ listing_result = api.put_listings_item(
430
+ "SELLER_ID",
431
+ "SKU123",
432
+ Marketplace.id("US"),
433
+ {
434
+ productType: "PRODUCT",
435
+ requirements: "LISTING_OFFER_ONLY",
436
+ attributes: {
437
+ merchant_suggested_asin: [{
438
+ value: "B08N5WRWNW",
439
+ marketplace_id: Marketplace.id("US")
440
+ }],
441
+ condition_type: [{
442
+ value: "new_new",
443
+ marketplace_id: Marketplace.id("US")
444
+ }],
445
+ # Additional attributes...
446
+ }
447
+ }
448
+ )
449
+
450
+ # Update specific listing elements with JSON Patch
451
+ patch_result = api.patch_listings_item(
452
+ "SELLER_ID",
453
+ "SKU123",
454
+ Marketplace.id("US"),
455
+ {
456
+ productType: "PRODUCT",
457
+ patches: [
458
+ {
459
+ op: "replace",
460
+ path: "/attributes/purchasable_offer",
461
+ value: [{
462
+ currency: "USD",
463
+ our_price: [{
464
+ schedule: [{
465
+ value_with_tax: 39.99
466
+ }]
467
+ }]
468
+ }]
469
+ }
470
+ ]
471
+ }
472
+ )
473
+
474
+ # Get listing details
475
+ listing = api.get_listings_item(
476
+ "SELLER_ID",
477
+ "SKU123",
478
+ Marketplace.id("US"),
479
+ included_data: "attributes,issues"
480
+ )
481
+
482
+ # Delete a listing
483
+ api.delete_listings_item("SELLER_ID", "SKU123", Marketplace.id("US"))
484
+ ```
485
+
486
+ #### Listings Restrictions API
487
+
488
+ ```ruby
489
+ api = Peddler.listings_restrictions(aws_region, access_token)
490
+
491
+ # Check restrictions for an ASIN
492
+ restrictions = api.get_listings_restrictions(
493
+ "B08N5WRWNW",
494
+ "SELLER_ID",
495
+ Marketplace.id("US"),
496
+ condition_type: "new_new"
497
+ )
498
+ ```
499
+
500
+ #### Product Type Definitions API
501
+
502
+ ```ruby
503
+ api = Peddler.product_type_definitions(aws_region, access_token)
504
+
505
+ # Get schema for a product type
506
+ definition = api.get_definitions_product_type(
507
+ "PRODUCT",
508
+ Marketplace.id("US"),
509
+ requirements: "LISTING_OFFER_ONLY"
510
+ )
511
+
512
+ # Download the JSON schema
513
+ schema_url = definition.dig("schema", "link", "resource")
514
+ json_schema = HTTP.get(schema_url).parse(:json)
515
+ ```
516
+
517
+ #### Reports API
518
+
519
+ ```ruby
520
+ api = Peddler.reports(aws_region, access_token)
521
+
522
+ # Request a report
523
+ report_response = api.create_report({
524
+ "reportType" => "GET_MERCHANTS_LISTINGS_FYP_REPORT",
525
+ "marketplaceIds" => Marketplace.ids("US")
526
+ })
527
+ report_id = report_response.dig("reportId")
528
+
529
+ # Get report status
530
+ report = api.get_report(report_id)
531
+
532
+ # Get all reports of a specific type
533
+ reports = api.get_reports(report_types: ["GET_MERCHANTS_LISTINGS_FYP_REPORT"])
534
+
535
+ # Download a report document
536
+ document = api.get_report_document("DOCUMENT_ID")
537
+ download_url = document.dig("url")
538
+ # Process the downloaded report...
539
+ ```
540
+
541
+ #### Sellers API
542
+
543
+ ```ruby
544
+ api = Peddler.sellers(aws_region, access_token)
545
+
546
+ # Get marketplace participations
547
+ participations = api.get_marketplace_participations
548
+ ```
330
549
 
331
- For a complete list of available APIs, refer to the [API models repository](https://github.com/amzn/selling-partner-api-models).
550
+ For a complete list of available APIs and their detailed documentation, refer to the [API models repository](https://github.com/amzn/selling-partner-api-models).
332
551
 
333
552
  ## TODO
334
553
 
335
- - [ ] Code generate payload parsers
554
+ - [ ] Code generate payload parsers 🤔
336
555
  - [ ] Review and consider applying [these patches][patches]
337
556
 
338
557
  [build]: https://github.com/hakanensari/peddler/actions
data/lib/peddler/api.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "http"
4
+ require "uri"
4
5
 
5
6
  require "peddler/endpoint"
6
7
  require "peddler/error"
@@ -158,5 +159,15 @@ module Peddler
158
159
  def timestamp
159
160
  Time.now.utc.strftime("%Y%m%dT%H%M%SZ")
160
161
  end
162
+
163
+ # Encodes URL path components
164
+ def percent_encode(component)
165
+ URI.encode_uri_component(component)
166
+ end
167
+
168
+ # Converts an array to a comma-separated string, or returns the value as-is if not an array
169
+ def stringify_array(val)
170
+ val.is_a?(Array) ? val.join(",") : val
171
+ end
161
172
  end
162
173
  end
@@ -35,7 +35,7 @@ module Peddler
35
35
  # @param rate_limit [Float] Requests per second
36
36
  # @return [Peddler::Response] The API response
37
37
  def get_inbound(order_id, rate_limit: 2.0)
38
- path = "/awd/2024-05-09/inboundOrders/#{order_id}"
38
+ path = "/awd/2024-05-09/inboundOrders/#{percent_encode(order_id)}"
39
39
 
40
40
  meter(rate_limit).get(path)
41
41
  end
@@ -49,7 +49,7 @@ module Peddler
49
49
  # @param rate_limit [Float] Requests per second
50
50
  # @return [Peddler::Response] The API response
51
51
  def update_inbound(order_id, body, rate_limit: 1.0)
52
- path = "/awd/2024-05-09/inboundOrders/#{order_id}"
52
+ path = "/awd/2024-05-09/inboundOrders/#{percent_encode(order_id)}"
53
53
 
54
54
  meter(rate_limit).put(path, body:)
55
55
  end
@@ -61,7 +61,7 @@ module Peddler
61
61
  # @param rate_limit [Float] Requests per second
62
62
  # @return [Peddler::Response] The API response
63
63
  def cancel_inbound(order_id, rate_limit: 1.0)
64
- path = "/awd/2024-05-09/inboundOrders/#{order_id}/cancellation"
64
+ path = "/awd/2024-05-09/inboundOrders/#{percent_encode(order_id)}/cancellation"
65
65
 
66
66
  meter(rate_limit).post(path)
67
67
  end
@@ -73,7 +73,7 @@ module Peddler
73
73
  # @param rate_limit [Float] Requests per second
74
74
  # @return [Peddler::Response] The API response
75
75
  def confirm_inbound(order_id, rate_limit: 1.0)
76
- path = "/awd/2024-05-09/inboundOrders/#{order_id}/confirmation"
76
+ path = "/awd/2024-05-09/inboundOrders/#{percent_encode(order_id)}/confirmation"
77
77
 
78
78
  meter(rate_limit).post(path)
79
79
  end
@@ -87,7 +87,7 @@ module Peddler
87
87
  # @param rate_limit [Float] Requests per second
88
88
  # @return [Peddler::Response] The API response
89
89
  def get_inbound_shipment(shipment_id, sku_quantities: nil, rate_limit: 2.0)
90
- path = "/awd/2024-05-09/inboundShipments/#{shipment_id}"
90
+ path = "/awd/2024-05-09/inboundShipments/#{percent_encode(shipment_id)}"
91
91
  params = {
92
92
  "skuQuantities" => sku_quantities,
93
93
  }.compact
@@ -106,7 +106,7 @@ module Peddler
106
106
  # @param rate_limit [Float] Requests per second
107
107
  # @return [Peddler::Response] The API response
108
108
  def get_inbound_shipment_labels(shipment_id, page_type: nil, format_type: nil, rate_limit: 1.0)
109
- path = "/awd/2024-05-09/inboundShipments/#{shipment_id}/labels"
109
+ path = "/awd/2024-05-09/inboundShipments/#{percent_encode(shipment_id)}/labels"
110
110
  params = {
111
111
  "pageType" => page_type,
112
112
  "formatType" => format_type,
@@ -123,7 +123,7 @@ module Peddler
123
123
  # @param rate_limit [Float] Requests per second
124
124
  # @return [Peddler::Response] The API response
125
125
  def update_inbound_shipment_transport_details(shipment_id, body, rate_limit: 1.0)
126
- path = "/awd/2024-05-09/inboundShipments/#{shipment_id}/transport"
126
+ path = "/awd/2024-05-09/inboundShipments/#{percent_encode(shipment_id)}/transport"
127
127
 
128
128
  meter(rate_limit).put(path, body:)
129
129
  end