peddler 2.4.5 → 3.0.0

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