# # HttpUtils is a simple and easy class to work with http get requests with threads. # # autor: Diego Pacheco # since: 17/10/2010 # require 'net/http' require 'rubygems' require 'hpricot' class HttpUtils def get (url, path, callback) __executeOnNewThread { result = __doGetRequest url, path callback.call result } end private def __doGetRequest (url, path) h = Net::HTTP.new(url, 80) resp, data = h.get(path, nil ) return data end def __executeOnNewThread (&func) t = Thread.new() { func.call } t.join end end h = HttpUtils.new h.get "www.twitter.com", "/statuses/public_timeline.xml", proc { |data| doc = Hpricot::XML(data) puts (doc/"text") }