Skip to content

Instantly share code, notes, and snippets.

/ruby.rb Secret

Created May 31, 2016 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/80c8987986debe2b7a8f7bad910f2c9a to your computer and use it in GitHub Desktop.
Save anonymous/80c8987986debe2b7a8f7bad910f2c9a to your computer and use it in GitHub Desktop.
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