-
-
Save anonymous/80c8987986debe2b7a8f7bad910f2c9a 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 doRequest(url) | |
out = {'returncode' => 0} | |
puts "sending GET to #{url}" if $debug | |
begin | |
uri = URI.parse(url) | |
response = uri.read(:read_timeout => $timeout) | |
puts "Response: #{response}" if $debug | |
out['data'] = JSON.load(response) | |
rescue Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Errno::ECONNREFUSED, | |
Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError => e | |
out['text'] = "WARNING: Error '#{e}' while sending request to #{url}" | |
out['returncode'] = 1 | |
end | |
puts "Parsed: #{out['data']}" if $debug | |
return out | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment