Class: Worldline::Connect::SDK::Communication::MultipartFormDataObject
- Inherits:
-
Object
- Object
- Worldline::Connect::SDK::Communication::MultipartFormDataObject
- Defined in:
- lib/worldline/connect/sdk/communication/multipart_form_data_object.rb
Overview
A representation of a multipart/form-data object
Instance Attribute Summary collapse
-
#boundary ⇒ String
readonly
The current value of boundary.
-
#content_type ⇒ String
readonly
The current value of content_type.
-
#files ⇒ Hash
readonly
The current value of files.
-
#values ⇒ Hash
readonly
The current value of values.
Instance Method Summary collapse
-
#add_file(parameter_name, uploadable_file) ⇒ Object
Adds a file to the multipart Form Data Object.
- #add_value(parameter_name, value) ⇒ Object
-
#initialize ⇒ MultipartFormDataObject
constructor
A new instance of MultipartFormDataObject.
Constructor Details
#initialize ⇒ MultipartFormDataObject
Returns a new instance of MultipartFormDataObject.
14 15 16 17 18 19 |
# File 'lib/worldline/connect/sdk/communication/multipart_form_data_object.rb', line 14 def initialize @boundary = SecureRandom.uuid @content_type = 'multipart/form-data; boundary=' + @boundary @values = {} @files = {} end |
Instance Attribute Details
#boundary ⇒ String (readonly)
Returns the current value of boundary.
13 14 15 |
# File 'lib/worldline/connect/sdk/communication/multipart_form_data_object.rb', line 13 def boundary @boundary end |
#content_type ⇒ String (readonly)
Returns the current value of content_type.
13 14 15 |
# File 'lib/worldline/connect/sdk/communication/multipart_form_data_object.rb', line 13 def content_type @content_type end |
#files ⇒ Hash (readonly)
Returns the current value of files.
13 14 15 |
# File 'lib/worldline/connect/sdk/communication/multipart_form_data_object.rb', line 13 def files @files end |
#values ⇒ Hash (readonly)
Returns the current value of values.
13 14 15 |
# File 'lib/worldline/connect/sdk/communication/multipart_form_data_object.rb', line 13 def values @values end |
Instance Method Details
#add_file(parameter_name, uploadable_file) ⇒ Object
Adds a file to the multipart Form Data Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/worldline/connect/sdk/communication/multipart_form_data_object.rb', line 39 def add_file(parameter_name, uploadable_file) if parameter_name.nil? || parameter_name.strip.empty? raise ArgumentError, 'parameter_name is required' end raise ArgumentError, 'uploadable_file is required' if uploadable_file.nil? if @values.include?(parameter_name) || @files.include?(parameter_name) raise ArgumentError, 'duplicate parameterName: ' + parameter_name end @files[parameter_name] = uploadable_file end |
#add_value(parameter_name, value) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/worldline/connect/sdk/communication/multipart_form_data_object.rb', line 26 def add_value(parameter_name, value) if parameter_name.nil? || parameter_name.strip.empty? raise ArgumentError, 'parameter_name is required' end raise ArgumentError, 'value is required' if value.nil? if @values.include?(parameter_name) || @files.include?(parameter_name) raise ArgumentError, 'duplicate parameterName: ' + parameter_name end @values[parameter_name] = value end |