Skip to content

Instantly share code, notes, and snippets.

@bswinnerton
Created February 23, 2014 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bswinnerton/9175304 to your computer and use it in GitHub Desktop.
Save bswinnerton/9175304 to your computer and use it in GitHub Desktop.
require 'rest-client'
require 'json'
require 'pry'
endpoint_url = 'http://www.reddit.com/r/all.json'
response = RestClient.get(endpoint_url)
parsed_response = JSON.parse(response)
posts = parsed_response["data"]["children"].each_with_object([]) do |post, array|
array << {
title: post["data"]["title"],
url: post["data"]["url"],
author: post["data"]["author"]
}
end
html = posts.inject('') do |html, post|
html << "<a href='#{post[:url]}'>#{post[:title]}</a> - By #{post[:author]}<br>"
end
File.write('reddit.html', html)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment