Created
July 13, 2010 23:38
-
-
Save brianmichel/474750 to your computer and use it in GitHub Desktop.
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
#!/usr/local/bin/ruby | |
require 'net/http' | |
require 'rexml/document' | |
require 'uri' | |
include REXML | |
BASE_URL = 'api.foursquare.com' | |
def get_it!(user = "username goes here!", pass = "password goes here!") | |
url = URI.parse('http://api.foursquare.com/v1/history?sinceid=66040249&l=250') | |
req = Net::HTTP::Get.new('http://api.foursquare.com/v1/history?sinceid=66040249') | |
req.basic_auth(user, pass) | |
@response = Net::HTTP.start(url.host, url.port){|http| | |
http.request(req) | |
} | |
return @response.body | |
end | |
#run the get it function | |
history_data = get_it! | |
history_doc = REXML::Document.new(history_data) | |
#get the ids, names, icons, cities, and states into an array | |
ids = XPath.each(history_doc, "//checkin/id") | |
names = XPath.each(history_doc, "//name") | |
icons = XPath.each(history_doc, "//iconurl") | |
cities = XPath.each(history_doc, "//city") | |
states = XPath.each(history_doc, "//state") | |
#output all the information | |
for k in 0...names.count | |
puts "#{ids.to_a[k].text} #{names.to_a[k].text} #{cities.to_a[k].text} #{states.to_a[k].text}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment