class EasyTranslate::Detection::DetectionRequest
A convenience class for wrapping a detection request
Public Class Methods
new(texts, options = {}, http_options = {})
click to toggle source
Set the texts and options @param [String, Array] texts - The text (or texts) to translate @param [Hash] options - Options to override or pass along with the request
Calls superclass method
EasyTranslate::Request::new
# File lib/easy_translate/detection.rb, line 36 def initialize(texts, options = {}, http_options = {}) super(options, http_options) if replacement_api_key = @options.delete(:api_key) @options[:key] = replacement_api_key end self.texts = texts end
Public Instance Methods
body()
click to toggle source
The body for the request @return [String] the body for the request, URL escaped
# File lib/easy_translate/detection.rb, line 60 def body @texts.map { |t| "q=#{CGI::escape(t)}" }.join '&' end
multi?()
click to toggle source
Whether or not this was a request for multiple texts @return [Boolean]
# File lib/easy_translate/detection.rb, line 66 def multi? @multi end
params()
click to toggle source
The params for this request @return [Hash] the params for the request
Calls superclass method
EasyTranslate::Request#params
# File lib/easy_translate/detection.rb, line 46 def params params = super || {} params.merge! @options if @options params end
path()
click to toggle source
The path for the request @return [String] The path for the request
# File lib/easy_translate/detection.rb, line 54 def path '/language/translate/v2/detect' end
Private Instance Methods
texts=(texts)
click to toggle source
Set the texts for this request @param [String, Array] texts - The text or texts for this request
# File lib/easy_translate/detection.rb, line 74 def texts=(texts) if texts.is_a?(String) @multi = false @texts = [texts] else @multi = true @texts = texts end end