-
-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support to fetch a single key stat #106
Conversation
I definitely prefer the former because the latter is an API change, and we should only do this very carefully. Options is exactly designed for those ... optional options :) Next, the result of this is a single value? Should we just add a |
🤔 that's a great question. There's no reason that because IEX's API groups a single stat as a special case of all basic stats that the client need to do the same. I think having a
|
b7fd82d
to
3c8f4f1
Compare
spec/iex/endpoints/key_stat_spec.rb
Outdated
context 'invalid stat', vcr: { cassette_name: 'key_stat/invalid_stat' } do | ||
subject { client.key_stat(symbol, 'INVALID') } | ||
|
||
it 'returns a hash of the API response' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a weird API. So if you specify something invalid it fails silently and returns the whole stats object? That's just bad design - I don't expect an API to succeed and return a different type of object. Shall we have the client raise a specialized exception in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't either 🤷 I originally wrote the test to raise an error but was surprised when the test failed because the request "succeeded." I'm in favor of straight forward APIs w/ little nuance so an exception would be good here.
CHANGELOG.md
Outdated
@@ -1,5 +1,6 @@ | |||
### 1.4.2 (Next) | |||
* [#105](https://github.com/dblock/iex-ruby-client/pull/105): Added support for fetching latest foreign exchange rates - [@mathu97](https://github.com/mathu97). | |||
* [#106](https://github.com/dblock/iex-ruby-client/pull/106): Added support for fetching a single key stat in `key_stat(symbol, stat)` endpoint - [@agrberg](https://github.com/agrberg). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically in
-> with
:)
3c8f4f1
to
cb97bc8
Compare
Rebased and updated ☝️ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last question. This looks good.
module KeyStat | ||
def key_stat(symbol, stat, options = {}) | ||
result = get("stock/#{symbol}/stats/#{stat}", { token: publishable_token }.merge(options)) | ||
raise IEX::Errors::StatNotFoundError.new(stat, result) if result.is_a?(Hash) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be unless result.is_a?(Number)
or similar?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't able to find an exhaustive list of types IEX currently returns. From experience I know it can return numbers, strings (for strings and dates), and booleans. Testing for one type I know indicates an invalid stat is simpler and more permissive of future changes with IEX's API. 😅 For all I know IEX will return some stat as a tuple encoded as an array and someone would have a bad day debugging because the requested stat is valid.
Merged. Thanks! |
happy to give back 💪 |
Maybe time to cut a release? |
Good idea. Just launched v 1.5.0 w/ the new endpoint 🎉 |
Alternatives I considered:
Keep the method signature the same and supplying the stat in the
options
hashWrap the single stat in a
IEX::Resources::KeyStats
instanceThis would keep the return type the same and with
nil
being provided for any of the other stats. E.g.:Let me know what you think!