Class: DeepL::Requests::Document::Upload

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

Overview

rubocop:disable Metrics/ClassLength

Constant Summary collapse

SUPPORTED_OPTIONS =
%w[formality output_format enable_watermark].freeze

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, input_file_path, source_lang, target_lang, filename = nil, options = {}, additional_headers = {}) ⇒ Upload

rubocop:disable Metrics/ParameterLists



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/deepl/requests/document/upload.rb', line 16

def initialize(api, input_file_path, source_lang, target_lang, filename = nil, # rubocop:disable Metrics/ParameterLists
               options = {}, additional_headers = {})
  super(api, options, additional_headers)
  @input_file_path = input_file_path
  @source_lang = source_lang
  @target_lang = target_lang
  @filename = filename
  validate_languages!(source_lang, target_lang)
  validate_translation_memory_threshold!
  validate_glossary_source_lang!
end

Instance Attribute Details

#filename ⇒ Object (readonly)

Returns the value of attribute filename.



10
11
12
# File 'lib/deepl/requests/document/upload.rb', line 10

def filename
  @filename
end

#input_file_path ⇒ Object (readonly)

Returns the value of attribute input_file_path.



10
11
12
# File 'lib/deepl/requests/document/upload.rb', line 10

def input_file_path
  @input_file_path
end

#source_lang ⇒ Object (readonly)

Returns the value of attribute source_lang.



10
11
12
# File 'lib/deepl/requests/document/upload.rb', line 10

def source_lang
  @source_lang
end

#target_lang ⇒ Object (readonly)

Returns the value of attribute target_lang.



10
11
12
# File 'lib/deepl/requests/document/upload.rb', line 10

def target_lang
  @target_lang
end

Instance Method Details

#details ⇒ Object



37
38
39
40
41
42
# File 'lib/deepl/requests/document/upload.rb', line 37

def details
  "HTTP Headers: #{loggable_headers}\nPayload #{[
    ['file', "File at #{input_file_path} opened in binary mode"],
    ['source_lang', source_lang], ['target_lang', target_lang], ['filename', filename]
  ]}"
end

#request ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/deepl/requests/document/upload.rb', line 28

def request
  File.open(input_file_path, 'rb') do |input_file|
    form_data = build_base_form_data(input_file)
    apply_extra_body_parameters_to_form(form_data)
    build_doc_handle(*execute_request_with_retries(post_request_with_file(form_data),
                                                   [input_file]))
  end
end

#to_s ⇒ Object



44
45
46
# File 'lib/deepl/requests/document/upload.rb', line 44

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