class Hermes::Bot::Translator

Public Class Methods

create_model(attrs) click to toggle source
# File lib/hermes/bot/translator.rb, line 52
def self.create_model(attrs)
  response = self.post("/v2/models", body: attrs)

  parsed_response = JSON.parse(response.body)

  return Hermes::Bot::Model.new(parsed_response) if response.success?

  raise_exception(response.code, response.body)
end
destroy_model(id) click to toggle source
# File lib/hermes/bot/translator.rb, line 62
def self.destroy_model(id)
  response = delete("/v2/models/#{id}")
  response.success?
end
identifiable_languages() click to toggle source
# File lib/hermes/bot/translator.rb, line 16
def self.identifiable_languages
  response = get("/v2/identifiable_languages")

  parsed_response = JSON.parse(response.body)

  return parsed_response["languages"].map do |attrs|
    Hermes::Bot::IdentifiableLanguage.new(attrs)
  end if response.success?

  raise_exception(response.code, response.body)
end
identify(text) click to toggle source
# File lib/hermes/bot/translator.rb, line 28
def self.identify(text)
  response = self.post("/v2/identify", body: text, headers: { "Accept" => "application/json", "Content-Type" => "text/plain"})

  parsed_response = JSON.parse(response.body)

  return parsed_response["languages"].map do |attrs|
    Hermes::Bot::Language.new(attrs)
  end if response.success?

  raise_exception(response.code, response.body)
end
model(id) click to toggle source
# File lib/hermes/bot/translator.rb, line 67
def self.model(id)
  response = self.get("/v2/models/#{id}")

  parsed_response = JSON.parse(response.body)

  return Hermes::Bot::Model.new(parsed_response) if response.success?

  raise_exception(response.code, response.body)
end
models(filters = {}) click to toggle source
# File lib/hermes/bot/translator.rb, line 40
def self.models(filters = {})
  response = self.get("/v2/models", query: filters)

  parsed_response = JSON.parse(response.body)

  return parsed_response["models"].map do |attrs|
    Hermes::Bot::Model.new(attrs)
  end if response.success?

  raise_exception(response.code, response.body)
end
translate(params = {}) click to toggle source
# File lib/hermes/bot/translator.rb, line 9
def self.translate(params = {})
  response = post("/v2/translate", body: params)

  return response.body if response.success?
  raise_exception(response.code, response.body)
end