Created
January 8, 2011 16:39
-
-
Save seungjin/770970 to your computer and use it in GitHub Desktop.
ruby request to http or https
This file contains hidden or 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 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