crawlora-google 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 +7 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE +21 -0
- data/README.md +33 -0
- data/lib/crawlora/google/client.rb +356 -0
- data/lib/crawlora/google/version.rb +5 -0
- data/lib/crawlora/google.rb +2 -0
- metadata +51 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 18cb97858146446b152d077090c3002f739ed7bd0c9b465c2d03b852421c7e63
|
|
4
|
+
data.tar.gz: cc1118195caa128271b71a4ca07b899259ecb64181da5b214d6173a39cc532ee
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: a74a0ed73e22de63c4f4253c9830700598a2c89b4a7c465026e05ee7db14d9be4f91bab0a0bc789b233b77eabf327ce85e7d32de906aebf9275545701ba7ff85
|
|
7
|
+
data.tar.gz: 0f31064dc204e55cc8968e422f919b67d354579f096ee69a4298155e6e4ab0dc7054ba69a5b4417440e45b529d29bf7963efa324ea54b649bbb402d4842a56a9
|
data/CHANGELOG.md
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Crawlora
|
|
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,33 @@
|
|
|
1
|
+
# Crawlora Google Ruby client
|
|
2
|
+
|
|
3
|
+
This gem calls the Crawlora hosted API at `https://api.crawlora.net/api/v1`. It does not call or scrape Google directly. Requests require your Crawlora API key and use your account's service plan.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```ruby
|
|
8
|
+
gem "crawlora-google"
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Create an account at [crawlora.net](https://crawlora.net/signup?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=google-ruby-signup), open the [Crawlora console](https://crawlora.net/app?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=google-ruby-console) to get an API key, and set `CRAWLORA_API_KEY` before running the client:
|
|
12
|
+
|
|
13
|
+
```ruby
|
|
14
|
+
require "json"
|
|
15
|
+
require "crawlora/google"
|
|
16
|
+
|
|
17
|
+
client = Crawlora::Google::Client.new
|
|
18
|
+
result = client.request("google-finance-search", JSON.parse("{\"q\": \"sample\"}"))
|
|
19
|
+
puts result
|
|
20
|
+
client.close
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Use an operation-specific method for normal calls. `request(operation_id, params = {}, response_type: :auto)` is available for every operation. `response_type: :text` returns raw response text. This gem includes 40 API operations.
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
client = Crawlora::Google::Client.new(api_key: ENV.fetch("CRAWLORA_API_KEY"), timeout: 30)
|
|
27
|
+
# client.<operation_method>(<endpoint parameters>)
|
|
28
|
+
client.close
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Client options include `api_key`, `base_url`, and `timeout`. Ruby stdlib provides the HTTP and JSON support.
|
|
32
|
+
|
|
33
|
+
See [Crawlora](https://crawlora.net/?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=google-ruby-homepage), the [API documentation](https://crawlora.net/docs?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=google-ruby-api-docs), and [the package repository](https://github.com/Crawlora-org/crawlora-google) for account setup, the API operation reference, and release history.
|
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
require "net/http"
|
|
3
|
+
require "uri"
|
|
4
|
+
|
|
5
|
+
module Crawlora
|
|
6
|
+
module Google
|
|
7
|
+
module Errors
|
|
8
|
+
class Error < StandardError
|
|
9
|
+
attr_reader :status, :operation_id, :body
|
|
10
|
+
|
|
11
|
+
def initialize(message, status: nil, operation_id: nil, body: nil)
|
|
12
|
+
super(message)
|
|
13
|
+
@status, @operation_id, @body = status, operation_id, body
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
class ClientError < Error; end
|
|
17
|
+
class ServerError < Error; end
|
|
18
|
+
class NetworkError < Error; end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
OPERATIONS = JSON.parse(<<~'JSON').freeze
|
|
22
|
+
{"google-finance-analyst-articles": {"bodyParam": null, "bodyRequired": false, "id": "google-finance-analyst-articles", "method": "GET", "params": [{"description": "Quote identifier such as AAPL:NASDAQ", "in": "path", "name": "quote", "required": true, "type": "string", "x-example": "AAPL:NASDAQ"}], "path": "/google/finance/analyst-articles/{quote}", "pathParams": ["quote"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "google-finance-chart": {"bodyParam": null, "bodyRequired": false, "id": "google-finance-chart", "method": "GET", "params": [{"description": "Quote identifier such as AAPL:NASDAQ", "in": "path", "name": "quote", "required": true, "type": "string", "x-example": "AAPL:NASDAQ"}, {"description": "Window: 1d, 5d, 1m, 6m, ytd, 1y, 5y, max", "in": "query", "name": "window", "type": "string"}], "path": "/google/finance/chart/{quote}", "pathParams": ["quote"], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "window", "type": "string"}], "security": ["ApiKeyAuth"]}, "google-finance-classification": {"bodyParam": null, "bodyRequired": false, "id": "google-finance-classification", "method": "GET", "params": [{"description": "Quote identifier such as AAPL:NASDAQ", "in": "path", "name": "quote", "required": true, "type": "string", "x-example": "AAPL:NASDAQ"}], "path": "/google/finance/classification/{quote}", "pathParams": ["quote"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "google-finance-company": {"bodyParam": null, "bodyRequired": false, "id": "google-finance-company", "method": "GET", "params": [{"description": "Quote identifier such as AAPL:NASDAQ", "in": "path", "name": "quote", "required": true, "type": "string", "x-example": "AAPL:NASDAQ"}], "path": "/google/finance/company/{quote}", "pathParams": ["quote"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "google-finance-context": {"bodyParam": null, "bodyRequired": false, "id": "google-finance-context", "method": "GET", "params": [{"description": "Search query", "in": "query", "name": "q", "required": true, "type": "string", "x-example": "apple"}], "path": "/google/finance/context", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "q", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "google-finance-financials": {"bodyParam": null, "bodyRequired": false, "id": "google-finance-financials", "method": "GET", "params": [{"description": "Quote identifier such as AAPL:NASDAQ", "in": "path", "name": "quote", "required": true, "type": "string", "x-example": "AAPL:NASDAQ"}], "path": "/google/finance/financials/{quote}", "pathParams": ["quote"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "google-finance-markets-category-news": {"bodyParam": null, "bodyRequired": false, "id": "google-finance-markets-category-news", "method": "GET", "params": [{"description": "Google Finance category id", "in": "path", "name": "category", "required": true, "type": "string", "x-example": "2"}, {"description": "Result offset", "in": "query", "name": "offset", "type": "integer"}], "path": "/google/finance/markets/categories/{category}/news", "pathParams": ["category"], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "offset", "type": "integer"}], "security": ["ApiKeyAuth"]}, "google-finance-markets-category-stocks": {"bodyParam": null, "bodyRequired": false, "id": "google-finance-markets-category-stocks", "method": "GET", "params": [{"description": "Google Finance category id", "in": "path", "name": "category", "required": true, "type": "string", "x-example": "2"}, {"description": "Result offset", "in": "query", "name": "offset", "type": "integer"}], "path": "/google/finance/markets/categories/{category}/stocks", "pathParams": ["category"], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "offset", "type": "integer"}], "security": ["ApiKeyAuth"]}, "google-finance-markets-earnings": {"bodyParam": null, "bodyRequired": false, "id": "google-finance-markets-earnings", "method": "GET", "params": [], "path": "/google/finance/markets/earnings", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "google-finance-markets-featured": {"bodyParam": null, "bodyRequired": false, "id": "google-finance-markets-featured", "method": "GET", "params": [], "path": "/google/finance/markets/featured", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "google-finance-markets-headline": {"bodyParam": null, "bodyRequired": false, "id": "google-finance-markets-headline", "method": "GET", "params": [], "path": "/google/finance/markets/headline", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "google-finance-markets-indices": {"bodyParam": null, "bodyRequired": false, "id": "google-finance-markets-indices", "method": "GET", "params": [], "path": "/google/finance/markets/indices", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "google-finance-markets-movers": {"bodyParam": null, "bodyRequired": false, "id": "google-finance-markets-movers", "method": "GET", "params": [{"description": "Comma-separated numeric categories", "in": "query", "name": "categories", "type": "string"}, {"description": "Result count", "in": "query", "name": "count", "type": "integer"}, {"description": "Result offset", "in": "query", "name": "offset", "type": "integer"}], "path": "/google/finance/markets/movers", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "categories", "type": "string"}, {"in": "query", "name": "count", "type": "integer"}, {"in": "query", "name": "offset", "type": "integer"}], "security": ["ApiKeyAuth"]}, "google-finance-markets-top": {"bodyParam": null, "bodyRequired": false, "id": "google-finance-markets-top", "method": "GET", "params": [{"description": "Google Finance metric id", "in": "query", "name": "metric", "type": "integer"}, {"description": "Page number", "in": "query", "name": "page", "type": "integer"}], "path": "/google/finance/markets/top", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "metric", "type": "integer"}, {"in": "query", "name": "page", "type": "integer"}], "security": ["ApiKeyAuth"]}, "google-finance-markets-trending": {"bodyParam": null, "bodyRequired": false, "id": "google-finance-markets-trending", "method": "GET", "params": [{"description": "Result limit", "in": "query", "name": "limit", "type": "integer"}], "path": "/google/finance/markets/trending", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "limit", "type": "integer"}], "security": ["ApiKeyAuth"]}, "google-finance-news": {"bodyParam": null, "bodyRequired": false, "id": "google-finance-news", "method": "GET", "params": [{"description": "Quote identifier such as AAPL:NASDAQ", "in": "path", "name": "quote", "required": true, "type": "string", "x-example": "AAPL:NASDAQ"}, {"description": "Article limit", "in": "query", "name": "limit", "type": "integer"}], "path": "/google/finance/news/{quote}", "pathParams": ["quote"], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "limit", "type": "integer"}], "security": ["ApiKeyAuth"]}, "google-finance-quote": {"bodyParam": null, "bodyRequired": false, "id": "google-finance-quote", "method": "GET", "params": [{"description": "Stock symbol to fetch the latest quote for (e.g., AAPL:NASDAQ, BTC-USD)", "in": "path", "name": "quote", "required": true, "type": "string", "x-example": "AAPL:NASDAQ"}], "path": "/google/finance/quote/{quote}", "pathParams": ["quote"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "google-finance-related": {"bodyParam": null, "bodyRequired": false, "id": "google-finance-related", "method": "GET", "params": [{"description": "Quote identifier such as AAPL:NASDAQ", "in": "path", "name": "quote", "required": true, "type": "string", "x-example": "AAPL:NASDAQ"}], "path": "/google/finance/related/{quote}", "pathParams": ["quote"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "google-finance-search": {"bodyParam": null, "bodyRequired": false, "id": "google-finance-search", "method": "GET", "params": [{"description": "Keyword to search for (e.g., Apple)", "in": "query", "name": "q", "required": true, "type": "string", "x-example": "Apple"}], "path": "/google/finance/search", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "q", "required": true, "type": "string"}], "security": ["ApiKeyAuth"]}, "google-finance-ticker": {"bodyParam": null, "bodyRequired": false, "id": "google-finance-ticker", "method": "GET", "params": [{"description": "Ticker symbol to fetch data for example:AAPL:NASDAQ, BTC-USD ", "in": "path", "name": "ticker", "required": true, "type": "string", "x-example": "AAPL:NASDAQ"}, {"description": "Time window for the ticker data (default: 1d), options: 1d, 5d, 1m, 6m, 1y, 5y, max", "in": "query", "name": "window", "type": "string"}], "path": "/google/finance/ticker/{ticker}", "pathParams": ["ticker"], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "window", "type": "string"}], "security": ["ApiKeyAuth"]}, "google-jobs": {"bodyParam": "option", "bodyRequired": true, "id": "google-jobs", "method": "POST", "params": [{"description": "Google Jobs search payload", "in": "body", "name": "option", "required": true, "schema": {"$ref": "#/definitions/google.JobsOption"}}], "path": "/google/jobs", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "google-map-place": {"bodyParam": null, "bodyRequired": false, "id": "google-map-place", "method": "GET", "params": [{"description": "Google Place ID", "in": "path", "name": "place_id", "required": true, "type": "string", "x-example": "ChIJs3cv0KuvEmsRHcXYwNJ6GU0"}], "path": "/google/map/place/{place_id}", "pathParams": ["place_id"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "google-map-place-photos": {"bodyParam": null, "bodyRequired": false, "id": "google-map-place-photos", "method": "GET", "params": [{"description": "Google Place ID", "in": "path", "name": "place_id", "required": true, "type": "string", "x-example": "ChIJs3cv0KuvEmsRHcXYwNJ6GU0"}, {"description": "Maximum number of photos to return. Omit or 0 for all captured.", "in": "query", "name": "limit", "type": "integer"}], "path": "/google/map/place/{place_id}/photos", "pathParams": ["place_id"], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "limit", "type": "integer"}], "security": ["ApiKeyAuth"]}, "google-map-place-reviews": {"bodyParam": null, "bodyRequired": false, "id": "google-map-place-reviews", "method": "GET", "params": [{"description": "Google Place ID", "in": "path", "name": "place_id", "required": true, "type": "string", "x-example": "ChIJs3cv0KuvEmsRHcXYwNJ6GU0"}, {"description": "Maximum number of reviews to return. Omit or 0 for all captured.", "in": "query", "name": "limit", "type": "integer"}], "path": "/google/map/place/{place_id}/reviews", "pathParams": ["place_id"], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "limit", "type": "integer"}], "security": ["ApiKeyAuth"]}, "google-map-search": {"bodyParam": "mapSearchOption", "bodyRequired": true, "id": "google-map-search", "method": "POST", "params": [{"description": "Search options", "in": "body", "name": "mapSearchOption", "required": true, "schema": {"$ref": "#/definitions/google.MapSearchOption"}}], "path": "/google/map/search", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "google-news": {"bodyParam": null, "bodyRequired": false, "id": "google-news", "method": "GET", "params": [{"description": "Search query", "in": "query", "name": "q", "required": true, "type": "string", "x-example": "openai"}, {"description": "1-based page within the current finite result snapshot; defaults to 1", "in": "query", "minimum": 1, "name": "page", "type": "integer", "x-example": 1}, {"description": "Results per page; defaults to 10, clamped to 1..50", "in": "query", "maximum": 50, "minimum": 1, "name": "count", "type": "integer", "x-example": 10}, {"description": "Two-letter country code; defaults to us", "in": "query", "name": "country", "type": "string", "x-example": "us"}, {"description": "Google UI language; defaults to en", "in": "query", "name": "lang", "type": "string", "x-example": "en"}], "path": "/google/news", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "q", "required": true, "type": "string"}, {"in": "query", "name": "page", "type": "integer"}, {"in": "query", "name": "count", "type": "integer"}, {"in": "query", "name": "country", "type": "string"}, {"in": "query", "name": "lang", "type": "string"}], "security": ["ApiKeyAuth"]}, "google-news-search": {"bodyParam": "searchOption", "bodyRequired": true, "id": "google-news-search", "method": "POST", "params": [{"description": "Search options; keyword, language and country are required. limit defaults to 10 and is clamped to 10..100; page defaults to 1.", "in": "body", "name": "searchOption", "required": true, "schema": {"$ref": "#/definitions/google.SearchOption"}}], "path": "/google/news", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "google-suggest": {"bodyParam": null, "bodyRequired": false, "id": "google-suggest", "method": "GET", "params": [{"description": "Search query prefix", "in": "query", "name": "q", "required": true, "type": "string", "x-example": "openai"}, {"description": "Suggestions to return; defaults to 10, clamped to 1..12", "in": "query", "maximum": 12, "minimum": 1, "name": "count", "type": "integer", "x-example": 10}, {"description": "Google result country; defaults to us", "in": "query", "name": "country", "type": "string", "x-example": "us"}, {"description": "Google UI language; defaults to en", "in": "query", "name": "lang", "type": "string", "x-example": "en"}, {"default": "web", "description": "Suggestion source; defaults to web", "enum": ["web", "youtube", "shopping"], "in": "query", "name": "source", "type": "string"}, {"description": "Add Google's type, relevance score, and description to each suggestion; defaults to false", "in": "query", "name": "rich", "type": "boolean", "x-example": false}], "path": "/google/suggest", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "q", "required": true, "type": "string"}, {"in": "query", "name": "count", "type": "integer"}, {"in": "query", "name": "country", "type": "string"}, {"in": "query", "name": "lang", "type": "string"}, {"enum": ["web", "youtube", "shopping"], "in": "query", "name": "source", "type": "string"}, {"in": "query", "name": "rich", "type": "boolean"}], "security": ["ApiKeyAuth"]}, "google-trends-categories": {"bodyParam": null, "bodyRequired": false, "id": "google-trends-categories", "method": "GET", "params": [], "path": "/google/trends/categories", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "google-trends-enums": {"bodyParam": null, "bodyRequired": false, "id": "google-trends-enums", "method": "GET", "params": [], "path": "/google/trends/enums", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "google-trends-explore": {"bodyParam": "request", "bodyRequired": true, "id": "google-trends-explore", "method": "POST", "params": [{"description": "Explore request", "in": "body", "name": "request", "required": true, "schema": {"$ref": "#/definitions/trends.ExploreRequest"}}], "path": "/google/trends/explore", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "google-trends-explore-interest-by-region": {"bodyParam": "request", "bodyRequired": true, "id": "google-trends-explore-interest-by-region", "method": "POST", "params": [{"description": "Explore request", "in": "body", "name": "request", "required": true, "schema": {"$ref": "#/definitions/trends.ExploreRequest"}}], "path": "/google/trends/explore/interest-by-region", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "google-trends-explore-interest-over-time": {"bodyParam": "request", "bodyRequired": true, "id": "google-trends-explore-interest-over-time", "method": "POST", "params": [{"description": "Explore request", "in": "body", "name": "request", "required": true, "schema": {"$ref": "#/definitions/trends.ExploreRequest"}}], "path": "/google/trends/explore/interest-over-time", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "google-trends-explore-related-topics": {"bodyParam": "request", "bodyRequired": true, "id": "google-trends-explore-related-topics", "method": "POST", "params": [{"description": "Explore request", "in": "body", "name": "request", "required": true, "schema": {"$ref": "#/definitions/trends.ExploreRequest"}}], "path": "/google/trends/explore/related-topics", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "google-trends-explore-rising-queries": {"bodyParam": "request", "bodyRequired": true, "id": "google-trends-explore-rising-queries", "method": "POST", "params": [{"description": "Explore request", "in": "body", "name": "request", "required": true, "schema": {"$ref": "#/definitions/trends.ExploreRequest"}}], "path": "/google/trends/explore/rising-queries", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "google-trends-explore-top-queries": {"bodyParam": "request", "bodyRequired": true, "id": "google-trends-explore-top-queries", "method": "POST", "params": [{"description": "Explore request", "in": "body", "name": "request", "required": true, "schema": {"$ref": "#/definitions/trends.ExploreRequest"}}], "path": "/google/trends/explore/top-queries", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "google-trends-locations": {"bodyParam": null, "bodyRequired": false, "id": "google-trends-locations", "method": "GET", "params": [], "path": "/google/trends/locations", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "google-trends-trending": {"bodyParam": null, "bodyRequired": false, "id": "google-trends-trending", "method": "GET", "params": [{"default": "US", "description": "Country/territory location code", "enum": ["AF", "AX", "AL", "DZ", "AS", "AD", "AO", "AI", "AQ", "AG", "AR", "AM", "AW", "AU", "AT", "AZ", "BS", "BH", "BD", "BB", "BY", "BE", "BZ", "BJ", "BM", "BT", "BO", "BA", "BW", "BV", "BR", "IO", "VG", "BN", "BG", "BF", "BI", "KH", "CM", "CA", "CV", "BQ", "KY", "CF", "TD", "CL", "CN", "CX", "CC", "CO", "KM", "CG", "CD", "CK", "CR", "CI", "HR", "CU", "CW", "CY", "CZ", "DK", "DJ", "DM", "DO", "EC", "EG", "SV", "GQ", "ER", "EE", "SZ", "ET", "FK", "FO", "FJ", "FI", "FR", "GF", "PF", "TF", "GA", "GM", "GE", "DE", "GH", "GI", "GR", "GL", "GD", "GP", "GU", "GT", "GG", "GN", "GW", "GY", "HT", "HM", "HN", "HK", "HU", "IS", "IN", "ID", "IR", "IQ", "IE", "IM", "IL", "IT", "JM", "JP", "JE", "JO", "KZ", "KE", "KI", "XK", "KW", "KG", "LA", "LV", "LB", "LS", "LR", "LY", "LI", "LT", "LU", "MO", "MG", "MW", "MY", "MV", "ML", "MT", "MH", "MQ", "MR", "MU", "YT", "MX", "FM", "MD", "MC", "MN", "ME", "MS", "MA", "MZ", "MM", "NA", "NR", "NP", "NL", "NC", "NZ", "NI", "NE", "NG", "NU", "NF", "KP", "MK", "MP", "NO", "OM", "PK", "PW", "PS", "PA", "PG", "PY", "PE", "PH", "PN", "PL", "PT", "PR", "QA", "RE", "RO", "RU", "RW", "WS", "SM", "ST", "SA", "SN", "RS", "SC", "SL", "SG", "SX", "SK", "SI", "SB", "SO", "ZA", "GS", "KR", "SS", "ES", "LK", "BL", "SH", "KN", "LC", "MF", "PM", "VC", "SD", "SR", "SJ", "SE", "CH", "SY", "TW", "TJ", "TZ", "TH", "TL", "TG", "TK", "TO", "TT", "TN", "TR", "TM", "TC", "TV", "UM", "VI", "UG", "UA", "AE", "GB", "US", "UY", "UZ", "VU", "VA", "VE", "VN", "WF", "EH", "YE", "ZM", "ZW"], "in": "query", "name": "geo", "type": "string"}, {"default": "en-US", "description": "Google Trends UI locale", "in": "query", "name": "hl", "type": "string"}, {"default": 0, "description": "Timezone offset minutes", "in": "query", "name": "tz", "type": "integer"}, {"default": "24h", "description": "Trend window", "enum": ["4h", "24h", "48h", "7d"], "in": "query", "name": "window", "type": "string"}, {"description": "Alias for window", "enum": ["4h", "24h", "48h", "7d"], "in": "query", "name": "time_range", "type": "string"}, {"default": 0, "description": "Trending category id", "enum": [0, 3, 47, 44, 22, 12, 5, 7, 71, 8, 45, 65, 11, 13, 958, 19, 16, 299, 14, 66, 29, 533, 174, 18, 20, 67], "in": "query", "name": "category", "type": "integer"}, {"default": "all", "description": "Trend status filter", "enum": ["all", "active", "ended"], "in": "query", "name": "status", "type": "string"}, {"default": "relevance", "description": "Sort mode", "enum": ["relevance", "title", "recency", "search_volume"], "in": "query", "name": "sort_by", "type": "string"}, {"default": 20, "description": "Maximum rows to return", "in": "query", "name": "limit", "type": "integer"}], "path": "/google/trends/trending", "pathParams": [], "produces": ["application/json"], "queryParams": [{"enum": ["AF", "AX", "AL", "DZ", "AS", "AD", "AO", "AI", "AQ", "AG", "AR", "AM", "AW", "AU", "AT", "AZ", "BS", "BH", "BD", "BB", "BY", "BE", "BZ", "BJ", "BM", "BT", "BO", "BA", "BW", "BV", "BR", "IO", "VG", "BN", "BG", "BF", "BI", "KH", "CM", "CA", "CV", "BQ", "KY", "CF", "TD", "CL", "CN", "CX", "CC", "CO", "KM", "CG", "CD", "CK", "CR", "CI", "HR", "CU", "CW", "CY", "CZ", "DK", "DJ", "DM", "DO", "EC", "EG", "SV", "GQ", "ER", "EE", "SZ", "ET", "FK", "FO", "FJ", "FI", "FR", "GF", "PF", "TF", "GA", "GM", "GE", "DE", "GH", "GI", "GR", "GL", "GD", "GP", "GU", "GT", "GG", "GN", "GW", "GY", "HT", "HM", "HN", "HK", "HU", "IS", "IN", "ID", "IR", "IQ", "IE", "IM", "IL", "IT", "JM", "JP", "JE", "JO", "KZ", "KE", "KI", "XK", "KW", "KG", "LA", "LV", "LB", "LS", "LR", "LY", "LI", "LT", "LU", "MO", "MG", "MW", "MY", "MV", "ML", "MT", "MH", "MQ", "MR", "MU", "YT", "MX", "FM", "MD", "MC", "MN", "ME", "MS", "MA", "MZ", "MM", "NA", "NR", "NP", "NL", "NC", "NZ", "NI", "NE", "NG", "NU", "NF", "KP", "MK", "MP", "NO", "OM", "PK", "PW", "PS", "PA", "PG", "PY", "PE", "PH", "PN", "PL", "PT", "PR", "QA", "RE", "RO", "RU", "RW", "WS", "SM", "ST", "SA", "SN", "RS", "SC", "SL", "SG", "SX", "SK", "SI", "SB", "SO", "ZA", "GS", "KR", "SS", "ES", "LK", "BL", "SH", "KN", "LC", "MF", "PM", "VC", "SD", "SR", "SJ", "SE", "CH", "SY", "TW", "TJ", "TZ", "TH", "TL", "TG", "TK", "TO", "TT", "TN", "TR", "TM", "TC", "TV", "UM", "VI", "UG", "UA", "AE", "GB", "US", "UY", "UZ", "VU", "VA", "VE", "VN", "WF", "EH", "YE", "ZM", "ZW"], "in": "query", "name": "geo", "type": "string"}, {"in": "query", "name": "hl", "type": "string"}, {"in": "query", "name": "tz", "type": "integer"}, {"enum": ["4h", "24h", "48h", "7d"], "in": "query", "name": "window", "type": "string"}, {"enum": ["4h", "24h", "48h", "7d"], "in": "query", "name": "time_range", "type": "string"}, {"enum": ["0", "3", "47", "44", "22", "12", "5", "7", "71", "8", "45", "65", "11", "13", "958", "19", "16", "299", "14", "66", "29", "533", "174", "18", "20", "67"], "in": "query", "name": "category", "type": "integer"}, {"enum": ["all", "active", "ended"], "in": "query", "name": "status", "type": "string"}, {"enum": ["relevance", "title", "recency", "search_volume"], "in": "query", "name": "sort_by", "type": "string"}, {"in": "query", "name": "limit", "type": "integer"}], "security": ["ApiKeyAuth"]}, "google-trends-trending-detail": {"bodyParam": "request", "bodyRequired": true, "id": "google-trends-trending-detail", "method": "POST", "params": [{"description": "Trending detail request", "in": "body", "name": "request", "required": true, "schema": {"$ref": "#/definitions/trends.TrendingDetailRequest"}}], "path": "/google/trends/trending/detail", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "google-videos": {"bodyParam": null, "bodyRequired": false, "id": "google-videos", "method": "GET", "params": [{"description": "Search query", "in": "query", "name": "q", "required": true, "type": "string", "x-example": "openai"}, {"description": "1-based page number; defaults to 1", "in": "query", "minimum": 1, "name": "page", "type": "integer", "x-example": 1}, {"description": "Results per page; defaults to 10, clamped to 1..50", "in": "query", "maximum": 50, "minimum": 1, "name": "count", "type": "integer", "x-example": 10}, {"description": "Two-letter country code; defaults to us", "in": "query", "name": "country", "type": "string", "x-example": "us"}, {"description": "Google UI language; defaults to en", "in": "query", "name": "lang", "type": "string", "x-example": "en"}], "path": "/google/videos", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "q", "required": true, "type": "string"}, {"in": "query", "name": "page", "type": "integer"}, {"in": "query", "name": "count", "type": "integer"}, {"in": "query", "name": "country", "type": "string"}, {"in": "query", "name": "lang", "type": "string"}], "security": ["ApiKeyAuth"]}}
|
|
23
|
+
JSON
|
|
24
|
+
OPERATION_IDS = JSON.parse(<<~'JSON').freeze
|
|
25
|
+
["google-finance-analyst-articles", "google-finance-chart", "google-finance-classification", "google-finance-company", "google-finance-context", "google-finance-financials", "google-finance-markets-category-news", "google-finance-markets-category-stocks", "google-finance-markets-earnings", "google-finance-markets-featured", "google-finance-markets-headline", "google-finance-markets-indices", "google-finance-markets-movers", "google-finance-markets-top", "google-finance-markets-trending", "google-finance-news", "google-finance-quote", "google-finance-related", "google-finance-search", "google-finance-ticker", "google-jobs", "google-map-place", "google-map-place-photos", "google-map-place-reviews", "google-map-search", "google-news", "google-news-search", "google-suggest", "google-trends-categories", "google-trends-enums", "google-trends-explore", "google-trends-explore-interest-by-region", "google-trends-explore-interest-over-time", "google-trends-explore-related-topics", "google-trends-explore-rising-queries", "google-trends-explore-top-queries", "google-trends-locations", "google-trends-trending", "google-trends-trending-detail", "google-videos"]
|
|
26
|
+
JSON
|
|
27
|
+
OPERATION_COUNT = OPERATION_IDS.length
|
|
28
|
+
|
|
29
|
+
class Client
|
|
30
|
+
attr_reader :base_url
|
|
31
|
+
|
|
32
|
+
def initialize(api_key: ENV["CRAWLORA_API_KEY"], base_url: "https://api.crawlora.net/api/v1", timeout: 30, user_agent: "crawlora-google-ruby/0.1.0", transport: nil)
|
|
33
|
+
@api_key = api_key
|
|
34
|
+
@base_url = base_url.to_s.sub(%r{/+$}, "")
|
|
35
|
+
@timeout = Float(timeout)
|
|
36
|
+
@user_agent = user_agent
|
|
37
|
+
@transport = transport
|
|
38
|
+
@closed = false
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def request(operation_id, params = {}, response_type: :auto)
|
|
42
|
+
raise Errors::ClientError, "client is closed" if @closed
|
|
43
|
+
operation_id = operation_id.to_s
|
|
44
|
+
operation = OPERATIONS[operation_id]
|
|
45
|
+
raise Errors::ClientError.new("unknown operation: #{operation_id}", operation_id: operation_id) unless operation
|
|
46
|
+
raise Errors::ClientError.new("Crawlora API key is required", operation_id: operation_id) if @api_key.nil? || @api_key.to_s.empty?
|
|
47
|
+
normalized = params.each_with_object({}) { |(key, value), out| out[key.to_s] = value }
|
|
48
|
+
payload = request_body(operation, normalized)
|
|
49
|
+
url = build_url(operation, normalized)
|
|
50
|
+
uri = URI.parse(url)
|
|
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
|
|
56
|
+
request["x-api-key"] = @api_key
|
|
57
|
+
request["User-Agent"] = @user_agent
|
|
58
|
+
request["Accept"] = operation["produces"].include?("text/plain") ? "application/json, text/plain" : "application/json"
|
|
59
|
+
begin
|
|
60
|
+
if @transport
|
|
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
|
|
66
|
+
status = Integer(response.fetch(:status) { response.fetch("status") })
|
|
67
|
+
body = response.fetch(:body) { response.fetch("body", "") }
|
|
68
|
+
headers = response.fetch(:headers) { response.fetch("headers", {}) }
|
|
69
|
+
content_type = headers["content-type"] || headers["Content-Type"]
|
|
70
|
+
else
|
|
71
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
72
|
+
http.use_ssl = uri.scheme == "https"
|
|
73
|
+
http.open_timeout = @timeout
|
|
74
|
+
http.read_timeout = @timeout
|
|
75
|
+
response = http.start { |connection| connection.request(request) }
|
|
76
|
+
status = response.code.to_i
|
|
77
|
+
body = response.body
|
|
78
|
+
content_type = response["content-type"]
|
|
79
|
+
end
|
|
80
|
+
rescue Timeout::Error, SocketError, SystemCallError, IOError, EOFError, Net::HTTPBadResponse, Net::ProtocolError, OpenSSL::SSL::SSLError => error
|
|
81
|
+
raise Errors::NetworkError.new("Crawlora request failed: #{error.message}", operation_id: operation_id)
|
|
82
|
+
end
|
|
83
|
+
unless status >= 200 && status < 300
|
|
84
|
+
klass = status >= 500 ? Errors::ServerError : Errors::ClientError
|
|
85
|
+
raise klass.new("Crawlora returned HTTP #{status}", status: status, operation_id: operation_id, body: body)
|
|
86
|
+
end
|
|
87
|
+
parse_response(body, content_type, operation, normalized, response_type)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def close
|
|
91
|
+
@closed = true
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def closed?
|
|
95
|
+
@closed
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def with
|
|
99
|
+
return self unless block_given?
|
|
100
|
+
yield self
|
|
101
|
+
ensure
|
|
102
|
+
close if block_given?
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def self.operation_count
|
|
106
|
+
OPERATION_COUNT
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def self.operation_ids
|
|
110
|
+
OPERATION_IDS
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def self.operations
|
|
114
|
+
OPERATIONS
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
define_method('finance_analyst_articles') do |**params|
|
|
118
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
119
|
+
request('google-finance-analyst-articles', params, response_type: response_type)
|
|
120
|
+
end
|
|
121
|
+
define_method('finance_chart') do |**params|
|
|
122
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
123
|
+
request('google-finance-chart', params, response_type: response_type)
|
|
124
|
+
end
|
|
125
|
+
define_method('finance_classification') do |**params|
|
|
126
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
127
|
+
request('google-finance-classification', params, response_type: response_type)
|
|
128
|
+
end
|
|
129
|
+
define_method('finance_company') do |**params|
|
|
130
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
131
|
+
request('google-finance-company', params, response_type: response_type)
|
|
132
|
+
end
|
|
133
|
+
define_method('finance_context') do |**params|
|
|
134
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
135
|
+
request('google-finance-context', params, response_type: response_type)
|
|
136
|
+
end
|
|
137
|
+
define_method('finance_financials') do |**params|
|
|
138
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
139
|
+
request('google-finance-financials', params, response_type: response_type)
|
|
140
|
+
end
|
|
141
|
+
define_method('finance_markets_category_news') do |**params|
|
|
142
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
143
|
+
request('google-finance-markets-category-news', params, response_type: response_type)
|
|
144
|
+
end
|
|
145
|
+
define_method('finance_markets_category_stocks') do |**params|
|
|
146
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
147
|
+
request('google-finance-markets-category-stocks', params, response_type: response_type)
|
|
148
|
+
end
|
|
149
|
+
define_method('finance_markets_earnings') do |**params|
|
|
150
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
151
|
+
request('google-finance-markets-earnings', params, response_type: response_type)
|
|
152
|
+
end
|
|
153
|
+
define_method('finance_markets_featured') do |**params|
|
|
154
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
155
|
+
request('google-finance-markets-featured', params, response_type: response_type)
|
|
156
|
+
end
|
|
157
|
+
define_method('finance_markets_headline') do |**params|
|
|
158
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
159
|
+
request('google-finance-markets-headline', params, response_type: response_type)
|
|
160
|
+
end
|
|
161
|
+
define_method('finance_markets_indices') do |**params|
|
|
162
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
163
|
+
request('google-finance-markets-indices', params, response_type: response_type)
|
|
164
|
+
end
|
|
165
|
+
define_method('finance_markets_movers') do |**params|
|
|
166
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
167
|
+
request('google-finance-markets-movers', params, response_type: response_type)
|
|
168
|
+
end
|
|
169
|
+
define_method('finance_markets_top') do |**params|
|
|
170
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
171
|
+
request('google-finance-markets-top', params, response_type: response_type)
|
|
172
|
+
end
|
|
173
|
+
define_method('finance_markets_trending') do |**params|
|
|
174
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
175
|
+
request('google-finance-markets-trending', params, response_type: response_type)
|
|
176
|
+
end
|
|
177
|
+
define_method('finance_news') do |**params|
|
|
178
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
179
|
+
request('google-finance-news', params, response_type: response_type)
|
|
180
|
+
end
|
|
181
|
+
define_method('finance_quote') do |**params|
|
|
182
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
183
|
+
request('google-finance-quote', params, response_type: response_type)
|
|
184
|
+
end
|
|
185
|
+
define_method('finance_related') do |**params|
|
|
186
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
187
|
+
request('google-finance-related', params, response_type: response_type)
|
|
188
|
+
end
|
|
189
|
+
define_method('finance_search') do |**params|
|
|
190
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
191
|
+
request('google-finance-search', params, response_type: response_type)
|
|
192
|
+
end
|
|
193
|
+
define_method('finance_ticker') do |**params|
|
|
194
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
195
|
+
request('google-finance-ticker', params, response_type: response_type)
|
|
196
|
+
end
|
|
197
|
+
define_method('jobs') do |**params|
|
|
198
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
199
|
+
request('google-jobs', params, response_type: response_type)
|
|
200
|
+
end
|
|
201
|
+
define_method('map_place') do |**params|
|
|
202
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
203
|
+
request('google-map-place', params, response_type: response_type)
|
|
204
|
+
end
|
|
205
|
+
define_method('map_place_photos') do |**params|
|
|
206
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
207
|
+
request('google-map-place-photos', params, response_type: response_type)
|
|
208
|
+
end
|
|
209
|
+
define_method('map_place_reviews') do |**params|
|
|
210
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
211
|
+
request('google-map-place-reviews', params, response_type: response_type)
|
|
212
|
+
end
|
|
213
|
+
define_method('map_search') do |**params|
|
|
214
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
215
|
+
request('google-map-search', params, response_type: response_type)
|
|
216
|
+
end
|
|
217
|
+
define_method('news') do |**params|
|
|
218
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
219
|
+
request('google-news', params, response_type: response_type)
|
|
220
|
+
end
|
|
221
|
+
define_method('news_search') do |**params|
|
|
222
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
223
|
+
request('google-news-search', params, response_type: response_type)
|
|
224
|
+
end
|
|
225
|
+
define_method('suggest') do |**params|
|
|
226
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
227
|
+
request('google-suggest', params, response_type: response_type)
|
|
228
|
+
end
|
|
229
|
+
define_method('trends_categories') do |**params|
|
|
230
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
231
|
+
request('google-trends-categories', params, response_type: response_type)
|
|
232
|
+
end
|
|
233
|
+
define_method('trends_enums') do |**params|
|
|
234
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
235
|
+
request('google-trends-enums', params, response_type: response_type)
|
|
236
|
+
end
|
|
237
|
+
define_method('trends_explore') do |**params|
|
|
238
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
239
|
+
request('google-trends-explore', params, response_type: response_type)
|
|
240
|
+
end
|
|
241
|
+
define_method('trends_explore_interest_by_region') do |**params|
|
|
242
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
243
|
+
request('google-trends-explore-interest-by-region', params, response_type: response_type)
|
|
244
|
+
end
|
|
245
|
+
define_method('trends_explore_interest_over_time') do |**params|
|
|
246
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
247
|
+
request('google-trends-explore-interest-over-time', params, response_type: response_type)
|
|
248
|
+
end
|
|
249
|
+
define_method('trends_explore_related_topics') do |**params|
|
|
250
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
251
|
+
request('google-trends-explore-related-topics', params, response_type: response_type)
|
|
252
|
+
end
|
|
253
|
+
define_method('trends_explore_rising_queries') do |**params|
|
|
254
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
255
|
+
request('google-trends-explore-rising-queries', params, response_type: response_type)
|
|
256
|
+
end
|
|
257
|
+
define_method('trends_explore_top_queries') do |**params|
|
|
258
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
259
|
+
request('google-trends-explore-top-queries', params, response_type: response_type)
|
|
260
|
+
end
|
|
261
|
+
define_method('trends_locations') do |**params|
|
|
262
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
263
|
+
request('google-trends-locations', params, response_type: response_type)
|
|
264
|
+
end
|
|
265
|
+
define_method('trends_trending') do |**params|
|
|
266
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
267
|
+
request('google-trends-trending', params, response_type: response_type)
|
|
268
|
+
end
|
|
269
|
+
define_method('trends_trending_detail') do |**params|
|
|
270
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
271
|
+
request('google-trends-trending-detail', params, response_type: response_type)
|
|
272
|
+
end
|
|
273
|
+
define_method('videos') do |**params|
|
|
274
|
+
response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
|
|
275
|
+
request('google-videos', params, response_type: response_type)
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
private
|
|
279
|
+
|
|
280
|
+
# POST operations take their JSON body under the body parameter name or "body".
|
|
281
|
+
def request_body(operation, params)
|
|
282
|
+
name = operation["bodyParam"]
|
|
283
|
+
return nil if name.nil?
|
|
284
|
+
value = params.key?(name) ? params[name] : params["body"]
|
|
285
|
+
if value.nil?
|
|
286
|
+
raise Errors::ClientError.new("missing request body: #{name}", operation_id: operation["id"]) if operation["bodyRequired"]
|
|
287
|
+
return nil
|
|
288
|
+
end
|
|
289
|
+
value.is_a?(String) ? value : JSON.generate(value)
|
|
290
|
+
end
|
|
291
|
+
|
|
292
|
+
def build_url(operation, params)
|
|
293
|
+
known = operation["params"].map { |param| param["name"] }
|
|
294
|
+
known << "body" if operation["bodyParam"]
|
|
295
|
+
unknown = params.keys - known
|
|
296
|
+
raise Errors::ClientError.new("unknown parameters: #{unknown.join(', ')}", operation_id: operation["id"]) unless unknown.empty?
|
|
297
|
+
path = operation["path"].dup
|
|
298
|
+
operation["params"].select { |param| param["in"] == "path" }.each do |param|
|
|
299
|
+
value = params[param["name"]]
|
|
300
|
+
raise Errors::ClientError.new("missing path parameter: #{param['name']}", operation_id: operation["id"]) if value.nil?
|
|
301
|
+
path.sub!("{" + param["name"] + "}", percent_encode(value.to_s))
|
|
302
|
+
end
|
|
303
|
+
pairs = []
|
|
304
|
+
operation["queryParams"].each do |param|
|
|
305
|
+
name = param["name"]
|
|
306
|
+
value = params.key?(name) ? params[name] : param["default"]
|
|
307
|
+
if value.nil?
|
|
308
|
+
raise Errors::ClientError.new("missing query parameter: #{name}", operation_id: operation["id"]) if param["required"]
|
|
309
|
+
next
|
|
310
|
+
end
|
|
311
|
+
enum_values = param["enum"] || (param["items"] && param["items"]["enum"])
|
|
312
|
+
if enum_values && !(value.is_a?(Array) ? value : [value]).all? { |item| enum_values.map(&:to_s).include?(item.to_s) }
|
|
313
|
+
raise Errors::ClientError.new("invalid value for #{name}", operation_id: operation["id"])
|
|
314
|
+
end
|
|
315
|
+
if value.is_a?(Array)
|
|
316
|
+
format = param["collectionFormat"] || "csv"
|
|
317
|
+
if format == "multi"
|
|
318
|
+
value.each { |item| pairs << [name, scalar(item)] }
|
|
319
|
+
else
|
|
320
|
+
separator = {"csv" => ",", "ssv" => " ", "tsv" => "\t", "pipes" => "|"}[format] || ","
|
|
321
|
+
pairs << [name, value.map { |item| scalar(item) }.join(separator)]
|
|
322
|
+
end
|
|
323
|
+
else
|
|
324
|
+
pairs << [name, scalar(value)]
|
|
325
|
+
end
|
|
326
|
+
end
|
|
327
|
+
query = pairs.map { |name, value| "#{percent_encode(name)}=#{percent_encode(value)}" }.join("&")
|
|
328
|
+
@base_url + path + (query.empty? ? "" : "?" + query)
|
|
329
|
+
end
|
|
330
|
+
|
|
331
|
+
def scalar(value)
|
|
332
|
+
value == true ? "true" : (value == false ? "false" : value.to_s)
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
def percent_encode(value)
|
|
336
|
+
URI::DEFAULT_PARSER.escape(value.to_s, /[^A-Za-z0-9\-._~]/)
|
|
337
|
+
end
|
|
338
|
+
|
|
339
|
+
def parse_response(body, content_type, operation, params, response_type)
|
|
340
|
+
type = response_type.to_s
|
|
341
|
+
raise Errors::ClientError.new("response_type must be auto, json, or text", operation_id: operation["id"]) unless %w[auto json text].include?(type)
|
|
342
|
+
format = operation["params"].find { |param| param["name"] == "format" }
|
|
343
|
+
text_formats = format && format["enum"] ? format["enum"].reject { |value| %w[json application/json].include?(value.to_s.downcase) } : []
|
|
344
|
+
raw_format = params["format"] && text_formats.include?(params["format"].to_s)
|
|
345
|
+
json_format = format && format["enum"] && format["enum"].any? { |value| %w[json application/json].include?(value.to_s.downcase) } && %w[json application/json].include?(params["format"].to_s.downcase)
|
|
346
|
+
is_json = json_format || content_type.to_s.downcase.include?("json") || operation["produces"] == ["application/json"]
|
|
347
|
+
return body if type == "text" || raw_format || (type == "auto" && !is_json)
|
|
348
|
+
JSON.parse(body)
|
|
349
|
+
rescue JSON::ParserError => error
|
|
350
|
+
raise Errors::Error.new("invalid JSON response from Crawlora: #{error.message}", operation_id: operation["id"], body: body)
|
|
351
|
+
end
|
|
352
|
+
|
|
353
|
+
public
|
|
354
|
+
end
|
|
355
|
+
end
|
|
356
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: crawlora-google
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Crawlora
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-10-11 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: Credential-free Google API access through Crawlora's hosted service.
|
|
14
|
+
email:
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- CHANGELOG.md
|
|
20
|
+
- LICENSE
|
|
21
|
+
- README.md
|
|
22
|
+
- lib/crawlora/google.rb
|
|
23
|
+
- lib/crawlora/google/client.rb
|
|
24
|
+
- lib/crawlora/google/version.rb
|
|
25
|
+
homepage: https://crawlora.net/?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=google-ruby-homepage
|
|
26
|
+
licenses:
|
|
27
|
+
- MIT
|
|
28
|
+
metadata:
|
|
29
|
+
source_code_uri: https://github.com/Crawlora-org/crawlora-google
|
|
30
|
+
documentation_uri: https://github.com/Crawlora-org/crawlora-google/blob/main/ruby/README.md
|
|
31
|
+
rubygems_mfa_required: 'true'
|
|
32
|
+
post_install_message:
|
|
33
|
+
rdoc_options: []
|
|
34
|
+
require_paths:
|
|
35
|
+
- lib
|
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '2.6'
|
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
42
|
+
requirements:
|
|
43
|
+
- - ">="
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: '0'
|
|
46
|
+
requirements: []
|
|
47
|
+
rubygems_version: 3.4.19
|
|
48
|
+
signing_key:
|
|
49
|
+
specification_version: 4
|
|
50
|
+
summary: Google client for the Crawlora hosted API
|
|
51
|
+
test_files: []
|