Skip to content

Instantly share code, notes, and snippets.

@lemoogle
Created May 31, 2015 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lemoogle/ea00942d4360a44c9e5a to your computer and use it in GitHub Desktop.
Save lemoogle/ea00942d4360a44c9e5a to your computer and use it in GitHub Desktop.
Async batch job
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