Class: EasyTranslate::Translation::TranslationRequest
- Defined in:
- lib/easy_translate/translation.rb
Overview
A convenience class for wrapping a translation request
Instance Attribute Summary
Attributes inherited from Request
Instance Method Summary collapse
-
#body ⇒ String
The body for the request.
-
#initialize(texts, options, http_options = {}) ⇒ TranslationRequest
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 = {}) ⇒ TranslationRequest
Set the texts and options
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/easy_translate/translation.rb', line 47 def initialize(texts, , = {}) = .dup self.texts = texts self.html = .delete(:html) @source = .delete(:from) @target = .delete(:to) @model = .delete(:model) raise ArgumentError.new('No target language provided') unless @target raise ArgumentError.new('Support for multiple targets dropped in V2') if @target.is_a?(Array) = if = if replacement_api_key = .delete(:api_key) [:key] = replacement_api_key end end end |
Instance Method Details
#body ⇒ String
The body for the request
85 86 87 |
# File 'lib/easy_translate/translation.rb', line 85 def body @texts.map { |t| "q=#{CGI::escape(t)}" }.join '&' end |
#multi? ⇒ Boolean
Whether or not this was a request for multiple texts
91 92 93 |
# File 'lib/easy_translate/translation.rb', line 91 def multi? @multi end |
#params ⇒ Hash
The params for this request
67 68 69 70 71 72 73 74 75 |
# File 'lib/easy_translate/translation.rb', line 67 def params params = super || {} params[:source] = lang(@source) unless @source.nil? params[:target] = lang(@target) unless @target.nil? params[:model] = @model unless @model.nil? params[:format] = @format unless @format.nil? params.merge! if params end |
#path ⇒ String
The path for the request
79 80 81 |
# File 'lib/easy_translate/translation.rb', line 79 def path '/language/translate/v2' end |