Skip to content

Instantly share code, notes, and snippets.

@databyte
Created March 11, 2013 21:19
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 databyte/5137853 to your computer and use it in GitHub Desktop.
Save databyte/5137853 to your computer and use it in GitHub Desktop.
Parse JSON from a Secure URL using Ruby
require "json"
require "net/https"
require "uri"
uri = URI.parse("https://github.com/databyte.json")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(uri.request_uri)
response = http.request(request)
if response.code == "200"
result = JSON.parse(response.body)
puts result
else
puts "ERROR #{response.code}!!!"
end
# http://www.rubyinside.com/nethttp-cheat-sheet-2940.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment