Class: TranslatorText::Client
- Inherits:
-
Object
- Object
- TranslatorText::Client
- Includes:
- HTTParty
- Defined in:
- lib/translator_text/client.rb
Constant Summary collapse
- API_VERSION =
'3.0'.freeze
Instance Method Summary collapse
-
#detect(sentences) ⇒ Array<TranslatorText::Types::DetectionResult>
Identifies the language of a piece of text.
-
#initialize(api_key) ⇒ Client
constructor
Initialize the client.
-
#translate(sentences, to:, **options) ⇒ Array<TranslatorText::Types::TranslationResult>
Translate a group of sentences.
Constructor Details
#initialize(api_key) ⇒ Client
Initialize the client
17 18 19 |
# File 'lib/translator_text/client.rb', line 17 def initialize(api_key) @api_key = api_key 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.
52 53 54 55 56 57 58 59 |
# File 'lib/translator_text/client.rb', line 52 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.
32 33 34 35 36 37 38 39 40 |
# File 'lib/translator_text/client.rb', line 32 def translate(sentences, to:, **) results = post( '/translate', body: build_sentences(sentences).to_json, query: Hash[to: to, **] ) results.map { |r| Types::TranslationResult.new(r) } end |