Created
May 16, 2011 12:32
-
-
Save amirci/974365 to your computer and use it in GitHub Desktop.
Testing PrDC API
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 'rubygems' | |
require 'net/http' | |
require 'json' | |
require 'uri' | |
require 'date' | |
@host = 'prairiedevcon.com' | |
#@host = 'localhost' | |
@port = '80' | |
#@port = '50758' | |
def get_page(loc) | |
http = Net::HTTP.new(@host, @port) | |
page = nil | |
http.start do |http| | |
request = Net::HTTP::Get.new(loc + '.json') | |
response = http.request(request) | |
response.value | |
page = response.body | |
end | |
page | |
end | |
puts "\n\n ***** PRDC Speakers:" | |
speakers = JSON.load(get_page("/speakers"))['speakers'] | |
speakers.each { |s| puts "#{s['id']} - #{s['first_name']} #{s['last_name']}, #{s['twitter'].strip}, #{s['blog']}" } | |
puts "\n\n***** PRDC Sessions:" | |
sessions = JSON.load( get_page("/sessions") )['sessions'] | |
sessions.each do |r| | |
pres = speakers. | |
select { |sp| r['speakers'].include? sp['id'] }. | |
map { |sp| "#{sp['first_name']} #{sp['last_name']}" }.join(',') | |
puts "#{r['id']} - #{r['title']} by #{pres} #{r['tags'].inspect}" | |
end | |
puts "\n\n***** PRDC schedule:" | |
schedule = JSON.load(get_page("/schedule"))['schedule'] | |
schedule['day_1'].each do |e| | |
start = DateTime.parse(e['start']).strftime('%I:%H') | |
finish = DateTime.parse(e['start']).strftime('%I:%H') | |
puts "#{start} - #{finish}: #{e['custom']}" | |
end | |
puts "\n\n***** PRDC sponsors:" | |
sponsors = JSON.load(get_page("/sponsors"))['sponsors'] | |
sponsors.each do |spon| | |
puts "#{spon['name']} is #{spon['category']}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment