Skip to content
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

Gimme some sugar? #3

Open
bibliotechy opened this issue Dec 1, 2017 · 1 comment
Open

Gimme some sugar? #3

bibliotechy opened this issue Dec 1, 2017 · 1 comment

Comments

@bibliotechy
Copy link
Contributor

Maybe we can make interacting with this library a little bit sweeter with some convenience methods.

This is a discussion, not a request for changes...yet.

Ideas:
1:
Iterate over response docs from the response object.
If we have a response object
response = Primo.find("otters")
currently we have to navigate to the docs attribute to iterate over the docs
response.docs.each {|d| puts d.title }
Would be simpler to just iterate directly from the response object, and would hide some of the internal details about the object.
response.each {|d| puts d.title }

2: Not so sure about this one
Expose the top level keys of the JSON response in the response object.
Currently we have to go response.response.keys to get the top level structure of the json response, which is ["highlights", "docs", "timelog", "lang3", "info", "facets", "beaconO22"]
I found it useful when trying to understand what data was available in the response to see what else I might want to dig into.

3: Add some convenience methods for number of results, paging, etc.
Instead of response.info.total we just response.total.
Same for response.info.first, response.info.last etc.

@dkinzer
Copy link
Member

dkinzer commented Dec 4, 2017

I like these ideas. Maybe we should also make it an Enumerable if we are defining each anyway.

By the way, we are already defining a "fields" methods that is essentially the "keys" methods. I guess we can alias fields to keys.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants