peddler 4.0.0 → 4.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 989f5bec7dce426405b687e65c4677fe8b359b355d815df799a048ef1907809f
4
- data.tar.gz: eec2f1236bf285bf00c7d32e1482ae2fadaadeb2db9f0bc0a9beb64cf3ec7072
3
+ metadata.gz: 7677959689b208211817ca535b18ec25d495df736d1e502e8b758cdb2c826603
4
+ data.tar.gz: c4c4f26d97ab8bcbb18e2ee0bbac890e7e2284b475a0d19286ea1c15e456b942
5
5
  SHA512:
6
- metadata.gz: 361ce5ea21116bbc09efb9590d080db5275f35dbc6717ccd318c291eb32e4b122b24d06ad4f78c9c693298d8e6e70fc81f3d7a128b843b7949579a601683bf91
7
- data.tar.gz: 956ad0c6b2b7d1a490dffbf846a4c4415e1323510ac52c0eebdb2b42835f5a2f14354f2e0d16fa19099d0823ed47f09218255e98973735e7ccfa1579f08ccefa
6
+ metadata.gz: cc020ae6bda468c2d82044b8a7b226f6101ea141b63d3cd8731ae1c58507b93f11c9e8e18040cb8a31ff0c8dcef40617bdc080f76346f029ddab1b35076027e3
7
+ data.tar.gz: 9e8d25fbdfe70c203331fa4ffda8147000b59e66b0ec0658b99d17a25342e975706d9366d6b7c2d6d9314593cfc6a4fbd7e4bc50b4ff5613aaf452337b7b1061
data/README.md CHANGED
@@ -22,7 +22,7 @@ To begin using the Amazon SP-API, you must [register as a developer][register-as
22
22
  Add this line to your Gemfile.
23
23
 
24
24
  ```ruby
25
- gem "peddler", "~> 3.0"
25
+ gem "peddler", "~> 4.0"
26
26
  ```
27
27
 
28
28
  And then execute:
@@ -102,10 +102,24 @@ end
102
102
 
103
103
  ### Rate limiting
104
104
 
105
- Amazon’s Selling Partner API (SP-API) imposes [rate limits][rate-limits] on most operations. Peddler respects these limits and automatically backs off when throttled. To override the default rate limit, pass a `:rate_limit` argument when running an operation.
105
+ Amazon’s Selling Partner API (SP-API) imposes [rate limits][rate-limits] on most operations. Peddler respects these limits and will automatically back off when throttled. You can override the default rate limit by passing a `:rate_limit` to the operation.
106
+
107
+ You can also provide an optional `:retries` argument when initializing an API to specify the number of retries if throttled. By default, this is set to 0, meaning no retries will be attempted. If set to a positive value, Peddler will retry the request that many times if throttled, backing off based on the specified rate limit.
106
108
 
107
109
  **Note:** This functionality requires version 6 of the underlying [HTTP library][httprb]. As of writing, this is not released yet. To use rate limiting, point to their main branch on GitHub.
108
110
 
111
+ Example usage:
112
+
113
+ ```ruby
114
+ api = Peddler.orders_v0(aws_region, access_token, retries: 3)
115
+ api.get_orders(
116
+ marketplaceIds: ["ATVPDKIKX0DER"],
117
+ createdAfter: "2023-01-01T00:00:00Z"
118
+ )
119
+ ```
120
+
121
+ In this example, if the request to `get_orders` is throttled, Peddler will retry the request up to 3 times, backing off according to the rate limit specified by Amazon.
122
+
109
123
  ### The APIs
110
124
 
111
125
  Peddler provides a class for each API version under an eponymous namespace. Below is a list of the more important APIs, along with brief descriptions and code examples to help you get started.
@@ -493,10 +507,10 @@ response.parse
493
507
 
494
508
  ## TODO
495
509
 
496
- - Code generate models to parse payload. Consider using `dry-struct`.
497
- - Code generate the APIs section—descriptions and code examples—in this README here.
498
- - Schedule code generation with GitHub Actions. Push new gem when models change.
499
- - Review and consider applying [these patches][patches].
510
+ - [ ] Code generate payload parsers.
511
+ - [ ] Code generate the APIs section—descriptions and code examples—in this README here.
512
+ - [ ] Schedule code generation with GitHub Actions. Push new gem when models change.
513
+ - [ ] Review and consider applying [these patches][patches].
500
514
 
501
515
  [build]: https://github.com/hakanensari/peddler/actions
502
516
  [maintainability]: https://codeclimate.com/github/hakanensari/peddler/maintainability
data/lib/peddler/api.rb CHANGED
@@ -25,11 +25,17 @@ module Peddler
25
25
  # @return [String]
26
26
  attr_reader :access_token
27
27
 
28
+ # Number of retries if throttled (default: 0)
29
+ #
30
+ # @return [Integer]
31
+ attr_reader :retries
32
+
28
33
  # @param [String] aws_region
29
34
  # @param [String] access_token
30
- def initialize(aws_region, access_token)
35
+ def initialize(aws_region, access_token, retries: 0)
31
36
  @endpoint = Endpoint.find(aws_region)
32
37
  @access_token = access_token
38
+ @retries = retries
33
39
  @sandbox = false
34
40
  end
35
41
 
@@ -66,13 +72,15 @@ module Peddler
66
72
 
67
73
  # Throttles with a rate limit and retries when the API returns a 429
68
74
  #
69
- # @param [Float] rate_limit The delay in seconds before retrying
75
+ # @param [Float] requests_per_second
70
76
  # @return [self]
71
- def meter(rate_limit)
77
+ def meter(requests_per_second)
78
+ return self if retries.zero?
79
+
72
80
  # HTTP v6.0 will implement retriable. Until then, point to their GitHub repo, or it's a no-op.
73
81
  # https://github.com/httprb/http/pull/790
74
- delay = sandbox? ? 0.2 : 1.0 / rate_limit
75
- retriable(delay: delay, retry_statuses: [429])
82
+ delay = sandbox? ? 0.2 : 1.0 / requests_per_second
83
+ retriable(delay:, tries: retries + 1, retry_statuses: [429])
76
84
 
77
85
  self
78
86
  end
@@ -96,8 +104,8 @@ module Peddler
96
104
  # @param (see Performer#initialize)
97
105
  # @return [self]
98
106
  [:via, :use, :retriable].each do |method|
99
- define_method(method) do |*args, &block|
100
- @http = http.send(method, *args, &block) if http.respond_to?(method)
107
+ define_method(method) do |*args, **kwargs, &block|
108
+ @http = http.send(method, *args, **kwargs, &block) if http.respond_to?(method)
101
109
  self
102
110
  end
103
111
  end
@@ -39,10 +39,9 @@ module Peddler
39
39
  # @param isbn [String] The unique commercial book identifier used to identify books internationally.
40
40
  # @param jan [String] A Japanese article number that uniquely identifies the product, manufacturer, and its
41
41
  # attributes.
42
- # @param rate_limit [Float] Requests per second
43
42
  # @return [Peddler::Response] The API response
44
43
  def list_catalog_items(marketplace_id, query: nil, query_context_id: nil, seller_sku: nil, upc: nil, ean: nil,
45
- isbn: nil, jan: nil, rate_limit: nil)
44
+ isbn: nil, jan: nil)
46
45
  path = "/catalog/v0/items"
47
46
  params = {
48
47
  "MarketplaceId" => marketplace_id,
@@ -68,9 +67,8 @@ module Peddler
68
67
  # @note This operation can make a static sandbox call.
69
68
  # @param marketplace_id [String] A marketplace identifier. Specifies the marketplace for the item.
70
69
  # @param asin [String] The Amazon Standard Identification Number (ASIN) of the item.
71
- # @param rate_limit [Float] Requests per second
72
70
  # @return [Peddler::Response] The API response
73
- def get_catalog_item(marketplace_id, asin, rate_limit: nil)
71
+ def get_catalog_item(marketplace_id, asin)
74
72
  path = "/catalog/v0/items/#{asin}"
75
73
  params = {
76
74
  "MarketplaceId" => marketplace_id,
@@ -68,9 +68,8 @@ module Peddler
68
68
  #
69
69
  # @note This operation can make a dynamic sandbox call.
70
70
  # @param create_inventory_item_request_body [Hash] CreateInventoryItem Request Body Parameter.
71
- # @param rate_limit [Float] Requests per second
72
71
  # @return [Peddler::Response] The API response
73
- def create_inventory_item(create_inventory_item_request_body, rate_limit: nil)
72
+ def create_inventory_item(create_inventory_item_request_body)
74
73
  must_sandbox!
75
74
 
76
75
  path = "/fba/inventory/v1/items"
@@ -86,9 +85,8 @@ module Peddler
86
85
  # @note This operation can make a dynamic sandbox call.
87
86
  # @param seller_sku [String] A single seller SKU used for querying the specified seller SKU inventory summaries.
88
87
  # @param marketplace_id [String] The marketplace ID for the marketplace for which the sellerSku is to be deleted.
89
- # @param rate_limit [Float] Requests per second
90
88
  # @return [Peddler::Response] The API response
91
- def delete_inventory_item(seller_sku, marketplace_id, rate_limit: nil)
89
+ def delete_inventory_item(seller_sku, marketplace_id)
92
90
  must_sandbox!
93
91
 
94
92
  path = "/fba/inventory/v1/items/#{seller_sku}"
@@ -107,9 +105,8 @@ module Peddler
107
105
  # @note This operation can make a dynamic sandbox call.
108
106
  # @param x_amzn_idempotency_token [String] A unique token/requestId provided with each call to ensure idempotency.
109
107
  # @param add_inventory_request_body [Hash] List of items to add to Sandbox inventory.
110
- # @param rate_limit [Float] Requests per second
111
108
  # @return [Peddler::Response] The API response
112
- def add_inventory(x_amzn_idempotency_token, add_inventory_request_body, rate_limit: nil)
109
+ def add_inventory(x_amzn_idempotency_token, add_inventory_request_body)
113
110
  must_sandbox!
114
111
 
115
112
  path = "/fba/inventory/v1/items/inventory"
@@ -184,9 +184,8 @@ module Peddler
184
184
  # @param seller_fulfillment_order_id [String] The identifier assigned to the item by the seller when the
185
185
  # fulfillment order was created.
186
186
  # @param body [Hash] The identifier assigned to the item by the seller when the fulfillment order was created.
187
- # @param rate_limit [Float] Requests per second
188
187
  # @return [Peddler::Response] The API response
189
- def submit_fulfillment_order_status_update(seller_fulfillment_order_id, body, rate_limit: nil)
188
+ def submit_fulfillment_order_status_update(seller_fulfillment_order_id, body)
190
189
  must_sandbox!
191
190
 
192
191
  path = "/fba/outbound/2020-07-01/fulfillmentOrders/#{seller_fulfillment_order_id}/status"
@@ -258,9 +258,8 @@ module Peddler
258
258
  # @param marketplace_ids [Array<String>] A marketplace identifier. This specifies the marketplace in which the
259
259
  # order was placed. Only one marketplace can be specified.
260
260
  # @param body [Hash]
261
- # @param rate_limit [Float] Requests per second
262
261
  # @return [Peddler::Response] The API response
263
- def send_invoice(amazon_order_id, marketplace_ids, body, rate_limit: nil)
262
+ def send_invoice(amazon_order_id, marketplace_ids, body)
264
263
  path = "/messaging/v1/orders/#{amazon_order_id}/messages/invoice"
265
264
  params = {
266
265
  "marketplaceIds" => marketplace_ids,
@@ -19,9 +19,8 @@ module Peddler
19
19
  # @note This operation can make a static sandbox call.
20
20
  # @param next_page_token [String] The pagination token to retrieve a specific page of results.
21
21
  # @param page_size [Number] The number of supply sources to return per paginated request.
22
- # @param rate_limit [Float] Requests per second
23
22
  # @return [Peddler::Response] The API response
24
- def get_supply_sources(next_page_token: nil, page_size: 10, rate_limit: nil)
23
+ def get_supply_sources(next_page_token: nil, page_size: 10)
25
24
  path = "/supplySources/2020-07-01/supplySources"
26
25
  params = {
27
26
  "nextPageToken" => next_page_token,
@@ -35,9 +34,8 @@ module Peddler
35
34
  #
36
35
  # @note This operation can make a static sandbox call.
37
36
  # @param payload [Hash] A request to create a supply source.
38
- # @param rate_limit [Float] Requests per second
39
37
  # @return [Peddler::Response] The API response
40
- def create_supply_source(payload, rate_limit: nil)
38
+ def create_supply_source(payload)
41
39
  path = "/supplySources/2020-07-01/supplySources"
42
40
  body = payload
43
41
 
@@ -48,9 +46,8 @@ module Peddler
48
46
  #
49
47
  # @note This operation can make a static sandbox call.
50
48
  # @param supply_source_id [String] The unique identifier of a supply source.
51
- # @param rate_limit [Float] Requests per second
52
49
  # @return [Peddler::Response] The API response
53
- def get_supply_source(supply_source_id, rate_limit: nil)
50
+ def get_supply_source(supply_source_id)
54
51
  path = "/supplySources/2020-07-01/supplySources/#{supply_source_id}"
55
52
 
56
53
  get(path)
@@ -61,9 +58,8 @@ module Peddler
61
58
  # @note This operation can make a static sandbox call.
62
59
  # @param supply_source_id [String] The unique identitier of a supply source.
63
60
  # @param payload [Hash]
64
- # @param rate_limit [Float] Requests per second
65
61
  # @return [Peddler::Response] The API response
66
- def update_supply_source(supply_source_id, payload: nil, rate_limit: nil)
62
+ def update_supply_source(supply_source_id, payload: nil)
67
63
  path = "/supplySources/2020-07-01/supplySources/#{supply_source_id}"
68
64
  body = payload
69
65
 
@@ -74,9 +70,8 @@ module Peddler
74
70
  #
75
71
  # @note This operation can make a static sandbox call.
76
72
  # @param supply_source_id [String] The unique identifier of a supply source.
77
- # @param rate_limit [Float] Requests per second
78
73
  # @return [Peddler::Response] The API response
79
- def archive_supply_source(supply_source_id, rate_limit: nil)
74
+ def archive_supply_source(supply_source_id)
80
75
  path = "/supplySources/2020-07-01/supplySources/#{supply_source_id}"
81
76
 
82
77
  delete(path)
@@ -87,9 +82,8 @@ module Peddler
87
82
  # @note This operation can make a static sandbox call.
88
83
  # @param supply_source_id [String] The unique identifier of a supply source.
89
84
  # @param payload [Hash]
90
- # @param rate_limit [Float] Requests per second
91
85
  # @return [Peddler::Response] The API response
92
- def update_supply_source_status(supply_source_id, payload: nil, rate_limit: nil)
86
+ def update_supply_source_status(supply_source_id, payload: nil)
93
87
  path = "/supplySources/2020-07-01/supplySources/#{supply_source_id}/status"
94
88
  body = payload
95
89
 
@@ -19,9 +19,8 @@ module Peddler
19
19
  #
20
20
  # @note This operation can make a dynamic sandbox call.
21
21
  # @param body [Hash] The request payload containing parameters for generating test order data scenarios.
22
- # @param rate_limit [Float] Requests per second
23
22
  # @return [Peddler::Response] The API response
24
- def generate_order_scenarios(body, rate_limit: nil)
23
+ def generate_order_scenarios(body)
25
24
  path = "/vendor/directFulfillment/sandbox/2021-10-28/orders"
26
25
 
27
26
  post(path, body:)
@@ -33,9 +32,8 @@ module Peddler
33
32
  # @note This operation can make a dynamic sandbox call.
34
33
  # @param transaction_id [String] The transaction identifier returned in the response to the generateOrderScenarios
35
34
  # operation.
36
- # @param rate_limit [Float] Requests per second
37
35
  # @return [Peddler::Response] The API response
38
- def get_order_scenarios(transaction_id, rate_limit: nil)
36
+ def get_order_scenarios(transaction_id)
39
37
  path = "/vendor/directFulfillment/sandbox/2021-10-28/transactions/#{transaction_id}"
40
38
 
41
39
  get(path)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Peddler
4
- VERSION = "4.0.0"
4
+ VERSION = "4.1.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: peddler
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hakan Ensari
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-12-13 00:00:00.000000000 Z
11
+ date: 2024-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http