Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
AllCops:
Exclude:
- vendor/**/*
TargetRubyVersion: 2.4
NewCops: enable
TargetRubyVersion: 2.7

Style/FrozenStringLiteralComment:
Enabled: false
Expand All @@ -16,6 +17,9 @@ Naming/FileName:
Style/Documentation:
Enabled: false

Layout/LineLength:
Comment thread
agrberg marked this conversation as resolved.
Enabled: false

Metrics:
Enabled: false

Expand Down
26 changes: 17 additions & 9 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2022-07-21 13:04:05 -0500 using RuboCop version 0.75.0.
# on 2022-07-21 19:29:23 UTC using RuboCop version 1.32.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 4
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/GlobalStdStream:
Exclude:
- 'lib/iex/logger.rb'
- 'spec/iex/client_spec.rb'
- 'spec/iex/config/client_spec.rb'
- 'spec/iex/config/logger_spec.rb'

# Offense count: 1
# Configuration parameters: AllowedChars.
Style/AsciiComments:
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/HashTransformValues:
Exclude:
- 'lib/iex/resources/quote.rb'
- 'lib/iex/endpoints/ohlc.rb'

# Offense count: 2
# Configuration parameters: EnforcedStyle.
# SupportedStyles: annotated, template, unannotated
Style/FormatStringToken:
# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/MapToHash:
Exclude:
- 'lib/iex/resources/resource.rb'
- 'lib/iex/endpoints/ohlc.rb'
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* [#111](https://github.com/dblock/iex-ruby-client/pull/111): Added `Symbols#exchange_suffix`, `exchange_name`, `exchange_segment`, `exchange_segment_name`, and `lei` - [@mathu97](https://github.com/mathu97).
* [#113](https://github.com/dblock/iex-ruby-client/pull/113): Explicitly require Ruby >= 2.4 - [@agrberg](https://github.com/agrberg).
* [#113](https://github.com/dblock/iex-ruby-client/pull/113): Remove default SSL options for `ca_file` and `ca_path` - [@agrberg](https://github.com/agrberg).
* [#114](https://github.com/dblock/iex-ruby-client/pull/114): Update to minimum supported Ruby >= 2.7 - [@agrberg](https://github.com/agrberg).
* Your contribution here.

### 1.6.0 (2021/10/17)
Expand Down
2 changes: 1 addition & 1 deletion UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Upgrading iex-ruby-client

### Upgrading to >= 2.0.0

[#113](https://github.com/dblock/iex-ruby-client/pull/113) Minimum Ruby version is 2.4
[#114](https://github.com/dblock/iex-ruby-client/pull/114) Require maintained Ruby version >= 2.7

[#113](https://github.com/dblock/iex-ruby-client/pull/113) Removes default values for Faraday's SSL settings `ca_file` and `ca_path`.

Expand Down
16 changes: 8 additions & 8 deletions iex-ruby-client.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ Gem::Specification.new do |s|
s.authors = ['Daniel Doubrovkine']
s.email = 'dblock@dblock.org'
s.platform = Gem::Platform::RUBY
s.required_rubygems_version = '>= 1.3.6'
s.required_ruby_version = '>= 2.4.0'
s.required_rubygems_version = '>= 3.0'
s.required_ruby_version = '>= 2.7'
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- spec/*`.split("\n")
Comment thread
dblock marked this conversation as resolved.
s.require_paths = ['lib']
s.homepage = 'http://github.com/dblock/iex-ruby-client'
s.licenses = ['MIT']
Expand All @@ -20,9 +19,10 @@ Gem::Specification.new do |s|
s.add_dependency 'faraday_middleware'
s.add_dependency 'hashie'
s.add_dependency 'money', '~> 6.0'
s.add_development_dependency 'rake', '~> 10'
s.add_development_dependency 'rspec'
s.add_development_dependency 'rubocop', '0.75.0'
s.add_development_dependency 'vcr'
s.add_development_dependency 'webmock'
s.add_development_dependency 'rake', '~> 13.0'
s.add_development_dependency 'rspec', '~> 3.11'
s.add_development_dependency 'rubocop', '~> 1.32'
s.add_development_dependency 'vcr', '~> 6.1'
s.add_development_dependency 'webmock', '~> 3.14'
s.metadata['rubygems_mfa_required'] = 'true'
end
4 changes: 2 additions & 2 deletions lib/iex/api/config/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class << self

def reset!
self.endpoint = 'https://cloud.iexapis.com/v1'
self.publishable_token = ENV['IEX_API_PUBLISHABLE_TOKEN']
self.secret_token = ENV['IEX_API_SECRET_TOKEN']
self.publishable_token = ENV.fetch('IEX_API_PUBLISHABLE_TOKEN', nil)
self.secret_token = ENV.fetch('IEX_API_SECRET_TOKEN', nil)
self.user_agent = "IEX Ruby Client/#{IEX::VERSION}"

self.ca_file = nil
Expand Down
3 changes: 2 additions & 1 deletion lib/iex/endpoints/advanced_stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ module IEX
module Endpoints
module AdvancedStats
def advanced_stats(symbol, options = {})
IEX::Resources::AdvancedStats.new(get("stock/#{symbol}/advanced-stats", { token: publishable_token }.merge(options)))
IEX::Resources::AdvancedStats.new(get("stock/#{symbol}/advanced-stats",
{ token: publishable_token }.merge(options)))
rescue Faraday::ResourceNotFound => e
raise IEX::Errors::SymbolNotFoundError.new(symbol, e.response[:body])
end
Expand Down
3 changes: 2 additions & 1 deletion lib/iex/endpoints/balance_sheet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ module IEX
module Endpoints
module BalanceSheet
def balance_sheet(symbol, options = {})
(get("stock/#{symbol}/balance-sheet", { token: publishable_token }.merge(options))['balancesheet'] || []).map do |data|
(get("stock/#{symbol}/balance-sheet",
{ token: publishable_token }.merge(options))['balancesheet'] || []).map do |data|
IEX::Resources::BalanceSheet.new(data)
end
rescue Faraday::ResourceNotFound => e
Expand Down
4 changes: 2 additions & 2 deletions lib/iex/endpoints/ohlc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ def ohlc(symbol, options = {})
end

def market(options = {})
Hash[get('stock/market/ohlc', { token: publishable_token }.merge(options)).map do |k, v|
get('stock/market/ohlc', { token: publishable_token }.merge(options)).map do |k, v|
[k, IEX::Resources::OHLC.new(v)]
end]
end.to_h
end
end
end
Expand Down
3 changes: 1 addition & 2 deletions lib/iex/errors/invalid_symbols_list.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
module IEX
module Errors
class InvalidSymbolsList < StandardError
attr_reader :symbols
attr_reader :response
attr_reader :symbols, :response

def initialize(symbols, response)
@response = response
Expand Down
3 changes: 1 addition & 2 deletions lib/iex/errors/symbol_not_found_error.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
module IEX
module Errors
class SymbolNotFoundError < StandardError
attr_reader :symbol
attr_reader :response
attr_reader :symbol, :response

def initialize(symbol, response)
@response = response
Expand Down
12 changes: 9 additions & 3 deletions lib/iex/resources/advanced_stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,17 @@ class AdvancedStats < Resource
property 'market_cap', from: 'marketcap'
property 'market_cap_dollar', from: 'marketcap', with: ->(v) { Resource.to_dollar(amount: v) }
property 'week_52_high', from: 'week52high'
property 'week_52_high_dollar', from: 'week52high', with: ->(v) { Resource.to_dollar(amount: v, ignore_cents: false) }
property 'week_52_high_dollar', from: 'week52high', with: lambda { |v|
Resource.to_dollar(amount: v, ignore_cents: false)
}
property 'week_52_low', from: 'week52low'
property 'week_52_low_dollar', from: 'week52low', with: ->(v) { Resource.to_dollar(amount: v, ignore_cents: false) }
property 'week_52_low_dollar', from: 'week52low', with: lambda { |v|
Resource.to_dollar(amount: v, ignore_cents: false)
}
property 'week_52_change', from: 'week52change'
property 'week_52_change_dollar', from: 'week52change', with: ->(v) { Resource.to_dollar(amount: v, ignore_cents: false) }
property 'week_52_change_dollar', from: 'week52change', with: lambda { |v|
Resource.to_dollar(amount: v, ignore_cents: false)
}
property 'dividend_yield', from: 'dividendYield'
property 'ex_dividend_date', from: 'exDividendDate'
property 'shares_outstanding', from: 'sharesOutstanding'
Expand Down
8 changes: 6 additions & 2 deletions lib/iex/resources/cash_flow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@ class CashFlow < Resource
property 'investing_activity_other', from: 'investingActivityOther'
property 'investing_activity_other_dollar', from: 'investingActivityOther', with: ->(v) { to_dollar(amount: v) }
property 'total_investing_cash_flows', from: 'totalInvestingCashFlows'
property 'total_investing_cash_flows_dollar', from: 'totalInvestingCashFlows', with: ->(v) { to_dollar(amount: v) }
property 'total_investing_cash_flows_dollar', from: 'totalInvestingCashFlows', with: lambda { |v|
to_dollar(amount: v)
}
property 'dividends_paid', from: 'dividendsPaid'
property 'dividends_paid_dollar', from: 'dividendsPaid', with: ->(v) { to_dollar(amount: v) }
property 'net_borrowings', from: 'netBorrowings'
property 'net_borrowings_dollar', from: 'netBorrowings', with: ->(v) { to_dollar(amount: v) }
property 'other_financing_cash_flows', from: 'otherFinancingCashFlows'
property 'other_financing_cash_flows_dollar', from: 'otherFinancingCashFlows', with: ->(v) { to_dollar(amount: v) }
property 'other_financing_cash_flows_dollar', from: 'otherFinancingCashFlows', with: lambda { |v|
to_dollar(amount: v)
}
property 'cash_flow_financing', from: 'cashFlowFinancing'
property 'cash_flow_financing_dollar', from: 'cashFlowFinancing', with: ->(v) { to_dollar(amount: v) }
property 'exchange_rate_effect', from: 'exchangeRateEffect'
Expand Down
4 changes: 3 additions & 1 deletion lib/iex/resources/earnings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ class Earnings < Resource
property 'fiscal_end_date', from: 'fiscalEndDate'
property 'year_ago', from: 'yearAgo'
property 'year_ago_change_percent', from: 'yearAgoChangePercent'
property 'year_ago_change_percent_s', from: 'yearAgoChangePercent', with: ->(v) { Resource.float_to_percentage(v) }
property 'year_ago_change_percent_s', from: 'yearAgoChangePercent', with: lambda { |v|
Resource.float_to_percentage(v)
}
end
end
end
12 changes: 9 additions & 3 deletions lib/iex/resources/key_stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@ class KeyStats < Resource
property 'market_cap', from: 'marketcap'
property 'market_cap_dollar', from: 'marketcap', with: ->(v) { Resource.to_dollar(amount: v) }
property 'week_52_high', from: 'week52high'
property 'week_52_high_dollar', from: 'week52high', with: ->(v) { Resource.to_dollar(amount: v, ignore_cents: false) }
property 'week_52_high_dollar', from: 'week52high', with: lambda { |v|
Resource.to_dollar(amount: v, ignore_cents: false)
}
property 'week_52_low', from: 'week52low'
property 'week_52_low_dollar', from: 'week52low', with: ->(v) { Resource.to_dollar(amount: v, ignore_cents: false) }
property 'week_52_low_dollar', from: 'week52low', with: lambda { |v|
Resource.to_dollar(amount: v, ignore_cents: false)
}
property 'week_52_change', from: 'week52change'
property 'week_52_change_dollar', from: 'week52change', with: ->(v) { Resource.to_dollar(amount: v, ignore_cents: false) }
property 'week_52_change_dollar', from: 'week52change', with: lambda { |v|
Resource.to_dollar(amount: v, ignore_cents: false)
}
property 'dividend_yield', from: 'dividendYield'
property 'ex_dividend_date', from: 'exDividendDate'
property 'shares_outstanding', from: 'sharesOutstanding'
Expand Down
8 changes: 6 additions & 2 deletions lib/iex/resources/quote.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ class Quote < Resource
property 'latest_source', from: 'latestSource' # the source of latestPrice - IEX real time price, 15 minute delayed price, Close or Previous close
property 'latest_time', from: 'latestTime' # human readable time of the latestPrice
property 'latest_update', from: 'latestUpdate' # the update time of latestPrice in milliseconds since midnight Jan 1, 1970
property 'latest_update_t', from: 'latestUpdate', with: ->(v) { v&.positive? ? Time.at(v / 1000) : nil } # the update time of latestPrice
property 'latest_update_t', from: 'latestUpdate', with: lambda { |v|
v&.positive? ? Time.at(v / 1000) : nil
} # the update time of latestPrice
property 'latest_volume', from: 'latestVolume' # the total market volume of the stock
property 'iex_realtime_price', from: 'iexRealtimePrice' # last sale price of the stock on IEX
property 'iex_realtime_size', from: 'iexRealtimeSize' # last sale size of the stock on IEX
property 'iex_last_updated', from: 'iexLastUpdated' # last update time of the data in milliseconds since midnight Jan 1, 1970 UTC or -1 or 0; if the value is -1 or 0, IEX has not quoted the symbol in the trading day
property 'iex_last_updated_t', from: 'iexLastUpdated', with: ->(v) { v&.positive? ? Time.at(v / 1000) : nil } # last update time of the data
property 'iex_last_updated_t', from: 'iexLastUpdated', with: lambda { |v|
v&.positive? ? Time.at(v / 1000) : nil
} # last update time of the data
property 'delayed_price', from: 'delayedPrice' # 15 minute delayed market price
property 'delayed_price_time', from: 'delayedPriceTime' # time of the delayed market price
property 'extended_price', from: 'extendedPrice' # the pre market and post market price
Expand Down
8 changes: 4 additions & 4 deletions spec/iex/endpoints/key_stat_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@

it 'keeps the API response so it can be used if caught' do
response = begin
subject
rescue IEX::Errors::StatNotFoundError => e
e.response
end
subject
rescue IEX::Errors::StatNotFoundError => e
e.response
end

expect(response).to be_a(Hash)
expect(response).to have_key(stat)
Expand Down
4 changes: 2 additions & 2 deletions spec/support/vcr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
# config.default_cassette_options = { record: :new_episodes }
config.configure_rspec_metadata!

config.filter_sensitive_data('test-iex-api-publishable-token') { ENV['IEX_API_PUBLISHABLE_TOKEN'] }
config.filter_sensitive_data('test-iex-api-secret-token') { ENV['IEX_API_SECRET_TOKEN'] }
config.filter_sensitive_data('test-iex-api-publishable-token') { ENV.fetch('IEX_API_PUBLISHABLE_TOKEN', nil) }
config.filter_sensitive_data('test-iex-api-secret-token') { ENV.fetch('IEX_API_SECRET_TOKEN', nil) }
end