yahoo_finance_client 0.1.0 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -0
- data/CHANGELOG.md +17 -1
- data/README.md +6 -1
- data/lib/yahoo_finance_client/stock.rb +20 -4
- data/lib/yahoo_finance_client/version.rb +1 -1
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2e9d16b1b8d40611c624f46e03ad7ca01e98ae8cbf58fe733c4ff72e37ee829
|
4
|
+
data.tar.gz: 1d38747c9ff732268ad4d40121e4cfb058817ecc40df10f78d063949810f0fa4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eaf8f4c30384d727e32c4e3fa4e2e2877f16f157f20791cb7b2012e19fd9bbd77f466ea67a31b6887129b833901274ab756e65353fd677e80ee7f834c11a6fed
|
7
|
+
data.tar.gz: 368918db13051ddfcc9297c956fb019bef8340ba2a3faedebf663a8c0667db26efdda55171cbbf31644297237c7782d5b5ec3707d0723527a934243ec5bf084a
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,20 @@
|
|
1
|
-
|
1
|
+
# Change Log
|
2
|
+
|
3
|
+
## [0.1.4] - 2025-02-18
|
4
|
+
|
5
|
+
- Fix version & Gemfile.lock issues
|
6
|
+
|
7
|
+
## [0.1.3] - 2025-02-18
|
8
|
+
|
9
|
+
- Minor changes on doc
|
10
|
+
|
11
|
+
## [0.1.2] - 2025-02-18
|
12
|
+
|
13
|
+
- Fix dependencies
|
14
|
+
|
15
|
+
## [0.1.1] - 2025-02-18
|
16
|
+
|
17
|
+
- Get cookie & crumb to be able to get Y! data
|
2
18
|
|
3
19
|
## [0.1.0] - 2025-02-18
|
4
20
|
|
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
A basic client to query Yahoo! Finance API.
|
4
4
|
|
5
|
+
Work in process, it might work, or not :)
|
6
|
+
|
5
7
|
It was created to support https://github.com/fleveque/dividend-portfolio pet project.
|
6
8
|
|
7
9
|
## Installation
|
@@ -30,7 +32,10 @@ gem install yahoo_finance_client
|
|
30
32
|
|
31
33
|
## Usage
|
32
34
|
|
33
|
-
|
35
|
+
You should be able to get stock data by calling this method and passing a string with the stock ticker:
|
36
|
+
```ruby
|
37
|
+
YahooFinanceClient::Stock.get_quote("AAPL")
|
38
|
+
```
|
34
39
|
|
35
40
|
## Development
|
36
41
|
|
@@ -7,10 +7,16 @@ module YahooFinanceClient
|
|
7
7
|
# This class provides methods to interact with Yahoo Finance API for stock data.
|
8
8
|
class Stock
|
9
9
|
BASE_URL = "https://query1.finance.yahoo.com/v7/finance/quote"
|
10
|
+
COOKIE_URL = "https://fc.yahoo.com"
|
11
|
+
CRUMB_URL = "https://query1.finance.yahoo.com/v1/test/getcrumb"
|
12
|
+
|
13
|
+
USER_AGENT = "YahooFinanceClient/#{YahooFinanceClient::VERSION}".freeze
|
10
14
|
|
11
15
|
def self.get_quote(symbol)
|
12
|
-
|
13
|
-
|
16
|
+
cookie = fetch_cookie
|
17
|
+
crumb = fetch_crumb(cookie)
|
18
|
+
url = build_url(symbol, crumb)
|
19
|
+
response = HTTParty.get(url, headers: { "User-Agent" => USER_AGENT })
|
14
20
|
|
15
21
|
if response.success?
|
16
22
|
parse_response(response.body, symbol)
|
@@ -19,8 +25,18 @@ module YahooFinanceClient
|
|
19
25
|
end
|
20
26
|
end
|
21
27
|
|
22
|
-
def self.build_url(symbol)
|
23
|
-
"#{BASE_URL}?symbols=#{symbol}"
|
28
|
+
def self.build_url(symbol, crumb)
|
29
|
+
"#{BASE_URL}?symbols=#{symbol}&crumb=#{crumb}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.fetch_cookie
|
33
|
+
response = HTTParty.get(COOKIE_URL, headers: { "User-Agent" => USER_AGENT })
|
34
|
+
response.headers["set-cookie"]
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.fetch_crumb(cookie)
|
38
|
+
response = HTTParty.get(CRUMB_URL, headers: { "User-Agent" => USER_AGENT, "Cookie" => cookie })
|
39
|
+
response.body
|
24
40
|
end
|
25
41
|
|
26
42
|
def self.parse_response(body, symbol)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yahoo_finance_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Francesc Leveque
|
@@ -9,6 +9,20 @@ bindir: exe
|
|
9
9
|
cert_chain: []
|
10
10
|
date: 2025-02-18 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: csv
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ">="
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '0'
|
19
|
+
type: :runtime
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - ">="
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '0'
|
12
26
|
- !ruby/object:Gem::Dependency
|
13
27
|
name: httparty
|
14
28
|
requirement: !ruby/object:Gem::Requirement
|