-
-
Notifications
You must be signed in to change notification settings - Fork 60
Add Search endpoint #58
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
base: master
Are you sure you want to change the base?
Conversation
Generated by 🚫 Danger |
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 hadn't used VCR before... thanks for the introduction! it is a fantastic tool for writing specs!
@@ -1,14 +1,27 @@ | |||
module IEX | |||
module Errors | |||
class SymbolNotFoundError < StandardError | |||
attr_reader :symbol | |||
class IexError < StandardError |
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.
added an Error superclass to allow for other projects to:
rescue IEX::Errors::IexError
instead of having to:
rescue IEX::Errors::SymbolNotFoundError, IEX::Errors::SearchNotFoundError, ... # as more errors are added
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.
tbh, I hadn't realized there were other errors defined (I thought I was creating the second one). If I had, I probably would have put this into a separate PR. sorry for the confusion!
spec/iex/client_spec.rb
Outdated
@@ -135,4 +135,36 @@ | |||
end | |||
end | |||
end | |||
|
|||
context '#search' 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.
tests for this endpoint were added to client_spect.rb
because other endpoints have associated resources, where #search
(eventually, according to the documentation) returns any type of resource.
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.
Make a directory, search
and create search/quote_spec.rb
and such? For the general use case of errors make a search_spec.rb
.
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 great and is on the right track! See comments. Also needs README documentation.
http_interactions: | ||
- request: | ||
method: get | ||
uri: https://sandbox.iexapis.com/v1/search/?token=Tsk_341c973d296e4e18aa61dd63050ce235 |
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.
Remove your actual token from here.
spec/iex/client_spec.rb
Outdated
@@ -135,4 +135,36 @@ | |||
end | |||
end | |||
end | |||
|
|||
context '#search' 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.
Make a directory, search
and create search/quote_spec.rb
and such? For the general use case of errors make a search_spec.rb
.
spec/iex/client_spec.rb
Outdated
# order for VCR to record the response, we need the endpoint to work | ||
client.endpoint = 'https://sandbox.iexapis.com/v1' | ||
# using the documentation-provided token | ||
client.publishable_token = 'Tsk_341c973d296e4e18aa61dd63050ce235' |
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.
We default this to token
and replace it everywhere for tests, as they are run from a recording. Don't leak your tokens!
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 particular endpoint is not available to free tier accounts (the plan I'm on!), so I had to update the endpoint to the sandbox, where of course, different keys are needed. the token in this code is copy/pasted from the iexcloud docs, so it's already publicly exposed!
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.
Is it that they have it in sandbox but not in production yet? In which case you can manually remove the sandbox part from tests and edit VCRs once you have a working recording.
'search', | ||
fragment | ||
].compact.join('/'), options).map do |data| | ||
# Per the IEX documentation, any type of Resource could be returned |
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.
Yes, please. And create a base resource for anything unsupported.
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.
fyi, they have not released this feature yet, the docs just mention that it is coming
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 don't see a problem supporting something in pre-release, but we have to say it in README and point to whatever IEX docs that say the same
The code here looks good. You still need to remove your actual secret token from everywhere! |
Also add a comment when this is ready to re-review, commits don't get flagged in notifications. |
Bump @pmn4, want to finish this? |
@dblock there are a few items here:
do these make sense? sorry for the confusion, and the delay! (tbh, I was only evaluating IEX when I authored this PR, and have since switched gears to another provider.) |
ok
you just don't want the real token in this PR because someone will steal it; once a recording was made you can just replace it with a placeholder |
I'll leave this open for someone/you to finish it. |
This PR adds the "Search" endpoint. Search doesn't quite fit the Resourceful pattern, so I put the tests in
client_spec.rb
. Happy to move them if you'd prefer them to be in their own file (I just felt strange because there is no resource to use indescribe <Resource>
).I also added a new Error class, and to allow for better rescuing, created an error superclass for the gem. Also happy to revert if it doesn't feel right.