-
Notifications
You must be signed in to change notification settings - Fork 3
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
Response class? #8
Comments
@mfenner What is best practice in Ruby with respect to this question? From your point of view, would you rather get back the raw |
See my utility class here: https://github.com/lagotto/lagotto/blob/master/app/models/concerns/networkable.rb. The tricky bit is error handling, as you want to catch them and give a meaningful message back to the user. I use response.body and parse the JSON (or XML) if there is no error. |
In other words, if there is no error you probably are only interested in response.body. |
My utility class for DOIs is here: https://github.com/lagotto/lagotto/blob/master/app/models/concerns/resolvable.rb |
Thanks. Right, that is a lot of work for error handling |
You can probably get away with less. But I collected this over time. A simpler version is at https://github.com/crosscite/doi-metadata-search/blob/master/lib/network.rb |
Given cursor for paging in the API #14 I think it makes sense to have a class for the response object so that we can maintain state, esp since this cursor approach to paging is esp not very easy for a user to handle manually |
Would still be nice to return a hash by default if no errors since users can easily process that as needed |
yes, I like hash as standard response, with an |
data is a good idea, haven't had to do that so far as no internal paing, but once that's used, will need to do that when combining results |
haven't thought much about it, but would be interesting to see how much you can propagate API conventions into the processing of the response. |
Good idea. will think about that |
will need to create a class for maintaining state for using cursor, see #14 , but can still just return hash/array |
closing for now, returning hash/array |
Make a new response class to hold results? Or stick with
Faraday::Response
object? Benefits of a new class is full control, but sticking with theFaraday::Response
builds on all the hard work done already on that gemThe text was updated successfully, but these errors were encountered: