Skip to content

Instantly share code, notes, and snippets.

@seungjin
Created January 8, 2011 16:39
Show Gist options
  • Save seungjin/770970 to your computer and use it in GitHub Desktop.
Save seungjin/770970 to your computer and use it in GitHub Desktop.
ruby request to http or https
def reportToInstanceService(arg)
instance_service_url = JSON.parse(arg)['atmosphere']['instance_service_url']
token = JSON.parse(arg)['atmosphere']['token']
userid = JSON.parse(arg)['atmosphere']['userid']
res = Net::HTTP.post_form(URI.parse(instance_service_url), {'token'=> token, 'userid'=>userid,'vminfo'=>$instance_info_json})
end
def reportToInstanceServiceSSL(arg)
instance_service_url = JSON.parse(arg)['atmosphere']['instance_service_url']
token = JSON.parse(arg)['atmosphere']['token']
userid = JSON.parse(arg)['atmosphere']['userid']
uri = URI.parse(instance_service_url)
http = Net::HTTP.new(uri.host,uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
path = uri.path
data = 'token='+token+"&userid="+userid+"&vminfo="+$instance_info_json
res = http.post(path,data)
end
def main(arg)
URI.parse(JSON.parse(arg)['atmosphere']['instance_service_url']).scheme == "https" ? reportToInstanceServiceSSL(arg) : reportToInstanceService(arg)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment