Skip to content

Instantly share code, notes, and snippets.

@dhiraka
Last active August 29, 2015 14:22
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 dhiraka/1923d65865331c420d42 to your computer and use it in GitHub Desktop.
Save dhiraka/1923d65865331c420d42 to your computer and use it in GitHub Desktop.
Sentiment Analysis for a bunch of texts to be done asynchronously
require 'httparty'
module SentimentAnalysis
texts = [
"I am a pathetic person",
"Today is going to be a good day",
"I wish you were dead"
]
def self.calculate(texts)
actions = []
for text in texts
actions.push(
{
params:{
text:text,
apikey: ENV['SENTIMENT_ANALYSIS_API_KEY']
}
}
)
end
job_id = HTTParty.post(
'https://api.idolondemand.com/1/job',
{
query: {
actions: actions
}
}
)
puts job_id.response.inspect
result = HTTParty.get(
'https://api.idolondemand.com/1/job/result/' + job_id,
{
query: {
apikey: ENV['SENTIMENT_ANALYSIS_API_KEY'],
}
}
)
puts result.inspect
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment