Class: DeepL::Requests::Document::Upload
- Defined in:
- lib/deepl/requests/document/upload.rb
Constant Summary collapse
- SUPPORTED_OPTIONS =
%w[formality glossary_id output_format].freeze
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#input_file_path ⇒ Object
readonly
Returns the value of attribute input_file_path.
-
#source_lang ⇒ Object
readonly
Returns the value of attribute source_lang.
-
#target_lang ⇒ Object
readonly
Returns the value of attribute target_lang.
Attributes inherited from Base
Instance Method Summary collapse
- #details ⇒ Object
-
#initialize(api, input_file_path, source_lang, target_lang, filename = nil, options = {}, additional_headers = {}) ⇒ Upload
constructor
rubocop:disable Metrics/ParameterLists.
-
#request ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/MethodLength.
- #to_s ⇒ Object
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 = {}, additional_headers = {}) super(api, , additional_headers) @input_file_path = input_file_path @source_lang = source_lang @target_lang = target_lang @filename = filename 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
39 40 41 42 43 44 |
# File 'lib/deepl/requests/document/upload.rb', line 39 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 |
#request ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/MethodLength
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/deepl/requests/document/upload.rb', line 23 def request # rubocop:disable Metrics/AbcSize,Metrics/MethodLength input_file = File.open(input_file_path, 'rb') form_data = [ ['file', input_file], ['source_lang', source_lang], ['target_lang', target_lang] ] filename_param = filename || File.basename(input_file_path) form_data.push(['filename', filename_param]) unless filename_param.nil? # Manually add options due to multipart/form-data request SUPPORTED_OPTIONS.each do |option| form_data.push([option, [option]]) unless [option].nil? end build_doc_handle(*execute_request_with_retries(post_request_with_file(form_data), [input_file])) end |
#to_s ⇒ Object
46 47 48 |
# File 'lib/deepl/requests/document/upload.rb', line 46 def to_s "POST #{uri.request_uri}" end |