google-finance-ruby-client 0.1.0 → 0.2.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 +4 -4
- data/.rubocop_todo.yml +47 -13
- data/CHANGELOG.md +4 -0
- data/README.md +52 -2
- data/lib/google-finance-ruby-client.rb +3 -1
- data/lib/google-finance/api.rb +2 -0
- data/lib/google-finance/api/get_prices.rb +46 -0
- data/lib/google-finance/api/index.rb +26 -0
- data/lib/google-finance/price.rb +13 -0
- data/lib/google-finance/prices.rb +97 -0
- data/lib/google-finance/quote.rb +1 -1
- data/lib/google-finance/quotes.rb +1 -1
- data/lib/google-finance/version.rb +1 -1
- data/spec/fixtures/google-finance/get_prices_goog_with_few_fields.yml +82 -0
- data/spec/fixtures/google-finance/get_prices_goog_with_options.yml +1818 -0
- data/spec/fixtures/google-finance/get_prices_invalid.yml +60 -0
- data/spec/fixtures/google-finance/get_prices_msft.yml +82 -0
- data/spec/google-finance/prices_spec.rb +87 -0
- metadata +17 -3
- data/lib/google-finance/resources.rb +0 -28
@@ -0,0 +1,60 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://finance.google.com/finance/getprices?q=INVALID
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.13.1
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
14
|
+
Accept:
|
15
|
+
- "*/*"
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Content-Type:
|
22
|
+
- text/plain; charset=ISO-8859-1
|
23
|
+
Cache-Control:
|
24
|
+
- private,max-age=60
|
25
|
+
Vary:
|
26
|
+
- Accept-Encoding
|
27
|
+
X-Content-Type-Options:
|
28
|
+
- nosniff
|
29
|
+
P3p:
|
30
|
+
- CP="This is not a P3P policy! See g.co/p3phelp for more info."
|
31
|
+
Date:
|
32
|
+
- Thu, 28 Dec 2017 19:06:05 GMT
|
33
|
+
X-Frame-Options:
|
34
|
+
- SAMEORIGIN
|
35
|
+
X-Xss-Protection:
|
36
|
+
- 1; mode=block
|
37
|
+
Server:
|
38
|
+
- GSE
|
39
|
+
Set-Cookie:
|
40
|
+
- NID=120=NQ2JSPX88dHGwyNpeclQrvh65rb71_CXKqoa-gwNVXleRJ-vorthDIB9vFZR0Xe1pd6HnVKDKY2dTl4xD49VJnC4zue3JOTiA4jPUp8FEMwXrseIigk0qrbg2EbGzEiZ;Domain=.google.com;Path=/;Expires=Fri,
|
41
|
+
29-Jun-2018 19:06:05 GMT;HttpOnly
|
42
|
+
Alt-Svc:
|
43
|
+
- hq=":443"; ma=2592000; quic=51303431; quic=51303339; quic=51303338; quic=51303337;
|
44
|
+
quic=51303335,quic=":443"; ma=2592000; v="41,39,38,37,35"
|
45
|
+
Expires:
|
46
|
+
- Thu, 28 Dec 2017 19:06:05 GMT
|
47
|
+
Transfer-Encoding:
|
48
|
+
- chunked
|
49
|
+
body:
|
50
|
+
encoding: ASCII-8BIT
|
51
|
+
string: |
|
52
|
+
EXCHANGE%3DUNKNOWN+EXCHANGE
|
53
|
+
MARKET_OPEN_MINUTE=570
|
54
|
+
MARKET_CLOSE_MINUTE=960
|
55
|
+
INTERVAL=86400
|
56
|
+
COLUMNS=DATE,CLOSE,HIGH,LOW,OPEN,VOLUME
|
57
|
+
DATA=
|
58
|
+
http_version:
|
59
|
+
recorded_at: Thu, 28 Dec 2017 19:06:05 GMT
|
60
|
+
recorded_with: VCR 3.0.3
|
@@ -0,0 +1,82 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://finance.google.com/finance/getprices?q=MSFT
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
User-Agent:
|
11
|
+
- Faraday v0.13.1
|
12
|
+
Accept-Encoding:
|
13
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
14
|
+
Accept:
|
15
|
+
- "*/*"
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Content-Type:
|
22
|
+
- text/plain; charset=ISO-8859-1
|
23
|
+
Cache-Control:
|
24
|
+
- private,max-age=60
|
25
|
+
Vary:
|
26
|
+
- Accept-Encoding
|
27
|
+
X-Content-Type-Options:
|
28
|
+
- nosniff
|
29
|
+
P3p:
|
30
|
+
- CP="This is not a P3P policy! See g.co/p3phelp for more info."
|
31
|
+
Date:
|
32
|
+
- Thu, 28 Dec 2017 17:36:02 GMT
|
33
|
+
X-Frame-Options:
|
34
|
+
- SAMEORIGIN
|
35
|
+
X-Xss-Protection:
|
36
|
+
- 1; mode=block
|
37
|
+
Server:
|
38
|
+
- GSE
|
39
|
+
Set-Cookie:
|
40
|
+
- NID=120=rQwDiRAJ6enXL1rj3-FNIB1RCMkB-Ed3cKNKyBqoscW2M_0MfHmwtDaiOjCj3Rn8Fj0-V6uzybRtIA8XkUCgM0RWGi2x1jetNMWvw4xopJaGjvoKs1ZI6V1ZwLM-DAGv;Domain=.google.com;Path=/;Expires=Fri,
|
41
|
+
29-Jun-2018 17:36:02 GMT;HttpOnly
|
42
|
+
Alt-Svc:
|
43
|
+
- hq=":443"; ma=2592000; quic=51303431; quic=51303339; quic=51303338; quic=51303337;
|
44
|
+
quic=51303335,quic=":443"; ma=2592000; v="41,39,38,37,35"
|
45
|
+
Expires:
|
46
|
+
- Thu, 28 Dec 2017 17:36:02 GMT
|
47
|
+
Transfer-Encoding:
|
48
|
+
- chunked
|
49
|
+
body:
|
50
|
+
encoding: ASCII-8BIT
|
51
|
+
string: |
|
52
|
+
EXCHANGE%3DNASDAQ
|
53
|
+
MARKET_OPEN_MINUTE=570
|
54
|
+
MARKET_CLOSE_MINUTE=960
|
55
|
+
INTERVAL=86400
|
56
|
+
COLUMNS=DATE,CLOSE,HIGH,LOW,OPEN,VOLUME
|
57
|
+
DATA=
|
58
|
+
TIMEZONE_OFFSET=-300
|
59
|
+
a1511902800,84.88,85.06,84.02,84.07,21925959
|
60
|
+
1,83.34,84.9172,83.175,84.71,27381109
|
61
|
+
2,84.17,84.52,83.34,83.51,33054647
|
62
|
+
3,84.26,84.81,83.22,83.6,29532132
|
63
|
+
6,81.08,84.4299,80.7,84.42,39094880
|
64
|
+
7,81.59,82.68,80.9801,81.34,26152261
|
65
|
+
8,82.78,83.14,81.43,81.55,26162054
|
66
|
+
9,82.49,82.8,82,82.54,23184547
|
67
|
+
10,84.16,84.58,83.33,83.63,24489106
|
68
|
+
13,85.23,85.37,84.12,84.29,22857854
|
69
|
+
14,85.58,86.05,85.08,85.31,23924105
|
70
|
+
15,85.35,86,85.17,85.74,22062679
|
71
|
+
16,84.69,85.8739,84.53,85.43,19305961
|
72
|
+
17,86.85,87.09,84.88,85.26,53936687
|
73
|
+
20,86.38,87.4999,86.23,87.12,22283752
|
74
|
+
21,85.83,86.35,85.27,86.35,23524787
|
75
|
+
22,85.52,86.3,84.71,86.2,23674931
|
76
|
+
23,85.5,86.1,85.4,86.05,17990745
|
77
|
+
24,85.51,85.63,84.92,85.4,14145841
|
78
|
+
28,85.4,85.5346,85.03,85.31,9891237
|
79
|
+
29,85.71,85.98,85.215,85.65,14678025
|
80
|
+
http_version:
|
81
|
+
recorded_at: Thu, 28 Dec 2017 17:36:02 GMT
|
82
|
+
recorded_with: VCR 3.0.3
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe GoogleFinance::Prices do
|
4
|
+
context 'known symbol', vcr: { cassette_name: 'get_prices_msft' } do
|
5
|
+
subject do
|
6
|
+
GoogleFinance::Prices.get('MSFT')
|
7
|
+
end
|
8
|
+
it 'retrieves price history' do
|
9
|
+
expect(subject.exchange).to eq 'NASDAQ'
|
10
|
+
expect(subject.market_open_minute).to eq 570
|
11
|
+
expect(subject.market_close_minute).to eq 960
|
12
|
+
expect(subject.interval).to eq 86_400
|
13
|
+
expect(subject.columns).to eq(%w[date close high low open volume])
|
14
|
+
expect(subject.count).to eq 21
|
15
|
+
end
|
16
|
+
context 'row' do
|
17
|
+
let(:price) { subject.first }
|
18
|
+
it 'includes a price' do
|
19
|
+
expect(price).to be_a GoogleFinance::Price
|
20
|
+
expect(price.timezone_offset).to eq -300
|
21
|
+
expect(price.close).to eq 84.88
|
22
|
+
expect(price.high).to eq 85.06
|
23
|
+
expect(price.low).to eq 84.02
|
24
|
+
expect(price.open).to eq 84.07
|
25
|
+
expect(price.volume).to eq 21_925_959
|
26
|
+
expect(price.date).to eq Time.parse('2017-11-28 16:00 -0500')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
context 'with custom fields', vcr: { cassette_name: 'get_prices_goog_with_options' } do
|
31
|
+
subject do
|
32
|
+
GoogleFinance::Prices.get('GOOG', i: 60 * 60, p: '1Y', f: 'd,c,v,k,o,h,l', df: 'cpct', auto: 0)
|
33
|
+
end
|
34
|
+
it 'retrieves price history' do
|
35
|
+
expect(subject.exchange).to eq 'NASDAQ'
|
36
|
+
expect(subject.interval).to eq 3600
|
37
|
+
expect(subject.columns).to eq(%w[date close high low open volume cdays])
|
38
|
+
expect(subject.count).to eq 1755
|
39
|
+
end
|
40
|
+
it 'knows timezone_offset' do
|
41
|
+
expect(subject.first.timezone_offset).to eq -300
|
42
|
+
expect(subject[1024].timezone_offset).to eq -240
|
43
|
+
expect(subject.last.timezone_offset).to eq -300
|
44
|
+
end
|
45
|
+
end
|
46
|
+
context 'with custom named fields', vcr: { cassette_name: 'get_prices_goog_with_options' } do
|
47
|
+
subject do
|
48
|
+
GoogleFinance::Prices.get('GOOG', interval: 60 * 60, period: '1Y', fields: %i[date close volume k open high low], df: 'cpct', auto: 0)
|
49
|
+
end
|
50
|
+
it 'retrieves price history' do
|
51
|
+
expect(subject.exchange).to eq 'NASDAQ'
|
52
|
+
expect(subject.interval).to eq 3600
|
53
|
+
expect(subject.columns).to eq(%w[date close high low open volume cdays])
|
54
|
+
expect(subject.count).to eq 1755
|
55
|
+
end
|
56
|
+
it 'knows timezone_offset' do
|
57
|
+
expect(subject.first.timezone_offset).to eq -300
|
58
|
+
expect(subject[1024].timezone_offset).to eq -240
|
59
|
+
expect(subject.last.timezone_offset).to eq -300
|
60
|
+
end
|
61
|
+
end
|
62
|
+
context 'with few fields', vcr: { cassette_name: 'get_prices_goog_with_few_fields' } do
|
63
|
+
subject do
|
64
|
+
GoogleFinance::Prices.get('GOOG', fields: %i[date close])
|
65
|
+
end
|
66
|
+
it 'retrieves price history' do
|
67
|
+
expect(subject.exchange).to eq 'NASDAQ'
|
68
|
+
expect(subject.columns).to eq(%w[date close])
|
69
|
+
expect(subject.count).to eq 21
|
70
|
+
end
|
71
|
+
it 'retrieves some fields' do
|
72
|
+
price = subject.first
|
73
|
+
expect(price.close).to eq 1047.41
|
74
|
+
expect(price.date).to eq Time.parse('2017-11-28 16:00:00 -0500')
|
75
|
+
expect(price.timezone_offset).to eq -300
|
76
|
+
expect(price.high).to be nil
|
77
|
+
end
|
78
|
+
end
|
79
|
+
context 'unknown symbol', vcr: { cassette_name: 'get_prices_invalid' } do
|
80
|
+
subject do
|
81
|
+
GoogleFinance::Prices.get('INVALID')
|
82
|
+
end
|
83
|
+
it 'fails with SymbolNotFoundError' do
|
84
|
+
expect { subject }.to raise_error GoogleFinance::Errors::SymbolNotFoundError, 'Symbol INVALID Not Found'
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-finance-ruby-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Doubrovkine
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -143,21 +143,30 @@ files:
|
|
143
143
|
- google-finance-ruby-client.gemspec
|
144
144
|
- google-finance.png
|
145
145
|
- lib/google-finance-ruby-client.rb
|
146
|
+
- lib/google-finance/api.rb
|
147
|
+
- lib/google-finance/api/get_prices.rb
|
148
|
+
- lib/google-finance/api/index.rb
|
146
149
|
- lib/google-finance/errors.rb
|
147
150
|
- lib/google-finance/errors/symbol_not_found_error.rb
|
148
151
|
- lib/google-finance/errors/symbols_not_found_error.rb
|
149
152
|
- lib/google-finance/faraday_middleware/preprocessor.rb
|
153
|
+
- lib/google-finance/price.rb
|
154
|
+
- lib/google-finance/prices.rb
|
150
155
|
- lib/google-finance/quote.rb
|
151
156
|
- lib/google-finance/quotes.rb
|
152
157
|
- lib/google-finance/resource.rb
|
153
|
-
- lib/google-finance/resources.rb
|
154
158
|
- lib/google-finance/version.rb
|
159
|
+
- spec/fixtures/google-finance/get_prices_goog_with_few_fields.yml
|
160
|
+
- spec/fixtures/google-finance/get_prices_goog_with_options.yml
|
161
|
+
- spec/fixtures/google-finance/get_prices_invalid.yml
|
162
|
+
- spec/fixtures/google-finance/get_prices_msft.yml
|
155
163
|
- spec/fixtures/google-finance/invalid.yml
|
156
164
|
- spec/fixtures/google-finance/msft.yml
|
157
165
|
- spec/fixtures/google-finance/msft_ab.yml
|
158
166
|
- spec/fixtures/google-finance/msft_ab_invalid.yml
|
159
167
|
- spec/fixtures/google-finance/search_invalid.yml
|
160
168
|
- spec/fixtures/google-finance/search_msft.yml
|
169
|
+
- spec/google-finance/prices_spec.rb
|
161
170
|
- spec/google-finance/quote_spec.rb
|
162
171
|
- spec/google-finance/quotes_spec.rb
|
163
172
|
- spec/google-finance/version_spec.rb
|
@@ -188,12 +197,17 @@ signing_key:
|
|
188
197
|
specification_version: 4
|
189
198
|
summary: Google Finance web API ruby client.
|
190
199
|
test_files:
|
200
|
+
- spec/fixtures/google-finance/get_prices_goog_with_few_fields.yml
|
201
|
+
- spec/fixtures/google-finance/get_prices_goog_with_options.yml
|
202
|
+
- spec/fixtures/google-finance/get_prices_invalid.yml
|
203
|
+
- spec/fixtures/google-finance/get_prices_msft.yml
|
191
204
|
- spec/fixtures/google-finance/invalid.yml
|
192
205
|
- spec/fixtures/google-finance/msft.yml
|
193
206
|
- spec/fixtures/google-finance/msft_ab.yml
|
194
207
|
- spec/fixtures/google-finance/msft_ab_invalid.yml
|
195
208
|
- spec/fixtures/google-finance/search_invalid.yml
|
196
209
|
- spec/fixtures/google-finance/search_msft.yml
|
210
|
+
- spec/google-finance/prices_spec.rb
|
197
211
|
- spec/google-finance/quote_spec.rb
|
198
212
|
- spec/google-finance/quotes_spec.rb
|
199
213
|
- spec/google-finance/version_spec.rb
|
@@ -1,28 +0,0 @@
|
|
1
|
-
module GoogleFinance
|
2
|
-
module Resources
|
3
|
-
def self.fetch(params = {})
|
4
|
-
get(params)
|
5
|
-
end
|
6
|
-
|
7
|
-
def self.get(params)
|
8
|
-
connection.get do |c|
|
9
|
-
c.params[:output] = :json
|
10
|
-
c.params.merge!(params)
|
11
|
-
end.body
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.connection
|
15
|
-
Faraday.new(
|
16
|
-
url: 'https://finance.google.com/finance',
|
17
|
-
request: {
|
18
|
-
params_encoder: Faraday::FlatParamsEncoder
|
19
|
-
}
|
20
|
-
) do |c|
|
21
|
-
c.use ::FaradayMiddleware::ParseJson
|
22
|
-
c.use GoogleFinance::FaradayMiddleware::Preprocessor
|
23
|
-
c.use Faraday::Response::RaiseError
|
24
|
-
c.use Faraday::Adapter::NetHttp
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|