Class: CodicCaller::Codic
- Inherits:
-
Object
- Object
- CodicCaller::Codic
- Defined in:
- lib/codic_caller.rb
Constant Summary collapse
- HOST =
'https://api.codic.jp'
Instance Method Summary collapse
-
#initialize ⇒ Codic
constructor
A new instance of Codic.
- #project_id ⇒ Object
- #translate(text, casing: 'lower underscore') ⇒ Object
Constructor Details
#initialize ⇒ Codic
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_id ⇒ Object
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 |