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

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

Constant Summary collapse

SUPPORTED_OPTIONS =
%w[formality glossary_id output_format].freeze

Instance Attribute Summary collapse

Attributes inherited from Base

#api, #options, #response

Instance Method Summary collapse

Constructor Details

#initialize(api, input_file_path, source_lang, target_lang, filename = nil, options = {}, additional_headers = {}) ⇒ Upload

rubocop:disable Metrics/ParameterLists



14
15
16
17
18
19
20
21
# File 'lib/deepl/requests/document/upload.rb', line 14

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
end

Instance Attribute Details

#filenameObject (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_pathObject (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_langObject (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_langObject (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

#detailsObject



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

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

#requestObject



23
24
25
26
27
28
29
# File 'lib/deepl/requests/document/upload.rb', line 23

def request
  input_file = File.open(input_file_path, 'rb')
  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

#to_sObject



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

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