Created
February 10, 2010 21:08
-
-
Save barinek/300837 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/bin/env ruby | |
require 'rubygems' | |
require 'net/http' | |
require 'uri' | |
class SimpleCometClient | |
def initialize() | |
@uri = URI.parse('http://www.localhash.com/publishers/myspace/stream') | |
@http = Net::HTTP.new(@uri.host, @uri.port) | |
end | |
def read_data(post_body = nil) | |
if post_body | |
request = Net::HTTP::Post.new(@uri.path) | |
else | |
request = Net::HTTP::Get.new(@uri.path) | |
end | |
@http.request(request, post_body) do |response| | |
case response | |
when Net::HTTPClientError, Net::HTTPServerError: | |
end | |
response.read_body do |data| | |
yield data | |
end | |
end | |
end | |
end | |
@client = SimpleCometClient.new | |
begin | |
@client.read_data("hub.lat=34.052&hub.lon=-118.243&hub.precision=3") do |data| | |
puts data | |
end | |
rescue Exception => e | |
puts e | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment