Created
May 31, 2015 12:26
-
-
Save lemoogle/ea00942d4360a44c9e5a to your computer and use it in GitHub Desktop.
Async batch job
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
require 'httparty' | |
require 'json' | |
apikey="" | |
texts = [ | |
"I am a pathetic person", | |
"Today is going to be a good day", | |
"I wish you were dead" | |
] | |
def calculate(texts,apikey) | |
actions = [] | |
for text in texts | |
actions.push( | |
{ | |
name:"analyzesentiment", | |
version:"v1", | |
params:{ | |
text:text | |
} | |
} | |
) | |
end | |
job={actions:actions} | |
job_id = HTTParty.post( | |
'https://api.idolondemand.com/1/job', | |
:body => { | |
apikey: apikey, | |
job: JSON.dump(job) | |
} | |
) | |
job_id_str=JSON.parse(job_id.response.body)["jobID"] | |
puts job_id_str | |
result = HTTParty.get( | |
'https://api.idolondemand.com/1/job/result/' + job_id_str, | |
{ | |
query: { | |
apikey: apikey, | |
} | |
} | |
) | |
puts result.inspect | |
end | |
calculate(texts,apikey) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment