Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add Search endpoint #58

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add Search endpoint #58

wants to merge 1 commit into from

Conversation

pmn4
Copy link

@pmn4 pmn4 commented Nov 27, 2019

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 in describe <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.

@dangerpr-bot
Copy link

dangerpr-bot commented Nov 27, 2019

1 Warning
⚠️ [DEPRECATION] check is deprecated. Please use check! instead.

Generated by 🚫 Danger

Copy link
Author

@pmn4 pmn4 left a 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
Copy link
Author

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

Copy link
Author

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!

@@ -135,4 +135,36 @@
end
end
end

context '#search' do
Copy link
Author

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.

Copy link
Owner

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.

Copy link
Owner

@dblock dblock left a 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.

CHANGELOG.md Outdated Show resolved Hide resolved
lib/iex/endpoints/search.rb Outdated Show resolved Hide resolved
lib/iex/errors/symbol_not_found_error.rb Outdated Show resolved Hide resolved
http_interactions:
- request:
method: get
uri: https://sandbox.iexapis.com/v1/search/?token=Tsk_341c973d296e4e18aa61dd63050ce235
Copy link
Owner

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.

@@ -135,4 +135,36 @@
end
end
end

context '#search' do
Copy link
Owner

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.

# 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'
Copy link
Owner

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!

Copy link
Author

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!

Copy link
Owner

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.

spec/iex/client_spec.rb Outdated Show resolved Hide resolved
'search',
fragment
].compact.join('/'), options).map do |data|
# Per the IEX documentation, any type of Resource could be returned
Copy link
Owner

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.

Copy link
Author

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

Copy link
Owner

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

@dblock
Copy link
Owner

dblock commented Jan 6, 2020

The code here looks good. You still need to remove your actual secret token from everywhere!

@dblock
Copy link
Owner

dblock commented Jan 6, 2020

Also add a comment when this is ready to re-review, commits don't get flagged in notifications.

@dblock
Copy link
Owner

dblock commented Feb 1, 2020

Bump @pmn4, want to finish this?

@pmn4
Copy link
Author

pmn4 commented Feb 3, 2020

@dblock there are a few items here:

  1. Resource Type: I introduced some confusion with the search results "Resource Type." IEX has not yet launched this feature, so there is nothing to support, or even details about how to support it. The documentation says it's coming, so I left a comment mentioning that it is coming.

  2. Tokens: the token in this PR is copy/pasted from IEX's documentation (it is their sandbox API key). I used it because the search endpoint is a paid feature, for which I do not have an API key. Instead, for this one test case, I updated both the endpoint and API key to point to the sandbox environment, so if we need to recreate the VCR response, we can without having to pay.

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.)

@dblock
Copy link
Owner

dblock commented Feb 4, 2020

@dblock there are a few items here:

  1. Resource Type: I introduced some confusion with the search results "Resource Type." IEX has not yet launched this feature, so there is nothing to support, or even details about how to support it. The documentation says it's coming, so I left a comment mentioning that it is coming.

ok

  1. Tokens: the token in this PR is copy/pasted from IEX's documentation (it is their sandbox API key). I used it because the search endpoint is a paid feature, for which I do not have an API key. Instead, for this one test case, I updated both the endpoint and API key to point to the sandbox environment, so if we need to recreate the VCR response, we can without having to pay.

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

@dblock
Copy link
Owner

dblock commented Feb 4, 2020

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.)

I'll leave this open for someone/you to finish it.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants