peddler 2.4.4 → 3.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +406 -134
  3. data/lib/peddler/access_token.rb +76 -0
  4. data/lib/peddler/api/amazon_warehousing_and_distribution_2024_05_09.rb +80 -0
  5. data/lib/peddler/api/aplus_content_2020_11_01.rb +208 -0
  6. data/lib/peddler/api/application_management_2023_11_30.rb +25 -0
  7. data/lib/peddler/api/catalog_items_2020_12_01.rb +70 -0
  8. data/lib/peddler/api/catalog_items_2022_04_01.rb +83 -0
  9. data/lib/peddler/api/catalog_items_v0.rb +90 -0
  10. data/lib/peddler/api/data_kiosk_2023_11_15.rb +92 -0
  11. data/lib/peddler/api/easy_ship_2022_03_23.rb +108 -0
  12. data/lib/peddler/api/fba_inbound_eligibility_v1.rb +36 -0
  13. data/lib/peddler/api/fba_inventory_v1.rb +106 -0
  14. data/lib/peddler/api/feeds_2021_06_30.rb +104 -0
  15. data/lib/peddler/api/finances_v0.rb +121 -0
  16. data/lib/peddler/api/fulfillment_inbound_2024_03_20.rb +660 -0
  17. data/lib/peddler/api/fulfillment_inbound_v0.rb +314 -0
  18. data/lib/peddler/api/fulfillment_outbound_2020_07_01.rb +222 -0
  19. data/lib/peddler/api/listings_items_2020_09_01.rb +84 -0
  20. data/lib/peddler/api/listings_items_2021_08_01.rb +154 -0
  21. data/lib/peddler/api/listings_restrictions_2021_08_01.rb +37 -0
  22. data/lib/peddler/api/merchant_fulfillment_v0.rb +64 -0
  23. data/lib/peddler/api/messaging_v1.rb +241 -0
  24. data/lib/peddler/api/notifications_v1.rb +114 -0
  25. data/lib/peddler/api/orders_v0.rb +264 -0
  26. data/lib/peddler/api/product_fees_v0.rb +69 -0
  27. data/lib/peddler/api/product_pricing_2022_05_01.rb +43 -0
  28. data/lib/peddler/api/product_pricing_v0.rb +144 -0
  29. data/lib/peddler/api/product_type_definitions_2020_09_01.rb +75 -0
  30. data/lib/peddler/api/replenishment_2022_11_07.rb +45 -0
  31. data/lib/peddler/api/reports_2021_06_30.rb +139 -0
  32. data/lib/peddler/api/sales_v1.rb +69 -0
  33. data/lib/peddler/api/sellers_v1.rb +33 -0
  34. data/lib/peddler/api/services_v1.rb +308 -0
  35. data/lib/peddler/api/shipment_invoicing_v0.rb +46 -0
  36. data/lib/peddler/api/shipping_v1.rb +107 -0
  37. data/lib/peddler/api/shipping_v2.rb +267 -0
  38. data/lib/peddler/api/solicitations_v1.rb +53 -0
  39. data/lib/peddler/api/supply_sources_2020_07_01.rb +82 -0
  40. data/lib/peddler/api/tokens_2021_03_01.rb +30 -0
  41. data/lib/peddler/api/uploads_2020_11_01.rb +40 -0
  42. data/lib/peddler/api/vendor_direct_fulfillment_inventory_v1.rb +24 -0
  43. data/lib/peddler/api/vendor_direct_fulfillment_orders_2021_12_28.rb +72 -0
  44. data/lib/peddler/api/vendor_direct_fulfillment_orders_v1.rb +72 -0
  45. data/lib/peddler/api/vendor_direct_fulfillment_payments_v1.rb +23 -0
  46. data/lib/peddler/api/vendor_direct_fulfillment_sandbox_test_data_2021_10_28.rb +35 -0
  47. data/lib/peddler/api/vendor_direct_fulfillment_shipping_2021_12_28.rb +177 -0
  48. data/lib/peddler/api/vendor_direct_fulfillment_shipping_v1.rb +165 -0
  49. data/lib/peddler/api/vendor_direct_fulfillment_transactions_2021_12_28.rb +24 -0
  50. data/lib/peddler/api/vendor_direct_fulfillment_transactions_v1.rb +24 -0
  51. data/lib/peddler/api/vendor_invoices_v1.rb +22 -0
  52. data/lib/peddler/api/vendor_orders_v1.rb +148 -0
  53. data/lib/peddler/api/vendor_shipments_v1.rb +120 -0
  54. data/lib/peddler/api/vendor_transaction_status_v1.rb +24 -0
  55. data/lib/peddler/api.rb +115 -0
  56. data/lib/peddler/error.rb +30 -0
  57. data/lib/peddler/region.rb +30 -0
  58. data/lib/peddler/version.rb +1 -1
  59. data/lib/peddler.rb +52 -1
  60. metadata +70 -80
  61. data/lib/mws/easy_ship/client.rb +0 -93
  62. data/lib/mws/easy_ship.rb +0 -3
  63. data/lib/mws/feeds/client.rb +0 -122
  64. data/lib/mws/feeds.rb +0 -3
  65. data/lib/mws/finances/client.rb +0 -82
  66. data/lib/mws/finances.rb +0 -3
  67. data/lib/mws/fulfillment_inbound_shipment/client.rb +0 -388
  68. data/lib/mws/fulfillment_inbound_shipment.rb +0 -3
  69. data/lib/mws/fulfillment_inventory/client.rb +0 -57
  70. data/lib/mws/fulfillment_inventory.rb +0 -3
  71. data/lib/mws/fulfillment_outbound_shipment/client.rb +0 -211
  72. data/lib/mws/fulfillment_outbound_shipment.rb +0 -3
  73. data/lib/mws/merchant_fulfillment/client.rb +0 -87
  74. data/lib/mws/merchant_fulfillment.rb +0 -3
  75. data/lib/mws/off_amazon_payments.rb +0 -3
  76. data/lib/mws/orders/client.rb +0 -120
  77. data/lib/mws/orders.rb +0 -3
  78. data/lib/mws/products/client.rb +0 -268
  79. data/lib/mws/products.rb +0 -3
  80. data/lib/mws/recommendations/client.rb +0 -72
  81. data/lib/mws/recommendations.rb +0 -3
  82. data/lib/mws/reports/client.rb +0 -236
  83. data/lib/mws/reports.rb +0 -3
  84. data/lib/mws/sellers/client.rb +0 -44
  85. data/lib/mws/sellers.rb +0 -3
  86. data/lib/mws/shipment_invoicing/client.rb +0 -74
  87. data/lib/mws/shipment_invoicing.rb +0 -3
  88. data/lib/mws/subscriptions/client.rb +0 -179
  89. data/lib/mws/subscriptions.rb +0 -3
  90. data/lib/mws.rb +0 -29
  91. data/lib/peddler/client.rb +0 -159
  92. data/lib/peddler/errors/builder.rb +0 -64
  93. data/lib/peddler/errors/class_generator.rb +0 -40
  94. data/lib/peddler/errors/error.rb +0 -45
  95. data/lib/peddler/errors/parser.rb +0 -28
  96. data/lib/peddler/flat_file_parser.rb +0 -56
  97. data/lib/peddler/headers.rb +0 -102
  98. data/lib/peddler/marketplace.rb +0 -78
  99. data/lib/peddler/operation.rb +0 -78
  100. data/lib/peddler/parser.rb +0 -33
  101. data/lib/peddler/structured_list.rb +0 -23
  102. data/lib/peddler/vcr_matcher.rb +0 -97
  103. data/lib/peddler/xml_parser.rb +0 -38
  104. data/lib/peddler/xml_response_parser.rb +0 -25
@@ -0,0 +1,148 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "peddler/api"
4
+
5
+ module Peddler
6
+ class API
7
+ # Selling Partner API for Retail Procurement Orders
8
+ #
9
+ # The Selling Partner API for Retail Procurement Orders provides programmatic access to vendor orders data.
10
+ class VendorOrdersV1 < API
11
+ # Returns a list of purchase orders created or changed during the time frame that you specify. You define the time
12
+ # frame using the `createdAfter`, `createdBefore`, `changedAfter` and `changedBefore` parameters. The date range
13
+ # to search must not be more than 7 days. You can choose to get only the purchase order numbers by setting
14
+ # `includeDetails` to false. You can then use the `getPurchaseOrder` operation to receive details for a specific
15
+ # purchase order.
16
+ #
17
+ # @param [Integer] limit The limit to the number of records returned. Default value is 100 records.
18
+ # @param [String] created_after Purchase orders that became available after this time will be included in the
19
+ # result. Must be in ISO-8601 date/time format.
20
+ # @param [String] created_before Purchase orders that became available before this time will be included in the
21
+ # result. Must be in ISO-8601 date/time format.
22
+ # @param [String] sort_order Sort in ascending or descending order by purchase order creation date.
23
+ # @param [String] next_token Used for pagination when there is more purchase orders than the specified result size
24
+ # limit. The token value is returned in the previous API call
25
+ # @param [String] include_details When true, returns purchase orders with complete details. Otherwise, only
26
+ # purchase order numbers are returned. Default value is true.
27
+ # @param [String] changed_after Purchase orders that changed after this timestamp will be included in the result.
28
+ # Must be in ISO-8601 date/time format.
29
+ # @param [String] changed_before Purchase orders that changed before this timestamp will be included in the
30
+ # result. Must be in ISO-8601 date/time format.
31
+ # @param [String] po_item_state Current state of the purchase order item. If this value is Cancelled, this API
32
+ # will return purchase orders which have one or more items cancelled by Amazon with updated item quantity as
33
+ # zero.
34
+ # @param [String] is_po_changed When true, returns purchase orders which were modified after the order was placed.
35
+ # Vendors are required to pull the changed purchase order and fulfill the updated purchase order and not the
36
+ # original one. Default value is false.
37
+ # @param [String] purchase_order_state Filters purchase orders based on the purchase order state.
38
+ # @param [String] ordering_vendor_code Filters purchase orders based on the specified ordering vendor code. This
39
+ # value should be same as 'sellingParty.partyId' in the purchase order. If not included in the filter, all
40
+ # purchase orders for all of the vendor codes that exist in the vendor group used to authorize the API client
41
+ # application are returned.
42
+ # @return [Hash] The API response
43
+ def get_purchase_orders(
44
+ limit: nil, created_after: nil, created_before: nil, sort_order: nil, next_token: nil, include_details: nil,
45
+ changed_after: nil, changed_before: nil, po_item_state: nil, is_po_changed: nil, purchase_order_state: nil,
46
+ ordering_vendor_code: nil
47
+ )
48
+ path = "/vendor/orders/v1/purchaseOrders"
49
+ params = {
50
+ "limit" => limit,
51
+ "createdAfter" => created_after,
52
+ "createdBefore" => created_before,
53
+ "sortOrder" => sort_order,
54
+ "nextToken" => next_token,
55
+ "includeDetails" => include_details,
56
+ "changedAfter" => changed_after,
57
+ "changedBefore" => changed_before,
58
+ "poItemState" => po_item_state,
59
+ "isPOChanged" => is_po_changed,
60
+ "purchaseOrderState" => purchase_order_state,
61
+ "orderingVendorCode" => ordering_vendor_code,
62
+ }.compact
63
+
64
+ rate_limit(10.0).get(path, params:)
65
+ end
66
+
67
+ # Returns a purchase order based on the `purchaseOrderNumber` value that you specify.
68
+ #
69
+ # @param [String] purchase_order_number The purchase order identifier for the order that you want. Formatting
70
+ # Notes: 8-character alpha-numeric code.
71
+ # @return [Hash] The API response
72
+ def get_purchase_order(purchase_order_number)
73
+ path = "/vendor/orders/v1/purchaseOrders/#{purchase_order_number}"
74
+
75
+ rate_limit(10.0).get(path)
76
+ end
77
+
78
+ # Submits acknowledgements for one or more purchase orders.
79
+ #
80
+ # @param [Hash] body
81
+ # @return [Hash] The API response
82
+ def submit_acknowledgement(body)
83
+ path = "/vendor/orders/v1/acknowledgements"
84
+
85
+ rate_limit(10.0).post(path, body:)
86
+ end
87
+
88
+ # Returns purchase order statuses based on the filters that you specify. Date range to search must not be more
89
+ # than 7 days. You can return a list of purchase order statuses using the available filters, or a single purchase
90
+ # order status by providing the purchase order number.
91
+ #
92
+ # @param [Integer] limit The limit to the number of records returned. Default value is 100 records.
93
+ # @param [String] sort_order Sort in ascending or descending order by purchase order creation date.
94
+ # @param [String] next_token Used for pagination when there are more purchase orders than the specified result
95
+ # size limit.
96
+ # @param [String] created_after Purchase orders that became available after this timestamp will be included in the
97
+ # result. Must be in ISO-8601 date/time format.
98
+ # @param [String] created_before Purchase orders that became available before this timestamp will be included in
99
+ # the result. Must be in ISO-8601 date/time format.
100
+ # @param [String] updated_after Purchase orders for which the last purchase order update happened after this
101
+ # timestamp will be included in the result. Must be in ISO-8601 date/time format.
102
+ # @param [String] updated_before Purchase orders for which the last purchase order update happened before this
103
+ # timestamp will be included in the result. Must be in ISO-8601 date/time format.
104
+ # @param [String] purchase_order_number Provides purchase order status for the specified purchase order number.
105
+ # @param [String] purchase_order_status Filters purchase orders based on the specified purchase order status. If
106
+ # not included in filter, this will return purchase orders for all statuses.
107
+ # @param [String] item_confirmation_status Filters purchase orders based on their item confirmation status. If the
108
+ # item confirmation status is not included in the filter, purchase orders for all confirmation statuses are
109
+ # included.
110
+ # @param [String] item_receive_status Filters purchase orders based on the purchase order's item receive status.
111
+ # If the item receive status is not included in the filter, purchase orders for all receive statuses are
112
+ # included.
113
+ # @param [String] ordering_vendor_code Filters purchase orders based on the specified ordering vendor code. This
114
+ # value should be same as 'sellingParty.partyId' in the purchase order. If not included in filter, all purchase
115
+ # orders for all the vendor codes that exist in the vendor group used to authorize API client application are
116
+ # returned.
117
+ # @param [String] ship_to_party_id Filters purchase orders for a specific buyer's Fulfillment Center/warehouse by
118
+ # providing ship to location id here. This value should be same as 'shipToParty.partyId' in the purchase order.
119
+ # If not included in filter, this will return purchase orders for all the buyer's warehouses used for vendor
120
+ # group purchase orders.
121
+ # @return [Hash] The API response
122
+ def get_purchase_orders_status(
123
+ limit: nil, sort_order: nil, next_token: nil, created_after: nil, created_before: nil, updated_after: nil,
124
+ updated_before: nil, purchase_order_number: nil, purchase_order_status: nil, item_confirmation_status: nil,
125
+ item_receive_status: nil, ordering_vendor_code: nil, ship_to_party_id: nil
126
+ )
127
+ path = "/vendor/orders/v1/purchaseOrdersStatus"
128
+ params = {
129
+ "limit" => limit,
130
+ "sortOrder" => sort_order,
131
+ "nextToken" => next_token,
132
+ "createdAfter" => created_after,
133
+ "createdBefore" => created_before,
134
+ "updatedAfter" => updated_after,
135
+ "updatedBefore" => updated_before,
136
+ "purchaseOrderNumber" => purchase_order_number,
137
+ "purchaseOrderStatus" => purchase_order_status,
138
+ "itemConfirmationStatus" => item_confirmation_status,
139
+ "itemReceiveStatus" => item_receive_status,
140
+ "orderingVendorCode" => ordering_vendor_code,
141
+ "shipToPartyId" => ship_to_party_id,
142
+ }.compact
143
+
144
+ rate_limit(10.0).get(path, params:)
145
+ end
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,120 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "peddler/api"
4
+
5
+ module Peddler
6
+ class API
7
+ # Selling Partner API for Retail Procurement Shipments
8
+ #
9
+ # The Selling Partner API for Retail Procurement Shipments provides programmatic access to retail shipping data for
10
+ # vendors.
11
+ class VendorShipmentsV1 < API
12
+ # Submits one or more shipment confirmations for vendor orders.
13
+ #
14
+ # @param [Hash] body A request to submit shipment confirmation.
15
+ # @return [Hash] The API response
16
+ def submit_shipment_confirmations(body)
17
+ path = "/vendor/shipping/v1/shipmentConfirmations"
18
+
19
+ rate_limit(10.0).post(path, body:)
20
+ end
21
+
22
+ # Submits one or more shipment request for vendor Orders.
23
+ #
24
+ # @param [Hash] body A request to submit shipment request.
25
+ # @return [Hash] The API response
26
+ def submit_shipments(body)
27
+ path = "/vendor/shipping/v1/shipments"
28
+
29
+ rate_limit(10.0).post(path, body:)
30
+ end
31
+
32
+ # Returns the Details about Shipment, Carrier Details, status of the shipment, container details and other details
33
+ # related to shipment based on the filter parameters value that you specify.
34
+ #
35
+ # @param [Integer] limit The limit to the number of records returned. Default value is 50 records.
36
+ # @param [String] sort_order Sort in ascending or descending order by purchase order creation date.
37
+ # @param [String] next_token Used for pagination when there are more shipments than the specified result size
38
+ # limit.
39
+ # @param [String] created_after Get Shipment Details that became available after this timestamp will be included
40
+ # in the result. Must be in [ISO 8601](https://developer-docs.amazon.com/sp-api/docs/iso-8601) format.
41
+ # @param [String] created_before Get Shipment Details that became available before this timestamp will be included
42
+ # in the result. Must be in [ISO 8601](https://developer-docs.amazon.com/sp-api/docs/iso-8601) format.
43
+ # @param [String] shipment_confirmed_before Get Shipment Details by passing Shipment confirmed create Date Before.
44
+ # Must be in [ISO 8601](https://developer-docs.amazon.com/sp-api/docs/iso-8601) format.
45
+ # @param [String] shipment_confirmed_after Get Shipment Details by passing Shipment confirmed create Date After.
46
+ # Must be in [ISO 8601](https://developer-docs.amazon.com/sp-api/docs/iso-8601) format.
47
+ # @param [String] package_label_created_before Get Shipment Details by passing Package label create Date by buyer.
48
+ # Must be in [ISO 8601](https://developer-docs.amazon.com/sp-api/docs/iso-8601) format.
49
+ # @param [String] package_label_created_after Get Shipment Details by passing Package label create Date After by
50
+ # buyer. Must be in [ISO 8601](https://developer-docs.amazon.com/sp-api/docs/iso-8601) format.
51
+ # @param [String] shipped_before Get Shipment Details by passing Shipped Date Before. Must be in [ISO
52
+ # 8601](https://developer-docs.amazon.com/sp-api/docs/iso-8601) format.
53
+ # @param [String] shipped_after Get Shipment Details by passing Shipped Date After. Must be in [ISO
54
+ # 8601](https://developer-docs.amazon.com/sp-api/docs/iso-8601) format.
55
+ # @param [String] estimated_delivery_before Get Shipment Details by passing Estimated Delivery Date Before. Must
56
+ # be in [ISO 8601](https://developer-docs.amazon.com/sp-api/docs/iso-8601) format.
57
+ # @param [String] estimated_delivery_after Get Shipment Details by passing Estimated Delivery Date Before. Must be
58
+ # in [ISO 8601](https://developer-docs.amazon.com/sp-api/docs/iso-8601) format.
59
+ # @param [String] shipment_delivery_before Get Shipment Details by passing Shipment Delivery Date Before. Must be
60
+ # in [ISO 8601](https://developer-docs.amazon.com/sp-api/docs/iso-8601) format.
61
+ # @param [String] shipment_delivery_after Get Shipment Details by passing Shipment Delivery Date After. Must be in
62
+ # [ISO 8601](https://developer-docs.amazon.com/sp-api/docs/iso-8601) format.
63
+ # @param [String] requested_pick_up_before Get Shipment Details by passing Before Requested pickup date. Must be
64
+ # in [ISO 8601](https://developer-docs.amazon.com/sp-api/docs/iso-8601) format.
65
+ # @param [String] requested_pick_up_after Get Shipment Details by passing After Requested pickup date. Must be in
66
+ # [ISO 8601](https://developer-docs.amazon.com/sp-api/docs/iso-8601) format.
67
+ # @param [String] scheduled_pick_up_before Get Shipment Details by passing Before scheduled pickup date. Must be
68
+ # in [ISO 8601](https://developer-docs.amazon.com/sp-api/docs/iso-8601) format.
69
+ # @param [String] scheduled_pick_up_after Get Shipment Details by passing After Scheduled pickup date. Must be in
70
+ # [ISO 8601](https://developer-docs.amazon.com/sp-api/docs/iso-8601) format.
71
+ # @param [String] current_shipment_status Get Shipment Details by passing Current shipment status.
72
+ # @param [String] vendor_shipment_identifier Get Shipment Details by passing Vendor Shipment ID
73
+ # @param [String] buyer_reference_number Get Shipment Details by passing buyer Reference ID
74
+ # @param [String] buyer_warehouse_code Get Shipping Details based on buyer warehouse code. This value should be
75
+ # same as 'shipToParty.partyId' in the Shipment.
76
+ # @param [String] seller_warehouse_code Get Shipping Details based on vendor warehouse code. This value should be
77
+ # same as 'sellingParty.partyId' in the Shipment.
78
+ # @return [Hash] The API response
79
+ def get_shipment_details(
80
+ limit: nil, sort_order: nil, next_token: nil, created_after: nil, created_before: nil,
81
+ shipment_confirmed_before: nil, shipment_confirmed_after: nil, package_label_created_before: nil,
82
+ package_label_created_after: nil, shipped_before: nil, shipped_after: nil, estimated_delivery_before: nil,
83
+ estimated_delivery_after: nil, shipment_delivery_before: nil, shipment_delivery_after: nil,
84
+ requested_pick_up_before: nil, requested_pick_up_after: nil, scheduled_pick_up_before: nil,
85
+ scheduled_pick_up_after: nil, current_shipment_status: nil, vendor_shipment_identifier: nil,
86
+ buyer_reference_number: nil, buyer_warehouse_code: nil, seller_warehouse_code: nil
87
+ )
88
+ path = "/vendor/shipping/v1/shipments"
89
+ params = {
90
+ "limit" => limit,
91
+ "sortOrder" => sort_order,
92
+ "nextToken" => next_token,
93
+ "createdAfter" => created_after,
94
+ "createdBefore" => created_before,
95
+ "shipmentConfirmedBefore" => shipment_confirmed_before,
96
+ "shipmentConfirmedAfter" => shipment_confirmed_after,
97
+ "packageLabelCreatedBefore" => package_label_created_before,
98
+ "packageLabelCreatedAfter" => package_label_created_after,
99
+ "shippedBefore" => shipped_before,
100
+ "shippedAfter" => shipped_after,
101
+ "estimatedDeliveryBefore" => estimated_delivery_before,
102
+ "estimatedDeliveryAfter" => estimated_delivery_after,
103
+ "shipmentDeliveryBefore" => shipment_delivery_before,
104
+ "shipmentDeliveryAfter" => shipment_delivery_after,
105
+ "requestedPickUpBefore" => requested_pick_up_before,
106
+ "requestedPickUpAfter" => requested_pick_up_after,
107
+ "scheduledPickUpBefore" => scheduled_pick_up_before,
108
+ "scheduledPickUpAfter" => scheduled_pick_up_after,
109
+ "currentShipmentStatus" => current_shipment_status,
110
+ "vendorShipmentIdentifier" => vendor_shipment_identifier,
111
+ "buyerReferenceNumber" => buyer_reference_number,
112
+ "buyerWarehouseCode" => buyer_warehouse_code,
113
+ "sellerWarehouseCode" => seller_warehouse_code,
114
+ }.compact
115
+
116
+ rate_limit(10.0).get(path, params:)
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "peddler/api"
4
+
5
+ module Peddler
6
+ class API
7
+ # Selling Partner API for Retail Procurement Transaction Status
8
+ #
9
+ # The Selling Partner API for Retail Procurement Transaction Status provides programmatic access to status
10
+ # information on specific asynchronous POST transactions for vendors.
11
+ class VendorTransactionStatusV1 < API
12
+ # Returns the status of the transaction that you specify.
13
+ #
14
+ # @param [String] transaction_id The GUID provided by Amazon in the 'transactionId' field in response to the post
15
+ # request of a specific transaction.
16
+ # @return [Hash] The API response
17
+ def get_transaction(transaction_id)
18
+ path = "/vendor/transactions/v1/transactions/#{transaction_id}"
19
+
20
+ rate_limit(10.0).get(path)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,115 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "http"
4
+
5
+ require "peddler/error"
6
+ require "peddler/region"
7
+
8
+ module Peddler
9
+ # Wraps an Amazon Selling Partner API (SP-API)
10
+ class API
11
+ # @return [Peddler::Region]
12
+ attr_reader :region
13
+
14
+ # @return [String]
15
+ attr_reader :access_token
16
+
17
+ # @param [String] aws_region
18
+ # @param [String] access_token
19
+ def initialize(aws_region, access_token)
20
+ @region = Region.new(aws_region)
21
+ @access_token = access_token
22
+ end
23
+
24
+ def endpoint
25
+ @endpoint ||= region.endpoint
26
+ end
27
+
28
+ # @see https://developer-docs.amazon.com/sp-api/docs/the-selling-partner-api-sandbox
29
+ # @return [self]
30
+ def sandbox
31
+ @endpoint = endpoint.sub(/(?:sandbox.)?sellingpartnerapi/, "sandbox.sellingpartnerapi")
32
+ self
33
+ end
34
+
35
+ # @see https://developer-docs.amazon.com/sp-api/docs/include-a-user-agent-header-in-all-requests
36
+ # @see https://developer-docs.amazon.com/amazon-shipping/docs/connecting-to-the-selling-partner-api#step-3-add-headers-to-the-uri
37
+ # @return [HTTP::Client]
38
+ def http
39
+ @http ||= HTTP.headers(
40
+ "Host" => endpoint_host,
41
+ "User-Agent" => user_agent,
42
+ "X-Amz-Access-Token" => access_token,
43
+ "X-Amz-Date" => timestamp,
44
+ )
45
+ end
46
+
47
+ # Retries with a rate limit when the API returns a 429
48
+ #
49
+ # @param [Float] delay The delay in seconds before retrying
50
+ # @return [self]
51
+ def rate_limit(rate)
52
+ # HTTP v6.0 will implement retriable
53
+ # https://github.com/httprb/http/pull/790
54
+ retriable(delay: 1.0 / rate, retry_statuses: [429]) if @http.respond_to?(:retriable)
55
+ self
56
+ end
57
+
58
+ # @!method use(*features)
59
+ # Turn on [HTTP](https://github.com/httprb/http) features
60
+ #
61
+ # @param features
62
+ # @return [self]
63
+ #
64
+ # @!method via(*proxy)
65
+ # Make a request through an HTTP proxy
66
+ #
67
+ # @param [Array] proxy
68
+ # @raise [HTTP::Request::Error] if HTTP proxy is invalid
69
+ # @return [self]
70
+ #
71
+ # @!method retriable(**options)
72
+ # Retries requests if they fail due to socket or `5xx` errors
73
+ #
74
+ # @param (see Performer#initialize)
75
+ # @return [self]
76
+ [:via, :use, :retriable].each do |method|
77
+ define_method(method) do |*args, &block|
78
+ @http = http.send(method, *args, &block)
79
+ self
80
+ end
81
+ end
82
+ alias_method :through, :via
83
+
84
+ [:get, :post, :put, :delete, :patch].each do |method|
85
+ define_method(method) do |path, **options|
86
+ if options[:body] && !options[:body].is_a?(String)
87
+ options[:json] = options.delete(:body)
88
+ end
89
+
90
+ response = http.send(method, [endpoint, path].join, **options)
91
+
92
+ if response.status.client_error?
93
+ error = Error.build(response)
94
+ raise error if error
95
+ end
96
+
97
+ response
98
+ end
99
+ end
100
+
101
+ private
102
+
103
+ def endpoint_host
104
+ URI.parse(endpoint).host
105
+ end
106
+
107
+ def user_agent
108
+ "Peddler/#{Peddler::VERSION} (Language=Ruby; #{Socket.gethostname})"
109
+ end
110
+
111
+ def timestamp
112
+ Time.now.utc.strftime("%Y%m%dT%H%M%SZ")
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Peddler
4
+ class Error < StandardError
5
+ class InvalidInput < Error; end
6
+ class QuotaExceeded < Error; end
7
+ class Unauthorized < Error; end
8
+
9
+ attr_reader :cause
10
+
11
+ # @!visibility private
12
+ class << self
13
+ def build(response)
14
+ error = JSON.parse(response).dig("errors").first
15
+ class_name = error.dig("code")
16
+ klass = const_get(class_name)
17
+
18
+ klass.new(error.dig("message"), response)
19
+ rescue NameError
20
+ const_set(class_name, Class.new(Error))
21
+ retry
22
+ end
23
+ end
24
+
25
+ def initialize(msg = nil, cause = nil)
26
+ @cause = cause
27
+ super(msg)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "uri"
4
+
5
+ module Peddler
6
+ class Region
7
+ class UnknownRegion < ArgumentError; end
8
+
9
+ # @see https://developer-docs.amazon.com/sp-api/docs/sp-api-endpoints
10
+ ENDPOINTS = {
11
+ "us-east-1" => "https://sellingpartnerapi-na.amazon.com",
12
+ "us-west-2" => "https://sellingpartnerapi-fe.amazon.com",
13
+ "eu-west-1" => "https://sellingpartnerapi-eu.amazon.com",
14
+ }
15
+
16
+ attr_reader :name
17
+
18
+ # @param [String] name
19
+ def initialize(name)
20
+ @name = name
21
+ end
22
+
23
+ # @return [String]
24
+ def endpoint
25
+ ENDPOINTS.fetch(name) do
26
+ raise UnknownRegion, "#{name} not found"
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Peddler
4
- VERSION = '2.4.4'
4
+ VERSION = "3.0.0.beta1"
5
5
  end
data/lib/peddler.rb CHANGED
@@ -1,3 +1,54 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'mws'
3
+ require "peddler/access_token"
4
+ require "peddler/api/amazon_warehousing_and_distribution_2024_05_09.rb"
5
+ require "peddler/api/aplus_content_2020_11_01.rb"
6
+ require "peddler/api/application_management_2023_11_30.rb"
7
+ require "peddler/api/catalog_items_v0.rb"
8
+ require "peddler/api/catalog_items_2020_12_01.rb"
9
+ require "peddler/api/catalog_items_2022_04_01.rb"
10
+ require "peddler/api/data_kiosk_2023_11_15.rb"
11
+ require "peddler/api/easy_ship_2022_03_23.rb"
12
+ require "peddler/api/fba_inbound_eligibility_v1.rb"
13
+ require "peddler/api/fba_inventory_v1.rb"
14
+ require "peddler/api/feeds_2021_06_30.rb"
15
+ require "peddler/api/finances_v0.rb"
16
+ require "peddler/api/fulfillment_inbound_v0.rb"
17
+ require "peddler/api/fulfillment_inbound_2024_03_20.rb"
18
+ require "peddler/api/fulfillment_outbound_2020_07_01.rb"
19
+ require "peddler/api/listings_items_2020_09_01.rb"
20
+ require "peddler/api/listings_items_2021_08_01.rb"
21
+ require "peddler/api/listings_restrictions_2021_08_01.rb"
22
+ require "peddler/api/merchant_fulfillment_v0.rb"
23
+ require "peddler/api/messaging_v1.rb"
24
+ require "peddler/api/notifications_v1.rb"
25
+ require "peddler/api/orders_v0.rb"
26
+ require "peddler/api/product_fees_v0.rb"
27
+ require "peddler/api/product_pricing_v0.rb"
28
+ require "peddler/api/product_pricing_2022_05_01.rb"
29
+ require "peddler/api/product_type_definitions_2020_09_01.rb"
30
+ require "peddler/api/replenishment_2022_11_07.rb"
31
+ require "peddler/api/reports_2021_06_30.rb"
32
+ require "peddler/api/sales_v1.rb"
33
+ require "peddler/api/sellers_v1.rb"
34
+ require "peddler/api/services_v1.rb"
35
+ require "peddler/api/shipment_invoicing_v0.rb"
36
+ require "peddler/api/shipping_v1.rb"
37
+ require "peddler/api/shipping_v2.rb"
38
+ require "peddler/api/solicitations_v1.rb"
39
+ require "peddler/api/supply_sources_2020_07_01.rb"
40
+ require "peddler/api/tokens_2021_03_01.rb"
41
+ require "peddler/api/uploads_2020_11_01.rb"
42
+ require "peddler/api/vendor_direct_fulfillment_inventory_v1.rb"
43
+ require "peddler/api/vendor_direct_fulfillment_orders_v1.rb"
44
+ require "peddler/api/vendor_direct_fulfillment_orders_2021_12_28.rb"
45
+ require "peddler/api/vendor_direct_fulfillment_payments_v1.rb"
46
+ require "peddler/api/vendor_direct_fulfillment_sandbox_test_data_2021_10_28.rb"
47
+ require "peddler/api/vendor_direct_fulfillment_shipping_v1.rb"
48
+ require "peddler/api/vendor_direct_fulfillment_shipping_2021_12_28.rb"
49
+ require "peddler/api/vendor_direct_fulfillment_transactions_v1.rb"
50
+ require "peddler/api/vendor_direct_fulfillment_transactions_2021_12_28.rb"
51
+ require "peddler/api/vendor_invoices_v1.rb"
52
+ require "peddler/api/vendor_orders_v1.rb"
53
+ require "peddler/api/vendor_shipments_v1.rb"
54
+ require "peddler/api/vendor_transaction_status_v1.rb"