crawlora-yahoo-finance 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: ac799f275383fa551f6f2bd4cd138408a410d0ca61db40ccbc9d2d47497003ef
4
+ data.tar.gz: 4ca0c46c54890966018d2968353b3f69db9b604d84770f70623fec5ce83cd455
5
+ SHA512:
6
+ metadata.gz: d76f06a2d5128cecb39d8ea8442719510c35f85413a976c4675f2d575a36b56f46c54f9e53f518db21aa95e1c6ff39d88bbdce92b4d95656eff33aff30b53ee1
7
+ data.tar.gz: 298a774f56a206e2ac65921122752a44393c3b63db6f716b609e07e84ca24d0913a71317b5cd069ac3e6c7600f5122f1d375bb5d2a324c9e01bbcace454182ad
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0
4
+
5
+ - Initial focused Yahoo Finance Ruby client for Crawlora's hosted API.
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,79 @@
1
+ # Crawlora Yahoo Finance API client for Ruby (`crawlora-yahoo-finance`)
2
+
3
+ This Ruby gem calls Crawlora's hosted Yahoo Finance API at `https://api.crawlora.net/api/v1`. It exposes 39 endpoints covering quotes, market data, company information, financial statements, calendars, and chart history; it does not call or scrape Yahoo Finance directly. Requests require your Crawlora API key and use your account's service plan.
4
+
5
+ ## Install
6
+
7
+ ```ruby
8
+ gem "crawlora-yahoo-finance"
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=yahoo-finance-ruby-signup), open the [Crawlora console](https://crawlora.net/app?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=yahoo-finance-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/yahoo-finance"
16
+
17
+ client = Crawlora::YahooFinance::Client.new
18
+ result = client.request("yahoo-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 39 API operations.
24
+
25
+ ```ruby
26
+ client = Crawlora::YahooFinance::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
+ ## Supported Yahoo Finance API endpoints
34
+
35
+ Browse every route included in this gem. The [endpoint reference](https://github.com/Crawlora-org/crawlora-yahoo-finance/blob/main/docs/usage.md) includes parameter and response details.
36
+
37
+ | Method | Endpoint | API operation | Description |
38
+ | --- | --- | --- | --- |
39
+ | `GET` | `/yahoo-finance/calendars` | `yahoo-finance-calendars` | Yahoo Finance calendar types |
40
+ | `GET` | `/yahoo-finance/calendars/{type}` | `yahoo-finance-calendar` | Yahoo Finance calendar results |
41
+ | `POST` | `/yahoo-finance/download` | `yahoo-finance-download` | Yahoo Finance batch historical prices |
42
+ | `GET` | `/yahoo-finance/industries` | `yahoo-finance-industries` | Yahoo Finance industries |
43
+ | `GET` | `/yahoo-finance/industries/{key}` | `yahoo-finance-industry` | Yahoo Finance industry detail |
44
+ | `GET` | `/yahoo-finance/lookup` | `yahoo-finance-lookup` | Yahoo Finance lookup |
45
+ | `GET` | `/yahoo-finance/market/{market}/status` | `yahoo-finance-market-status` | Yahoo Finance market status |
46
+ | `GET` | `/yahoo-finance/market/{market}/summary` | `yahoo-finance-market-summary` | Yahoo Finance market summary |
47
+ | `POST` | `/yahoo-finance/screener` | `yahoo-finance-screener-custom` | Yahoo Finance custom screener |
48
+ | `GET` | `/yahoo-finance/screener/{id}` | `yahoo-finance-screener` | Yahoo Finance predefined screener results |
49
+ | `GET` | `/yahoo-finance/screeners` | `yahoo-finance-screeners` | Yahoo Finance predefined screeners |
50
+ | `GET` | `/yahoo-finance/search` | `yahoo-finance-search` | Yahoo Finance search |
51
+ | `GET` | `/yahoo-finance/sectors` | `yahoo-finance-sectors` | Yahoo Finance sectors |
52
+ | `GET` | `/yahoo-finance/sectors/{key}` | `yahoo-finance-sector` | Yahoo Finance sector detail |
53
+ | `GET` | `/yahoo-finance/ticker/{symbol}/actions` | `yahoo-finance-ticker-actions` | Yahoo Finance corporate actions |
54
+ | `GET` | `/yahoo-finance/ticker/{symbol}/analysts` | `yahoo-finance-ticker-analysts` | Yahoo Finance analyst data |
55
+ | `GET` | `/yahoo-finance/ticker/{symbol}/calendar` | `yahoo-finance-ticker-calendar` | Yahoo Finance calendar |
56
+ | `GET` | `/yahoo-finance/ticker/{symbol}/capital-gains` | `yahoo-finance-ticker-capital-gains` | Yahoo Finance capital gains |
57
+ | `GET` | `/yahoo-finance/ticker/{symbol}/dividends` | `yahoo-finance-ticker-dividends` | Yahoo Finance dividends |
58
+ | `GET` | `/yahoo-finance/ticker/{symbol}/earnings` | `yahoo-finance-ticker-earnings` | Yahoo Finance earnings |
59
+ | `GET` | `/yahoo-finance/ticker/{symbol}/earnings-dates` | `yahoo-finance-ticker-earnings-dates` | Yahoo Finance earnings dates |
60
+ | `GET` | `/yahoo-finance/ticker/{symbol}/financials` | `yahoo-finance-ticker-financials` | Yahoo Finance financial statements |
61
+ | `GET` | `/yahoo-finance/ticker/{symbol}/funds` | `yahoo-finance-ticker-funds` | Yahoo Finance fund data |
62
+ | `GET` | `/yahoo-finance/ticker/{symbol}/history` | `yahoo-finance-ticker-history` | Yahoo Finance historical prices |
63
+ | `GET` | `/yahoo-finance/ticker/{symbol}/history-metadata` | `yahoo-finance-ticker-history-metadata` | Yahoo Finance history metadata |
64
+ | `GET` | `/yahoo-finance/ticker/{symbol}/holders` | `yahoo-finance-ticker-holders` | Yahoo Finance holders |
65
+ | `GET` | `/yahoo-finance/ticker/{symbol}/info` | `yahoo-finance-ticker-info` | Yahoo Finance ticker info |
66
+ | `GET` | `/yahoo-finance/ticker/{symbol}/isin` | `yahoo-finance-ticker-isin` | Yahoo Finance ticker ISIN |
67
+ | `GET` | `/yahoo-finance/ticker/{symbol}/news` | `yahoo-finance-ticker-news` | Yahoo Finance ticker news |
68
+ | `GET` | `/yahoo-finance/ticker/{symbol}/options` | `yahoo-finance-ticker-options` | Yahoo Finance options chain |
69
+ | `GET` | `/yahoo-finance/ticker/{symbol}/options/{expiration}` | `yahoo-finance-ticker-options-expiration` | Yahoo Finance options chain by expiration |
70
+ | `GET` | `/yahoo-finance/ticker/{symbol}/quote` | `yahoo-finance-ticker-quote` | Yahoo Finance ticker quote |
71
+ | `GET` | `/yahoo-finance/ticker/{symbol}/sec-filings` | `yahoo-finance-ticker-sec-filings` | Yahoo Finance SEC filings |
72
+ | `GET` | `/yahoo-finance/ticker/{symbol}/shares` | `yahoo-finance-ticker-shares` | Yahoo Finance share counts |
73
+ | `GET` | `/yahoo-finance/ticker/{symbol}/shares-full` | `yahoo-finance-ticker-shares-full` | Yahoo Finance historical share counts |
74
+ | `GET` | `/yahoo-finance/ticker/{symbol}/splits` | `yahoo-finance-ticker-splits` | Yahoo Finance splits |
75
+ | `GET` | `/yahoo-finance/ticker/{symbol}/sustainability` | `yahoo-finance-ticker-sustainability` | Yahoo Finance sustainability |
76
+ | `GET` | `/yahoo-finance/ticker/{symbol}/valuation` | `yahoo-finance-ticker-valuation` | Yahoo Finance valuation measures |
77
+ | `GET` | `/yahoo-finance/trending/{region}` | `yahoo-finance-trending` | Yahoo Finance trending symbols |
78
+
79
+ See [Crawlora](https://crawlora.net/?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=yahoo-finance-ruby-homepage), the [API documentation](https://crawlora.net/docs?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=yahoo-finance-ruby-api-docs), and [the package repository](https://github.com/Crawlora-org/crawlora-yahoo-finance) for account setup, the API operation reference, and release history.
@@ -0,0 +1,352 @@
1
+ require "json"
2
+ require "net/http"
3
+ require "uri"
4
+
5
+ module Crawlora
6
+ module YahooFinance
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
+ {"yahoo-finance-calendar": {"bodyParam": null, "bodyRequired": false, "id": "yahoo-finance-calendar", "method": "GET", "params": [{"description": "Calendar type: earnings, ipo, economic-events, or splits", "enum": ["earnings", "ipo", "economic-events", "splits"], "in": "path", "name": "type", "required": true, "type": "string", "x-example": "earnings"}, {"description": "Start date as YYYY-MM-DD, RFC3339, or Unix seconds", "in": "query", "name": "start", "type": "string"}, {"description": "End date as YYYY-MM-DD, RFC3339, or Unix seconds", "in": "query", "name": "end", "type": "string"}, {"description": "Result count, max 100", "in": "query", "name": "limit", "type": "integer"}, {"description": "Result offset", "in": "query", "name": "offset", "type": "integer"}, {"description": "Earnings-only market cap minimum", "in": "query", "name": "market_cap", "type": "number"}, {"description": "Earnings-only most-active filter, default true", "in": "query", "name": "filter_most_active", "type": "boolean"}], "path": "/yahoo-finance/calendars/{type}", "pathParams": ["type"], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "start", "type": "string"}, {"in": "query", "name": "end", "type": "string"}, {"in": "query", "name": "limit", "type": "integer"}, {"in": "query", "name": "offset", "type": "integer"}, {"in": "query", "name": "market_cap", "type": "number"}, {"in": "query", "name": "filter_most_active", "type": "boolean"}], "security": ["ApiKeyAuth"]}, "yahoo-finance-calendars": {"bodyParam": null, "bodyRequired": false, "id": "yahoo-finance-calendars", "method": "GET", "params": [], "path": "/yahoo-finance/calendars", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "yahoo-finance-download": {"bodyParam": "request", "bodyRequired": true, "id": "yahoo-finance-download", "method": "POST", "params": [{"description": "Batch download request", "in": "body", "name": "request", "required": true, "schema": {"$ref": "#/definitions/yahoofinance.DownloadRequest"}}], "path": "/yahoo-finance/download", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "yahoo-finance-industries": {"bodyParam": null, "bodyRequired": false, "id": "yahoo-finance-industries", "method": "GET", "params": [], "path": "/yahoo-finance/industries", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "yahoo-finance-industry": {"bodyParam": null, "bodyRequired": false, "id": "yahoo-finance-industry", "method": "GET", "params": [{"description": "Industry key such as semiconductors", "in": "path", "name": "key", "required": true, "type": "string", "x-example": "semiconductors"}], "path": "/yahoo-finance/industries/{key}", "pathParams": ["key"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "yahoo-finance-lookup": {"bodyParam": null, "bodyRequired": false, "id": "yahoo-finance-lookup", "method": "GET", "params": [{"description": "Ticker symbol or company name", "in": "query", "name": "query", "required": true, "type": "string", "x-example": "apple"}, {"description": "Instrument type filter", "enum": ["all", "equity", "etf", "mutualfund", "index", "future", "currency", "cryptocurrency"], "in": "query", "name": "type", "type": "string"}, {"description": "Result count", "in": "query", "name": "count", "type": "integer"}, {"description": "Result offset", "in": "query", "name": "start", "type": "integer"}], "path": "/yahoo-finance/lookup", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "query", "required": true, "type": "string"}, {"enum": ["all", "equity", "etf", "mutualfund", "index", "future", "currency", "cryptocurrency"], "in": "query", "name": "type", "type": "string"}, {"in": "query", "name": "count", "type": "integer"}, {"in": "query", "name": "start", "type": "integer"}], "security": ["ApiKeyAuth"]}, "yahoo-finance-market-status": {"bodyParam": null, "bodyRequired": false, "id": "yahoo-finance-market-status", "method": "GET", "params": [{"description": "Market such as US", "in": "path", "name": "market", "required": true, "type": "string", "x-example": "US"}], "path": "/yahoo-finance/market/{market}/status", "pathParams": ["market"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "yahoo-finance-market-summary": {"bodyParam": null, "bodyRequired": false, "id": "yahoo-finance-market-summary", "method": "GET", "params": [{"description": "Market such as US", "in": "path", "name": "market", "required": true, "type": "string", "x-example": "US"}], "path": "/yahoo-finance/market/{market}/summary", "pathParams": ["market"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "yahoo-finance-screener": {"bodyParam": null, "bodyRequired": false, "id": "yahoo-finance-screener", "method": "GET", "params": [{"description": "Predefined screener id", "in": "path", "name": "id", "required": true, "type": "string", "x-example": "day_gainers"}, {"description": "Result count", "in": "query", "name": "count", "type": "integer"}, {"description": "Result offset", "in": "query", "name": "offset", "type": "integer"}, {"description": "Sort field for offset/customized runs", "in": "query", "name": "sort_field", "type": "string"}, {"description": "Sort ascending", "in": "query", "name": "sort_asc", "type": "boolean"}], "path": "/yahoo-finance/screener/{id}", "pathParams": ["id"], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "count", "type": "integer"}, {"in": "query", "name": "offset", "type": "integer"}, {"in": "query", "name": "sort_field", "type": "string"}, {"in": "query", "name": "sort_asc", "type": "boolean"}], "security": ["ApiKeyAuth"]}, "yahoo-finance-screener-custom": {"bodyParam": "request", "bodyRequired": true, "id": "yahoo-finance-screener-custom", "method": "POST", "params": [{"description": "JSON body for a custom screen. The query field is required; quote_type, count, offset, sort_field, and sort_asc are optional.", "in": "body", "name": "request", "required": true, "schema": {"$ref": "#/definitions/yahoofinance.ScreenerRequest"}}], "path": "/yahoo-finance/screener", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "yahoo-finance-screeners": {"bodyParam": null, "bodyRequired": false, "id": "yahoo-finance-screeners", "method": "GET", "params": [], "path": "/yahoo-finance/screeners", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "yahoo-finance-search": {"bodyParam": null, "bodyRequired": false, "id": "yahoo-finance-search", "method": "GET", "params": [{"description": "Ticker symbol or company name", "in": "query", "name": "q", "required": true, "type": "string", "x-example": "apple"}, {"description": "Quote result count", "in": "query", "name": "quotes_count", "type": "integer"}, {"description": "News result count", "in": "query", "name": "news_count", "type": "integer"}, {"description": "List result count", "in": "query", "name": "lists_count", "type": "integer"}, {"description": "Include research reports when Yahoo returns them", "in": "query", "name": "include_research", "type": "boolean"}, {"description": "Enable fuzzy matching", "in": "query", "name": "enable_fuzzy_query", "type": "boolean"}], "path": "/yahoo-finance/search", "pathParams": [], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "q", "required": true, "type": "string"}, {"in": "query", "name": "quotes_count", "type": "integer"}, {"in": "query", "name": "news_count", "type": "integer"}, {"in": "query", "name": "lists_count", "type": "integer"}, {"in": "query", "name": "include_research", "type": "boolean"}, {"in": "query", "name": "enable_fuzzy_query", "type": "boolean"}], "security": ["ApiKeyAuth"]}, "yahoo-finance-sector": {"bodyParam": null, "bodyRequired": false, "id": "yahoo-finance-sector", "method": "GET", "params": [{"description": "Sector key such as technology", "in": "path", "name": "key", "required": true, "type": "string", "x-example": "technology"}], "path": "/yahoo-finance/sectors/{key}", "pathParams": ["key"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "yahoo-finance-sectors": {"bodyParam": null, "bodyRequired": false, "id": "yahoo-finance-sectors", "method": "GET", "params": [], "path": "/yahoo-finance/sectors", "pathParams": [], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "yahoo-finance-ticker-actions": {"bodyParam": null, "bodyRequired": false, "id": "yahoo-finance-ticker-actions", "method": "GET", "params": [{"description": "Yahoo Finance symbol such as AAPL", "in": "path", "name": "symbol", "required": true, "type": "string", "x-example": "AAPL"}], "path": "/yahoo-finance/ticker/{symbol}/actions", "pathParams": ["symbol"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "yahoo-finance-ticker-analysts": {"bodyParam": null, "bodyRequired": false, "id": "yahoo-finance-ticker-analysts", "method": "GET", "params": [{"description": "Yahoo Finance symbol such as AAPL", "in": "path", "name": "symbol", "required": true, "type": "string", "x-example": "AAPL"}], "path": "/yahoo-finance/ticker/{symbol}/analysts", "pathParams": ["symbol"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "yahoo-finance-ticker-calendar": {"bodyParam": null, "bodyRequired": false, "id": "yahoo-finance-ticker-calendar", "method": "GET", "params": [{"description": "Yahoo Finance symbol such as AAPL", "in": "path", "name": "symbol", "required": true, "type": "string", "x-example": "AAPL"}], "path": "/yahoo-finance/ticker/{symbol}/calendar", "pathParams": ["symbol"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "yahoo-finance-ticker-capital-gains": {"bodyParam": null, "bodyRequired": false, "id": "yahoo-finance-ticker-capital-gains", "method": "GET", "params": [{"description": "Yahoo Finance symbol such as SPY", "in": "path", "name": "symbol", "required": true, "type": "string", "x-example": "SPY"}], "path": "/yahoo-finance/ticker/{symbol}/capital-gains", "pathParams": ["symbol"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "yahoo-finance-ticker-dividends": {"bodyParam": null, "bodyRequired": false, "id": "yahoo-finance-ticker-dividends", "method": "GET", "params": [{"description": "Yahoo Finance symbol such as AAPL", "in": "path", "name": "symbol", "required": true, "type": "string", "x-example": "AAPL"}], "path": "/yahoo-finance/ticker/{symbol}/dividends", "pathParams": ["symbol"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "yahoo-finance-ticker-earnings": {"bodyParam": null, "bodyRequired": false, "id": "yahoo-finance-ticker-earnings", "method": "GET", "params": [{"description": "Yahoo Finance symbol such as AAPL", "in": "path", "name": "symbol", "required": true, "type": "string", "x-example": "AAPL"}], "path": "/yahoo-finance/ticker/{symbol}/earnings", "pathParams": ["symbol"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "yahoo-finance-ticker-earnings-dates": {"bodyParam": null, "bodyRequired": false, "id": "yahoo-finance-ticker-earnings-dates", "method": "GET", "params": [{"description": "Yahoo Finance symbol such as AAPL", "in": "path", "name": "symbol", "required": true, "type": "string", "x-example": "AAPL"}, {"description": "Result count, max 100", "in": "query", "name": "limit", "type": "integer"}, {"description": "Result offset", "in": "query", "name": "offset", "type": "integer"}], "path": "/yahoo-finance/ticker/{symbol}/earnings-dates", "pathParams": ["symbol"], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "limit", "type": "integer"}, {"in": "query", "name": "offset", "type": "integer"}], "security": ["ApiKeyAuth"]}, "yahoo-finance-ticker-financials": {"bodyParam": null, "bodyRequired": false, "id": "yahoo-finance-ticker-financials", "method": "GET", "params": [{"description": "Yahoo Finance symbol such as AAPL", "in": "path", "name": "symbol", "required": true, "type": "string", "x-example": "AAPL"}, {"description": "Statement type. Allowed values: income (alias income-statement), balance-sheet (alias balance), cash-flow (alias cashflow)", "enum": ["income", "income-statement", "balance-sheet", "balance", "cash-flow", "cashflow"], "in": "query", "name": "statement", "type": "string"}, {"description": "annual, quarterly, or trailing", "enum": ["annual", "quarterly", "trailing"], "in": "query", "name": "period", "type": "string"}], "path": "/yahoo-finance/ticker/{symbol}/financials", "pathParams": ["symbol"], "produces": ["application/json"], "queryParams": [{"enum": ["income", "income-statement", "balance-sheet", "balance", "cash-flow", "cashflow"], "in": "query", "name": "statement", "type": "string"}, {"enum": ["annual", "quarterly", "trailing"], "in": "query", "name": "period", "type": "string"}], "security": ["ApiKeyAuth"]}, "yahoo-finance-ticker-funds": {"bodyParam": null, "bodyRequired": false, "id": "yahoo-finance-ticker-funds", "method": "GET", "params": [{"description": "Yahoo Finance symbol such as SPY", "in": "path", "name": "symbol", "required": true, "type": "string", "x-example": "SPY"}], "path": "/yahoo-finance/ticker/{symbol}/funds", "pathParams": ["symbol"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "yahoo-finance-ticker-history": {"bodyParam": null, "bodyRequired": false, "id": "yahoo-finance-ticker-history", "method": "GET", "params": [{"description": "Yahoo Finance symbol such as AAPL", "in": "path", "name": "symbol", "required": true, "type": "string", "x-example": "AAPL"}, {"description": "Range such as 1d, 1mo, 1y, max", "in": "query", "name": "period", "type": "string"}, {"description": "Unix seconds, RFC3339, or YYYY-MM-DD", "in": "query", "name": "start", "type": "string"}, {"description": "Unix seconds, RFC3339, or YYYY-MM-DD", "in": "query", "name": "end", "type": "string"}, {"description": "Interval such as 1d, 1h, 5m", "in": "query", "name": "interval", "type": "string"}, {"description": "Include pre/post market data", "in": "query", "name": "include_prepost", "type": "boolean"}, {"description": "Include dividends, splits, and capital gains", "in": "query", "name": "include_actions", "type": "boolean"}, {"description": "Adjust OHLC prices with adjusted close", "in": "query", "name": "auto_adjust", "type": "boolean"}, {"description": "Back-adjust OHLC prices while keeping close", "in": "query", "name": "back_adjust", "type": "boolean"}, {"description": "Keep fully empty chart rows", "in": "query", "name": "keepna", "type": "boolean"}, {"description": "Round prices to two decimals", "in": "query", "name": "rounding", "type": "boolean"}], "path": "/yahoo-finance/ticker/{symbol}/history", "pathParams": ["symbol"], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "period", "type": "string"}, {"in": "query", "name": "start", "type": "string"}, {"in": "query", "name": "end", "type": "string"}, {"in": "query", "name": "interval", "type": "string"}, {"in": "query", "name": "include_prepost", "type": "boolean"}, {"in": "query", "name": "include_actions", "type": "boolean"}, {"in": "query", "name": "auto_adjust", "type": "boolean"}, {"in": "query", "name": "back_adjust", "type": "boolean"}, {"in": "query", "name": "keepna", "type": "boolean"}, {"in": "query", "name": "rounding", "type": "boolean"}], "security": ["ApiKeyAuth"]}, "yahoo-finance-ticker-history-metadata": {"bodyParam": null, "bodyRequired": false, "id": "yahoo-finance-ticker-history-metadata", "method": "GET", "params": [{"description": "Yahoo Finance symbol such as AAPL", "in": "path", "name": "symbol", "required": true, "type": "string", "x-example": "AAPL"}], "path": "/yahoo-finance/ticker/{symbol}/history-metadata", "pathParams": ["symbol"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "yahoo-finance-ticker-holders": {"bodyParam": null, "bodyRequired": false, "id": "yahoo-finance-ticker-holders", "method": "GET", "params": [{"description": "Yahoo Finance symbol such as AAPL", "in": "path", "name": "symbol", "required": true, "type": "string", "x-example": "AAPL"}], "path": "/yahoo-finance/ticker/{symbol}/holders", "pathParams": ["symbol"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "yahoo-finance-ticker-info": {"bodyParam": null, "bodyRequired": false, "id": "yahoo-finance-ticker-info", "method": "GET", "params": [{"description": "Yahoo Finance symbol such as AAPL", "in": "path", "name": "symbol", "required": true, "type": "string", "x-example": "AAPL"}], "path": "/yahoo-finance/ticker/{symbol}/info", "pathParams": ["symbol"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "yahoo-finance-ticker-isin": {"bodyParam": null, "bodyRequired": false, "id": "yahoo-finance-ticker-isin", "method": "GET", "params": [{"description": "Yahoo Finance symbol such as AAPL", "in": "path", "name": "symbol", "required": true, "type": "string", "x-example": "AAPL"}], "path": "/yahoo-finance/ticker/{symbol}/isin", "pathParams": ["symbol"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "yahoo-finance-ticker-news": {"bodyParam": null, "bodyRequired": false, "id": "yahoo-finance-ticker-news", "method": "GET", "params": [{"description": "Yahoo Finance symbol such as AAPL", "in": "path", "name": "symbol", "required": true, "type": "string", "x-example": "AAPL"}, {"description": "News result count", "in": "query", "name": "count", "type": "integer"}, {"description": "News tab: news, all, or press_releases", "in": "query", "name": "tab", "type": "string"}], "path": "/yahoo-finance/ticker/{symbol}/news", "pathParams": ["symbol"], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "count", "type": "integer"}, {"in": "query", "name": "tab", "type": "string"}], "security": ["ApiKeyAuth"]}, "yahoo-finance-ticker-options": {"bodyParam": null, "bodyRequired": false, "id": "yahoo-finance-ticker-options", "method": "GET", "params": [{"description": "Yahoo Finance symbol such as AAPL", "in": "path", "name": "symbol", "required": true, "type": "string", "x-example": "AAPL"}], "path": "/yahoo-finance/ticker/{symbol}/options", "pathParams": ["symbol"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "yahoo-finance-ticker-options-expiration": {"bodyParam": null, "bodyRequired": false, "id": "yahoo-finance-ticker-options-expiration", "method": "GET", "params": [{"description": "Yahoo Finance symbol such as AAPL", "in": "path", "name": "symbol", "required": true, "type": "string", "x-example": "AAPL"}, {"description": "Unix expiration timestamp", "in": "path", "name": "expiration", "required": true, "type": "string", "x-example": "1863475200"}], "path": "/yahoo-finance/ticker/{symbol}/options/{expiration}", "pathParams": ["symbol", "expiration"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "yahoo-finance-ticker-quote": {"bodyParam": null, "bodyRequired": false, "id": "yahoo-finance-ticker-quote", "method": "GET", "params": [{"description": "Yahoo Finance symbol such as AAPL", "in": "path", "name": "symbol", "required": true, "type": "string", "x-example": "AAPL"}], "path": "/yahoo-finance/ticker/{symbol}/quote", "pathParams": ["symbol"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "yahoo-finance-ticker-sec-filings": {"bodyParam": null, "bodyRequired": false, "id": "yahoo-finance-ticker-sec-filings", "method": "GET", "params": [{"description": "Yahoo Finance symbol such as AAPL", "in": "path", "name": "symbol", "required": true, "type": "string", "x-example": "AAPL"}], "path": "/yahoo-finance/ticker/{symbol}/sec-filings", "pathParams": ["symbol"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "yahoo-finance-ticker-shares": {"bodyParam": null, "bodyRequired": false, "id": "yahoo-finance-ticker-shares", "method": "GET", "params": [{"description": "Yahoo Finance symbol such as AAPL", "in": "path", "name": "symbol", "required": true, "type": "string", "x-example": "AAPL"}], "path": "/yahoo-finance/ticker/{symbol}/shares", "pathParams": ["symbol"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "yahoo-finance-ticker-shares-full": {"bodyParam": null, "bodyRequired": false, "id": "yahoo-finance-ticker-shares-full", "method": "GET", "params": [{"description": "Yahoo Finance symbol such as AAPL", "in": "path", "name": "symbol", "required": true, "type": "string", "x-example": "AAPL"}, {"description": "Start date as YYYY-MM-DD, RFC3339, or Unix seconds", "in": "query", "name": "start", "type": "string"}, {"description": "End date as YYYY-MM-DD, RFC3339, or Unix seconds", "in": "query", "name": "end", "type": "string"}], "path": "/yahoo-finance/ticker/{symbol}/shares-full", "pathParams": ["symbol"], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "start", "type": "string"}, {"in": "query", "name": "end", "type": "string"}], "security": ["ApiKeyAuth"]}, "yahoo-finance-ticker-splits": {"bodyParam": null, "bodyRequired": false, "id": "yahoo-finance-ticker-splits", "method": "GET", "params": [{"description": "Yahoo Finance symbol such as AAPL", "in": "path", "name": "symbol", "required": true, "type": "string", "x-example": "AAPL"}], "path": "/yahoo-finance/ticker/{symbol}/splits", "pathParams": ["symbol"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "yahoo-finance-ticker-sustainability": {"bodyParam": null, "bodyRequired": false, "id": "yahoo-finance-ticker-sustainability", "method": "GET", "params": [{"description": "Yahoo Finance symbol such as AAPL", "in": "path", "name": "symbol", "required": true, "type": "string", "x-example": "AAPL"}], "path": "/yahoo-finance/ticker/{symbol}/sustainability", "pathParams": ["symbol"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "yahoo-finance-ticker-valuation": {"bodyParam": null, "bodyRequired": false, "id": "yahoo-finance-ticker-valuation", "method": "GET", "params": [{"description": "Yahoo Finance symbol such as AAPL", "in": "path", "name": "symbol", "required": true, "type": "string", "x-example": "AAPL"}], "path": "/yahoo-finance/ticker/{symbol}/valuation", "pathParams": ["symbol"], "produces": ["application/json"], "queryParams": [], "security": ["ApiKeyAuth"]}, "yahoo-finance-trending": {"bodyParam": null, "bodyRequired": false, "id": "yahoo-finance-trending", "method": "GET", "params": [{"description": "Region such as US", "in": "path", "name": "region", "required": true, "type": "string", "x-example": "US"}, {"description": "Symbol count", "in": "query", "name": "count", "type": "integer"}], "path": "/yahoo-finance/trending/{region}", "pathParams": ["region"], "produces": ["application/json"], "queryParams": [{"in": "query", "name": "count", "type": "integer"}], "security": ["ApiKeyAuth"]}}
23
+ JSON
24
+ OPERATION_IDS = JSON.parse(<<~'JSON').freeze
25
+ ["yahoo-finance-calendar", "yahoo-finance-calendars", "yahoo-finance-download", "yahoo-finance-industries", "yahoo-finance-industry", "yahoo-finance-lookup", "yahoo-finance-market-status", "yahoo-finance-market-summary", "yahoo-finance-screener", "yahoo-finance-screener-custom", "yahoo-finance-screeners", "yahoo-finance-search", "yahoo-finance-sector", "yahoo-finance-sectors", "yahoo-finance-ticker-actions", "yahoo-finance-ticker-analysts", "yahoo-finance-ticker-calendar", "yahoo-finance-ticker-capital-gains", "yahoo-finance-ticker-dividends", "yahoo-finance-ticker-earnings", "yahoo-finance-ticker-earnings-dates", "yahoo-finance-ticker-financials", "yahoo-finance-ticker-funds", "yahoo-finance-ticker-history", "yahoo-finance-ticker-history-metadata", "yahoo-finance-ticker-holders", "yahoo-finance-ticker-info", "yahoo-finance-ticker-isin", "yahoo-finance-ticker-news", "yahoo-finance-ticker-options", "yahoo-finance-ticker-options-expiration", "yahoo-finance-ticker-quote", "yahoo-finance-ticker-sec-filings", "yahoo-finance-ticker-shares", "yahoo-finance-ticker-shares-full", "yahoo-finance-ticker-splits", "yahoo-finance-ticker-sustainability", "yahoo-finance-ticker-valuation", "yahoo-finance-trending"]
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-yahoo-finance-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('calendars') do |**params|
118
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
119
+ request('yahoo-finance-calendars', params, response_type: response_type)
120
+ end
121
+ define_method('calendar') do |**params|
122
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
123
+ request('yahoo-finance-calendar', params, response_type: response_type)
124
+ end
125
+ define_method('download') do |**params|
126
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
127
+ request('yahoo-finance-download', params, response_type: response_type)
128
+ end
129
+ define_method('industries') do |**params|
130
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
131
+ request('yahoo-finance-industries', params, response_type: response_type)
132
+ end
133
+ define_method('industry') do |**params|
134
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
135
+ request('yahoo-finance-industry', params, response_type: response_type)
136
+ end
137
+ define_method('lookup') do |**params|
138
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
139
+ request('yahoo-finance-lookup', params, response_type: response_type)
140
+ end
141
+ define_method('market_status') do |**params|
142
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
143
+ request('yahoo-finance-market-status', params, response_type: response_type)
144
+ end
145
+ define_method('market_summary') do |**params|
146
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
147
+ request('yahoo-finance-market-summary', params, response_type: response_type)
148
+ end
149
+ define_method('screener_custom') do |**params|
150
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
151
+ request('yahoo-finance-screener-custom', params, response_type: response_type)
152
+ end
153
+ define_method('screener') do |**params|
154
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
155
+ request('yahoo-finance-screener', params, response_type: response_type)
156
+ end
157
+ define_method('screeners') do |**params|
158
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
159
+ request('yahoo-finance-screeners', params, response_type: response_type)
160
+ end
161
+ define_method('search') do |**params|
162
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
163
+ request('yahoo-finance-search', params, response_type: response_type)
164
+ end
165
+ define_method('sectors') do |**params|
166
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
167
+ request('yahoo-finance-sectors', params, response_type: response_type)
168
+ end
169
+ define_method('sector') do |**params|
170
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
171
+ request('yahoo-finance-sector', params, response_type: response_type)
172
+ end
173
+ define_method('ticker_actions') do |**params|
174
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
175
+ request('yahoo-finance-ticker-actions', params, response_type: response_type)
176
+ end
177
+ define_method('ticker_analysts') do |**params|
178
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
179
+ request('yahoo-finance-ticker-analysts', params, response_type: response_type)
180
+ end
181
+ define_method('ticker_calendar') do |**params|
182
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
183
+ request('yahoo-finance-ticker-calendar', params, response_type: response_type)
184
+ end
185
+ define_method('ticker_capital_gains') do |**params|
186
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
187
+ request('yahoo-finance-ticker-capital-gains', params, response_type: response_type)
188
+ end
189
+ define_method('ticker_dividends') do |**params|
190
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
191
+ request('yahoo-finance-ticker-dividends', params, response_type: response_type)
192
+ end
193
+ define_method('ticker_earnings') do |**params|
194
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
195
+ request('yahoo-finance-ticker-earnings', params, response_type: response_type)
196
+ end
197
+ define_method('ticker_earnings_dates') do |**params|
198
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
199
+ request('yahoo-finance-ticker-earnings-dates', params, response_type: response_type)
200
+ end
201
+ define_method('ticker_financials') do |**params|
202
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
203
+ request('yahoo-finance-ticker-financials', params, response_type: response_type)
204
+ end
205
+ define_method('ticker_funds') do |**params|
206
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
207
+ request('yahoo-finance-ticker-funds', params, response_type: response_type)
208
+ end
209
+ define_method('ticker_history') do |**params|
210
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
211
+ request('yahoo-finance-ticker-history', params, response_type: response_type)
212
+ end
213
+ define_method('ticker_history_metadata') do |**params|
214
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
215
+ request('yahoo-finance-ticker-history-metadata', params, response_type: response_type)
216
+ end
217
+ define_method('ticker_holders') do |**params|
218
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
219
+ request('yahoo-finance-ticker-holders', params, response_type: response_type)
220
+ end
221
+ define_method('ticker_info') do |**params|
222
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
223
+ request('yahoo-finance-ticker-info', params, response_type: response_type)
224
+ end
225
+ define_method('ticker_isin') do |**params|
226
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
227
+ request('yahoo-finance-ticker-isin', params, response_type: response_type)
228
+ end
229
+ define_method('ticker_news') do |**params|
230
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
231
+ request('yahoo-finance-ticker-news', params, response_type: response_type)
232
+ end
233
+ define_method('ticker_options') do |**params|
234
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
235
+ request('yahoo-finance-ticker-options', params, response_type: response_type)
236
+ end
237
+ define_method('ticker_options_expiration') do |**params|
238
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
239
+ request('yahoo-finance-ticker-options-expiration', params, response_type: response_type)
240
+ end
241
+ define_method('ticker_quote') do |**params|
242
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
243
+ request('yahoo-finance-ticker-quote', params, response_type: response_type)
244
+ end
245
+ define_method('ticker_sec_filings') do |**params|
246
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
247
+ request('yahoo-finance-ticker-sec-filings', params, response_type: response_type)
248
+ end
249
+ define_method('ticker_shares') do |**params|
250
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
251
+ request('yahoo-finance-ticker-shares', params, response_type: response_type)
252
+ end
253
+ define_method('ticker_shares_full') do |**params|
254
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
255
+ request('yahoo-finance-ticker-shares-full', params, response_type: response_type)
256
+ end
257
+ define_method('ticker_splits') do |**params|
258
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
259
+ request('yahoo-finance-ticker-splits', params, response_type: response_type)
260
+ end
261
+ define_method('ticker_sustainability') do |**params|
262
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
263
+ request('yahoo-finance-ticker-sustainability', params, response_type: response_type)
264
+ end
265
+ define_method('ticker_valuation') do |**params|
266
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
267
+ request('yahoo-finance-ticker-valuation', params, response_type: response_type)
268
+ end
269
+ define_method('trending') do |**params|
270
+ response_type = params.delete(:response_type) || params.delete(:_response_type) || :auto
271
+ request('yahoo-finance-trending', params, response_type: response_type)
272
+ end
273
+
274
+ private
275
+
276
+ # POST operations take their JSON body under the body parameter name or "body".
277
+ def request_body(operation, params)
278
+ name = operation["bodyParam"]
279
+ return nil if name.nil?
280
+ value = params.key?(name) ? params[name] : params["body"]
281
+ if value.nil?
282
+ raise Errors::ClientError.new("missing request body: #{name}", operation_id: operation["id"]) if operation["bodyRequired"]
283
+ return nil
284
+ end
285
+ value.is_a?(String) ? value : JSON.generate(value)
286
+ end
287
+
288
+ def build_url(operation, params)
289
+ known = operation["params"].map { |param| param["name"] }
290
+ known << "body" if operation["bodyParam"]
291
+ unknown = params.keys - known
292
+ raise Errors::ClientError.new("unknown parameters: #{unknown.join(', ')}", operation_id: operation["id"]) unless unknown.empty?
293
+ path = operation["path"].dup
294
+ operation["params"].select { |param| param["in"] == "path" }.each do |param|
295
+ value = params[param["name"]]
296
+ raise Errors::ClientError.new("missing path parameter: #{param['name']}", operation_id: operation["id"]) if value.nil?
297
+ path.sub!("{" + param["name"] + "}", percent_encode(value.to_s))
298
+ end
299
+ pairs = []
300
+ operation["queryParams"].each do |param|
301
+ name = param["name"]
302
+ value = params.key?(name) ? params[name] : param["default"]
303
+ if value.nil?
304
+ raise Errors::ClientError.new("missing query parameter: #{name}", operation_id: operation["id"]) if param["required"]
305
+ next
306
+ end
307
+ enum_values = param["enum"] || (param["items"] && param["items"]["enum"])
308
+ if enum_values && !(value.is_a?(Array) ? value : [value]).all? { |item| enum_values.map(&:to_s).include?(item.to_s) }
309
+ raise Errors::ClientError.new("invalid value for #{name}", operation_id: operation["id"])
310
+ end
311
+ if value.is_a?(Array)
312
+ format = param["collectionFormat"] || "csv"
313
+ if format == "multi"
314
+ value.each { |item| pairs << [name, scalar(item)] }
315
+ else
316
+ separator = {"csv" => ",", "ssv" => " ", "tsv" => "\t", "pipes" => "|"}[format] || ","
317
+ pairs << [name, value.map { |item| scalar(item) }.join(separator)]
318
+ end
319
+ else
320
+ pairs << [name, scalar(value)]
321
+ end
322
+ end
323
+ query = pairs.map { |name, value| "#{percent_encode(name)}=#{percent_encode(value)}" }.join("&")
324
+ @base_url + path + (query.empty? ? "" : "?" + query)
325
+ end
326
+
327
+ def scalar(value)
328
+ value == true ? "true" : (value == false ? "false" : value.to_s)
329
+ end
330
+
331
+ def percent_encode(value)
332
+ URI::DEFAULT_PARSER.escape(value.to_s, /[^A-Za-z0-9\-._~]/)
333
+ end
334
+
335
+ def parse_response(body, content_type, operation, params, response_type)
336
+ type = response_type.to_s
337
+ raise Errors::ClientError.new("response_type must be auto, json, or text", operation_id: operation["id"]) unless %w[auto json text].include?(type)
338
+ format = operation["params"].find { |param| param["name"] == "format" }
339
+ text_formats = format && format["enum"] ? format["enum"].reject { |value| %w[json application/json].include?(value.to_s.downcase) } : []
340
+ raw_format = params["format"] && text_formats.include?(params["format"].to_s)
341
+ 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)
342
+ is_json = json_format || content_type.to_s.downcase.include?("json") || operation["produces"] == ["application/json"]
343
+ return body if type == "text" || raw_format || (type == "auto" && !is_json)
344
+ JSON.parse(body)
345
+ rescue JSON::ParserError => error
346
+ raise Errors::Error.new("invalid JSON response from Crawlora: #{error.message}", operation_id: operation["id"], body: body)
347
+ end
348
+
349
+ public
350
+ end
351
+ end
352
+ end
@@ -0,0 +1,5 @@
1
+ module Crawlora
2
+ module YahooFinance
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require_relative "yahoo-finance/version"
2
+ require_relative "yahoo-finance/client"
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: crawlora-yahoo-finance
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-11-29 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Ruby client for Crawlora's hosted Yahoo Finance API. Covers quotes, market
14
+ data, company information, financial statements, calendars, and chart history across
15
+ 39 endpoints.
16
+ email:
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - CHANGELOG.md
22
+ - LICENSE
23
+ - README.md
24
+ - lib/crawlora/yahoo-finance.rb
25
+ - lib/crawlora/yahoo-finance/client.rb
26
+ - lib/crawlora/yahoo-finance/version.rb
27
+ homepage: https://crawlora.net/?utm_source=rubygems&utm_medium=referral&utm_campaign=platform-clients&utm_content=yahoo-finance-ruby-homepage
28
+ licenses:
29
+ - MIT
30
+ metadata:
31
+ source_code_uri: https://github.com/Crawlora-org/crawlora-yahoo-finance
32
+ documentation_uri: https://github.com/Crawlora-org/crawlora-yahoo-finance/blob/main/ruby/README.md
33
+ rubygems_mfa_required: 'true'
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '2.6'
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirements: []
49
+ rubygems_version: 3.4.19
50
+ signing_key:
51
+ specification_version: 4
52
+ summary: Yahoo Finance API client for Crawlora (39 endpoints)
53
+ test_files: []