Class: DeepL::Requests::Correct

Inherits:
Base
  • Object
show all
Includes:
WriteImprovements
Defined in:
lib/deepl/requests/correct.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, options = {}, additional_headers = {}) ⇒ Correct

Returns a new instance of Correct.



13
14
15
16
17
18
19
# File 'lib/deepl/requests/correct.rb', line 13

def initialize(api, text, target_lang = nil, options = {}, additional_headers = {})
  super(api, options, additional_headers)
  @text = text
  @target_lang = target_lang
  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/correct.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/correct.rb', line 11

def text
  @text
end

Instance Method Details

#details ⇒ Object



27
28
29
# File 'lib/deepl/requests/correct.rb', line 27

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

#request ⇒ Object



21
22
23
24
25
# File 'lib/deepl/requests/correct.rb', line 21

def request
  payload = { text: text_arrayified }
  payload[:target_lang] = target_lang unless target_lang.nil?
  build_texts(*execute_request_with_retries(post_request(payload)))
end

#to_s ⇒ Object



31
32
33
# File 'lib/deepl/requests/correct.rb', line 31

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