Skip to content

Instantly share code, notes, and snippets.

@progapandist
Created December 16, 2016 14:30
Show Gist options
  • Save progapandist/98062626ccb501dba1456347f32c8c13 to your computer and use it in GitHub Desktop.
Save progapandist/98062626ccb501dba1456347f32c8c13 to your computer and use it in GitHub Desktop.
def get_parsed_response(url, query)
# Use HTTParty gem to make a get request
response = HTTParty.get(url + query)
# Parse the resulting JSON so it's now a Ruby Hash
parsed = JSON.parse(response.body)
# Return nil if we got no results from the API.
parsed['status'] != 'ZERO_RESULTS' ? parsed : nil
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment