Last active
August 29, 2015 13:56
-
-
Save negamorgan/9093628 to your computer and use it in GitHub Desktop.
Create array of reddit front page posts; no type data included
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'json' | |
require 'rest-client' | |
r = JSON.parse(RestClient.get('http://reddit.com/.json')) | |
p = r["data"]["children"] | |
posts_array = p.collect { |post| post["data"] } | |
# posts_array is an array of post hashes | |
# you can iterate over posts_array or do posts_array[0]["url"] | |
posts_array.each do |p| | |
puts "#{p['title']}: #{p['permalink']}" | |
end | |
# key glossary | |
posts_array[0]["title"] #=> post title | |
posts_array[0]["permalink"] #=> post permalink | |
posts_array[0]["url"] #=> post reference URL (link out) | |
posts_array[0]["ups"] #=> post upvote count | |
posts_array[0]["downs"] #=> post downvote count | |
posts_array[0]["thumbnail"] #=> post thumbnail |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You are da bomb.