Skip to content

Instantly share code, notes, and snippets.

@davidbella
Created October 2, 2013 14:04
Show Gist options
  • Save davidbella/6794313 to your computer and use it in GitHub Desktop.
Save davidbella/6794313 to your computer and use it in GitHub Desktop.
Ruby: Reddit API and HTML output
require 'json'
require 'rest_client'
reddit_hash = JSON.parse(RestClient.get('http://reddit.com/.json'))
reddit_hash["data"]["children"].select! { |story| story["data"]["subreddit"] != "gaming" }
puts "<html>"
puts "<head>"
puts "</head>"
puts "<body>"
puts "<ul>"
reddit_hash["data"]["children"].each do |story|
puts "<li>"
puts "<a href=\"#{story["data"]["url"]}\">"
puts "<h1>#{story["data"]["title"]}</h1>"
puts "<img src=\"#{story["data"]["thumbnail"]}\" />"
puts "<h4>Upvotes:</p>"
puts "<p>#{story["data"]["ups"]}</h4>"
puts "<p>Downvotes:</p>"
puts "<h4>#{story["data"]["downs"]}</h4>"
puts "</a>"
puts "</li>"
end
puts "</ul>"
puts "</body>"
puts "</html>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment