asindotdev 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 170ee5aab5befec0bdc0e4cf1bc00e0e9ded747cf2ea3a28e357c3d945b78274
4
- data.tar.gz: 99c1e85a7ec4aa97b72ec8490516bf0f8884a734568f2fd28d00913b5fcaac7e
3
+ metadata.gz: c76fbf769366acb714265ed960d8b11fcc3996eb5f9b39c1e159bea783edc0d0
4
+ data.tar.gz: 80c7853253e3aca4135eb1ad514e348958697a8cdd66bb6734e0c22262dd89af
5
5
  SHA512:
6
- metadata.gz: 3043522567bc7a0cc8d49d4ad405ffc8a09a4e77b5a87bc7464206e1b5e6b6bd68bd4b28bc64c60fb26cb3e1c3a313d269ff9d1b07f201f130ebeb45394b0e54
7
- data.tar.gz: 0d666a57f3fab1f81bf8f442bfbc92b114cd5cea5412c5e3ba312c1e98a3986ee85ecbbefdbc993208dcd22f859716564910604facb16d2fb9a5830d5854d1b8
6
+ metadata.gz: 58df38bb877353143cc1b18b2dc76ac6ea352fc62570fc46ecdc8c6bbbfb06600ecb6956c8aa6f10f2f23b6914ab360e6eb7aa33ad32ed5e51393525a485d271
7
+ data.tar.gz: 97d7843b833262be91ff39d1858662389dcc9372fb84dca7787aef9bd88669298a3158f7c9f379e1448ba9060b7b90c6feddbe129a744ab673a12311732516e6
data/README.md CHANGED
@@ -4,7 +4,7 @@ The official Ruby SDK for the [Asin](https://www.asin.dev) Amazon price tracking
4
4
 
5
5
  Track Amazon prices and products with a scheduled watchlist, price history, offers and alerts.
6
6
 
7
- The SDK exposes **11 methods**, one per documented endpoint, plus a generic `request`. It only uses the Ruby standard library.
7
+ The SDK exposes **11 methods**, one per documented endpoint, plus `clear_target_price` and a generic `request`. It only uses the Ruby standard library.
8
8
 
9
9
  ## Requirements
10
10
 
@@ -40,7 +40,7 @@ Keyword arguments use the parameter names of the [API reference](https://www.asi
40
40
 
41
41
  ## HTTP methods
42
42
 
43
- Each method uses the HTTP verb of its endpoint. `GET` and `DELETE` send parameters in the query string; `POST` and `PATCH` send them as a JSON body, except `wait` on `/products/{id}/check`, which stays in the query string. Null values are never sent, so `target_price` cannot be removed through the SDK yet.
43
+ Each method uses the HTTP verb of its endpoint. `GET` and `DELETE` send parameters in the query string; `POST` and `PATCH` send them as a JSON body, except `wait` on `/products/{id}/check`, which stays in the query string. `nil` values are never sent, so `update_product(target_price: nil)` leaves the target price as it is; `client.clear_target_price(id: product_id)` removes it (it sends `PATCH /products/{id}` with `{"target_price": null}`).
44
44
 
45
45
  `nil` values are omitted, `false` and `0` are sent, and arrays repeat the parameter name.
46
46
 
@@ -65,14 +65,14 @@ end
65
65
  | `Asin::ConfigurationError` | Missing API key, invalid options or unsupported method. |
66
66
  | `Asin::SerializationError` | A required parameter is missing, unknown or can't be sent. |
67
67
  | `Asin::TransportError` | Network failure or timeout. |
68
- | `Asin::APIError` | Non-2xx status (`status`, `error_message`, `response_body`, `raw_response`). |
68
+ | `Asin::APIError` | Non-2xx status (`status`, `error_code`, `error_message`, `response_body`, `raw_response`). `error_code` is the API's `error.code`, such as `"insufficient_credits"` or `"product_limit"`, or `nil` when the body has none. |
69
69
  | `Asin::ResponseDecodingError` | A success response could not be decoded. |
70
70
 
71
71
  All of them inherit from `Asin::Error`.
72
72
 
73
73
  ## Retries
74
74
 
75
- Requests are retried up to 3 times after a network error, a `408`, `429`, `500`, `502`, `503` or `504`. Other statuses, such as `400`, `401`, `402` or `404`, and client-side timeouts are not retried. The delay starts at 1 second and grows 1.5× per retry (capped at 30 seconds); a `Retry-After` header wins.
75
+ Requests are retried up to 3 times after a network error, a `408`, `500`, `502`, `503` or `504`. Other statuses, such as `400`, `401`, `402`, `404` or `429`, and client-side timeouts are not retried: the API's rate limits last until the hour (or the day) is over, and on the free plan every retry would count as a request. The delay starts at 1 second and grows 1.5× per retry (capped at 30 seconds); a `Retry-After` header wins.
76
76
 
77
77
  ```ruby
78
78
  client = Asin::Client.new(max_retries: 5, retry_delay: 0.5)
@@ -99,7 +99,7 @@ end
99
99
  | --- | --- | --- |
100
100
  | `Asin::Client::DEFAULT_CONCURRENCY` | `10` | Tasks run at the same time by batch |
101
101
  | `Asin::Client::DEFAULT_TIMEOUT` | `120` | Request timeout (seconds) |
102
- | `Asin::Client::MAX_RETRIES` | `3` | Retry attempts after a network error, a 408/429/5xx |
102
+ | `Asin::Client::MAX_RETRIES` | `3` | Retry attempts after a network error, a 408/5xx |
103
103
  | `Asin::Client::RETRY_BACKOFF_FACTOR` | `1.5` | Exponential backoff multiplier |
104
104
  | `Asin::Client::DEFAULT_RETRY_DELAY` | `1.0` | Delay before the first retry (seconds) |
105
105
 
@@ -119,16 +119,35 @@ A transport is any object with `call(method:, url:, headers:, body:, timeout:)`
119
119
  | Method | HTTP | Description |
120
120
  | --- | --- | --- |
121
121
  | `check_product` | POST `/products/{id}/check` | Asks for a check right away (1 credit), at most once per 5 minutes; earlier calls return the product unchanged. A paused product has to be… |
122
+ | `clear_target_price` | PATCH `/products/{id}` | Removes the target price: sends `{"target_price": null}`, which `update_product` cannot since `nil` values are omitted. |
122
123
  | `delete_product` | DELETE `/products/{id}` | Removes the product and its price history. |
123
124
  | `fetch_offers` | POST `/offers` | Reads the offers on Amazon for 1 credit, refunded if it doesn't answer. A read made in the last 3 hours, by anyone, is returned instead, fo… |
124
- | `get_account` | GET `/account` | Your plan, the credits left (monthly allowance and packs), how many products you track and the credits they use per month. |
125
+ | `get_account` | GET `/account` | Your plan, the credits left (monthly allowance and packs), how many products you track and the credits they use per month, the credits each… |
125
126
  | `get_asin_history` | GET `/history` | Every price Asin read for an ASIN on a marketplace over the period, whoever tracks it, oldest first, with the lowest, highest and average o… |
126
127
  | `get_offers` | GET `/offers` | Who sells the product and at what price, as last read, cheapest first, with Amazon's own price and the cheapest new and used offers (used i… |
127
128
  | `get_product` | GET `/products/{id}` | The product's latest state and every price read of the period, oldest first. The history covers every read of this ASIN on this marketplace… |
128
129
  | `list_products` | GET `/products` | Your watchlist, newest first, with each product's latest state and its recent prices (trend). Filter with asin (and marketplace) to know if… |
129
130
  | `search_amazon` | GET `/search` | Amazon search results (up to 60, sponsored included), to find the ASIN of a product. Free, limited to 30 searches per hour. |
130
131
  | `track_product` | POST `/products` | Adds an ASIN, an Amazon link or a short link (amzn.to, a.co…) to your watchlist. The first check runs in the background within seconds (che… |
131
- | `update_product` | PATCH `/products/{id}` | Target price, drop alerts, check interval, or pause. Send only what changes. |
132
+ | `update_product` | PATCH `/products/{id}` | Target price, drop alerts, check interval, or pause. Send only what changes. On the free plan, alerts (price drop, back in stock, target pr… |
133
+
134
+ ## All Asin SDKs
135
+
136
+ | SDK | Package | Install |
137
+ | --- | --- | --- |
138
+ | Node.js | [`@asindev/sdk`](https://www.npmjs.com/package/@asindev/sdk) | `npm install @asindev/sdk` |
139
+ | Python | [`asindotdev`](https://pypi.org/project/asindotdev/) | `pip install asindotdev` |
140
+ | Go | [`asin-go`](https://pkg.go.dev/github.com/asindotdev/asin-go) | `go get github.com/asindotdev/asin-go` |
141
+ | .NET | [`Asin`](https://www.nuget.org/packages/Asin) | `dotnet add package Asin` |
142
+ | Ruby | [`asindotdev`](https://rubygems.org/gems/asindotdev) | `gem install asindotdev` |
143
+ | PHP | [`asindotdev/sdk`](https://packagist.org/packages/asindotdev/sdk) | `composer require asindotdev/sdk` |
144
+ | Java | [`asin-java`](https://github.com/asindotdev/asin-java) | build from source, see its README |
145
+ | CLI | [`@asindev/cli`](https://www.npmjs.com/package/@asindev/cli) | `npm install -g @asindev/cli` |
146
+ | MCP server | [`@asindev/mcp`](https://www.npmjs.com/package/@asindev/mcp) | `npx -y @asindev/mcp` |
147
+
148
+ ## Trademarks
149
+
150
+ Amazon® is a trademark of Amazon.com, Inc. or its affiliates. Asin is not affiliated with, endorsed or sponsored by Amazon.
132
151
 
133
152
  ## License
134
153
 
data/lib/asin/client.rb CHANGED
@@ -11,14 +11,14 @@ module Asin
11
11
  DEFAULT_TIMEOUT = 120
12
12
  # Tasks run at the same time by #batch.
13
13
  DEFAULT_CONCURRENCY = 10
14
- # Retries after a network error or a 408, 429, 500, 502, 503 or 504 response.
14
+ # Retries after a network error or a 408, 500, 502, 503 or 504 response (never a 429).
15
15
  MAX_RETRIES = 3
16
16
  # Each retry waits this many times longer than the previous one (a Retry-After header wins).
17
17
  RETRY_BACKOFF_FACTOR = 1.5
18
18
  # Seconds before the first retry.
19
19
  DEFAULT_RETRY_DELAY = 1.0
20
20
  MAX_RETRY_DELAY = 30.0
21
- RETRYABLE_STATUSES = [408, 429, 500, 502, 503, 504].freeze
21
+ RETRYABLE_STATUSES = [408, 500, 502, 503, 504].freeze
22
22
  API_KEY_ENVIRONMENT_VARIABLE = "ASIN_API_KEY"
23
23
  ERROR_MESSAGE_KEYS = %w[error message error_message detail].freeze
24
24
 
@@ -26,7 +26,7 @@ module Asin
26
26
  # @param base_url [String] API origin
27
27
  # @param timeout [Numeric, nil] seconds per request; nil disables it
28
28
  # @param headers [Hash] extra headers for every request
29
- # @param max_retries [Integer] retries after a network error or a 408/429/5xx response; 0 disables them
29
+ # @param max_retries [Integer] retries after a network error or a 408/5xx response; 0 disables them
30
30
  # @param retry_delay [Numeric] seconds before the first retry, growing 1.5x per retry
31
31
  # @param transport [#call] custom transport, see {NetHTTPTransport}
32
32
  def initialize(api_key: nil, base_url: DEFAULT_BASE_URL, timeout: DEFAULT_TIMEOUT, headers: {},
@@ -190,9 +190,11 @@ module Asin
190
190
  def api_error(raw)
191
191
  parsed = parse_json(raw.body)
192
192
  message = nil
193
+ code = nil
193
194
  if parsed.is_a?(Hash)
194
195
  # The API answers {"error": {"code", "message"}}.
195
196
  message = parsed["error"]["message"] if parsed["error"].is_a?(Hash) && parsed["error"]["message"].is_a?(String)
197
+ code = parsed["error"]["code"] if parsed["error"].is_a?(Hash) && parsed["error"]["code"].is_a?(String)
196
198
  ERROR_MESSAGE_KEYS.each do |key|
197
199
  value = parsed[key]
198
200
  if value.is_a?(String) && !value.empty?
@@ -201,7 +203,7 @@ module Asin
201
203
  end
202
204
  end
203
205
  end
204
- APIError.new(raw_response: raw, response_body: parsed == NOT_JSON ? nil : parsed, error_message: message)
206
+ APIError.new(raw_response: raw, response_body: parsed == NOT_JSON ? nil : parsed, error_message: message, error_code: code)
205
207
  end
206
208
 
207
209
  def decode(raw, expected)
data/lib/asin/errors.rb CHANGED
@@ -22,11 +22,13 @@ module Asin
22
22
 
23
23
  # Asin returned a non-success HTTP status.
24
24
  class APIError < Error
25
- attr_reader :status, :error_message, :response_body, :raw_response
25
+ # error_code is the API's error.code (e.g. "insufficient_credits"), nil when the body has none.
26
+ attr_reader :status, :error_code, :error_message, :response_body, :raw_response
26
27
 
27
- def initialize(raw_response:, response_body: nil, error_message: nil)
28
+ def initialize(raw_response:, response_body: nil, error_message: nil, error_code: nil)
28
29
  super(error_message || "Asin API request failed with status #{raw_response.status}.")
29
30
  @status = raw_response.status
31
+ @error_code = error_code
30
32
  @error_message = error_message
31
33
  @response_body = response_body
32
34
  @raw_response = raw_response
@@ -41,7 +41,7 @@ module Asin
41
41
  call_operation("fetch_offers", params, request_options)
42
42
  end
43
43
 
44
- # Plan and remaining credits. Your plan, the credits left (monthly allowance and packs), how many products you track and the credits they use per month.
44
+ # Plan and remaining credits. Your plan, the credits left (monthly allowance and packs), how many products you track and the credits they use per month, the credits each alert email costs, the days of history you can read and, on the free plan, the API and MCP requests…
45
45
  #
46
46
  # +GET /account+
47
47
  #
@@ -51,13 +51,13 @@ module Asin
51
51
  call_operation("get_account", params, request_options)
52
52
  end
53
53
 
54
- # Price history of any ASIN. Every price Asin read for an ASIN on a marketplace over the period, whoever tracks it, oldest first, with the lowest, highest and average of those prices. A history of more than 5000 points is thinned evenly, keeping its first and last poi…
54
+ # Price history of any ASIN. Every price Asin read for an ASIN on a marketplace over the period, whoever tracks it, oldest first, with the lowest, highest and average of those prices. A price the store gave in another currency than the marketplace's isn't part of it.…
55
55
  #
56
56
  # +GET /history+
57
57
  #
58
58
  # @param asin [String] (required) 10-character ASIN
59
59
  # @param marketplace [String] Amazon store, e.g. com for amazon.com
60
- # @param days [Integer] History period in days
60
+ # @param days [Integer] History period in days. The free plan reads the last 30: history_days says which period was returned.
61
61
  # @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
62
62
  # @return [JsonResponse]
63
63
  def get_asin_history(request_options: nil, **params)
@@ -81,7 +81,7 @@ module Asin
81
81
  # +GET /products/{id}+
82
82
  #
83
83
  # @param id [String] (required) product_id returned when the product was added
84
- # @param days [Integer] History period in days
84
+ # @param days [Integer] History period in days. The free plan reads the last 30: history_days says which period was returned.
85
85
  # @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
86
86
  # @return [JsonResponse]
87
87
  def get_product(request_options: nil, **params)
@@ -119,9 +119,9 @@ module Asin
119
119
  #
120
120
  # +POST /products+
121
121
  #
122
- # @param product [String] (required) ASIN (B09DFCB66S) or Amazon product link
122
+ # @param product [String] (required) ASIN (B09DFCB66S) or Amazon product link.
123
123
  # @param marketplace [String] Amazon store, e.g. com for amazon.com. A product link sets it on its own.
124
- # @param target_price [Numeric] Email the owner when the price goes at or below this amount. null removes it.
124
+ # @param target_price [Numeric] Email the owner when the price goes at or below this amount (on the free plan, for the first 5 products with an alert). null removes it.
125
125
  # @param interval_minutes [Integer] Minutes between two checks (1440 = daily). Checks faster than daily need a plan or a credit pack: every 60 minutes with a pack or Starter, 30 with Pro, 5 with Business.
126
126
  # @param wait [Boolean] Answer once the first check is done (up to 45 seconds)
127
127
  # @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
@@ -130,19 +130,30 @@ module Asin
130
130
  call_operation("track_product", params, request_options)
131
131
  end
132
132
 
133
- # Change alerts and checks. Target price, drop alerts, check interval, or pause. Send only what changes.
133
+ # Change alerts and checks. Target price, drop alerts, check interval, or pause. Send only what changes. On the free plan, alerts (price drop, back in stock, target price) email for the first 5 products added among the active ones with an alert set; the others stay t…
134
134
  #
135
135
  # +PATCH /products/{id}+
136
136
  #
137
137
  # @param id [String] (required) product_id returned when the product was added
138
- # @param target_price [Numeric] Email the owner when the price goes at or below this amount. null removes it.
138
+ # @param target_price [Numeric] Email the owner when the price goes at or below this amount (on the free plan, for the first 5 products with an alert). null removes it.
139
139
  # @param interval_minutes [Integer] Minutes between two checks (1440 = daily). Checks faster than daily need a plan or a credit pack: every 60 minutes with a pack or Starter, 30 with Pro, 5 with Business.
140
- # @param alert_on_drop [Boolean] Email when the price drops or the product is back in stock
140
+ # @param alert_on_drop [Boolean] Email when the price drops or the product is back in stock (on the free plan, for the first 5 products with an alert)
141
141
  # @param paused [Boolean] Stop checking (and charging) for now; false resumes
142
142
  # @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
143
143
  # @return [JsonResponse]
144
144
  def update_product(request_options: nil, **params)
145
145
  call_operation("update_product", params, request_options)
146
146
  end
147
+
148
+ # Remove the target price. Sends exactly {"target_price": null}: update_product cannot, since nil values are omitted.
149
+ #
150
+ # +PATCH /products/{id}+
151
+ #
152
+ # @param id [String] (required) product_id returned when the product was added
153
+ # @param request_options [Hash, nil] +:timeout+ (seconds), +:headers+, +:max_retries+
154
+ # @return [JsonResponse] the same response as update_product
155
+ def clear_target_price(id:, request_options: nil)
156
+ call_operation("update_product", { "id" => id, "target_price" => Serialization::JSON_NULL }, request_options)
157
+ end
147
158
  end
148
159
  end
@@ -7,6 +7,9 @@ module Asin
7
7
  # Request serialization: path filling, query pairs and JSON bodies.
8
8
  module Serialization
9
9
  QUERY_STRING_PARAMS = { "/products/{id}/check" => %w[wait] }.freeze
10
+ # @api private
11
+ # A body value sent as an explicit JSON null (nil values are omitted). Used by Operations#clear_target_price.
12
+ JSON_NULL = Object.new.freeze
10
13
 
11
14
  module_function
12
15
 
@@ -27,7 +30,7 @@ module Asin
27
30
  if %w[POST PATCH].include?(method)
28
31
  # The API reads wait from the query string on POST /products/{id}/check.
29
32
  globals = QUERY_STRING_PARAMS.fetch(path_template, []).filter_map { |name| [name, wire_string(name, remaining.delete(name))] if remaining.key?(name) }
30
- return [path, globals, remaining]
33
+ return [path, globals, remaining.transform_values { |value| value.equal?(JSON_NULL) ? nil : value }]
31
34
  end
32
35
 
33
36
  pairs = []
data/lib/asin/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Asin
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
data/sig/asin.rbs CHANGED
@@ -14,6 +14,7 @@ module Asin
14
14
  end
15
15
  class APIError < Error
16
16
  attr_reader status: Integer
17
+ attr_reader error_code: String?
17
18
  attr_reader error_message: String?
18
19
  attr_reader response_body: untyped
19
20
  attr_reader raw_response: RawResponse
@@ -58,6 +59,7 @@ module Asin
58
59
 
59
60
  module Operations
60
61
  def check_product: (id: String, ?wait: bool, ?request_options: request_options?) -> JsonResponse
62
+ def clear_target_price: (id: String, ?request_options: request_options?) -> JsonResponse
61
63
  def delete_product: (id: String, ?request_options: request_options?) -> JsonResponse
62
64
  def fetch_offers: (asin: String, ?marketplace: String, ?refresh: bool, ?request_options: request_options?) -> JsonResponse
63
65
  def get_account: (?request_options: request_options?) -> JsonResponse
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asindotdev
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Asin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-11-06 00:00:00.000000000 Z
11
+ date: 2026-12-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Track Amazon prices and products with a scheduled watchlist, price history,
14
14
  offers and alerts.