Class: CodicCaller::Codic

Inherits:
Object
  • Object
show all
Defined in:
lib/codic_caller.rb

Constant Summary collapse

HOST =
'https://api.codic.jp'

Instance Method Summary collapse

Constructor Details

#initializeCodic

Returns a new instance of Codic.



10
11
12
# File 'lib/codic_caller.rb', line 10

def initialize
  @token = ENV['CODIC']
end

Instance Method Details

#project_idObject



26
27
28
29
30
31
32
33
# File 'lib/codic_caller.rb', line 26

def project_id
  JSON.load(
    client.get {|req|
      req.url '/v1/user_projects.json'
      req.headers['Authorization'] = "Bearer #{@token}"
    }.body
  ).first['id']
end

#translate(text, casing: 'lower underscore') ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/codic_caller.rb', line 14

def translate(text, casing: 'lower underscore')
  JSON.load(
    client.get {|req|
      req.url '/v1/engine/translate.json'
      req.params[:project_id] = project_id
      req.params[:casing] = casing
      req.params[:text] = text
      req.headers['Authorization'] = "Bearer #{@token}"
    }.body
  ).first['translated_text']
end