Skip to content

Instantly share code, notes, and snippets.

@bswinnerton
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save bswinnerton/10010601 to your computer and use it in GitHub Desktop.
Save bswinnerton/10010601 to your computer and use it in GitHub Desktop.
require 'json'
require 'rest-client'
url = 'http://reddit.com/.json'
response = RestClient.get(url)
parsed_response = JSON.parse(response)
posts = parsed_response['data']['children'].map do |post|
{
title: post['data']['title'],
author: post['data']['author'],
url: post['data']['url']
}
end
posts.each do |post|
puts "Title: #{post[:title]}"
puts "Author: #{post[:author]}"
puts "URL: #{post[:url]}"
puts
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment