Class: DeepL::Requests::Rephrase

Inherits:
Base
  • Object
show all
Defined in:
lib/deepl/requests/rephrase.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#api, #options, #response

Instance Method Summary collapse

Constructor Details

#initialize(api, text, target_lang = nil, writing_style = nil, tone = nil, options = {}) ⇒ Rephrase

rubocop:disable Metrics/ParameterLists



11
12
13
14
15
16
17
# File 'lib/deepl/requests/rephrase.rb', line 11

def initialize(api, text, target_lang = nil, writing_style = nil, tone = nil, options = {}) # rubocop:disable Metrics/ParameterLists
  super(api, options)
  @text = text
  @target_lang = target_lang
  @writing_style = writing_style
  @tone = tone
end

Instance Attribute Details

#target_langObject (readonly)

Returns the value of attribute target_lang.



9
10
11
# File 'lib/deepl/requests/rephrase.rb', line 9

def target_lang
  @target_lang
end

#textObject (readonly)

Returns the value of attribute text.



9
10
11
# File 'lib/deepl/requests/rephrase.rb', line 9

def text
  @text
end

#toneObject (readonly)

Returns the value of attribute tone.



9
10
11
# File 'lib/deepl/requests/rephrase.rb', line 9

def tone
  @tone
end

#writing_styleObject (readonly)

Returns the value of attribute writing_style.



9
10
11
# File 'lib/deepl/requests/rephrase.rb', line 9

def writing_style
  @writing_style
end

Instance Method Details

#detailsObject



28
29
30
31
# File 'lib/deepl/requests/rephrase.rb', line 28

def details
  "HTTP Headers: #{headers}\nPayload #{{ text: text, target_lang: target_lang,
                                         writing_style: writing_style, tone: tone }}"
end

#requestObject

rubocop:disable Metrics/AbcSize



19
20
21
22
23
24
25
26
# File 'lib/deepl/requests/rephrase.rb', line 19

def request # rubocop:disable Metrics/AbcSize
  text_arrayified = text.is_a?(Array) ? text : [text]
  payload = { text: text_arrayified }
  payload[:target_lang] = target_lang unless target_lang.nil?
  payload[:writing_style] = writing_style unless writing_style.nil?
  payload[:tone] = tone unless tone.nil?
  build_texts(*execute_request_with_retries(post_request(payload)))
end

#to_sObject



33
34
35
# File 'lib/deepl/requests/rephrase.rb', line 33

def to_s
  "POST #{uri.request_uri}"
end