Skip to content

Commit

Permalink
Fix income endpoint if the API returns no result (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
brunjo authored Feb 1, 2020
1 parent 0a648d0 commit fa1f2a3
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 49 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### 1.1.1 (Next)

* Your contribution here.
* [#61](https://github.com/dblock/iex-ruby-client/pull/61): Fix income endpoint if the api returns no result - [@brunjo](https://github.com/brunjo).
* [#57](https://github.com/dblock/iex-ruby-client/pull/57): Update properties for chart api endpoint - [@brunjo](https://github.com/brunjo).

### 1.1.0 (2019/07/08)
Expand Down
2 changes: 1 addition & 1 deletion lib/iex/endpoints/income.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module IEX
module Endpoints
module Income
def income(symbol, options = {})
get("stock/#{symbol}/income", options)['income'].map do |data|
(get("stock/#{symbol}/income", options)['income'] || []).map do |data|
IEX::Resources::Income.new(data)
end
rescue Faraday::ResourceNotFound => e
Expand Down
94 changes: 47 additions & 47 deletions spec/fixtures/iex/income/invalid.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions spec/fixtures/iex/income/nsrgy.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion spec/iex/endpoints/income_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,18 @@
end
end

context 'no result', vcr: { cassette_name: 'income/nsrgy' } do
subject do
client.income('nsrgy')
end
it 'returns empty array' do
expect(subject).to eq []
end
end

context 'invalid symbol', vcr: { cassette_name: 'income/invalid' } do
subject do
client.earnings('INVALID')
client.income('INVALID')
end
it 'fails with SymbolNotFoundError' do
expect { subject }.to raise_error IEX::Errors::SymbolNotFoundError, 'Symbol INVALID Not Found'
Expand Down

0 comments on commit fa1f2a3

Please sign in to comment.