Skip to content

Instantly share code, notes, and snippets.

@huydx
Last active December 11, 2015 09:59
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 huydx/4583805 to your computer and use it in GitHub Desktop.
Save huydx/4583805 to your computer and use it in GitHub Desktop.
https get with parameters in Ruby
def get_currentuser_info cookies=nil
uri_domain = "https://www.googleapis.com"
uri_path = "/oauth2/v1/userinfo"
params = {alt: "json", access_token: cookies[:access_token]}
uri_string = uri_domain + uri_path + "?" +
params.map{|k,v| "#{k}=#{CGI::escape(v.to_s)}"}.join('&')
uri = URI(uri_string)
response_hash = nil
Net::HTTP.start(uri.host,
uri.port,
:use_ssl => uri.scheme == 'https',
:verify_mode => OpenSSL::SSL::VERIFY_NONE) do |http|
request = Net::HTTP::Get.new uri.request_uri
response = http.request request
end
response_hash = ActiveSupport::JSON.decode(response.body) unless response.nil?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment