mardi 5 mai 2015

Rails: Tips for parsing JSON [on hold]

I'm relatively new to rails. Was curious if I'm parsing JSON the 'right/best' way. So I'm trying to get a list of subreddits from Reddit so I used the subreddits JSON from Reddit.

Here is what I first did to convert the JSON to hash -

require 'open-uri'

hash = JSON.load(open('http://ift.tt/1k5Yusm'));

I then, got the list display_name (subreddit names) from my hash the following way -

subreddit_arr = hash["data"]["children"].map { |c| c["data"]["display_name"]}

which gave me -

["funny", "pics", "AdviceAnimals", "aww", "todayilearned", "videos", "gaming", "gifs", "BlackPeopleTwitter", "WTF", "fatpeoplehate", "leagueoflegends", "AskReddit", "pcmasterrace", "me_irl", "worldnews", "news", "Showerthoughts", "DotA2", "4chan", "mildlyinteresting", "TrollXChromosomes", "nba", "politics", "trees"]

How can I get a list of all subreddits (not just 25) in the most efficient manner?

Aucun commentaire:

Enregistrer un commentaire