Skip to content

Instantly share code, notes, and snippets.

@mecampbellsoup
Created July 31, 2013 16:32
Show Gist options
  • Save mecampbellsoup/6123659 to your computer and use it in GitHub Desktop.
Save mecampbellsoup/6123659 to your computer and use it in GitHub Desktop.
surprising result - was hoping the with_index would allow me give each subreddit an :id without persisting to database
require 'rest_client'
require 'pry'
require 'json'
def get_subreddits
parsed_response = JSON.load(RestClient.get("http://reddit.com/reddits.json"))
parsed_response["data"]["children"].each_with_index do |subreddit,i|
{ subreddit: subreddit["data"]["url"], image: subreddit["data"]["header_img"], name: subreddit["data"]["display_name"], id: i }
end
end
p get_subreddits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment