Last active
December 11, 2015 09:59
-
-
Save huydx/4583805 to your computer and use it in GitHub Desktop.
https get with parameters in Ruby
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 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