Class: LanguagecloudSdl::API

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/languagecloud-sdl.rb,
lib/languagecloud-sdl/version.rb

Constant Summary collapse

VERSION =
"0.1.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ API

Returns a new instance of API.



19
20
21
22
# File 'lib/languagecloud-sdl.rb', line 19

def initialize(options = {})
  @api_key = options.fetch(:api_key)
  @source_lang = options.fetch(:source_lang)
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



17
18
19
# File 'lib/languagecloud-sdl.rb', line 17

def api_key
  @api_key
end

#source_langObject

Returns the value of attribute source_lang.



17
18
19
# File 'lib/languagecloud-sdl.rb', line 17

def source_lang
  @source_lang
end

Instance Method Details

#asyncObject



24
25
26
27
# File 'lib/languagecloud-sdl.rb', line 24

def async
  @async = true
  self
end

#syncObject



29
30
31
32
# File 'lib/languagecloud-sdl.rb', line 29

def sync
  @async = false
  self
end

#translations(to_lang, params = {}) ⇒ Object

'texts': [
  'text a',
  'text b'
]

Translating array of strings

Parameters:

  • to_lang (String)
  • params (Hash) (defaults to: {})


43
44
45
46
47
48
49
50
51
52
# File 'lib/languagecloud-sdl.rb', line 43

def translations(to_lang, params = {})
  params = normalized_params(params)
  params[:from] = source_lang
  params[:to] = to_lang
  call_sdl do
    res = self.class.post('/translations', body: params.to_json, headers: headers_auth)
    res = LanguagecloudSdl::Response.new(res)
    yield res if block_given? or return res
  end
end