Class: DeepL::Requests::Rephrase

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

Constant Summary

Constants inherited from Base

Base::MAX_GLOSSARY_IDS, Base::NETWORK_ERRORS, Base::RESPONSE_FORMAT_ERRORS, Base::RETRYABLE_NETWORK_ERRORS, Base::TECHNICAL_HEADERS

Instance Attribute Summary collapse

Attributes inherited from Base

#api, #options, #response

Instance Method Summary collapse

Methods inherited from Base

accepted_options, accepts_options, inherited, validate_options!

Constructor Details

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

rubocop:disable Metrics/ParameterLists



13
14
15
16
17
18
19
20
21
22
# File 'lib/deepl/requests/rephrase.rb', line 13

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

Instance Attribute Details

#target_lang ⇒ Object (readonly)

Returns the value of attribute target_lang.



11
12
13
# File 'lib/deepl/requests/rephrase.rb', line 11

def target_lang
  @target_lang
end

#text ⇒ Object (readonly)

Returns the value of attribute text.



11
12
13
# File 'lib/deepl/requests/rephrase.rb', line 11

def text
  @text
end

#tone ⇒ Object (readonly)

Returns the value of attribute tone.



11
12
13
# File 'lib/deepl/requests/rephrase.rb', line 11

def tone
  @tone
end

#writing_style ⇒ Object (readonly)

Returns the value of attribute writing_style.



11
12
13
# File 'lib/deepl/requests/rephrase.rb', line 11

def writing_style
  @writing_style
end

Instance Method Details

#details ⇒ Object



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

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

#request ⇒ Object

rubocop:disable Metrics/AbcSize



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

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_s ⇒ Object



38
39
40
# File 'lib/deepl/requests/rephrase.rb', line 38

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