peddler 3.0.0.beta1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +96 -106
- data/lib/peddler/api/amazon_warehousing_and_distribution_2024_05_09.rb +34 -22
- data/lib/peddler/api/aplus_content_2020_11_01.rb +86 -48
- data/lib/peddler/api/application_integrations_2024_04_01.rb +56 -0
- data/lib/peddler/api/application_management_2023_11_30.rb +12 -2
- data/lib/peddler/api/catalog_items_2020_12_01.rb +31 -20
- data/lib/peddler/api/catalog_items_2022_04_01.rb +35 -25
- data/lib/peddler/api/catalog_items_v0.rb +39 -26
- data/lib/peddler/api/data_kiosk_2023_11_15.rb +41 -25
- data/lib/peddler/api/easy_ship_2022_03_23.rb +62 -43
- data/lib/peddler/api/fba_inbound_eligibility_v1.rb +13 -5
- data/lib/peddler/api/fba_inventory_v1.rb +40 -24
- data/lib/peddler/api/feeds_2021_06_30.rb +43 -25
- data/lib/peddler/api/finances_2024_06_19.rb +50 -0
- data/lib/peddler/api/finances_v0.rb +86 -59
- data/lib/peddler/api/fulfillment_inbound_2024_03_20.rb +304 -205
- data/lib/peddler/api/fulfillment_inbound_v0.rb +112 -74
- data/lib/peddler/api/fulfillment_outbound_2020_07_01.rb +90 -53
- data/lib/peddler/api/invoices_2024_06_19.rb +180 -0
- data/lib/peddler/api/listings_items_2020_09_01.rb +44 -33
- data/lib/peddler/api/listings_items_2021_08_01.rb +76 -60
- data/lib/peddler/api/listings_restrictions_2021_08_01.rb +19 -9
- data/lib/peddler/api/merchant_fulfillment_v0.rb +31 -15
- data/lib/peddler/api/messaging_v1.rb +93 -61
- data/lib/peddler/api/notifications_v1.rb +54 -23
- data/lib/peddler/api/orders_v0.rb +87 -72
- data/lib/peddler/api/product_fees_v0.rb +39 -31
- data/lib/peddler/api/product_pricing_2022_05_01.rb +17 -6
- data/lib/peddler/api/product_pricing_v0.rb +63 -45
- data/lib/peddler/api/product_type_definitions_2020_09_01.rb +29 -18
- data/lib/peddler/api/replenishment_2022_11_07.rb +21 -9
- data/lib/peddler/api/reports_2021_06_30.rb +60 -36
- data/lib/peddler/api/sales_v1.rb +20 -12
- data/lib/peddler/api/sellers_v1.rb +16 -4
- data/lib/peddler/api/services_v1.rb +138 -98
- data/lib/peddler/api/shipment_invoicing_v0.rb +25 -12
- data/lib/peddler/api/shipping_v1.rb +54 -29
- data/lib/peddler/api/shipping_v2.rb +132 -80
- data/lib/peddler/api/solicitations_v1.rb +18 -8
- data/lib/peddler/api/supply_sources_2020_07_01.rb +33 -15
- data/lib/peddler/api/tokens_2021_03_01.rb +13 -5
- data/lib/peddler/api/uploads_2020_11_01.rb +16 -6
- data/lib/peddler/api/vendor_direct_fulfillment_inventory_v1.rb +12 -4
- data/lib/peddler/api/vendor_direct_fulfillment_orders_2021_12_28.rb +29 -17
- data/lib/peddler/api/vendor_direct_fulfillment_orders_v1.rb +29 -17
- data/lib/peddler/api/vendor_direct_fulfillment_payments_v1.rb +11 -3
- data/lib/peddler/api/vendor_direct_fulfillment_sandbox_test_data_2021_10_28.rb +14 -4
- data/lib/peddler/api/vendor_direct_fulfillment_shipping_2021_12_28.rb +74 -48
- data/lib/peddler/api/vendor_direct_fulfillment_shipping_v1.rb +74 -50
- data/lib/peddler/api/vendor_direct_fulfillment_transactions_2021_12_28.rb +11 -3
- data/lib/peddler/api/vendor_direct_fulfillment_transactions_v1.rb +11 -3
- data/lib/peddler/api/vendor_invoices_v1.rb +11 -3
- data/lib/peddler/api/vendor_orders_v1.rb +54 -43
- data/lib/peddler/api/vendor_shipments_v1.rb +63 -51
- data/lib/peddler/api/vendor_transaction_status_v1.rb +12 -3
- data/lib/peddler/api.rb +41 -18
- data/lib/peddler/endpoint.rb +51 -0
- data/lib/peddler/error.rb +1 -0
- data/lib/peddler/marketplace.rb +49 -0
- data/lib/peddler/token.rb +70 -0
- data/lib/peddler/version.rb +1 -1
- data/lib/peddler.rb +56 -52
- metadata +10 -6
- data/lib/peddler/access_token.rb +0 -76
- 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
|
-
# @
|
18
|
-
# @param [
|
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]
|
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]
|
23
|
-
# @param [String]
|
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]
|
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]
|
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]
|
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]
|
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]
|
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]
|
38
|
-
# @param [String]
|
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
|
-
|
45
|
-
|
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
|
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
|
-
# @
|
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
|
83
|
+
meter(rate_limit).get(path)
|
76
84
|
end
|
77
85
|
|
78
86
|
# Submits acknowledgements for one or more purchase orders.
|
79
87
|
#
|
80
|
-
# @
|
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
|
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
|
-
# @
|
93
|
-
# @param [
|
94
|
-
# @param [String]
|
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]
|
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]
|
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]
|
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]
|
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]
|
105
|
-
# @param [String]
|
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]
|
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]
|
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]
|
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]
|
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
|
-
|
124
|
-
|
125
|
-
|
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
|
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
|
-
# @
|
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
|
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]
|
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
|
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]
|
36
|
-
# @param [String]
|
37
|
-
# @param [String]
|
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]
|
40
|
-
# in the result. Must be in
|
41
|
-
# @param [String]
|
42
|
-
# in the result. Must be in
|
43
|
-
# @param [String]
|
44
|
-
# Must be in
|
45
|
-
# @param [String]
|
46
|
-
# Must be in
|
47
|
-
# @param [String]
|
48
|
-
# Must be in
|
49
|
-
# @param [String]
|
50
|
-
# buyer. Must be in
|
51
|
-
# @param [String]
|
52
|
-
#
|
53
|
-
# @param [String]
|
54
|
-
#
|
55
|
-
# @param [String]
|
56
|
-
# be in
|
57
|
-
# @param [String]
|
58
|
-
# in
|
59
|
-
# @param [String]
|
60
|
-
# in
|
61
|
-
# @param [String]
|
62
|
-
#
|
63
|
-
# @param [String]
|
64
|
-
# in
|
65
|
-
# @param [String]
|
66
|
-
#
|
67
|
-
# @param [String]
|
68
|
-
# in
|
69
|
-
# @param [String]
|
70
|
-
#
|
71
|
-
# @param [String]
|
72
|
-
# @param [String]
|
73
|
-
# @param [String]
|
74
|
-
# @param [String]
|
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]
|
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
|
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]
|
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
|
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/
|
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
|
-
|
12
|
-
|
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
|
-
@
|
24
|
+
@endpoint = Endpoint.find(aws_region)
|
21
25
|
@access_token = access_token
|
26
|
+
@sandbox = false
|
22
27
|
end
|
23
28
|
|
24
|
-
|
25
|
-
|
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
|
-
@
|
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" =>
|
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
|
-
#
|
68
|
+
# Throttles with a rate limit and retries when the API returns a 429
|
48
69
|
#
|
49
|
-
# @param [Float]
|
70
|
+
# @param [Float] rate_limit The delay in seconds before retrying
|
50
71
|
# @return [self]
|
51
|
-
def rate_limit
|
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
|
-
|
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
|
-
|
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
@@ -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
|