Class: SyllabsApi::Modules::SentimentAnalysis::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/syllabs-api/modules/sentiment_analysis/base.rb

Constant Summary collapse

MOD_GENERIC =
'generic'
MOD_HOTEL =
'hotel'
MOD_RESTAURANT =
'restaurant'
MOD_TELECOM =
'telecom'
API_URL =
'http://api.syllabs.com/v0/sentiment'
RESPONSE_FORMAT =
'json'

Class Method Summary collapse

Class Method Details

.fetch_response(body) ⇒ Object



24
25
26
27
28
# File 'lib/syllabs-api/modules/sentiment_analysis/base.rb', line 24

def self.fetch_response(body)
  SentimentAnalysis::Response.new JSON.parse(body)
rescue Exception => e
  raise e
end

.process(api_key, text, mod = MOD_GENERIC, lang = 'fr') ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/syllabs-api/modules/sentiment_analysis/base.rb', line 15

def self.process(api_key, text, mod=MOD_GENERIC, lang='fr')
  api_url = "#{API_URL}/#{mod}"
  params = {content: text, format: RESPONSE_FORMAT, lang: lang}
  http_response = HttpProcessor.post(api_key, api_url, params)
  fetch_response(http_response.body)
rescue Exception => e
  raise e
end