Skip to content

Instantly share code, notes, and snippets.

@tatey tatey/gist:17135
Created Oct 16, 2008

Embed
What would you like to do?
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
You can’t perform that action at this time.