pricebell 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: cc865367b9239dbc87f5212653125a857dbb5e4a39ee6e4460c81d375f2f6430
4
+ data.tar.gz: 645670286c2167acf0599042ad027a038da99150c6183c76dd9bbb0762cb62c6
5
+ SHA512:
6
+ metadata.gz: 2158929454445f844758ed2ba0878bd364ff71f90e89a682883f60f7796cafbe2467f9b7aa5fa2ab7689506611b7e756d8fd517be1055605161661974bcff49c
7
+ data.tar.gz: fbb8020a013f429e13b8c52f1ead9caa78fb290f08c6a3d46cf6f2023149c9f1d2fdfe49dde2d1ff18bb836ef399adc7343b383acbf15e763bfbc90d8f4bc549
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 PriceBell
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,157 @@
1
+ # PriceBell Ruby SDK
2
+
3
+ The official Ruby SDK for the [PriceBell](https://www.pricebell.dev) Google Shopping price tracking API.
4
+
5
+ Track Google Shopping prices in 33 countries with a scheduled watchlist, price history, sellers, cross-country comparison and alerts.
6
+
7
+ The SDK exposes **14 methods**, one per documented endpoint, plus `clear_target_price` and a generic `request`. It only uses the Ruby standard library.
8
+
9
+ ## Requirements
10
+
11
+ - Ruby 3.1 or newer
12
+
13
+ ## Installation
14
+
15
+ ```sh
16
+ gem install pricebell
17
+ ```
18
+
19
+ Or in your `Gemfile`:
20
+
21
+ ```ruby
22
+ gem "pricebell"
23
+ ```
24
+
25
+ ## Get your API key
26
+
27
+ [Sign up for PriceBell](https://www.pricebell.dev/signup) or sign in, then copy your API key from the [dashboard](https://www.pricebell.dev/app). The client reads `ENV["PRICEBELL_API_KEY"]` when no key is passed.
28
+
29
+ ## Quick start
30
+
31
+ ```ruby
32
+ require "pricebell"
33
+
34
+ client = PriceBell::Client.new(api_key: ENV.fetch("PRICEBELL_API_KEY"))
35
+ response = client.search_google_shopping(query: "airpods pro 2")
36
+ puts response.data
37
+ ```
38
+
39
+ Keyword arguments use the parameter names of the [API reference](https://www.pricebell.dev/docs). Unknown names raise `PriceBell::SerializationError`; use `request` for undocumented parameters.
40
+
41
+ ## HTTP methods
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. `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
+
45
+ `nil` values are omitted, `false` and `0` are sent, and arrays repeat the parameter name.
46
+
47
+ ## Any endpoint
48
+
49
+ ```ruby
50
+ response = client.request("GET", "/account")
51
+ ```
52
+
53
+ ## Errors
54
+
55
+ ```ruby
56
+ begin
57
+ client.search_google_shopping(query: "airpods pro 2")
58
+ rescue PriceBell::APIError => e
59
+ warn "HTTP #{e.status}: #{e.message}"
60
+ end
61
+ ```
62
+
63
+ | Error | When |
64
+ | --- | --- |
65
+ | `PriceBell::ConfigurationError` | Missing API key, invalid options or unsupported method. |
66
+ | `PriceBell::SerializationError` | A required parameter is missing, unknown or can't be sent. |
67
+ | `PriceBell::TransportError` | Network failure or timeout. |
68
+ | `PriceBell::APIError` | Non-2xx status (`status`, `error_code`, `error_message`, `response_body`, `raw_response`). `error_code` is the API's `error.code`, such as `"rate_limited"` or `"product_limit"`, or `nil` when the body has none. |
69
+ | `PriceBell::ResponseDecodingError` | A success response could not be decoded. |
70
+
71
+ All of them inherit from `PriceBell::Error`.
72
+
73
+ ## Retries
74
+
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
+
77
+ ```ruby
78
+ client = PriceBell::Client.new(max_retries: 5, retry_delay: 0.5)
79
+ client.search_google_shopping(query: "airpods pro 2", request_options: { max_retries: 0 }) # one request without retries
80
+ ```
81
+
82
+ ## Batch requests
83
+
84
+ `batch` runs the block for every item on 10 threads (`concurrency:`) and returns one `BatchResult` per item, in input order. A failing item never stops the others.
85
+
86
+ ```ruby
87
+ inputs = ["airpods pro 2", "nintendo switch 2", "dyson v15"]
88
+ results = client.batch(inputs, concurrency: 5) { |value| client.search_google_shopping(query: value) }
89
+ results.each do |result|
90
+ if result.ok?
91
+ puts result.value.data
92
+ else
93
+ warn "#{inputs[result.index]}: #{result.error.message}"
94
+ end
95
+ end
96
+ ```
97
+
98
+ | Constant | Default | Description |
99
+ | --- | --- | --- |
100
+ | `PriceBell::Client::DEFAULT_CONCURRENCY` | `10` | Tasks run at the same time by batch |
101
+ | `PriceBell::Client::DEFAULT_TIMEOUT` | `120` | Request timeout (seconds) |
102
+ | `PriceBell::Client::MAX_RETRIES` | `3` | Retry attempts after a network error, a 408/5xx |
103
+ | `PriceBell::Client::RETRY_BACKOFF_FACTOR` | `1.5` | Exponential backoff multiplier |
104
+ | `PriceBell::Client::DEFAULT_RETRY_DELAY` | `1.0` | Delay before the first retry (seconds) |
105
+
106
+ ## Timeouts and custom transports
107
+
108
+ ```ruby
109
+ client = PriceBell::Client.new(timeout: 60) # seconds, default 120
110
+ client.search_google_shopping(query: "airpods pro 2", request_options: { timeout: 30 })
111
+ ```
112
+
113
+ A transport is any object with `call(method:, url:, headers:, body:, timeout:)` returning `[status, headers, body]`; the default is `PriceBell::NetHTTPTransport`.
114
+
115
+ ## Endpoints
116
+
117
+ 14 methods, generated from the [OpenAPI document](https://www.pricebell.dev/openapi.json).
118
+
119
+ | Method | HTTP | Description |
120
+ | --- | --- | --- |
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
+ | `compare_regions` | GET `/products/{id}/compare` | The same product tracked in several countries, cheapest first: each country's local price, the price converted into the comparison's curren… |
123
+ | `clear_target_price` | PATCH `/products/{id}` | Removes the target price: sends `{"target_price": null}`, which `update_product` cannot since `nil` values are omitted. |
124
+ | `delete_product` | DELETE `/products/{id}` | Removes the product and its price history. |
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… |
126
+ | `get_google_product_history` | GET `/history` | Every price PriceBell read for a product ID on a marketplace over the period, whoever tracks it, oldest first, with the lowest, highest and… |
127
+ | `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 product ID on this marke… |
128
+ | `get_sellers` | GET `/products/{id}/sellers` | The sellers of a tracked product at its latest check, cheapest first: each offer that is the product as sold new (accessories, used, refurb… |
129
+ | `leave_comparison` | DELETE `/products/{id}/compare` | The product leaves its comparison and stays tracked on its own. |
130
+ | `list_products` | GET `/products` | Your watchlist, newest first, with each product's latest state and its recent prices (trend). Filter with google_product_id (and marketplac… |
131
+ | `search_google_shopping` | GET `/search` | Google Shopping search results (sponsored included), to find the product ID of a product. Free, limited to 30 searches per hour. |
132
+ | `track_in_regions` | POST `/products/{id}/compare` | Tracks the same product in other countries, each one a product of your watchlist (its own checks and credits, within your plan's product li… |
133
+ | `track_product` | POST `/products` | Adds a product ID or a Google Shopping link to your watchlist. A product ID alone works only for a product PriceBell already knows in that… |
134
+ | `update_comparison` | PATCH `/products/{id}/compare` | The currency prices are converted into, and the "cheaper in another country" alert: an email (and chat channels) when another country's con… |
135
+ | `update_product` | PATCH `/products/{id}` | Target price, drop alerts, check interval, or pause. Send only what changes. On the free plan, alerts (price drop, offered again, target pr… |
136
+
137
+ ## All PriceBell SDKs
138
+
139
+ | SDK | Package | Install |
140
+ | --- | --- | --- |
141
+ | Node.js | [`@pricebell/sdk`](https://www.npmjs.com/package/@pricebell/sdk) | `npm install @pricebell/sdk` |
142
+ | Python | [`pricebell`](https://pypi.org/project/pricebell/) | `pip install pricebell` |
143
+ | Go | [`pricebell-go`](https://pkg.go.dev/github.com/pricebelldev/pricebell-go) | `go get github.com/pricebelldev/pricebell-go` |
144
+ | .NET | [`PriceBell`](https://www.nuget.org/packages/PriceBell) | `dotnet add package PriceBell` |
145
+ | Ruby | [`pricebell`](https://rubygems.org/gems/pricebell) | `gem install pricebell` |
146
+ | PHP | [`pricebell/sdk`](https://packagist.org/packages/pricebell/sdk) | `composer require pricebell/sdk` |
147
+ | Java | [`pricebell-java`](https://github.com/pricebelldev/pricebell-java) | build from source, see its README |
148
+ | CLI | [`@pricebell/cli`](https://www.npmjs.com/package/@pricebell/cli) | `npm install -g @pricebell/cli` |
149
+ | MCP server | [`@pricebell/mcp`](https://www.npmjs.com/package/@pricebell/mcp) | `npx -y @pricebell/mcp` |
150
+
151
+ ## Trademarks
152
+
153
+ Google and Google Shopping are trademarks of Google LLC. PriceBell is not affiliated with, endorsed or sponsored by Google.
154
+
155
+ ## License
156
+
157
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,10 @@
1
+ # Examples
2
+
3
+ ```sh
4
+ gem install pricebell
5
+ export PRICEBELL_API_KEY="YOUR_API_KEY"
6
+ ruby examples/json.rb
7
+ ```
8
+
9
+ - `json.rb` — call the featured endpoint and print the JSON result.
10
+ - `request.rb` — call any path with `request` and handle API errors.
data/examples/json.rb ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "pricebell"
5
+
6
+ client = PriceBell::Client.new # reads PRICEBELL_API_KEY
7
+ response = client.search_google_shopping(query: "airpods pro 2")
8
+ puts JSON.pretty_generate(response.data)
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pricebell"
4
+
5
+ client = PriceBell::Client.new # reads PRICEBELL_API_KEY
6
+ begin
7
+ response = client.request("GET", "/account")
8
+ puts response.data if response.json?
9
+ rescue PriceBell::APIError => e
10
+ warn "HTTP #{e.status}: #{e.message}"
11
+ end
@@ -0,0 +1,241 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ module PriceBell
6
+ # Official PriceBell API client. Create one instance and reuse it.
7
+ class Client
8
+ include Operations
9
+
10
+ DEFAULT_BASE_URL = "https://www.pricebell.dev/api/v1"
11
+ DEFAULT_TIMEOUT = 120
12
+ # Tasks run at the same time by #batch.
13
+ DEFAULT_CONCURRENCY = 10
14
+ # Retries after a network error or a 408, 500, 502, 503 or 504 response (never a 429).
15
+ MAX_RETRIES = 3
16
+ # Each retry waits this many times longer than the previous one (a Retry-After header wins).
17
+ RETRY_BACKOFF_FACTOR = 1.5
18
+ # Seconds before the first retry.
19
+ DEFAULT_RETRY_DELAY = 1.0
20
+ MAX_RETRY_DELAY = 30.0
21
+ RETRYABLE_STATUSES = [408, 500, 502, 503, 504].freeze
22
+ API_KEY_ENVIRONMENT_VARIABLE = "PRICEBELL_API_KEY"
23
+ ERROR_MESSAGE_KEYS = %w[error message error_message detail].freeze
24
+
25
+ # @param api_key [String, nil] defaults to ENV["PRICEBELL_API_KEY"]
26
+ # @param base_url [String] API origin
27
+ # @param timeout [Numeric, nil] seconds per request; nil disables it
28
+ # @param headers [Hash] extra headers for every request
29
+ # @param max_retries [Integer] retries after a network error or a 408/5xx response; 0 disables them
30
+ # @param retry_delay [Numeric] seconds before the first retry, growing 1.5x per retry
31
+ # @param transport [#call] custom transport, see {NetHTTPTransport}
32
+ def initialize(api_key: nil, base_url: DEFAULT_BASE_URL, timeout: DEFAULT_TIMEOUT, headers: {},
33
+ max_retries: MAX_RETRIES, retry_delay: DEFAULT_RETRY_DELAY, transport: nil)
34
+ api_key = ENV.fetch(API_KEY_ENVIRONMENT_VARIABLE, nil) if api_key.nil?
35
+ if !api_key.is_a?(String) || api_key.strip.empty?
36
+ raise ConfigurationError,
37
+ "A non-blank PriceBell API key is required. Pass api_key: or set #{API_KEY_ENVIRONMENT_VARIABLE}."
38
+ end
39
+ raise ConfigurationError, "The PriceBell API key cannot be used in an HTTP header." if api_key.match?(/[\r\n]/)
40
+
41
+ uri = URI.parse(base_url.to_s)
42
+ unless %w[http https].include?(uri.scheme) && uri.host
43
+ raise ConfigurationError, "base_url must be an absolute http or https URL."
44
+ end
45
+ raise ConfigurationError, "timeout must be a positive number or nil." if timeout && !(timeout.is_a?(Numeric) && timeout.positive?)
46
+ raise ConfigurationError, "transport must respond to #call." if transport && !transport.respond_to?(:call)
47
+
48
+ @api_key = api_key
49
+ @base_url = base_url.to_s.sub(%r{/+\z}, "")
50
+ @timeout = timeout
51
+ @headers = headers.to_h { |name, value| [name.to_s, value.to_s] }.freeze
52
+ raise ConfigurationError, "max_retries must be a non-negative Integer." unless max_retries.is_a?(Integer) && max_retries >= 0
53
+ raise ConfigurationError, "retry_delay must be a non-negative number." unless retry_delay.is_a?(Numeric) && retry_delay >= 0
54
+
55
+ @max_retries = max_retries
56
+ @retry_delay = retry_delay
57
+ @transport = transport || NetHTTPTransport.new
58
+ end
59
+
60
+ def inspect
61
+ "#<#{self.class.name} base_url=#{@base_url.inspect}>"
62
+ end
63
+
64
+ # Sends any request, including endpoints released after this SDK version.
65
+ # GET parameters travel in the query string; POST parameters travel in a JSON body.
66
+ # @return [JsonResponse, BinaryResponse]
67
+ def request(method, path, params = nil, timeout: nil, headers: nil, max_retries: nil)
68
+ send_request(method.to_s.upcase, path, params, { timeout: timeout, headers: headers, max_retries: max_retries }, :any)
69
+ end
70
+
71
+ # Runs the block for every item on +concurrency+ threads (default 10) and returns one {BatchResult} per item,
72
+ # in input order. A failing item never stops the others; the client is thread-safe.
73
+ #
74
+ # results = client.batch(ids, concurrency: 5) { |id| client.some_endpoint(query: id) }
75
+ # @return [Array<BatchResult>]
76
+ def batch(items, concurrency: DEFAULT_CONCURRENCY)
77
+ raise ConfigurationError, "concurrency must be a positive Integer." unless concurrency.is_a?(Integer) && concurrency.positive?
78
+ raise ArgumentError, "batch needs a block" unless block_given?
79
+
80
+ list = items.to_a
81
+ results = Array.new(list.size)
82
+ queue = Queue.new
83
+ list.each_with_index { |item, index| queue << [item, index] }
84
+ queue.close
85
+ workers = Array.new([concurrency, list.size].min) do
86
+ Thread.new do
87
+ while (job = queue.pop)
88
+ item, index = job
89
+ results[index] = begin
90
+ BatchResult.new(index: index, value: yield(item), error: nil)
91
+ rescue StandardError => e
92
+ BatchResult.new(index: index, value: nil, error: e)
93
+ end
94
+ end
95
+ end
96
+ end
97
+ workers.each(&:join)
98
+ results
99
+ end
100
+
101
+ private
102
+
103
+ def call_operation(name, params, options)
104
+ endpoint = ENDPOINTS.fetch(name)
105
+ options = (options || {}).transform_keys(&:to_sym)
106
+ method = (options[:method] || endpoint[:methods].first).to_s.upcase
107
+ unless endpoint[:methods].include?(method)
108
+ raise ConfigurationError, "#{endpoint[:path]} supports #{endpoint[:methods].join(', ')}, not #{method}."
109
+ end
110
+
111
+ params = params.transform_keys(&:to_s)
112
+ unknown = params.keys - endpoint[:params]
113
+ unless unknown.empty?
114
+ raise SerializationError.new(
115
+ "Unknown parameter(s) for #{name}: #{unknown.join(', ')}. Use #request for undocumented parameters.",
116
+ unknown.first
117
+ )
118
+ end
119
+ endpoint[:required].each do |required|
120
+ raise SerializationError.new("The \"#{required}\" parameter is required.", required) if params[required].nil?
121
+ end
122
+ send_request(method, endpoint[:path], params, options, endpoint[:response])
123
+ end
124
+
125
+ def send_request(method, path, params, options, expected)
126
+ raise ConfigurationError, "Unsupported HTTP method: #{method.inspect}." unless %w[GET POST PATCH DELETE].include?(method)
127
+ raise ConfigurationError, 'The request path must start with "/".' unless path.is_a?(String) && path.start_with?("/")
128
+
129
+ path, pairs, body = Serialization.serialize(method, path, params)
130
+ url = @base_url + path
131
+ url += "?#{Serialization.encode_query(pairs)}" unless pairs.empty?
132
+ headers = {
133
+ "Accept" => "application/json, */*;q=0.8",
134
+ "User-Agent" => "pricebell-ruby/#{VERSION}"
135
+ }.merge(@headers).merge((options[:headers] || {}).to_h { |k, v| [k.to_s, v.to_s] })
136
+ headers["Authorization"] = "Bearer #{@api_key}"
137
+ payload = nil
138
+ if body
139
+ headers["Content-Type"] = "application/json"
140
+ payload = JSON.generate(body)
141
+ end
142
+
143
+ max_retries = options[:max_retries] || @max_retries
144
+ attempt = 0
145
+ loop do
146
+ begin
147
+ status, response_headers, response_body = @transport.call(
148
+ method: method, url: url, headers: headers, body: payload, timeout: options[:timeout] || @timeout
149
+ )
150
+ rescue Timeout::Error => e
151
+ raise TransportError, "PriceBell request timed out: #{e.message}"
152
+ rescue StandardError => e
153
+ raise TransportError, "PriceBell request failed before an HTTP response was received: #{e.message}" if attempt >= max_retries
154
+
155
+ sleep(retry_delay(attempt, nil))
156
+ attempt += 1
157
+ next
158
+ end
159
+ raw = build_raw_response(status, response_headers, response_body)
160
+ return decode(raw, expected) if (200..299).cover?(raw.status)
161
+ raise api_error(raw) unless retryable?(raw) && attempt < max_retries
162
+
163
+ sleep(retry_delay(attempt, raw.headers["retry-after"]&.first))
164
+ attempt += 1
165
+ end
166
+ end
167
+
168
+ def retryable?(raw)
169
+ RETRYABLE_STATUSES.include?(raw.status)
170
+ end
171
+
172
+ def retry_delay(attempt, retry_after)
173
+ seconds = Float(retry_after, exception: false) if retry_after
174
+ return [seconds, 60].min if seconds && seconds >= 0
175
+
176
+ [@retry_delay * (RETRY_BACKOFF_FACTOR**attempt), MAX_RETRY_DELAY].min
177
+ end
178
+
179
+ def build_raw_response(status, headers, body)
180
+ normalized = {}
181
+ (headers || {}).each { |name, values| normalized[name.to_s.downcase] = Array(values).map(&:to_s).freeze }
182
+ RawResponse.new(
183
+ status: status.to_i,
184
+ headers: normalized.freeze,
185
+ content_type: normalized["content-type"]&.first,
186
+ body: body.to_s.b
187
+ )
188
+ end
189
+
190
+ def api_error(raw)
191
+ parsed = parse_json(raw.body)
192
+ message = nil
193
+ code = nil
194
+ if parsed.is_a?(Hash)
195
+ # The API answers {"error": {"code", "message"}}.
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)
198
+ ERROR_MESSAGE_KEYS.each do |key|
199
+ value = parsed[key]
200
+ if value.is_a?(String) && !value.empty?
201
+ message = value
202
+ break
203
+ end
204
+ end
205
+ end
206
+ APIError.new(raw_response: raw, response_body: parsed == NOT_JSON ? nil : parsed, error_message: message, error_code: code)
207
+ end
208
+
209
+ def decode(raw, expected)
210
+ unless json_media_type?(raw.content_type)
211
+ if expected == :json
212
+ raise ResponseDecodingError.new("PriceBell returned a successful non-JSON response for a JSON operation.", raw)
213
+ end
214
+
215
+ return BinaryResponse.new(bytes: raw.body, content_type: raw.content_type, raw_response: raw)
216
+ end
217
+ data = parse_json(raw.body)
218
+ if data == NOT_JSON
219
+ raise ResponseDecodingError.new("PriceBell returned a successful JSON response that could not be decoded.", raw)
220
+ end
221
+
222
+ JsonResponse.new(data: data, raw_response: raw)
223
+ end
224
+
225
+ NOT_JSON = Object.new.freeze
226
+ private_constant :NOT_JSON
227
+
228
+ def parse_json(body)
229
+ JSON.parse(body.dup.force_encoding(Encoding::UTF_8))
230
+ rescue JSON::ParserError, EncodingError
231
+ NOT_JSON
232
+ end
233
+
234
+ def json_media_type?(content_type)
235
+ return false if content_type.nil?
236
+
237
+ media_type = content_type.split(";", 2).first.strip.downcase
238
+ media_type == "application/json" || media_type.end_with?("+json")
239
+ end
240
+ end
241
+ end
@@ -0,0 +1,107 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Generated from the PriceBell OpenAPI document. Do not edit by hand.
4
+
5
+ module PriceBell
6
+ # Path, methods, response kind and parameter names of every documented operation.
7
+ ENDPOINTS = {
8
+ "check_product" => {
9
+ path: "/products/{id}/check",
10
+ methods: ["POST"].freeze,
11
+ response: :json,
12
+ required: ["id"].freeze,
13
+ params: ["id", "wait"].freeze
14
+ }.freeze,
15
+ "compare_regions" => {
16
+ path: "/products/{id}/compare",
17
+ methods: ["GET"].freeze,
18
+ response: :json,
19
+ required: ["id"].freeze,
20
+ params: ["id", "currency"].freeze
21
+ }.freeze,
22
+ "delete_product" => {
23
+ path: "/products/{id}",
24
+ methods: ["DELETE"].freeze,
25
+ response: :json,
26
+ required: ["id"].freeze,
27
+ params: ["id"].freeze
28
+ }.freeze,
29
+ "get_account" => {
30
+ path: "/account",
31
+ methods: ["GET"].freeze,
32
+ response: :json,
33
+ required: [].freeze,
34
+ params: [].freeze
35
+ }.freeze,
36
+ "get_google_product_history" => {
37
+ path: "/history",
38
+ methods: ["GET"].freeze,
39
+ response: :json,
40
+ required: ["google_product_id"].freeze,
41
+ params: ["google_product_id", "marketplace", "days"].freeze
42
+ }.freeze,
43
+ "get_product" => {
44
+ path: "/products/{id}",
45
+ methods: ["GET"].freeze,
46
+ response: :json,
47
+ required: ["id"].freeze,
48
+ params: ["id", "days"].freeze
49
+ }.freeze,
50
+ "get_sellers" => {
51
+ path: "/products/{id}/sellers",
52
+ methods: ["GET"].freeze,
53
+ response: :json,
54
+ required: ["id"].freeze,
55
+ params: ["id"].freeze
56
+ }.freeze,
57
+ "leave_comparison" => {
58
+ path: "/products/{id}/compare",
59
+ methods: ["DELETE"].freeze,
60
+ response: :json,
61
+ required: ["id"].freeze,
62
+ params: ["id"].freeze
63
+ }.freeze,
64
+ "list_products" => {
65
+ path: "/products",
66
+ methods: ["GET"].freeze,
67
+ response: :json,
68
+ required: [].freeze,
69
+ params: ["google_product_id", "marketplace", "filter", "page", "limit"].freeze
70
+ }.freeze,
71
+ "search_google_shopping" => {
72
+ path: "/search",
73
+ methods: ["GET"].freeze,
74
+ response: :json,
75
+ required: ["query"].freeze,
76
+ params: ["query", "marketplace"].freeze
77
+ }.freeze,
78
+ "track_in_regions" => {
79
+ path: "/products/{id}/compare",
80
+ methods: ["POST"].freeze,
81
+ response: :json,
82
+ required: ["id", "regions"].freeze,
83
+ params: ["id", "regions", "currency"].freeze
84
+ }.freeze,
85
+ "track_product" => {
86
+ path: "/products",
87
+ methods: ["POST"].freeze,
88
+ response: :json,
89
+ required: ["product"].freeze,
90
+ params: ["product", "marketplace", "target_price", "interval_minutes", "wait"].freeze
91
+ }.freeze,
92
+ "update_comparison" => {
93
+ path: "/products/{id}/compare",
94
+ methods: ["PATCH"].freeze,
95
+ response: :json,
96
+ required: ["id"].freeze,
97
+ params: ["id", "currency", "alert", "alert_percent"].freeze
98
+ }.freeze,
99
+ "update_product" => {
100
+ path: "/products/{id}",
101
+ methods: ["PATCH"].freeze,
102
+ response: :json,
103
+ required: ["id"].freeze,
104
+ params: ["id", "target_price", "interval_minutes", "alert_on_drop", "paused"].freeze
105
+ }.freeze
106
+ }.freeze
107
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PriceBell
4
+ # Base class for every SDK-defined error.
5
+ class Error < StandardError; end
6
+
7
+ # The client configuration is missing or unusable.
8
+ class ConfigurationError < Error; end
9
+
10
+ # A request value cannot be represented safely on the wire.
11
+ class SerializationError < Error
12
+ attr_reader :param
13
+
14
+ def initialize(message, param = nil)
15
+ super(message)
16
+ @param = param
17
+ end
18
+ end
19
+
20
+ # The request failed before a complete HTTP response was received.
21
+ class TransportError < Error; end
22
+
23
+ # PriceBell returned a non-success HTTP status.
24
+ class APIError < Error
25
+ # error_code is the API's error.code (e.g. "rate_limited"), nil when the body has none.
26
+ attr_reader :status, :error_code, :error_message, :response_body, :raw_response
27
+
28
+ def initialize(raw_response:, response_body: nil, error_message: nil, error_code: nil)
29
+ super(error_message || "PriceBell API request failed with status #{raw_response.status}.")
30
+ @status = raw_response.status
31
+ @error_code = error_code
32
+ @error_message = error_message
33
+ @response_body = response_body
34
+ @raw_response = raw_response
35
+ end
36
+ end
37
+
38
+ # A successful response could not be decoded as the documented representation.
39
+ class ResponseDecodingError < Error
40
+ attr_reader :raw_response
41
+
42
+ def initialize(message, raw_response)
43
+ super(message)
44
+ @raw_response = raw_response
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,195 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Generated from the PriceBell OpenAPI document. Do not edit by hand.
4
+
5
+ module PriceBell
6
+ # One method per documented endpoint. Mixed into {Client}.
7
+ module Operations
8
+ # Check the price now. 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 resumed first. The check runs in the background; with wait=true the answer waits for it. Read last_e…
9
+ #
10
+ # +POST /products/{id}/check+
11
+ #
12
+ # @param id [String] (required) product_id returned when the product was added
13
+ # @param wait [Boolean] Answer once the check is done (up to 45 seconds)
14
+ # @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
15
+ # @return [JsonResponse]
16
+ def check_product(request_options: nil, **params)
17
+ call_operation("check_product", params, request_options)
18
+ end
19
+
20
+ # Compare a product across countries. The same product tracked in several countries, cheapest first: each country's local price, the price converted into the comparison's currency, and how much dearer it is than the cheapest (gap_percent). home is the country the comparison st…
21
+ #
22
+ # +GET /products/{id}/compare+
23
+ #
24
+ # @param id [String] (required) product_id of any of the compared products
25
+ # @param currency [String] Currency the prices are converted into; the comparison keeps the last one chosen (EUR or USD at first, after the account's language)
26
+ # @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
27
+ # @return [JsonResponse]
28
+ def compare_regions(request_options: nil, **params)
29
+ call_operation("compare_regions", params, request_options)
30
+ end
31
+
32
+ # Stop tracking a product. Removes the product and its price history.
33
+ #
34
+ # +DELETE /products/{id}+
35
+ #
36
+ # @param id [String] (required) product_id returned when the product was added
37
+ # @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
38
+ # @return [JsonResponse]
39
+ def delete_product(request_options: nil, **params)
40
+ call_operation("delete_product", params, request_options)
41
+ end
42
+
43
+ # 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…
44
+ #
45
+ # +GET /account+
46
+ #
47
+ # @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
48
+ # @return [JsonResponse]
49
+ def get_account(request_options: nil, **params)
50
+ call_operation("get_account", params, request_options)
51
+ end
52
+
53
+ # Price history of any product ID. Every price PriceBell read for a product ID 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 pa…
54
+ #
55
+ # +GET /history+
56
+ #
57
+ # @param google_product_id [String] (required) Google Shopping product ID (the catalogid in a Google Shopping link)
58
+ # @param marketplace [String] Country whose Google Shopping results are read, in its currency, e.g. us (US): us (USD), gb (GBP), fr (EUR), de (EUR), es (EUR), it (EUR), nl (EUR), be (EUR), at (EUR), ch (CHF), ie (EUR), pt (EUR),…
59
+ # @param days [Integer] History period in days. The free plan reads the last 30: history_days says which period was returned.
60
+ # @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
61
+ # @return [JsonResponse]
62
+ def get_google_product_history(request_options: nil, **params)
63
+ call_operation("get_google_product_history", params, request_options)
64
+ end
65
+
66
+ # Get a product and its price history. The product's latest state and every price read of the period, oldest first. The history covers every read of this product ID on this marketplace, including those made before you added it, so a product added today can come with months of p…
67
+ #
68
+ # +GET /products/{id}+
69
+ #
70
+ # @param id [String] (required) product_id returned when the product was added
71
+ # @param days [Integer] History period in days. The free plan reads the last 30: history_days says which period was returned.
72
+ # @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
73
+ # @return [JsonResponse]
74
+ def get_product(request_options: nil, **params)
75
+ call_operation("get_product", params, request_options)
76
+ end
77
+
78
+ # Get a product's sellers. The sellers of a tracked product at its latest check, cheapest first: each offer that is the product as sold new (accessories, used, refurbished and rental offers, copies and multipacks are left out by the check), who sells it, its price a…
79
+ #
80
+ # +GET /products/{id}/sellers+
81
+ #
82
+ # @param id [String] (required) product_id
83
+ # @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
84
+ # @return [JsonResponse]
85
+ def get_sellers(request_options: nil, **params)
86
+ call_operation("get_sellers", params, request_options)
87
+ end
88
+
89
+ # Take a product out of its comparison. The product leaves its comparison and stays tracked on its own.
90
+ #
91
+ # +DELETE /products/{id}/compare+
92
+ #
93
+ # @param id [String] (required) product_id of any of the compared products
94
+ # @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
95
+ # @return [JsonResponse]
96
+ def leave_comparison(request_options: nil, **params)
97
+ call_operation("leave_comparison", params, request_options)
98
+ end
99
+
100
+ # List tracked products. Your watchlist, newest first, with each product's latest state and its recent prices (trend). Filter with google_product_id (and marketplace) to know if a product is tracked, or with filter to get the same lists as the app's tabs.
101
+ #
102
+ # +GET /products+
103
+ #
104
+ # @param google_product_id [String] Only this product ID
105
+ # @param marketplace [String] Only this Google Shopping store
106
+ # @param filter [String] Only the products of one of the app's watchlist filters. all: Every tracked product (default). drops: Cheaper now than when the product was added. target: At or below its target price. out_of_stock:…
107
+ # @param page [Integer] Page number
108
+ # @param limit [Integer] Products per page
109
+ # @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
110
+ # @return [JsonResponse]
111
+ def list_products(request_options: nil, **params)
112
+ call_operation("list_products", params, request_options)
113
+ end
114
+
115
+ # Search Google Shopping. Google Shopping search results (sponsored included), to find the product ID of a product. Free, limited to 30 searches per hour.
116
+ #
117
+ # +GET /search+
118
+ #
119
+ # @param query [String] (required) Keywords
120
+ # @param marketplace [String] Country whose Google Shopping results are read, in its currency, e.g. us (US): us (USD), gb (GBP), fr (EUR), de (EUR), es (EUR), it (EUR), nl (EUR), be (EUR), at (EUR), ch (CHF), ie (EUR), pt (EUR),…
121
+ # @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
122
+ # @return [JsonResponse]
123
+ def search_google_shopping(request_options: nil, **params)
124
+ call_operation("search_google_shopping", params, request_options)
125
+ end
126
+
127
+ # Also track a product in other countries. Tracks the same product in other countries, each one a product of your watchlist (its own checks and credits, within your plan's product limit: all of them fit, or none is added), searched there with the product's title, with its drop aler…
128
+ #
129
+ # +POST /products/{id}/compare+
130
+ #
131
+ # @param id [String] (required) product_id of any of the compared products
132
+ # @param regions [Array<String>] (required) Countries (marketplace ids) to also track the product in
133
+ # @param currency [String] Currency the prices are converted into; the comparison keeps the last one chosen (EUR or USD at first, after the account's language)
134
+ # @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
135
+ # @return [JsonResponse]
136
+ def track_in_regions(request_options: nil, **params)
137
+ call_operation("track_in_regions", params, request_options)
138
+ end
139
+
140
+ # Track a product. Adds a product ID or a Google Shopping link to your watchlist. A product ID alone works only for a product PriceBell already knows in that country (a search result, or one added by its link before): otherwise send its Google Shopping link.…
141
+ #
142
+ # +POST /products+
143
+ #
144
+ # @param product [String] (required) product ID (6883422599141817139) or Google Shopping product link. A product ID alone works only for a product PriceBell already knows in that country (a search result, or one added by its link before…
145
+ # @param marketplace [String] Country whose Google Shopping results are read, in its currency, e.g. us (US): us (USD), gb (GBP), fr (EUR), de (EUR), es (EUR), it (EUR), nl (EUR), be (EUR), at (EUR), ch (CHF), ie (EUR), pt (EUR),…
146
+ # @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.
147
+ # @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, 30 with Business, 5 with Scale, 5 with Volume,…
148
+ # @param wait [Boolean] Answer once the first check is done (up to 45 seconds)
149
+ # @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
150
+ # @return [JsonResponse]
151
+ def track_product(request_options: nil, **params)
152
+ call_operation("track_product", params, request_options)
153
+ end
154
+
155
+ # Set the comparison's currency and alert. The currency prices are converted into, and the "cheaper in another country" alert: an email (and chat channels) when another country's converted price is at least alert_percent below home's, once when it gets there, then again only after…
156
+ #
157
+ # +PATCH /products/{id}/compare+
158
+ #
159
+ # @param id [String] (required) product_id of any of the compared products
160
+ # @param currency [String] Currency the prices are converted into; the comparison keeps the last one chosen (EUR or USD at first, after the account's language)
161
+ # @param alert [Boolean] Turn the alert on or off
162
+ # @param alert_percent [Integer] How much cheaper, in %, another country has to be
163
+ # @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
164
+ # @return [JsonResponse]
165
+ def update_comparison(request_options: nil, **params)
166
+ call_operation("update_comparison", params, request_options)
167
+ end
168
+
169
+ # Change alerts and checks. Target price, drop alerts, check interval, or pause. Send only what changes. On the free plan, alerts (price drop, offered again, target price) email for the first 5 products added among the active ones with an alert set; the others stay t…
170
+ #
171
+ # +PATCH /products/{id}+
172
+ #
173
+ # @param id [String] (required) product_id returned when the product was added
174
+ # @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.
175
+ # @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, 30 with Business, 5 with Scale, 5 with Volume,…
176
+ # @param alert_on_drop [Boolean] Email when the price drops or the product is offered again (on the free plan, for the first 5 products with an alert)
177
+ # @param paused [Boolean] Stop checking (and charging) for now; false resumes, unless our team paused it (paused_by_team)
178
+ # @param request_options [Hash, nil] +:method+ ("GET"/"POST"), +:timeout+ (seconds), +:headers+
179
+ # @return [JsonResponse]
180
+ def update_product(request_options: nil, **params)
181
+ call_operation("update_product", params, request_options)
182
+ end
183
+
184
+ # Remove the target price. Sends exactly {"target_price": null}: update_product cannot, since nil values are omitted.
185
+ #
186
+ # +PATCH /products/{id}+
187
+ #
188
+ # @param id [String] (required) product_id returned when the product was added
189
+ # @param request_options [Hash, nil] +:timeout+ (seconds), +:headers+, +:max_retries+
190
+ # @return [JsonResponse] the same response as update_product
191
+ def clear_target_price(id:, request_options: nil)
192
+ call_operation("update_product", { "id" => id, "target_price" => Serialization::JSON_NULL }, request_options)
193
+ end
194
+ end
195
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PriceBell
4
+ # Buffered HTTP response: status, lower-cased multi-value headers, content type and body bytes.
5
+ RawResponse = Struct.new(:status, :headers, :content_type, :body, keyword_init: true)
6
+
7
+ # Outcome of one Client#batch item: +value+ when +ok?+, else +error+.
8
+ BatchResult = Struct.new(:index, :value, :error, keyword_init: true) do
9
+ def ok? = error.nil?
10
+ end
11
+
12
+ # A successful JSON response; +data+ is the parsed body (string keys).
13
+ class JsonResponse
14
+ attr_reader :data, :raw_response
15
+
16
+ def initialize(data:, raw_response:)
17
+ @data = data
18
+ @raw_response = raw_response
19
+ end
20
+
21
+ def kind = :json
22
+ def json? = true
23
+ def binary? = false
24
+ end
25
+
26
+ # A successful non-JSON response (image, PDF, HTML…).
27
+ class BinaryResponse
28
+ attr_reader :bytes, :content_type, :raw_response
29
+
30
+ def initialize(bytes:, content_type:, raw_response:)
31
+ @bytes = bytes
32
+ @content_type = content_type
33
+ @raw_response = raw_response
34
+ end
35
+
36
+ def kind = :binary
37
+ def json? = false
38
+ def binary? = true
39
+
40
+ # Writes the body to +path+ and returns the number of bytes written.
41
+ def save(path)
42
+ File.binwrite(path, bytes)
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "uri"
5
+
6
+ module PriceBell
7
+ # Request serialization: path filling, query pairs and JSON bodies.
8
+ module Serialization
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
13
+
14
+ module_function
15
+
16
+ # Fills {name} path segments, then returns [path, query_pairs, body].
17
+ # nil values are omitted; false and 0 are sent.
18
+ def serialize(method, path_template, params)
19
+ raise SerializationError, "Request parameters must be a Hash." unless params.nil? || params.is_a?(Hash)
20
+
21
+ remaining = {}
22
+ (params || {}).each { |name, value| remaining[name.to_s] = value unless value.nil? }
23
+ path = path_template.gsub(/\{([^}]+)\}/) do
24
+ name = Regexp.last_match(1)
25
+ raise SerializationError.new("The \"#{name}\" path parameter is required.", name) unless remaining.key?(name)
26
+
27
+ URI.encode_www_form_component(wire_string(name, remaining.delete(name))).gsub("+", "%20")
28
+ end
29
+
30
+ if %w[POST PATCH].include?(method)
31
+ # The API reads wait from the query string on POST /products/{id}/check.
32
+ globals = QUERY_STRING_PARAMS.fetch(path_template, []).filter_map { |name| [name, wire_string(name, remaining.delete(name))] if remaining.key?(name) }
33
+ return [path, globals, remaining.transform_values { |value| value.equal?(JSON_NULL) ? nil : value }]
34
+ end
35
+
36
+ pairs = []
37
+ remaining.each do |name, value|
38
+ if value.is_a?(Array)
39
+ value.each { |item| pairs << [name, wire_string(name, item)] unless item.nil? }
40
+ else
41
+ pairs << [name, wire_string(name, value)]
42
+ end
43
+ end
44
+ [path, pairs, nil]
45
+ end
46
+
47
+ def wire_string(name, value)
48
+ case value
49
+ when String then value
50
+ when true, false, Integer, Symbol then value.to_s
51
+ when Float
52
+ raise SerializationError.new("The \"#{name}\" parameter must be a finite number.", name) unless value.finite?
53
+
54
+ value == value.floor ? value.to_i.to_s : value.to_s
55
+ when Hash, Array then JSON.generate(value)
56
+ else
57
+ raise SerializationError.new("The \"#{name}\" parameter has an unsupported type (#{value.class}).", name)
58
+ end
59
+ end
60
+
61
+ def encode_query(pairs)
62
+ pairs.map { |name, value| "#{escape(name)}=#{escape(value)}" }.join("&")
63
+ end
64
+
65
+ def escape(value)
66
+ URI.encode_www_form_component(value).gsub("+", "%20")
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+ require "uri"
5
+
6
+ module PriceBell
7
+ # Default transport on Net::HTTP. A custom transport is any object with
8
+ # +call(method:, url:, headers:, body:, timeout:)+ returning +[status, headers, body]+,
9
+ # where headers is a Hash of lower-cased names to arrays of values.
10
+ class NetHTTPTransport
11
+ def call(method:, url:, headers:, body:, timeout:)
12
+ uri = URI(url)
13
+ request = Net::HTTP.const_get(method.capitalize).new(uri)
14
+ headers.each { |name, value| request[name] = value }
15
+ request.body = body if body
16
+ http = Net::HTTP.new(uri.host, uri.port)
17
+ http.use_ssl = uri.scheme == "https"
18
+ if timeout
19
+ http.open_timeout = timeout
20
+ http.read_timeout = timeout
21
+ http.write_timeout = timeout
22
+ end
23
+ response = http.start { |connection| connection.request(request) }
24
+ [response.code.to_i, response.to_hash, response.body || ""]
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PriceBell
4
+ VERSION = "0.1.0"
5
+ end
data/lib/pricebell.rb ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "pricebell/version"
4
+ require_relative "pricebell/errors"
5
+ require_relative "pricebell/responses"
6
+ require_relative "pricebell/serialization"
7
+ require_relative "pricebell/transport"
8
+ require_relative "pricebell/endpoints"
9
+ require_relative "pricebell/operations"
10
+ require_relative "pricebell/client"
11
+
12
+ # Official Ruby SDK for the PriceBell API (https://www.pricebell.dev).
13
+ module PriceBell
14
+ end
data/sig/pricebell.rbs ADDED
@@ -0,0 +1,89 @@
1
+ module PriceBell
2
+ VERSION: String
3
+ ENDPOINTS: Hash[String, Hash[Symbol, untyped]]
4
+
5
+ class Error < StandardError
6
+ end
7
+ class ConfigurationError < Error
8
+ end
9
+ class SerializationError < Error
10
+ attr_reader param: String?
11
+ def initialize: (String message, ?String? param) -> void
12
+ end
13
+ class TransportError < Error
14
+ end
15
+ class APIError < Error
16
+ attr_reader status: Integer
17
+ attr_reader error_code: String?
18
+ attr_reader error_message: String?
19
+ attr_reader response_body: untyped
20
+ attr_reader raw_response: RawResponse
21
+ end
22
+ class ResponseDecodingError < Error
23
+ attr_reader raw_response: RawResponse
24
+ end
25
+
26
+ class RawResponse < Struct[untyped]
27
+ attr_accessor status: Integer
28
+ attr_accessor headers: Hash[String, Array[String]]
29
+ attr_accessor content_type: String?
30
+ attr_accessor body: String
31
+ end
32
+
33
+ class JsonResponse
34
+ attr_reader data: untyped
35
+ attr_reader raw_response: RawResponse
36
+ def kind: () -> :json
37
+ def json?: () -> true
38
+ def binary?: () -> false
39
+ end
40
+ class BinaryResponse
41
+ attr_reader bytes: String
42
+ attr_reader content_type: String?
43
+ attr_reader raw_response: RawResponse
44
+ def kind: () -> :binary
45
+ def json?: () -> false
46
+ def binary?: () -> true
47
+ def save: (String path) -> Integer
48
+ end
49
+
50
+ class BatchResult < Struct[untyped]
51
+ attr_accessor index: Integer
52
+ attr_accessor value: untyped
53
+ attr_accessor error: StandardError?
54
+ def ok?: () -> bool
55
+ end
56
+
57
+ type response = JsonResponse | BinaryResponse
58
+ type request_options = { ?method: String, ?timeout: Numeric?, ?headers: Hash[String, String], ?max_retries: Integer }
59
+
60
+ module Operations
61
+ def check_product: (id: String, ?wait: bool, ?request_options: request_options?) -> JsonResponse
62
+ def compare_regions: (id: String, ?currency: String, ?request_options: request_options?) -> JsonResponse
63
+ def clear_target_price: (id: String, ?request_options: request_options?) -> JsonResponse
64
+ def delete_product: (id: String, ?request_options: request_options?) -> JsonResponse
65
+ def get_account: (?request_options: request_options?) -> JsonResponse
66
+ def get_google_product_history: (google_product_id: String, ?marketplace: String, ?days: Integer, ?request_options: request_options?) -> JsonResponse
67
+ def get_product: (id: String, ?days: Integer, ?request_options: request_options?) -> JsonResponse
68
+ def get_sellers: (id: String, ?request_options: request_options?) -> JsonResponse
69
+ def leave_comparison: (id: String, ?request_options: request_options?) -> JsonResponse
70
+ def list_products: (?google_product_id: String, ?marketplace: String, ?filter: String, ?page: Integer, ?limit: Integer, ?request_options: request_options?) -> JsonResponse
71
+ def search_google_shopping: (query: String, ?marketplace: String, ?request_options: request_options?) -> JsonResponse
72
+ def track_in_regions: (id: String, regions: Array[untyped], ?currency: String, ?request_options: request_options?) -> JsonResponse
73
+ def track_product: (product: String, ?marketplace: String, ?target_price: Numeric, ?interval_minutes: Integer, ?wait: bool, ?request_options: request_options?) -> JsonResponse
74
+ def update_comparison: (id: String, ?currency: String, ?alert: bool, ?alert_percent: Integer, ?request_options: request_options?) -> JsonResponse
75
+ def update_product: (id: String, ?target_price: Numeric, ?interval_minutes: Integer, ?alert_on_drop: bool, ?paused: bool, ?request_options: request_options?) -> JsonResponse
76
+ end
77
+
78
+ class Client
79
+ include Operations
80
+ DEFAULT_CONCURRENCY: Integer
81
+ MAX_RETRIES: Integer
82
+ RETRY_BACKOFF_FACTOR: Float
83
+ DEFAULT_RETRY_DELAY: Float
84
+ DEFAULT_TIMEOUT: Integer
85
+ def initialize: (?api_key: String?, ?base_url: String, ?timeout: Numeric?, ?headers: Hash[untyped, untyped], ?max_retries: Integer, ?retry_delay: Numeric, ?transport: untyped) -> void
86
+ def request: (String | Symbol method, String path, ?Hash[untyped, untyped]? params, ?timeout: Numeric?, ?headers: Hash[untyped, untyped]?, ?max_retries: Integer?) -> response
87
+ def batch: [I, T] (Enumerable[I] items, ?concurrency: Integer) { (I item) -> T } -> Array[BatchResult]
88
+ end
89
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pricebell
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - PriceBell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-12-05 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Track Google Shopping prices in 33 countries with a scheduled watchlist,
14
+ price history, sellers, cross-country comparison and alerts.
15
+ email:
16
+ - contact@pricebell.dev
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - LICENSE
22
+ - README.md
23
+ - examples/README.md
24
+ - examples/json.rb
25
+ - examples/request.rb
26
+ - lib/pricebell.rb
27
+ - lib/pricebell/client.rb
28
+ - lib/pricebell/endpoints.rb
29
+ - lib/pricebell/errors.rb
30
+ - lib/pricebell/operations.rb
31
+ - lib/pricebell/responses.rb
32
+ - lib/pricebell/serialization.rb
33
+ - lib/pricebell/transport.rb
34
+ - lib/pricebell/version.rb
35
+ - sig/pricebell.rbs
36
+ homepage: https://www.pricebell.dev
37
+ licenses:
38
+ - MIT
39
+ metadata:
40
+ bug_tracker_uri: https://github.com/pricebelldev/pricebell-ruby/issues
41
+ documentation_uri: https://www.pricebell.dev/docs
42
+ homepage_uri: https://www.pricebell.dev
43
+ rubygems_mfa_required: 'true'
44
+ source_code_uri: https://github.com/pricebelldev/pricebell-ruby
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '3.1'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubygems_version: 3.5.22
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: Official Ruby SDK for the PriceBell Google Shopping price tracking API.
64
+ test_files: []