Created
February 12, 2009 00:48
-
-
Save reagent/62404 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
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