iex-ruby-client 1.0.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +5 -5
  2. data/.env.sample +2 -0
  3. data/.github/FUNDING.yml +1 -0
  4. data/.rubocop.yml +4 -1
  5. data/.rubocop_todo.yml +0 -8
  6. data/CHANGELOG.md +43 -9
  7. data/Dangerfile +2 -2
  8. data/Gemfile +3 -2
  9. data/README.md +134 -10
  10. data/iex-ruby-client.gemspec +3 -2
  11. data/lib/iex/api.rb +6 -1
  12. data/lib/iex/api/client.rb +13 -2
  13. data/lib/iex/api/config/client.rb +52 -0
  14. data/lib/iex/api/config/logger.rb +35 -0
  15. data/lib/iex/cloud/connection.rb +22 -19
  16. data/lib/iex/cloud/request.rb +1 -1
  17. data/lib/iex/cloud/response.rb +1 -1
  18. data/lib/iex/endpoints/advanced_stats.rb +11 -0
  19. data/lib/iex/endpoints/chart.rb +5 -6
  20. data/lib/iex/endpoints/company.rb +1 -1
  21. data/lib/iex/endpoints/crypto.rb +1 -1
  22. data/lib/iex/endpoints/dividends.rb +1 -1
  23. data/lib/iex/endpoints/earnings.rb +1 -1
  24. data/lib/iex/endpoints/income.rb +13 -0
  25. data/lib/iex/endpoints/key_stats.rb +1 -1
  26. data/lib/iex/endpoints/largest_trades.rb +1 -1
  27. data/lib/iex/endpoints/logo.rb +1 -1
  28. data/lib/iex/endpoints/news.rb +1 -1
  29. data/lib/iex/endpoints/ohlc.rb +2 -2
  30. data/lib/iex/endpoints/price.rb +1 -1
  31. data/lib/iex/endpoints/quote.rb +1 -1
  32. data/lib/iex/endpoints/ref_data.rb +22 -0
  33. data/lib/iex/endpoints/sectors.rb +1 -1
  34. data/lib/iex/endpoints/stock_market.rb +11 -0
  35. data/lib/iex/resources.rb +4 -0
  36. data/lib/iex/resources/advanced_stats.rb +42 -0
  37. data/lib/iex/resources/chart.rb +9 -14
  38. data/lib/iex/resources/company.rb +1 -0
  39. data/lib/iex/resources/income.rb +36 -0
  40. data/lib/iex/resources/key_stats.rb +2 -2
  41. data/lib/iex/resources/quote.rb +15 -5
  42. data/lib/iex/resources/resource.rb +1 -1
  43. data/lib/iex/resources/symbol.rb +10 -0
  44. data/lib/iex/resources/symbols.rb +19 -0
  45. data/lib/iex/version.rb +1 -1
  46. data/spec/fixtures/iex/advanced_stats/invalid.yml +50 -0
  47. data/spec/fixtures/iex/advanced_stats/msft.yml +57 -0
  48. data/spec/fixtures/iex/chart/1d.yml +440 -473
  49. data/spec/fixtures/iex/chart/20190306.yml +440 -473
  50. data/spec/fixtures/iex/chart/bad_option.yml +47 -81
  51. data/spec/fixtures/iex/chart/chartInterval.yml +89 -122
  52. data/spec/fixtures/iex/chart/dynamic/1m.yml +73 -107
  53. data/spec/fixtures/iex/chart/invalid.yml +47 -81
  54. data/spec/fixtures/iex/chart/msft.yml +74 -107
  55. data/spec/fixtures/iex/income/invalid.yml +49 -0
  56. data/spec/fixtures/iex/income/msft.yml +53 -0
  57. data/spec/fixtures/iex/income/nsrgy.yml +55 -0
  58. data/spec/fixtures/iex/ref-data/isin.yml +57 -0
  59. data/spec/fixtures/iex/ref-data/isin_mapped.yml +57 -0
  60. data/spec/fixtures/iex/ref-data/symbols.yml +9002 -0
  61. data/spec/fixtures/iex/ref-data/wrong_isin_mapped.yml +57 -0
  62. data/spec/fixtures/iex/stock_market/list_mostactive.yml +76 -0
  63. data/spec/iex/client_spec.rb +97 -14
  64. data/spec/iex/config/client_spec.rb +49 -0
  65. data/spec/iex/config/logger_spec.rb +46 -0
  66. data/spec/iex/endpoints/advanced_stats_spec.rb +54 -0
  67. data/spec/iex/endpoints/chart_spec.rb +7 -7
  68. data/spec/iex/endpoints/company_spec.rb +1 -0
  69. data/spec/iex/endpoints/income_spec.rb +68 -0
  70. data/spec/iex/endpoints/key_stats_spec.rb +2 -1
  71. data/spec/iex/endpoints/quote_spec.rb +2 -0
  72. data/spec/iex/endpoints/ref_data_spec.rb +76 -0
  73. data/spec/iex/endpoints/stock_market_spec.rb +14 -0
  74. data/spec/spec_helper.rb +3 -2
  75. data/spec/support/vcr.rb +3 -0
  76. metadata +56 -16
  77. data/lib/iex/api/config.rb +0 -45
  78. data/spec/iex/config_spec.rb +0 -22
@@ -0,0 +1,57 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://cloud.iexapis.com/v1/ref-data/isin?isin=WRONG12345&mapped=true&token=test-iex-api-publishable-token
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - application/json; charset=utf-8
12
+ Content-Type:
13
+ - application/json; charset=utf-8
14
+ User-Agent:
15
+ - IEX Ruby Client/1.1.3
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Server:
24
+ - nginx
25
+ Date:
26
+ - Fri, 10 Apr 2020 15:17:34 GMT
27
+ Content-Type:
28
+ - application/json; charset=utf-8
29
+ Content-Length:
30
+ - '19'
31
+ Connection:
32
+ - keep-alive
33
+ Set-Cookie:
34
+ - ctoken=84910330e5ea4058969d0af364c32947; Max-Age=43200; Path=/; Expires=Sat,
35
+ 11 Apr 2020 03:17:34 GMT
36
+ Iexcloud-Messages-Used:
37
+ - '100'
38
+ Iexcloud-Premium-Messages-Used:
39
+ - '0'
40
+ X-Content-Type-Options:
41
+ - nosniff
42
+ Strict-Transport-Security:
43
+ - max-age=15768000
44
+ Access-Control-Allow-Origin:
45
+ - "*"
46
+ Access-Control-Allow-Credentials:
47
+ - 'true'
48
+ Access-Control-Allow-Methods:
49
+ - GET, OPTIONS
50
+ Access-Control-Allow-Headers:
51
+ - Origin, X-Requested-With, Content-Type, Accept
52
+ body:
53
+ encoding: UTF-8
54
+ string: '{"WRONG12345":null}'
55
+ http_version: null
56
+ recorded_at: Fri, 10 Apr 2020 15:17:34 GMT
57
+ recorded_with: VCR 5.1.0
@@ -0,0 +1,76 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://cloud.iexapis.com/v1/stock/market/list/mostactive?token=test-iex-api-publishable-token
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - application/json; charset=utf-8
12
+ Content-Type:
13
+ - application/json; charset=utf-8
14
+ User-Agent:
15
+ - IEX Ruby Client/1.1.2
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Server:
24
+ - nginx
25
+ Date:
26
+ - Wed, 04 Mar 2020 13:00:24 GMT
27
+ Content-Type:
28
+ - application/json; charset=utf-8
29
+ Transfer-Encoding:
30
+ - chunked
31
+ Connection:
32
+ - keep-alive
33
+ Set-Cookie:
34
+ - ctoken=82c15565434a4dada8483b258390943b; Max-Age=43200; Path=/; Expires=Thu,
35
+ 05 Mar 2020 01:00:24 GMT
36
+ Iexcloud-Messages-Used:
37
+ - '20'
38
+ Iexcloud-Premium-Messages-Used:
39
+ - '0'
40
+ X-Content-Type-Options:
41
+ - nosniff
42
+ Strict-Transport-Security:
43
+ - max-age=15768000
44
+ Access-Control-Allow-Origin:
45
+ - "*"
46
+ Access-Control-Allow-Credentials:
47
+ - 'true'
48
+ Access-Control-Allow-Methods:
49
+ - GET, OPTIONS
50
+ Access-Control-Allow-Headers:
51
+ - Origin, X-Requested-With, Content-Type, Accept
52
+ body:
53
+ encoding: ASCII-8BIT
54
+ string: '[{"symbol":"AMD","companyName":"Advanced Micro Devices, Inc.","primaryExchange":"NASDAQ","calculationPrice":"close","open":null,"openTime":null,"close":null,"closeTime":null,"high":null,"low":null,"latestPrice":46.75,"latestSource":"Close","latestTime":"March
55
+ 3, 2020","latestUpdate":1583269200736,"latestVolume":null,"iexRealtimePrice":0,"iexRealtimeSize":0,"iexLastUpdated":0,"delayedPrice":null,"delayedPriceTime":null,"oddLotDelayedPrice":null,"oddLotDelayedPriceTime":null,"extendedPrice":null,"extendedChange":null,"extendedChangePercent":null,"extendedPriceTime":null,"previousClose":47.46,"previousVolume":102324726,"change":-0.71,"changePercent":-0.01496,"volume":null,"iexMarketPercent":null,"iexVolume":0,"avgTotalVolume":69781992,"iexBidPrice":0,"iexBidSize":0,"iexAskPrice":0,"iexAskSize":0,"marketCap":54681605000,"peRatio":152.73,"week52High":59.27,"week52Low":21.04,"ytdChange":-0.062822,"lastTradeTime":1583269200603,"isUSMarketOpen":false},{"symbol":"BAC","companyName":"Bank
56
+ of America Corp.","primaryExchange":"New York Stock Exchange","calculationPrice":"close","open":null,"openTime":null,"close":null,"closeTime":null,"high":null,"low":null,"latestPrice":27.75,"latestSource":"Close","latestTime":"March
57
+ 3, 2020","latestUpdate":1583269208334,"latestVolume":null,"iexRealtimePrice":0,"iexRealtimeSize":0,"iexLastUpdated":0,"delayedPrice":null,"delayedPriceTime":null,"oddLotDelayedPrice":null,"oddLotDelayedPriceTime":null,"extendedPrice":null,"extendedChange":null,"extendedChangePercent":null,"extendedPriceTime":null,"previousClose":29.37,"previousVolume":147776301,"change":-1.62,"changePercent":-0.05516,"volume":null,"iexMarketPercent":null,"iexVolume":0,"avgTotalVolume":59385616,"iexBidPrice":0,"iexBidSize":0,"iexAskPrice":0,"iexAskSize":0,"marketCap":242216707500,"peRatio":10.03,"week52High":35.72,"week52Low":26.21,"ytdChange":-0.27654,"lastTradeTime":1583269208300,"isUSMarketOpen":false},{"symbol":"INO","companyName":"Inovio
58
+ Pharmaceuticals, Inc.","primaryExchange":"NASDAQ","calculationPrice":"close","open":null,"openTime":null,"close":null,"closeTime":null,"high":null,"low":null,"latestPrice":7.45,"latestSource":"Close","latestTime":"March
59
+ 3, 2020","latestUpdate":1583269200743,"latestVolume":null,"iexRealtimePrice":0,"iexRealtimeSize":0,"iexLastUpdated":0,"delayedPrice":null,"delayedPriceTime":null,"oddLotDelayedPrice":null,"oddLotDelayedPriceTime":null,"extendedPrice":null,"extendedChange":null,"extendedChangePercent":null,"extendedPriceTime":null,"previousClose":4.39,"previousVolume":16179954,"change":3.06,"changePercent":0.69704,"volume":null,"iexMarketPercent":null,"iexVolume":0,"avgTotalVolume":18795754,"iexBidPrice":0,"iexBidSize":0,"iexAskPrice":0,"iexAskSize":0,"marketCap":755139450,"peRatio":-6.32,"week52High":7.48,"week52Low":1.92,"ytdChange":2.017912,"lastTradeTime":1583269200378,"isUSMarketOpen":false},{"symbol":"GE","companyName":"General
60
+ Electric Co.","primaryExchange":"New York Stock Exchange","calculationPrice":"close","open":null,"openTime":null,"close":null,"closeTime":null,"high":null,"low":null,"latestPrice":10.88,"latestSource":"Close","latestTime":"March
61
+ 3, 2020","latestUpdate":1583269204858,"latestVolume":null,"iexRealtimePrice":0,"iexRealtimeSize":0,"iexLastUpdated":0,"delayedPrice":null,"delayedPriceTime":null,"oddLotDelayedPrice":null,"oddLotDelayedPriceTime":null,"extendedPrice":null,"extendedChange":null,"extendedChangePercent":null,"extendedPriceTime":null,"previousClose":11.21,"previousVolume":124802207,"change":-0.33,"changePercent":-0.02944,"volume":null,"iexMarketPercent":null,"iexVolume":0,"avgTotalVolume":71758664,"iexBidPrice":0,"iexBidSize":0,"iexAskPrice":0,"iexAskSize":0,"marketCap":95093702400,"peRatio":143.16,"week52High":13.26,"week52Low":7.65,"ytdChange":-0.117453,"lastTradeTime":1583269204815,"isUSMarketOpen":false},{"symbol":"F","companyName":"Ford
62
+ Motor Co.","primaryExchange":"New York Stock Exchange","calculationPrice":"close","open":null,"openTime":null,"close":null,"closeTime":null,"high":null,"low":null,"latestPrice":6.97,"latestSource":"Close","latestTime":"March
63
+ 3, 2020","latestUpdate":1583269470045,"latestVolume":null,"iexRealtimePrice":0,"iexRealtimeSize":0,"iexLastUpdated":0,"delayedPrice":null,"delayedPriceTime":null,"oddLotDelayedPrice":null,"oddLotDelayedPriceTime":null,"extendedPrice":null,"extendedChange":null,"extendedChangePercent":null,"extendedPriceTime":null,"previousClose":7.2,"previousVolume":96766032,"change":-0.23,"changePercent":-0.03194,"volume":null,"iexMarketPercent":null,"iexVolume":0,"avgTotalVolume":79183546,"iexBidPrice":0,"iexBidSize":0,"iexAskPrice":0,"iexAskSize":0,"marketCap":27636398500,"peRatio":237.88,"week52High":10.56,"week52Low":6.67,"ytdChange":-0.29202500000000003,"lastTradeTime":1583269200123,"isUSMarketOpen":false},{"symbol":"AAPL","companyName":"Apple,
64
+ Inc.","primaryExchange":"NASDAQ","calculationPrice":"close","open":null,"openTime":null,"close":null,"closeTime":null,"high":null,"low":null,"latestPrice":289.32,"latestSource":"Close","latestTime":"March
65
+ 3, 2020","latestUpdate":1583269200249,"latestVolume":null,"iexRealtimePrice":0,"iexRealtimeSize":0,"iexLastUpdated":0,"delayedPrice":null,"delayedPriceTime":null,"oddLotDelayedPrice":null,"oddLotDelayedPriceTime":null,"extendedPrice":null,"extendedChange":null,"extendedChangePercent":null,"extendedPriceTime":null,"previousClose":298.81,"previousVolume":85349339,"change":-9.49,"changePercent":-0.03176,"volume":null,"iexMarketPercent":null,"iexVolume":0,"avgTotalVolume":41771302,"iexBidPrice":0,"iexBidSize":0,"iexAskPrice":0,"iexAskSize":0,"marketCap":1265913873600,"peRatio":22.68,"week52High":327.85,"week52Low":169.5,"ytdChange":-0.06848399999999999,"lastTradeTime":1583269200389,"isUSMarketOpen":false},{"symbol":"MSFT","companyName":"Microsoft
66
+ Corp.","primaryExchange":"NASDAQ","calculationPrice":"close","open":null,"openTime":null,"close":null,"closeTime":null,"high":null,"low":null,"latestPrice":164.51,"latestSource":"Close","latestTime":"March
67
+ 3, 2020","latestUpdate":1583269200720,"latestVolume":null,"iexRealtimePrice":0,"iexRealtimeSize":0,"iexLastUpdated":0,"delayedPrice":null,"delayedPriceTime":null,"oddLotDelayedPrice":null,"oddLotDelayedPriceTime":null,"extendedPrice":null,"extendedChange":null,"extendedChangePercent":null,"extendedPriceTime":null,"previousClose":172.79,"previousVolume":71030810,"change":-8.28,"changePercent":-0.04792,"volume":null,"iexMarketPercent":null,"iexVolume":0,"avgTotalVolume":43623452,"iexBidPrice":0,"iexBidSize":0,"iexAskPrice":0,"iexAskSize":0,"marketCap":1251271285500,"peRatio":28.37,"week52High":190.7,"week52Low":108.8,"ytdChange":-0.023700999999999996,"lastTradeTime":1583269200282,"isUSMarketOpen":false},{"symbol":"T","companyName":"AT&T,
68
+ Inc.","primaryExchange":"New York Stock Exchange","calculationPrice":"close","open":null,"openTime":null,"close":null,"closeTime":null,"high":null,"low":null,"latestPrice":36.3,"latestSource":"Close","latestTime":"March
69
+ 3, 2020","latestUpdate":1583269431180,"latestVolume":null,"iexRealtimePrice":0,"iexRealtimeSize":0,"iexLastUpdated":0,"delayedPrice":null,"delayedPriceTime":null,"oddLotDelayedPrice":null,"oddLotDelayedPriceTime":null,"extendedPrice":null,"extendedChange":null,"extendedChangePercent":null,"extendedPriceTime":null,"previousClose":37.18,"previousVolume":68432790,"change":-0.88,"changePercent":-0.02367,"volume":null,"iexMarketPercent":null,"iexVolume":0,"avgTotalVolume":39604055,"iexBidPrice":0,"iexBidSize":0,"iexAskPrice":0,"iexAskSize":0,"marketCap":260375544000,"peRatio":19.09,"week52High":39.7,"week52Low":29.67,"ytdChange":-0.089548,"lastTradeTime":1583269199998,"isUSMarketOpen":false},{"symbol":"XOM","companyName":"Exxon
70
+ Mobil Corp.","primaryExchange":"New York Stock Exchange","calculationPrice":"close","open":null,"openTime":null,"close":null,"closeTime":null,"high":null,"low":null,"latestPrice":51.3,"latestSource":"Close","latestTime":"March
71
+ 3, 2020","latestUpdate":1583269428549,"latestVolume":null,"iexRealtimePrice":0,"iexRealtimeSize":0,"iexLastUpdated":0,"delayedPrice":null,"delayedPriceTime":null,"oddLotDelayedPrice":null,"oddLotDelayedPriceTime":null,"extendedPrice":null,"extendedChange":null,"extendedChangePercent":null,"extendedPriceTime":null,"previousClose":53.88,"previousVolume":38127634,"change":-2.58,"changePercent":-0.04788,"volume":null,"iexMarketPercent":null,"iexVolume":0,"avgTotalVolume":24981447,"iexBidPrice":0,"iexBidSize":0,"iexAskPrice":0,"iexAskSize":0,"marketCap":217111347000,"peRatio":15.29,"week52High":83.49,"week52Low":48.01,"ytdChange":-0.324326,"lastTradeTime":1583269199431,"isUSMarketOpen":false},{"symbol":"INTC","companyName":"Intel
72
+ Corp.","primaryExchange":"NASDAQ","calculationPrice":"close","open":null,"openTime":null,"close":null,"closeTime":null,"high":null,"low":null,"latestPrice":55.97,"latestSource":"Close","latestTime":"March
73
+ 3, 2020","latestUpdate":1583269200750,"latestVolume":null,"iexRealtimePrice":0,"iexRealtimeSize":0,"iexLastUpdated":0,"delayedPrice":null,"delayedPriceTime":null,"oddLotDelayedPrice":null,"oddLotDelayedPriceTime":null,"extendedPrice":null,"extendedChange":null,"extendedChangePercent":null,"extendedPriceTime":null,"previousClose":58.18,"previousVolume":43140304,"change":-2.21,"changePercent":-0.03799,"volume":null,"iexMarketPercent":null,"iexVolume":0,"avgTotalVolume":28110407,"iexBidPrice":0,"iexBidSize":0,"iexAskPrice":0,"iexAskSize":0,"marketCap":239383690000,"peRatio":11.7,"week52High":69.29,"week52Low":42.86,"ytdChange":-0.118036,"lastTradeTime":1583269200602,"isUSMarketOpen":false}]'
74
+ http_version: null
75
+ recorded_at: Wed, 04 Mar 2020 13:00:24 GMT
76
+ recorded_with: VCR 5.1.0
@@ -3,6 +3,7 @@ require 'spec_helper'
3
3
  describe IEX::Api::Client do
4
4
  before do
5
5
  IEX::Api.config.reset!
6
+ IEX::Api.logger.reset!
6
7
  end
7
8
  context 'with defaults' do
8
9
  let(:client) { described_class.new }
@@ -14,23 +15,32 @@ describe IEX::Api::Client do
14
15
  expect(client.user_agent).to eq "IEX Ruby Client/#{IEX::VERSION}"
15
16
  end
16
17
  it 'sets user-agent' do
17
- expect(client.user_agent).to eq IEX::Api::Config.user_agent
18
+ expect(client.user_agent).to eq IEX::Api::Config::Client.user_agent
18
19
  expect(client.user_agent).to include IEX::VERSION
19
20
  end
20
- (IEX::Api::Config::ATTRIBUTES - [:logger]).each do |key|
21
+ it 'caches the Faraday connection to allow persistent adapters' do
22
+ first = client.send(:connection)
23
+ second = client.send(:connection)
24
+ expect(first).to equal second
25
+ end
26
+ it 'sets a nil logger' do
27
+ expect(client.logger.instance).to be_nil
28
+ expect(client.send(:connection).builder.handlers).not_to include(::Faraday::Response::Logger)
29
+ end
30
+ IEX::Api::Config::Client::ATTRIBUTES.each do |key|
21
31
  it "sets #{key}" do
22
- expect(client.send(key)).to eq IEX::Api::Config.send(key)
32
+ expect(client.send(key)).to eq IEX::Api::Config::Client.send(key)
23
33
  end
24
34
  end
25
35
  end
26
36
  end
27
37
  context 'with custom settings' do
28
38
  context '#initialize' do
29
- IEX::Api::Config::ATTRIBUTES.each do |key|
39
+ IEX::Api::Config::Client::ATTRIBUTES.each do |key|
30
40
  context key.to_s do
31
41
  let(:client) { described_class.new(key => 'custom') }
32
42
  it "sets #{key}" do
33
- expect(client.send(key)).to_not eq IEX::Api::Config.send(key)
43
+ expect(client.send(key)).to_not eq IEX::Api::Config::Client.send(key)
34
44
  expect(client.send(key)).to eq 'custom'
35
45
  end
36
46
  end
@@ -91,22 +101,74 @@ describe IEX::Api::Client do
91
101
  end
92
102
  end
93
103
  end
104
+
94
105
  context 'logger option' do
95
106
  let(:logger) { Logger.new(STDOUT) }
96
- before do
97
- IEX::Api.configure do |config|
98
- config.logger = logger
107
+
108
+ after { IEX::Api.logger.reset! }
109
+
110
+ context 'when assigning an instance' do
111
+ context '#initialize' do
112
+ context 'when directly assigning `logger`' do
113
+ before { IEX::Api.logger = logger }
114
+
115
+ it 'sets logger' do
116
+ expect(client.logger.instance).to eq(logger)
117
+ end
118
+
119
+ it 'creates a connection with a logger' do
120
+ expect(client.send(:connection).builder.handlers).to include ::Faraday::Response::Logger
121
+ end
122
+ end
123
+
124
+ context 'when assigning through `configure.logger`' do
125
+ it 'sets the logger' do
126
+ IEX::Api.configure.logger = logger
127
+ expect(client.logger.instance).to eq(logger)
128
+ end
129
+ end
130
+
131
+ context 'when passing in at initialization' do
132
+ it 'sets the logger' do
133
+ client = described_class.new(logger: logger)
134
+ expect(client.logger.instance).to eq(logger)
135
+ end
136
+
137
+ it 'can overwrite a set logger' do
138
+ IEX::Api.logger = logger
139
+ client = described_class.new(logger: nil)
140
+ expect(client.logger.instance).to be_nil
141
+ end
142
+ end
99
143
  end
100
144
  end
101
- context '#initialize' do
102
- it 'sets logger' do
103
- expect(client.logger).to eq logger
145
+
146
+ context 'when assigning a configuration' do
147
+ let(:opts) { { bodies: true } }
148
+ let(:proc_arg) { proc {} }
149
+
150
+ before do
151
+ IEX::Api.logger do |log_config|
152
+ log_config.instance = logger
153
+ log_config.options = opts
154
+ log_config.proc = proc_arg
155
+ end
104
156
  end
105
- it 'creates a connection with a logger' do
106
- expect(client.send(:connection).builder.handlers).to include ::Faraday::Response::Logger
157
+
158
+ context '#initialize' do
159
+ it 'sets logger' do
160
+ expect(client.logger.instance).to eq logger
161
+ expect(client.logger.options).to eq opts
162
+ expect(client.logger.proc).to eq proc_arg
163
+ end
164
+
165
+ it 'creates a connection with a logger' do
166
+ expect(client.send(:connection).builder.handlers).to include ::Faraday::Response::Logger
167
+ end
107
168
  end
108
169
  end
109
170
  end
171
+
110
172
  context 'timeout options' do
111
173
  before do
112
174
  IEX::Api.configure do |config|
@@ -126,11 +188,32 @@ describe IEX::Api::Client do
126
188
  end
127
189
  end
128
190
  end
191
+
192
+ context 'when resetting/changing configuration' do
193
+ before do
194
+ IEX::Api.configure { |config| config.user_agent = 'custom/user-agent' }
195
+ end
196
+
197
+ it 'does not reset the client' do
198
+ expect { IEX::Api.config.reset! }.not_to change(client, :user_agent).from('custom/user-agent')
199
+ end
200
+
201
+ it 'effects the next client' do
202
+ pre_config_client = described_class.new
203
+ IEX::Api.configure { |config| config.user_agent = 'custom/user-agent-2' }
204
+ expect(described_class.new.user_agent).not_to eq(pre_config_client.user_agent)
205
+ end
206
+
207
+ it 'should not allow the client to reset' do
208
+ expect { client.reset! }.to raise_error(NoMethodError)
209
+ end
210
+ end
211
+
129
212
  context 'without a token' do
130
213
  let(:client) { described_class.new }
131
214
  it 'results in an API key error', vcr: { cassette_name: 'client/access_denied' } do
132
215
  expect do
133
- client.get '/stock/msft/quote'
216
+ client.get '/stock/msft/quote', token: client.publishable_token
134
217
  end.to raise_error IEX::Errors::PermissionDeniedError, /The API key provided is not valid./
135
218
  end
136
219
  end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ describe IEX::Api::Config::Client do
4
+ before do
5
+ IEX::Api.config.reset!
6
+ end
7
+ describe '#defaults' do
8
+ it 'sets endpoint' do
9
+ expect(IEX::Api.config.endpoint).to eq 'https://cloud.iexapis.com/v1'
10
+ end
11
+ end
12
+ describe '#configure' do
13
+ before do
14
+ IEX::Api.configure do |config|
15
+ config.endpoint = 'updated'
16
+ end
17
+ end
18
+ it 'sets endpoint' do
19
+ expect(IEX::Api.config.endpoint).to eq 'updated'
20
+ end
21
+ end
22
+
23
+ context 'when configuring the logger' do
24
+ after { IEX::Api.configure.logger.reset! }
25
+
26
+ let(:logger) { Logger.new(STDOUT) }
27
+
28
+ describe '#logger=' do
29
+ it 'updates IEX::Api.config correctly' do
30
+ expect do
31
+ IEX::Api.configure { |config| config.logger = logger }
32
+ end.to change(IEX::Api.config.logger, :instance).from(nil).to(logger)
33
+ end
34
+
35
+ it 'updates IEX::Api.logger correctly' do
36
+ expect do
37
+ IEX::Api.configure { |config| config.logger = logger }
38
+ end.to change(IEX::Api.logger, :instance).from(nil).to(logger)
39
+ end
40
+ end
41
+
42
+ describe '#logger' do
43
+ it 'accesses the current logger' do
44
+ expect { IEX::Api.logger = logger }
45
+ .to change(IEX::Api.config.logger, :instance).from(nil).to(logger)
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ describe IEX::Api::Config::Logger do
4
+ after { IEX::Api.logger.reset! }
5
+
6
+ describe '#defaults' do
7
+ it 'sets the default values' do
8
+ expect(IEX::Api.logger.instance).to be_nil
9
+ expect(IEX::Api.logger.options).to eq({})
10
+ expect(IEX::Api.logger.proc).to be_nil
11
+ end
12
+ end
13
+
14
+ describe '#logger' do
15
+ let(:logger_instance) { Logger.new(STDOUT) }
16
+ let(:opts) { { bodies: true } }
17
+ let(:proc_arg) { proc {} }
18
+
19
+ it 'allows setting the instance directly' do
20
+ expect { IEX::Api.logger = logger_instance }
21
+ .to change(IEX::Api::Config::Logger, :instance).to(logger_instance)
22
+ end
23
+
24
+ context 'when configuing' do
25
+ after do
26
+ expect(IEX::Api.logger.instance).to eq(logger_instance)
27
+ expect(IEX::Api.logger.options).to eq(opts)
28
+ expect(IEX::Api.logger.proc).to eq(proc_arg)
29
+ end
30
+
31
+ it 'sets via assignment' do
32
+ IEX::Api.logger.instance = logger_instance
33
+ IEX::Api.logger.options = opts
34
+ IEX::Api.logger.proc = proc_arg
35
+ end
36
+
37
+ it 'sets via block' do
38
+ IEX::Api.logger do |logger|
39
+ logger.instance = logger_instance
40
+ logger.options = opts
41
+ logger.proc = proc_arg
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ describe IEX::Resources::AdvancedStats do
4
+ include_context 'client'
5
+
6
+ context 'general information', vcr: { cassette_name: 'advanced_stats/msft' } do
7
+ subject do
8
+ client.advanced_stats('MSFT')
9
+ end
10
+
11
+ it 'fetches advanced stats' do
12
+ expect(subject.total_cash).to eq 136_527_000_000
13
+ expect(subject.total_cash_dollars).to eq '$136,527,000,000'
14
+ expect(subject.current_debt).to eq 5_905_000_000
15
+ expect(subject.current_debt_dollars).to eq '$5,905,000,000'
16
+ expect(subject.revenue).to eq 143_015_000_000
17
+ expect(subject.revenue_dollars).to eq '$143,015,000,000'
18
+ expect(subject.gross_profit).to eq 96_937_000_000
19
+ expect(subject.gross_profit_dollar).to eq '$96,937,000,000'
20
+ expect(subject.total_revenue).to eq 143_015_000_000
21
+ expect(subject.total_revenue_dollar).to eq '$143,015,000,000'
22
+ expect(subject.ebitda).to eq 65_259_000_000
23
+ expect(subject.ebitda_dollar).to eq '$65,259,000,000'
24
+ expect(subject.revenue_per_share).to eq 18.9
25
+ expect(subject.revenue_per_share_dollars).to eq '$18'
26
+ expect(subject.revenue_per_employee).to eq 877_392.64
27
+ expect(subject.revenue_per_employee_dollar).to eq '$877,392'
28
+ expect(subject.debt_to_equity).to eq 0.69
29
+ expect(subject.profit_margin).to eq 0.3096248645247002
30
+ expect(subject.enterprise_value).to eq 1_607_892_999_000
31
+ expect(subject.enterprise_value_dollar).to eq '$1,607,892,999,000'
32
+ expect(subject.enterprise_value_to_revenue).to eq 11.24
33
+ expect(subject.price_to_sales).to eq 11.62
34
+ expect(subject.price_to_sales_dollar).to eq '$11'
35
+ expect(subject.price_to_book).to eq 13.703188252299162
36
+ expect(subject.forward_pe_ratio).to eq nil
37
+ expect(subject.peg_ratio).to eq 5.6
38
+ expect(subject.pe_high).to eq 40.49739130434783
39
+ expect(subject.week_52_high_date).to eq '2020-09-02'
40
+ expect(subject.pe_low).to eq 23.046956521739133
41
+ expect(subject.week_52_low_date).to eq '2020-03-23'
42
+ end
43
+ end
44
+
45
+ context 'invalid symbol', vcr: { cassette_name: 'advanced_stats/invalid' } do
46
+ subject do
47
+ client.advanced_stats('INVALID')
48
+ end
49
+
50
+ it 'fails with SymbolNotFoundError' do
51
+ expect { subject }.to raise_error IEX::Errors::SymbolNotFoundError, 'Symbol INVALID Not Found'
52
+ end
53
+ end
54
+ end