unsplash_rb
unsplash_rb copied to clipboard
Style update and DRY-up
Hello,
Was indenting to use your API gem, started reading the source and thought that I could help to dry it up and update the style.
This PR does two things:
-
Mainly changes double-quotes to single when possible and changes
Klass.new args
toKlass.new(args)
style -
Implements
get_json
intoconnection
class to dry out pattern of writingJSON.parse(connection.get(path, params).body)
throughout the library.
If you have certain style-guide that is against using single-quote string literals or are against the get_json
- will be waiting for your feedback.
We will definitely stick with the double quotes. There's no reason to prefer singles.
As for the get_json
, I'm not opposed to DRYing up the codebase but if you've gone this far would it not work to just add a JSON.parse(response.body)
at the end of Connection#request
?
Got it about the quotes.
Re DRYing - JSON.parse(response.body)
is used a lot, but not in all cases. There are few ones where the original response is kept to check the status. Maybe to cover that Connection#request
could have a named agument parse_json_body
that would default to true and could be passed as false in few places that need that?