Skip to content

Instantly share code, notes, and snippets.

@reagent
Created February 12, 2009 00:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reagent/62404 to your computer and use it in GitHub Desktop.
Save reagent/62404 to your computer and use it in GitHub Desktop.
class Response
def initialize(source_uri)
@source_uri = source_uri
@last_response = nil
end
def http_response_for(uri)
Net::HTTP.start(uri.host, uri.port) do |http|
@last_response = http.get(path_for(uri), 'User-Agent' => user_agent)
end
end
def path_for(uri)
uri.query.nil? ? uri.path : "#{uri.path}?#{uri.query}"
end
def valid?
# uri = @source_uri
#
# while (response = http_response_for(uri).is_a?(Net::HTTPSuccess))
# uri = response['location']
# end
#
# @last_response.is_a?(Net::HTTPSuccess)
end
end
def response
@response ||= Response.new(source)
end
def exists?
response.valid?
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment