Created
October 16, 2008 13:50
-
-
Save tatey/17135 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
def get_response_from_remote(url, retry_count, timeout_in_seconds) | |
begin | |
url = URI.parse(url) | |
timeout(timeout_in_seconds) do | |
Net::HTTP.start(url.host) do |session| | |
if url.query | |
response = session.get(url.path + "?" + url.query) | |
else | |
response = session.get(url.path) | |
end | |
if response.is_a? Net::HTTPSuccess | |
return response | |
else | |
RAILS_DEFAULT_LOGGER.error("ERROR #{ response.class } in RestfulServices.get_xml_from_remote, URL: #{ url }") | |
return nil | |
end | |
end | |
end | |
rescue Timeout::Error | |
if retry_count > 0 | |
retry_count -= 1 | |
retry | |
else | |
RAILS_DEFAULT_LOGGER.error("ERROR Timeout::Error in RestfulServices.get_xml_from_remote, URL: #{ url }") | |
return nil | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment