Class: TranslatorText::Client
- Inherits:
-
Object
- Object
- TranslatorText::Client
- Includes:
- HTTParty
- Defined in:
- lib/translator_text/client.rb
Constant Summary collapse
- API_VERSION =
'3.0'
Instance Method Summary collapse
-
#detect(sentences) ⇒ Array<TranslatorText::Types::DetectionResult>
Identifies the language of a piece of text.
-
#initialize(api_key, api_region = nil) ⇒ Client
constructor
Initialize the client.
-
#translate(sentences, to:, **options) ⇒ Array<TranslatorText::Types::TranslationResult>
Translate a group of sentences.
Constructor Details
#initialize(api_key, api_region = nil) ⇒ Client
Initialize the client
26 27 28 29 |
# File 'lib/translator_text/client.rb', line 26 def initialize(api_key, api_region = nil) @api_key = api_key @api_region = api_region end |
Instance Method Details
#detect(sentences) ⇒ Array<TranslatorText::Types::DetectionResult>
Identifies the language of a piece of text.
The following limitations apply:
-
The array sentences can have at most 100 elements.
-
The text value of an array element cannot exceed 10,000 characters including spaces.
-
The entire text included in the request cannot exceed 50,000 characters including spaces.
62 63 64 65 66 67 68 69 |
# File 'lib/translator_text/client.rb', line 62 def detect(sentences) results = post( '/detect', body: build_sentences(sentences).to_json ) results.map { |r| Types::DetectionResult.new(r) } end |
#translate(sentences, to:, **options) ⇒ Array<TranslatorText::Types::TranslationResult>
Translate a group of sentences.
The following limitations apply:
-
The array sentences can have at most 25 elements.
-
The entire text included in the request cannot exceed 5,000 characters including spaces.
42 43 44 45 46 47 48 49 50 |
# File 'lib/translator_text/client.rb', line 42 def translate(sentences, to:, **) results = post( '/translate', body: build_sentences(sentences).to_json, query: { to:, ** } ) results.map { |r| Types::TranslationResult.new(r) } end |