Dev Jangra February 2016

How to use Azure ML API with Ruby on Rails

I am using the code with a URL and API key but every time i will get the some error of 405 or 400. Is there any proper way to implement Azure ML API in Rails.

The code as below :-

data = {

"Inputs" => {

        "input1" =>
        {
            "ColumnNames" => @a,
            "Values" => [ @writer ]
        },        },
    "GlobalParameters" => {
}
}

body = data.to_json
puts "adssssssssssssssssssssssssssssss#{body}"
url = "https://ussouthcentral.services.azureml.net/workspaces/5aecd8f887e64999a9c854d724e5d45b/services/5f350fa1b48647ce95c5279eee2170d0/execute?api-version=2.0&details=true"
api_key = 'wGMMQGYlo4tttV+oTjrRwkSbZMcJXGfY7ejB1B1vxYU5hMEeRx/tyt6xYSmWskCezNKkbGwvAVt0wsessJUORQ==' # Replace this with the API key for the web service
headers = {'Content-Type' => 'application/json', 'Authorization' => ('Bearer '+ api_key)}



url = URI.parse(url)
req = Net::HTTP::Get.new(url.request_uri,headers)
http = Net::HTTP.new(url.host, url.port)
res = http.request(req)

{"Inputs":{"input1":{"ColumnNames":["encounter_id","patient_nbr","Fname","Lname","Email","Type","race","gender","Birth Date","Birth Year","age","Age Min","Age Max","weight","admission_type_id","discharge_disposition_id","admission_source_id","time_in_hospital","payer_code","medical_specialty","num_lab_procedures","num_procedures","num_medications","number_outpatient","number_emergency","number_inpatient","number_diagnoses","max_glu_serum","A1Cresult","metformin","repaglinide","nateglinide","chlorpropamide","glimepiride","acetohexamide","glipizide","glyburide","tolbutamide","pioglitazone","rosiglitazone","acarbose","miglitol","troglitazone","tolazamide","examide","citoglipton","insulin","glyburide-metformin","glipizide-metformin","glimepiride-pioglitazone","metformin-rosiglitazone","metformin-pioglitazone","change","diabetesMed","readmitted"],"Values":[[[{"$oid":"56b1ab886e75720ba23b5400"},"","Rana","Warhurst",null,"Patient","Caucasian","Male"        

Answers


Dev Jangra February 2016

After the research, atlast i got the answer, as it can be done by Unirest gem easily

url = "url for ml"
api = "ml API key"
headers = "same as above"

response = Unirest.post url, headers: headers, parameters: body

response.code
response.headers
response.body
response.raw_body

The result values will be stored in response.body

Post Status

Asked in February 2016
Viewed 1,787 times
Voted 12
Answered 1 times

Search




Leave an answer