Class: SyllabsApi::Modules::LanguageDetection::Base

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

Constant Summary collapse

API_URL =
'http://api.syllabs.com/v0/language'
RESPONSE_FORMAT =
'json'

Class Method Summary collapse

Class Method Details

.fetch_response(body) ⇒ Object



18
19
20
21
22
# File 'lib/syllabs-api/modules/language_detection/base.rb', line 18

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

.process(api_key, text) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/syllabs-api/modules/language_detection/base.rb', line 10

def self.process(api_key, text)
  params = {text: text, format: RESPONSE_FORMAT}
  http_response = HttpProcessor.post(api_key, API_URL, params)
  fetch_response(http_response.body)
rescue Exception => e
  raise e
end