crawlora-amazon 0.1.1 → 0.1.2
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 +14 -2
- data/lib/crawlora/amazon/client.rb +26 -4
- data/lib/crawlora/amazon/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: aee6c9db34ea55a3939500c3aaa3afa068cbe8793192c41fe0469ec9f4e1bad5
|
|
4
|
+
data.tar.gz: e075e45c55b0d68aa0073042fdb486df964ab8e96766c836cd8cd81e1ca24c4f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: db8f5b5aaf1a3b0b8ed945c9cfee7fdfb0f2bdb6db4f2541b8d92b96d5bc78589181c01c308eb24d4d3edd47da21537a3a744715da0d6b926bd5edf7668c5673
|
|
7
|
+
data.tar.gz: 25c5060806da56976123ac57cf3120150fd333f15730e55daea1a2e29ff5b1c0b24cc7fb897046537e81447dd0afc79b6a5a827a7e002e2567fc44ae716560c2
|
data/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# Crawlora Amazon Ruby
|
|
1
|
+
# Crawlora Amazon API client for Ruby (`crawlora-amazon`)
|
|
2
2
|
|
|
3
|
-
This gem calls
|
|
3
|
+
This Ruby gem calls Crawlora's hosted Amazon API at `https://api.crawlora.net/api/v1`. It exposes 5 endpoints covering product search, suggestions, product details, and chart/category discovery; it does not call or scrape Amazon directly. Requests require your Crawlora API key and use your account's service plan.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -30,4 +30,16 @@ client.close
|
|
|
30
30
|
|
|
31
31
|
Client options include `api_key`, `base_url`, and `timeout`. Ruby stdlib provides the HTTP and JSON support.
|
|
32
32
|
|
|
33
|
+
## Supported Amazon API endpoints
|
|
34
|
+
|
|
35
|
+
Browse every route included in this gem. The [endpoint reference](https://github.com/Crawlora-org/crawlora-amazon/blob/main/docs/usage.md) includes parameter and response details.
|
|
36
|
+
|
|
37
|
+
| Method | Endpoint | API operation | Description |
|
|
38
|
+
| --- | --- | --- | --- |
|
|
39
|
+
| `GET` | `/amazon/charts` | `amazon-charts` | Amazon product charts |
|
|
40
|
+
| `GET` | `/amazon/charts/categories` | `amazon-charts-categories` | Amazon chart categories |
|
|
41
|
+
| `GET` | `/amazon/product/{asin}` | `amazon-product` | Retrieve Amazon product details |
|
|
42
|
+
| `GET` | `/amazon/search` | `amazon-search` | Search Amazon products |
|
|
43
|
+
| `GET` | `/amazon/suggest/{keyword}` | `amazon-suggest` | Retrieve Amazon search suggestions |
|
|
44
|
+
|
|
33
45
|
See [Crawlora](https://crawlora.net/?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=amazon-ruby-homepage), the [API documentation](https://crawlora.net/docs?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=amazon-ruby-api-docs), and [the package repository](https://github.com/Crawlora-org/crawlora-amazon) for account setup, the API operation reference, and release history.
|
|
@@ -19,7 +19,7 @@ module Crawlora
|
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
OPERATIONS = JSON.parse(<<~'JSON').freeze
|
|
22
|
-
{"amazon-charts": {"id": "amazon-charts", "method": "GET", "params": [{"description": "Chart type", "enum": ["best_sellers", "new_releases", "most_wished_for"], "in": "query", "name": "chart", "required": true, "type": "string", "x-example": "best_sellers"}, {"description": "Amazon department slug", "in": "query", "name": "department", "required": true, "type": "string", "x-example": "electronics"}, {"description": "Numeric browse node id", "in": "query", "name": "node", "type": "string", "x-example": "172541"}, {"description": "1-based page number", "in": "query", "name": "page", "type": "integer", "x-example": 1}], "path": "/amazon/charts", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["best_sellers", "new_releases", "most_wished_for"], "in": "query", "name": "chart", "required": true, "type": "string"}, {"in": "query", "name": "department", "required": true, "type": "string"}, {"in": "query", "name": "node", "type": "string"}, {"in": "query", "name": "page", "type": "integer"}], "security": ["ApiKeyAuth"]}, "amazon-charts-categories": {"id": "amazon-charts-categories", "method": "GET", "params": [{"description": "Chart type", "enum": ["best_sellers", "new_releases", "most_wished_for"], "in": "query", "name": "chart", "required": true, "type": "string", "x-example": "best_sellers"}, {"description": "Amazon department slug", "in": "query", "name": "department", "type": "string", "x-example": "electronics"}, {"description": "Numeric browse node id (requires department)", "in": "query", "name": "node", "type": "string", "x-example": "172541"}], "path": "/amazon/charts/categories", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["best_sellers", "new_releases", "most_wished_for"], "in": "query", "name": "chart", "required": true, "type": "string"}, {"in": "query", "name": "department", "type": "string"}, {"in": "query", "name": "node", "type": "string"}], "security": ["ApiKeyAuth"]}, "amazon-product": {"id": "amazon-product", "method": "GET", "params": [{"description": "Amazon ASIN", "in": "path", "name": "asin", "required": true, "type": "string", "x-example": "B0DGJ736JM"}, {"default": "en_US", "description": "Amazon language", "enum": ["en_US"], "in": "query", "name": "language", "type": "string"}, {"default": "USD", "description": "Amazon currency", "enum": ["USD"], "in": "query", "name": "currency", "type": "string"}], "path": "/amazon/product/{asin}", "pathParams": ["asin"], "produces": ["application/json"], "queryParams": [{"enum": ["en_US"], "in": "query", "name": "language", "type": "string"}, {"enum": ["USD"], "in": "query", "name": "currency", "type": "string"}], "security": ["ApiKeyAuth"]}, "amazon-search": {"id": "amazon-search", "method": "GET", "params": [{"description": "Search keyword", "in": "query", "name": "k", "required": true, "type": "string", "x-example": "apple watch"}, {"description": "Sort order", "in": "query", "name": "s", "type": "string", "x-example": "review-rank"}, {"description": "1-based page number", "in": "query", "name": "page", "type": "integer", "x-example": 1}], "path": "/amazon/search", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "k", "required": true, "type": "string"}, {"in": "query", "name": "s", "type": "string"}, {"in": "query", "name": "page", "type": "integer"}], "security": ["ApiKeyAuth"]}, "amazon-suggest": {"id": "amazon-suggest", "method": "GET", "params": [{"description": "Suggestion prefix", "in": "path", "name": "keyword", "required": true, "type": "string", "x-example": "apple"}], "path": "/amazon/suggest/{keyword}", "pathParams": ["keyword"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}}
|
|
22
|
+
{"amazon-charts": {"bodyParam": null, "bodyRequired": false, "id": "amazon-charts", "method": "GET", "params": [{"description": "Chart type", "enum": ["best_sellers", "new_releases", "most_wished_for"], "in": "query", "name": "chart", "required": true, "type": "string", "x-example": "best_sellers"}, {"description": "Amazon department slug", "in": "query", "name": "department", "required": true, "type": "string", "x-example": "electronics"}, {"description": "Numeric browse node id", "in": "query", "name": "node", "type": "string", "x-example": "172541"}, {"description": "1-based page number", "in": "query", "name": "page", "type": "integer", "x-example": 1}], "path": "/amazon/charts", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["best_sellers", "new_releases", "most_wished_for"], "in": "query", "name": "chart", "required": true, "type": "string"}, {"in": "query", "name": "department", "required": true, "type": "string"}, {"in": "query", "name": "node", "type": "string"}, {"in": "query", "name": "page", "type": "integer"}], "security": ["ApiKeyAuth"]}, "amazon-charts-categories": {"bodyParam": null, "bodyRequired": false, "id": "amazon-charts-categories", "method": "GET", "params": [{"description": "Chart type", "enum": ["best_sellers", "new_releases", "most_wished_for"], "in": "query", "name": "chart", "required": true, "type": "string", "x-example": "best_sellers"}, {"description": "Amazon department slug", "in": "query", "name": "department", "type": "string", "x-example": "electronics"}, {"description": "Numeric browse node id (requires department)", "in": "query", "name": "node", "type": "string", "x-example": "172541"}], "path": "/amazon/charts/categories", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["best_sellers", "new_releases", "most_wished_for"], "in": "query", "name": "chart", "required": true, "type": "string"}, {"in": "query", "name": "department", "type": "string"}, {"in": "query", "name": "node", "type": "string"}], "security": ["ApiKeyAuth"]}, "amazon-product": {"bodyParam": null, "bodyRequired": false, "id": "amazon-product", "method": "GET", "params": [{"description": "Amazon ASIN", "in": "path", "name": "asin", "required": true, "type": "string", "x-example": "B0DGJ736JM"}, {"default": "en_US", "description": "Amazon language", "enum": ["en_US"], "in": "query", "name": "language", "type": "string"}, {"default": "USD", "description": "Amazon currency", "enum": ["USD"], "in": "query", "name": "currency", "type": "string"}], "path": "/amazon/product/{asin}", "pathParams": ["asin"], "produces": ["application/json"], "queryParams": [{"enum": ["en_US"], "in": "query", "name": "language", "type": "string"}, {"enum": ["USD"], "in": "query", "name": "currency", "type": "string"}], "security": ["ApiKeyAuth"]}, "amazon-search": {"bodyParam": null, "bodyRequired": false, "id": "amazon-search", "method": "GET", "params": [{"description": "Search keyword", "in": "query", "name": "k", "required": true, "type": "string", "x-example": "apple watch"}, {"description": "Sort order", "in": "query", "name": "s", "type": "string", "x-example": "review-rank"}, {"description": "1-based page number", "in": "query", "name": "page", "type": "integer", "x-example": 1}], "path": "/amazon/search", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "k", "required": true, "type": "string"}, {"in": "query", "name": "s", "type": "string"}, {"in": "query", "name": "page", "type": "integer"}], "security": ["ApiKeyAuth"]}, "amazon-suggest": {"bodyParam": null, "bodyRequired": false, "id": "amazon-suggest", "method": "GET", "params": [{"description": "Suggestion prefix", "in": "path", "name": "keyword", "required": true, "type": "string", "x-example": "apple"}], "path": "/amazon/suggest/{keyword}", "pathParams": ["keyword"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}}
|
|
23
23
|
JSON
|
|
24
24
|
OPERATION_IDS = JSON.parse(<<~'JSON').freeze
|
|
25
25
|
["amazon-charts", "amazon-charts-categories", "amazon-product", "amazon-search", "amazon-suggest"]
|
|
@@ -29,7 +29,7 @@ module Crawlora
|
|
|
29
29
|
class Client
|
|
30
30
|
attr_reader :base_url
|
|
31
31
|
|
|
32
|
-
def initialize(api_key: ENV["CRAWLORA_API_KEY"], base_url: "https://api.crawlora.net/api/v1", timeout: 30, user_agent: "crawlora-amazon-ruby/0.1.
|
|
32
|
+
def initialize(api_key: ENV["CRAWLORA_API_KEY"], base_url: "https://api.crawlora.net/api/v1", timeout: 30, user_agent: "crawlora-amazon-ruby/0.1.2", transport: nil)
|
|
33
33
|
@api_key = api_key
|
|
34
34
|
@base_url = base_url.to_s.sub(%r{/+$}, "")
|
|
35
35
|
@timeout = Float(timeout)
|
|
@@ -45,15 +45,24 @@ module Crawlora
|
|
|
45
45
|
raise Errors::ClientError.new("unknown operation: #{operation_id}", operation_id: operation_id) unless operation
|
|
46
46
|
raise Errors::ClientError.new("Crawlora API key is required", operation_id: operation_id) if @api_key.nil? || @api_key.to_s.empty?
|
|
47
47
|
normalized = params.each_with_object({}) { |(key, value), out| out[key.to_s] = value }
|
|
48
|
+
payload = request_body(operation, normalized)
|
|
48
49
|
url = build_url(operation, normalized)
|
|
49
50
|
uri = URI.parse(url)
|
|
50
|
-
request = Net::HTTP::Get.new(uri)
|
|
51
|
+
request = operation["method"] == "POST" ? Net::HTTP::Post.new(uri) : Net::HTTP::Get.new(uri)
|
|
52
|
+
unless payload.nil?
|
|
53
|
+
request.body = payload
|
|
54
|
+
request["Content-Type"] = "application/json"
|
|
55
|
+
end
|
|
51
56
|
request["x-api-key"] = @api_key
|
|
52
57
|
request["User-Agent"] = @user_agent
|
|
53
58
|
request["Accept"] = operation["produces"].include?("text/plain") ? "application/json, text/plain" : "application/json"
|
|
54
59
|
begin
|
|
55
60
|
if @transport
|
|
56
|
-
response =
|
|
61
|
+
response = if operation["method"] == "POST"
|
|
62
|
+
@transport.call(url, request.to_hash, @timeout, "POST", payload)
|
|
63
|
+
else
|
|
64
|
+
@transport.call(url, request.to_hash, @timeout)
|
|
65
|
+
end
|
|
57
66
|
status = Integer(response.fetch(:status) { response.fetch("status") })
|
|
58
67
|
body = response.fetch(:body) { response.fetch("body", "") }
|
|
59
68
|
headers = response.fetch(:headers) { response.fetch("headers", {}) }
|
|
@@ -128,8 +137,21 @@ module Crawlora
|
|
|
128
137
|
|
|
129
138
|
private
|
|
130
139
|
|
|
140
|
+
# POST operations take their JSON body under the body parameter name or "body".
|
|
141
|
+
def request_body(operation, params)
|
|
142
|
+
name = operation["bodyParam"]
|
|
143
|
+
return nil if name.nil?
|
|
144
|
+
value = params.key?(name) ? params[name] : params["body"]
|
|
145
|
+
if value.nil?
|
|
146
|
+
raise Errors::ClientError.new("missing request body: #{name}", operation_id: operation["id"]) if operation["bodyRequired"]
|
|
147
|
+
return nil
|
|
148
|
+
end
|
|
149
|
+
value.is_a?(String) ? value : JSON.generate(value)
|
|
150
|
+
end
|
|
151
|
+
|
|
131
152
|
def build_url(operation, params)
|
|
132
153
|
known = operation["params"].map { |param| param["name"] }
|
|
154
|
+
known << "body" if operation["bodyParam"]
|
|
133
155
|
unknown = params.keys - known
|
|
134
156
|
raise Errors::ClientError.new("unknown parameters: #{unknown.join(', ')}", operation_id: operation["id"]) unless unknown.empty?
|
|
135
157
|
path = operation["path"].dup
|
metadata
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: crawlora-amazon
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Crawlora
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-10-
|
|
11
|
+
date: 2026-10-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
|
-
description:
|
|
13
|
+
description: Ruby client for Crawlora's hosted Amazon API. Covers product search,
|
|
14
|
+
suggestions, product details, and chart/category discovery across 5 endpoints.
|
|
14
15
|
email:
|
|
15
16
|
executables: []
|
|
16
17
|
extensions: []
|
|
@@ -47,5 +48,5 @@ requirements: []
|
|
|
47
48
|
rubygems_version: 3.4.19
|
|
48
49
|
signing_key:
|
|
49
50
|
specification_version: 4
|
|
50
|
-
summary: Amazon client for
|
|
51
|
+
summary: Amazon API client for Crawlora (5 endpoints)
|
|
51
52
|
test_files: []
|