Class: EasyTranslate::Detection::DetectionRequest
- Defined in:
- lib/easy_translate/detection.rb
Overview
A convenience class for wrapping a detection request
Instance Attribute Summary
Attributes inherited from Request
Instance Method Summary collapse
-
#body ⇒ String
The body for the request.
-
#initialize(texts, options = {}, http_options = {}) ⇒ DetectionRequest
constructor
Set the texts and options.
-
#multi? ⇒ Boolean
Whether or not this was a request for multiple texts.
-
#params ⇒ Hash
The params for this request.
-
#path ⇒ String
The path for the request.
Methods inherited from Request
Constructor Details
#initialize(texts, options = {}, http_options = {}) ⇒ DetectionRequest
Set the texts and options
29 30 31 32 33 34 35 |
# File 'lib/easy_translate/detection.rb', line 29 def initialize(texts, = {}, = {}) super(, ) if replacement_api_key = @options.delete(:api_key) @options[:key] = replacement_api_key end self.texts = texts end |
Instance Method Details
#body ⇒ String
The body for the request
53 54 55 |
# File 'lib/easy_translate/detection.rb', line 53 def body @texts.map { |t| "q=#{URI.escape(t)}" }.join '&' end |
#multi? ⇒ Boolean
Whether or not this was a request for multiple texts
59 60 61 |
# File 'lib/easy_translate/detection.rb', line 59 def multi? @multi end |
#params ⇒ Hash
The params for this request
39 40 41 42 43 |
# File 'lib/easy_translate/detection.rb', line 39 def params params = super || {} params.merge! @options if @options params end |
#path ⇒ String
The path for the request
47 48 49 |
# File 'lib/easy_translate/detection.rb', line 47 def path '/language/translate/v2/detect' end |