Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'uri'
- require 'querystring'
- require 'net/https'
- # requires the latest hpricot
- # gem install hpricot --source code.whytheluckystiff.net
- require 'rubygems'
- require 'hpricot'
- class Net::HTTPResponse
- def page
- @parsed_body ||= Hpricot(self.body)
- end
- end
- class Website
- QS = QueryString
- def initialize(url)
- url = URI.parse(url)
- @http = Net::HTTP.new(url.host, url.port)
- @http.use_ssl = true if url.port == 443
- end
- def get(path, data = nil, headers = nil)
- path = URI.parse(path)
- case data.class.to_s # I dont why I have to convert to string here, but class detection does not work
- when 'Hash' : path.query = QS.create( QS.parse(path.query.to_s).merge(data) )
- when 'String' : path.query = ( path.query.to_s ) + '&' + data
- end
- #breakpoint
- request('GET', path.to_s, nil, headers)
- end
- protected
- def request(method, path, data, headers)
- @http.start do |http|
- http.send_request( method, path, data, headers )
- end
- end
- end
Add Comment
Please, Sign In to add comment