Class: LanguagecloudSdl::API
- Inherits:
-
Object
- Object
- LanguagecloudSdl::API
- Includes:
- HTTParty
- Defined in:
- lib/languagecloud-sdl.rb,
lib/languagecloud-sdl/version.rb
Constant Summary collapse
- VERSION =
"0.1.0"
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#source_lang ⇒ Object
Returns the value of attribute source_lang.
Instance Method Summary collapse
- #async ⇒ Object
-
#initialize(options = {}) ⇒ API
constructor
A new instance of API.
- #sync ⇒ Object
-
#translations(to_lang, params = {}) ⇒ Object
{ ‘texts’: [ ‘text a’, ‘text b’ ] } Translating array of strings.
Constructor Details
#initialize(options = {}) ⇒ API
Returns a new instance of API.
19 20 21 22 |
# File 'lib/languagecloud-sdl.rb', line 19 def initialize( = {}) @api_key = .fetch(:api_key) @source_lang = .fetch(:source_lang) end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
17 18 19 |
# File 'lib/languagecloud-sdl.rb', line 17 def api_key @api_key end |
#source_lang ⇒ Object
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
#async ⇒ Object
24 25 26 27 |
# File 'lib/languagecloud-sdl.rb', line 24 def async @async = true self end |
#sync ⇒ Object
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
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 |