unsplash_rb icon indicating copy to clipboard operation
unsplash_rb copied to clipboard

Style update and DRY-up

Open dvisockas opened this issue 4 years ago • 2 comments

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 to Klass.new(args) style

  • Implements get_json into connection class to dry out pattern of writing JSON.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.

dvisockas avatar Apr 03 '20 10:04 dvisockas

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?

aaronklaassen avatar Apr 03 '20 17:04 aaronklaassen

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?

dvisockas avatar Apr 04 '20 07:04 dvisockas