peddler 3.0.0.beta1 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +96 -106
  3. data/lib/peddler/api/amazon_warehousing_and_distribution_2024_05_09.rb +34 -22
  4. data/lib/peddler/api/aplus_content_2020_11_01.rb +86 -48
  5. data/lib/peddler/api/application_integrations_2024_04_01.rb +56 -0
  6. data/lib/peddler/api/application_management_2023_11_30.rb +12 -2
  7. data/lib/peddler/api/catalog_items_2020_12_01.rb +31 -20
  8. data/lib/peddler/api/catalog_items_2022_04_01.rb +35 -25
  9. data/lib/peddler/api/catalog_items_v0.rb +39 -26
  10. data/lib/peddler/api/data_kiosk_2023_11_15.rb +41 -25
  11. data/lib/peddler/api/easy_ship_2022_03_23.rb +62 -43
  12. data/lib/peddler/api/fba_inbound_eligibility_v1.rb +13 -5
  13. data/lib/peddler/api/fba_inventory_v1.rb +40 -24
  14. data/lib/peddler/api/feeds_2021_06_30.rb +43 -25
  15. data/lib/peddler/api/finances_2024_06_19.rb +50 -0
  16. data/lib/peddler/api/finances_v0.rb +86 -59
  17. data/lib/peddler/api/fulfillment_inbound_2024_03_20.rb +304 -205
  18. data/lib/peddler/api/fulfillment_inbound_v0.rb +112 -74
  19. data/lib/peddler/api/fulfillment_outbound_2020_07_01.rb +90 -53
  20. data/lib/peddler/api/invoices_2024_06_19.rb +180 -0
  21. data/lib/peddler/api/listings_items_2020_09_01.rb +44 -33
  22. data/lib/peddler/api/listings_items_2021_08_01.rb +76 -60
  23. data/lib/peddler/api/listings_restrictions_2021_08_01.rb +19 -9
  24. data/lib/peddler/api/merchant_fulfillment_v0.rb +31 -15
  25. data/lib/peddler/api/messaging_v1.rb +93 -61
  26. data/lib/peddler/api/notifications_v1.rb +54 -23
  27. data/lib/peddler/api/orders_v0.rb +87 -72
  28. data/lib/peddler/api/product_fees_v0.rb +39 -31
  29. data/lib/peddler/api/product_pricing_2022_05_01.rb +17 -6
  30. data/lib/peddler/api/product_pricing_v0.rb +63 -45
  31. data/lib/peddler/api/product_type_definitions_2020_09_01.rb +29 -18
  32. data/lib/peddler/api/replenishment_2022_11_07.rb +21 -9
  33. data/lib/peddler/api/reports_2021_06_30.rb +60 -36
  34. data/lib/peddler/api/sales_v1.rb +20 -12
  35. data/lib/peddler/api/sellers_v1.rb +16 -4
  36. data/lib/peddler/api/services_v1.rb +138 -98
  37. data/lib/peddler/api/shipment_invoicing_v0.rb +25 -12
  38. data/lib/peddler/api/shipping_v1.rb +54 -29
  39. data/lib/peddler/api/shipping_v2.rb +132 -80
  40. data/lib/peddler/api/solicitations_v1.rb +18 -8
  41. data/lib/peddler/api/supply_sources_2020_07_01.rb +33 -15
  42. data/lib/peddler/api/tokens_2021_03_01.rb +13 -5
  43. data/lib/peddler/api/uploads_2020_11_01.rb +16 -6
  44. data/lib/peddler/api/vendor_direct_fulfillment_inventory_v1.rb +12 -4
  45. data/lib/peddler/api/vendor_direct_fulfillment_orders_2021_12_28.rb +29 -17
  46. data/lib/peddler/api/vendor_direct_fulfillment_orders_v1.rb +29 -17
  47. data/lib/peddler/api/vendor_direct_fulfillment_payments_v1.rb +11 -3
  48. data/lib/peddler/api/vendor_direct_fulfillment_sandbox_test_data_2021_10_28.rb +14 -4
  49. data/lib/peddler/api/vendor_direct_fulfillment_shipping_2021_12_28.rb +74 -48
  50. data/lib/peddler/api/vendor_direct_fulfillment_shipping_v1.rb +74 -50
  51. data/lib/peddler/api/vendor_direct_fulfillment_transactions_2021_12_28.rb +11 -3
  52. data/lib/peddler/api/vendor_direct_fulfillment_transactions_v1.rb +11 -3
  53. data/lib/peddler/api/vendor_invoices_v1.rb +11 -3
  54. data/lib/peddler/api/vendor_orders_v1.rb +54 -43
  55. data/lib/peddler/api/vendor_shipments_v1.rb +63 -51
  56. data/lib/peddler/api/vendor_transaction_status_v1.rb +12 -3
  57. data/lib/peddler/api.rb +41 -18
  58. data/lib/peddler/endpoint.rb +51 -0
  59. data/lib/peddler/error.rb +1 -0
  60. data/lib/peddler/marketplace.rb +49 -0
  61. data/lib/peddler/token.rb +70 -0
  62. data/lib/peddler/version.rb +1 -1
  63. data/lib/peddler.rb +56 -52
  64. metadata +10 -6
  65. data/lib/peddler/access_token.rb +0 -76
  66. data/lib/peddler/region.rb +0 -30
@@ -3,6 +3,12 @@
3
3
  require "peddler/api"
4
4
 
5
5
  module Peddler
6
+ class << self
7
+ def vendor_orders_v1(...)
8
+ API::VendorOrdersV1.new(...)
9
+ end
10
+ end
11
+
6
12
  class API
7
13
  # Selling Partner API for Retail Procurement Orders
8
14
  #
@@ -14,37 +20,37 @@ module Peddler
14
20
  # `includeDetails` to false. You can then use the `getPurchaseOrder` operation to receive details for a specific
15
21
  # purchase order.
16
22
  #
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
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
19
26
  # 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
27
+ # @param created_before [String] Purchase orders that became available before this time will be included in the
21
28
  # 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
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
24
31
  # 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
32
+ # @param include_details [String] When true, returns purchase orders with complete details. Otherwise, only
26
33
  # 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.
34
+ # @param changed_after [String] Purchase orders that changed after this timestamp will be included in the result.
28
35
  # 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
36
+ # @param changed_before [String] Purchase orders that changed before this timestamp will be included in the
30
37
  # 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
38
+ # @param po_item_state [String] Current state of the purchase order item. If this value is Cancelled, this API
32
39
  # will return purchase orders which have one or more items cancelled by Amazon with updated item quantity as
33
40
  # zero.
34
- # @param [String] is_po_changed When true, returns purchase orders which were modified after the order was placed.
41
+ # @param is_po_changed [String] When true, returns purchase orders which were modified after the order was placed.
35
42
  # Vendors are required to pull the changed purchase order and fulfill the updated purchase order and not the
36
43
  # 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
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
39
46
  # value should be same as 'sellingParty.partyId' in the purchase order. If not included in the filter, all
40
47
  # purchase orders for all of the vendor codes that exist in the vendor group used to authorize the API client
41
48
  # application are returned.
49
+ # @param rate_limit [Float] Requests per second
42
50
  # @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
- )
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)
48
54
  path = "/vendor/orders/v1/purchaseOrders"
49
55
  params = {
50
56
  "limit" => limit,
@@ -61,69 +67,74 @@ module Peddler
61
67
  "orderingVendorCode" => ordering_vendor_code,
62
68
  }.compact
63
69
 
64
- rate_limit(10.0).get(path, params:)
70
+ meter(rate_limit).get(path, params:)
65
71
  end
66
72
 
67
73
  # Returns a purchase order based on the `purchaseOrderNumber` value that you specify.
68
74
  #
69
- # @param [String] purchase_order_number The purchase order identifier for the order that you want. Formatting
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
70
77
  # Notes: 8-character alpha-numeric code.
78
+ # @param rate_limit [Float] Requests per second
71
79
  # @return [Hash] The API response
72
- def get_purchase_order(purchase_order_number)
80
+ def get_purchase_order(purchase_order_number, rate_limit: 10.0)
73
81
  path = "/vendor/orders/v1/purchaseOrders/#{purchase_order_number}"
74
82
 
75
- rate_limit(10.0).get(path)
83
+ meter(rate_limit).get(path)
76
84
  end
77
85
 
78
86
  # Submits acknowledgements for one or more purchase orders.
79
87
  #
80
- # @param [Hash] body
88
+ # @note This operation can make a static sandbox call.
89
+ # @param body [Hash]
90
+ # @param rate_limit [Float] Requests per second
81
91
  # @return [Hash] The API response
82
- def submit_acknowledgement(body)
92
+ def submit_acknowledgement(body, rate_limit: 10.0)
83
93
  path = "/vendor/orders/v1/acknowledgements"
84
94
 
85
- rate_limit(10.0).post(path, body:)
95
+ meter(rate_limit).post(path, body:)
86
96
  end
87
97
 
88
98
  # Returns purchase order statuses based on the filters that you specify. Date range to search must not be more
89
99
  # than 7 days. You can return a list of purchase order statuses using the available filters, or a single purchase
90
100
  # order status by providing the purchase order number.
91
101
  #
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
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
95
106
  # size limit.
96
- # @param [String] created_after Purchase orders that became available after this timestamp will be included in the
107
+ # @param created_after [String] Purchase orders that became available after this timestamp will be included in the
97
108
  # 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
109
+ # @param created_before [String] Purchase orders that became available before this timestamp will be included in
99
110
  # 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
111
+ # @param updated_after [String] Purchase orders for which the last purchase order update happened after this
101
112
  # 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
113
+ # @param updated_before [String] Purchase orders for which the last purchase order update happened before this
103
114
  # 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
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
106
117
  # 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
118
+ # @param item_confirmation_status [String] Filters purchase orders based on their item confirmation status. If the
108
119
  # item confirmation status is not included in the filter, purchase orders for all confirmation statuses are
109
120
  # included.
110
- # @param [String] item_receive_status Filters purchase orders based on the purchase order's item receive status.
121
+ # @param item_receive_status [String] Filters purchase orders based on the purchase order's item receive status.
111
122
  # If the item receive status is not included in the filter, purchase orders for all receive statuses are
112
123
  # included.
113
- # @param [String] ordering_vendor_code Filters purchase orders based on the specified ordering vendor code. This
124
+ # @param ordering_vendor_code [String] Filters purchase orders based on the specified ordering vendor code. This
114
125
  # value should be same as 'sellingParty.partyId' in the purchase order. If not included in filter, all purchase
115
126
  # orders for all the vendor codes that exist in the vendor group used to authorize API client application are
116
127
  # returned.
117
- # @param [String] ship_to_party_id Filters purchase orders for a specific buyer's Fulfillment Center/warehouse by
128
+ # @param ship_to_party_id [String] Filters purchase orders for a specific buyer's Fulfillment Center/warehouse by
118
129
  # providing ship to location id here. This value should be same as 'shipToParty.partyId' in the purchase order.
119
130
  # If not included in filter, this will return purchase orders for all the buyer's warehouses used for vendor
120
131
  # group purchase orders.
132
+ # @param rate_limit [Float] Requests per second
121
133
  # @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
- )
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)
127
138
  path = "/vendor/orders/v1/purchaseOrdersStatus"
128
139
  params = {
129
140
  "limit" => limit,
@@ -141,7 +152,7 @@ module Peddler
141
152
  "shipToPartyId" => ship_to_party_id,
142
153
  }.compact
143
154
 
144
- rate_limit(10.0).get(path, params:)
155
+ meter(rate_limit).get(path, params:)
145
156
  end
146
157
  end
147
158
  end
@@ -3,6 +3,12 @@
3
3
  require "peddler/api"
4
4
 
5
5
  module Peddler
6
+ class << self
7
+ def vendor_shipments_v1(...)
8
+ API::VendorShipmentsV1.new(...)
9
+ end
10
+ end
11
+
6
12
  class API
7
13
  # Selling Partner API for Retail Procurement Shipments
8
14
  #
@@ -11,80 +17,86 @@ module Peddler
11
17
  class VendorShipmentsV1 < API
12
18
  # Submits one or more shipment confirmations for vendor orders.
13
19
  #
14
- # @param [Hash] body A request to submit shipment confirmation.
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
15
23
  # @return [Hash] The API response
16
- def submit_shipment_confirmations(body)
24
+ def submit_shipment_confirmations(body, rate_limit: 10.0)
17
25
  path = "/vendor/shipping/v1/shipmentConfirmations"
18
26
 
19
- rate_limit(10.0).post(path, body:)
27
+ meter(rate_limit).post(path, body:)
20
28
  end
21
29
 
22
30
  # Submits one or more shipment request for vendor Orders.
23
31
  #
24
- # @param [Hash] body A request to submit shipment request.
32
+ # @param body [Hash] A request to submit shipment request.
33
+ # @param rate_limit [Float] Requests per second
25
34
  # @return [Hash] The API response
26
- def submit_shipments(body)
35
+ def submit_shipments(body, rate_limit: 10.0)
36
+ cannot_sandbox!
37
+
27
38
  path = "/vendor/shipping/v1/shipments"
28
39
 
29
- rate_limit(10.0).post(path, body:)
40
+ meter(rate_limit).post(path, body:)
30
41
  end
31
42
 
32
43
  # Returns the Details about Shipment, Carrier Details, status of the shipment, container details and other details
33
44
  # related to shipment based on the filter parameters value that you specify.
34
45
  #
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
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
38
49
  # 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
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
75
86
  # 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
87
+ # @param seller_warehouse_code [String] Get Shipping Details based on vendor warehouse code. This value should be
77
88
  # same as 'sellingParty.partyId' in the Shipment.
89
+ # @param rate_limit [Float] Requests per second
78
90
  # @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,
91
+ def get_shipment_details(limit: nil, sort_order: nil, next_token: nil, created_after: nil, created_before: nil,
81
92
  shipment_confirmed_before: nil, shipment_confirmed_after: nil, package_label_created_before: nil,
82
93
  package_label_created_after: nil, shipped_before: nil, shipped_after: nil, estimated_delivery_before: nil,
83
94
  estimated_delivery_after: nil, shipment_delivery_before: nil, shipment_delivery_after: nil,
84
95
  requested_pick_up_before: nil, requested_pick_up_after: nil, scheduled_pick_up_before: nil,
85
96
  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
- )
97
+ buyer_reference_number: nil, buyer_warehouse_code: nil, seller_warehouse_code: nil, rate_limit: 10.0)
98
+ cannot_sandbox!
99
+
88
100
  path = "/vendor/shipping/v1/shipments"
89
101
  params = {
90
102
  "limit" => limit,
@@ -113,7 +125,7 @@ module Peddler
113
125
  "sellerWarehouseCode" => seller_warehouse_code,
114
126
  }.compact
115
127
 
116
- rate_limit(10.0).get(path, params:)
128
+ meter(rate_limit).get(path, params:)
117
129
  end
118
130
  end
119
131
  end
@@ -3,6 +3,12 @@
3
3
  require "peddler/api"
4
4
 
5
5
  module Peddler
6
+ class << self
7
+ def vendor_transaction_status_v1(...)
8
+ API::VendorTransactionStatusV1.new(...)
9
+ end
10
+ end
11
+
6
12
  class API
7
13
  # Selling Partner API for Retail Procurement Transaction Status
8
14
  #
@@ -11,13 +17,16 @@ module Peddler
11
17
  class VendorTransactionStatusV1 < API
12
18
  # Returns the status of the transaction that you specify.
13
19
  #
14
- # @param [String] transaction_id The GUID provided by Amazon in the 'transactionId' field in response to the post
20
+ # @param transaction_id [String] The GUID provided by Amazon in the 'transactionId' field in response to the post
15
21
  # request of a specific transaction.
22
+ # @param rate_limit [Float] Requests per second
16
23
  # @return [Hash] The API response
17
- def get_transaction(transaction_id)
24
+ def get_transaction(transaction_id, rate_limit: 10.0)
25
+ cannot_sandbox!
26
+
18
27
  path = "/vendor/transactions/v1/transactions/#{transaction_id}"
19
28
 
20
- rate_limit(10.0).get(path)
29
+ meter(rate_limit).get(path)
21
30
  end
22
31
  end
23
32
  end
data/lib/peddler/api.rb CHANGED
@@ -2,14 +2,18 @@
2
2
 
3
3
  require "http"
4
4
 
5
+ require "peddler/endpoint"
5
6
  require "peddler/error"
6
- require "peddler/region"
7
+ require "peddler/version"
7
8
 
8
9
  module Peddler
9
10
  # Wraps an Amazon Selling Partner API (SP-API)
10
11
  class API
11
- # @return [Peddler::Region]
12
- attr_reader :region
12
+ class CannotSandbox < StandardError; end
13
+ class MustSandbox < StandardError; end
14
+
15
+ # @return [Peddler::Endpoint]
16
+ attr_reader :endpoint
13
17
 
14
18
  # @return [String]
15
19
  attr_reader :access_token
@@ -17,41 +21,60 @@ module Peddler
17
21
  # @param [String] aws_region
18
22
  # @param [String] access_token
19
23
  def initialize(aws_region, access_token)
20
- @region = Region.new(aws_region)
24
+ @endpoint = Endpoint.find(aws_region)
21
25
  @access_token = access_token
26
+ @sandbox = false
22
27
  end
23
28
 
24
- def endpoint
25
- @endpoint ||= region.endpoint
29
+ # @return [URI::HTTPS]
30
+ def endpoint_uri
31
+ sandbox? ? endpoint.sandbox : endpoint.production
26
32
  end
27
33
 
28
34
  # @see https://developer-docs.amazon.com/sp-api/docs/the-selling-partner-api-sandbox
29
35
  # @return [self]
30
36
  def sandbox
31
- @endpoint = endpoint.sub(/(?:sandbox.)?sellingpartnerapi/, "sandbox.sellingpartnerapi")
37
+ @sandbox = true
32
38
  self
33
39
  end
34
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
+
35
56
  # @see https://developer-docs.amazon.com/sp-api/docs/include-a-user-agent-header-in-all-requests
36
57
  # @see https://developer-docs.amazon.com/amazon-shipping/docs/connecting-to-the-selling-partner-api#step-3-add-headers-to-the-uri
37
58
  # @return [HTTP::Client]
38
59
  def http
39
60
  @http ||= HTTP.headers(
40
- "Host" => endpoint_host,
61
+ "Host" => endpoint_uri.host,
41
62
  "User-Agent" => user_agent,
42
63
  "X-Amz-Access-Token" => access_token,
43
64
  "X-Amz-Date" => timestamp,
44
65
  )
45
66
  end
46
67
 
47
- # Retries with a rate limit when the API returns a 429
68
+ # Throttles with a rate limit and retries when the API returns a 429
48
69
  #
49
- # @param [Float] delay The delay in seconds before retrying
70
+ # @param [Float] rate_limit The delay in seconds before retrying
50
71
  # @return [self]
51
- def rate_limit(rate)
52
- # HTTP v6.0 will implement retriable
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.
53
74
  # https://github.com/httprb/http/pull/790
54
- retriable(delay: 1.0 / rate, retry_statuses: [429]) if @http.respond_to?(:retriable)
75
+ delay = sandbox? ? 0.2 : 1.0 / rate_limit
76
+ retriable(delay: delay, retry_statuses: [429]) if @http.respond_to?(:retriable)
77
+
55
78
  self
56
79
  end
57
80
 
@@ -87,7 +110,11 @@ module Peddler
87
110
  options[:json] = options.delete(:body)
88
111
  end
89
112
 
90
- response = http.send(method, [endpoint, path].join, **options)
113
+ uri = endpoint_uri.tap do |uri|
114
+ uri.path = path
115
+ end
116
+
117
+ response = http.send(method, uri, **options)
91
118
 
92
119
  if response.status.client_error?
93
120
  error = Error.build(response)
@@ -100,10 +127,6 @@ module Peddler
100
127
 
101
128
  private
102
129
 
103
- def endpoint_host
104
- URI.parse(endpoint).host
105
- end
106
-
107
130
  def user_agent
108
131
  "Peddler/#{Peddler::VERSION} (Language=Ruby; #{Socket.gethostname})"
109
132
  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
data/lib/peddler/error.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  module Peddler
4
4
  class Error < StandardError
5
5
  class InvalidInput < Error; end
6
+ class NotFound < Error; end
6
7
  class QuotaExceeded < Error; end
7
8
  class Unauthorized < Error; end
8
9
 
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "peddler/endpoint"
4
+
5
+ module Peddler
6
+ # @see https://developer-docs.amazon.com/sp-api/docs/marketplace-ids
7
+ MARKETPLACE_IDS = {
8
+ "CA" => { id: "A2EUQ1WTGCTBG2", country_name: "Canada", selling_region: "North America" },
9
+ "US" => { id: "ATVPDKIKX0DER", country_name: "United States", selling_region: "North America" },
10
+ "MX" => { id: "A1AM78C64UM0Y8", country_name: "Mexico", selling_region: "North America" },
11
+ "BR" => { id: "A2Q3Y263D00KWC", country_name: "Brazil", selling_region: "North America" },
12
+ "ES" => { id: "A1RKKUPIHCS9HS", country_name: "Spain", selling_region: "Europe" },
13
+ "UK" => { id: "A1F83G8C2ARO7P", country_name: "United Kingdom", selling_region: "Europe" },
14
+ "FR" => { id: "A13V1IB3VIYZZH", country_name: "France", selling_region: "Europe" },
15
+ "BE" => { id: "AMEN7PMS3EDWL", country_name: "Belgium", selling_region: "Europe" },
16
+ "NL" => { id: "A1805IZSGTT6HS", country_name: "Netherlands", selling_region: "Europe" },
17
+ "DE" => { id: "A1PA6795UKMFR9", country_name: "Germany", selling_region: "Europe" },
18
+ "IT" => { id: "APJ6JRA9NG5V4", country_name: "Italy", selling_region: "Europe" },
19
+ "SE" => { id: "A2NODRKZP88ZB9", country_name: "Sweden", selling_region: "Europe" },
20
+ "ZA" => { id: "AE08WJ6YKNBMC", country_name: "South Africa", selling_region: "Europe" },
21
+ "PL" => { id: "A1C3SOZRARQ6R3", country_name: "Poland", selling_region: "Europe" },
22
+ "EG" => { id: "ARBP9OOSHTCHU", country_name: "Egypt", selling_region: "Europe" },
23
+ "TR" => { id: "A33AVAJ2PDY3EV", country_name: "Turkey", selling_region: "Europe" },
24
+ "SA" => { id: "A17E79C6D8DWNP", country_name: "Saudi Arabia", selling_region: "Europe" },
25
+ "AE" => { id: "A2VIGQ35RCS4UG", country_name: "United Arab Emirates", selling_region: "Europe" },
26
+ "IN" => { id: "A21TJRUUN4KGV", country_name: "India", selling_region: "Europe" },
27
+ "SG" => { id: "A19VAU5U5O7RUS", country_name: "Singapore", selling_region: "Far East" },
28
+ "AU" => { id: "A39IBJ37TRP1C6", country_name: "Australia", selling_region: "Far East" },
29
+ "JP" => { id: "A1VC38T7YXB528", country_name: "Japan", selling_region: "Far East" },
30
+ }
31
+
32
+ Marketplace = Data.define(:id, :country_code, :country_name, :selling_region) do
33
+ class << self
34
+ # @param [String] country_code
35
+ def find(country_code)
36
+ values = MARKETPLACE_IDS.fetch(country_code) do
37
+ raise ArgumentError, "#{country_code} not found"
38
+ end
39
+
40
+ new(**values.merge(country_code: country_code))
41
+ end
42
+ end
43
+
44
+ # @return [Peddler::Endpoint]
45
+ def endpoint
46
+ Endpoint.find_by_selling_region(selling_region)
47
+ end
48
+ end
49
+ end