Skip to content

Instantly share code, notes, and snippets.

@rickcolosimo
Forked from bswinnerton/figuring_out_apis.rb
Created September 20, 2013 01:47
Show Gist options
  • Save rickcolosimo/6632334 to your computer and use it in GitHub Desktop.
Save rickcolosimo/6632334 to your computer and use it in GitHub Desktop.
require 'rest-client'
require 'json'
starting_url = "http://www.reddit.com/.json"
response = RestClient.get(starting_url)
parsed_response = JSON.load(response)
# now you can manipulate parsed_response and see all of the attributes and drill down to see where the things that you want are. Here is what we did:
parsed_response["data"]["children"].first["data"]["title"]
# and if you wanted to convert that to a loop:
parsed_response["data"]["children"].map do |reddit|
reddit["data"]["title"]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment