Skip to content

Instantly share code, notes, and snippets.

@tatey
Created October 16, 2008 13:50
Show Gist options
  • Save tatey/17135 to your computer and use it in GitHub Desktop.
Save tatey/17135 to your computer and use it in GitHub Desktop.
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