diff --git a/.rubocop.yml b/.rubocop.yml index b62cf20..1810bd7 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,7 +1,8 @@ AllCops: Exclude: - vendor/**/* - TargetRubyVersion: 2.4 + NewCops: enable + TargetRubyVersion: 2.7 Style/FrozenStringLiteralComment: Enabled: false @@ -16,6 +17,9 @@ Naming/FileName: Style/Documentation: Enabled: false +Layout/LineLength: + Enabled: false + Metrics: Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index d215ec2..0504e70 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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' diff --git a/CHANGELOG.md b/CHANGELOG.md index c098c06..a63c0eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/UPGRADING.md b/UPGRADING.md index 279c637..6fa42fe 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -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`. diff --git a/iex-ruby-client.gemspec b/iex-ruby-client.gemspec index 8679f1a..2455074 100644 --- a/iex-ruby-client.gemspec +++ b/iex-ruby-client.gemspec @@ -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") s.require_paths = ['lib'] s.homepage = 'http://github.com/dblock/iex-ruby-client' s.licenses = ['MIT'] @@ -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 diff --git a/lib/iex/api/config/client.rb b/lib/iex/api/config/client.rb index 2daede9..6064843 100644 --- a/lib/iex/api/config/client.rb +++ b/lib/iex/api/config/client.rb @@ -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 diff --git a/lib/iex/endpoints/advanced_stats.rb b/lib/iex/endpoints/advanced_stats.rb index c18000e..1ee5e12 100644 --- a/lib/iex/endpoints/advanced_stats.rb +++ b/lib/iex/endpoints/advanced_stats.rb @@ -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 diff --git a/lib/iex/endpoints/balance_sheet.rb b/lib/iex/endpoints/balance_sheet.rb index 498b2e9..823aa1a 100644 --- a/lib/iex/endpoints/balance_sheet.rb +++ b/lib/iex/endpoints/balance_sheet.rb @@ -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 diff --git a/lib/iex/endpoints/ohlc.rb b/lib/iex/endpoints/ohlc.rb index 22ca192..570a9cf 100644 --- a/lib/iex/endpoints/ohlc.rb +++ b/lib/iex/endpoints/ohlc.rb @@ -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 diff --git a/lib/iex/errors/invalid_symbols_list.rb b/lib/iex/errors/invalid_symbols_list.rb index aec4e7e..6939704 100644 --- a/lib/iex/errors/invalid_symbols_list.rb +++ b/lib/iex/errors/invalid_symbols_list.rb @@ -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 diff --git a/lib/iex/errors/symbol_not_found_error.rb b/lib/iex/errors/symbol_not_found_error.rb index 60bc234..a50955e 100644 --- a/lib/iex/errors/symbol_not_found_error.rb +++ b/lib/iex/errors/symbol_not_found_error.rb @@ -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 diff --git a/lib/iex/resources/advanced_stats.rb b/lib/iex/resources/advanced_stats.rb index 30c43ba..bc0a9af 100644 --- a/lib/iex/resources/advanced_stats.rb +++ b/lib/iex/resources/advanced_stats.rb @@ -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' diff --git a/lib/iex/resources/cash_flow.rb b/lib/iex/resources/cash_flow.rb index 05153c9..ddfedce 100644 --- a/lib/iex/resources/cash_flow.rb +++ b/lib/iex/resources/cash_flow.rb @@ -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' diff --git a/lib/iex/resources/earnings.rb b/lib/iex/resources/earnings.rb index 1a4fb54..3d10238 100644 --- a/lib/iex/resources/earnings.rb +++ b/lib/iex/resources/earnings.rb @@ -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 diff --git a/lib/iex/resources/key_stats.rb b/lib/iex/resources/key_stats.rb index e1d2fe8..a276f1d 100644 --- a/lib/iex/resources/key_stats.rb +++ b/lib/iex/resources/key_stats.rb @@ -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' diff --git a/lib/iex/resources/quote.rb b/lib/iex/resources/quote.rb index 6276af7..22e001f 100644 --- a/lib/iex/resources/quote.rb +++ b/lib/iex/resources/quote.rb @@ -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 diff --git a/spec/iex/endpoints/key_stat_spec.rb b/spec/iex/endpoints/key_stat_spec.rb index 309339b..6e183db 100644 --- a/spec/iex/endpoints/key_stat_spec.rb +++ b/spec/iex/endpoints/key_stat_spec.rb @@ -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) diff --git a/spec/support/vcr.rb b/spec/support/vcr.rb index fa44949..dff947b 100644 --- a/spec/support/vcr.rb +++ b/spec/support/vcr.rb @@ -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