Class: OnlinePayments::SDK::MultipartFormDataObject
- Inherits:
-
Object
- Object
- OnlinePayments::SDK::MultipartFormDataObject
- Defined in:
- lib/onlinepayments/sdk/multipart_form_data_object.rb
Overview
A representation of a multipart/form-data object
Instance Attribute Summary collapse
-
#boundary ⇒ Object
readonly
Returns the value of attribute boundary.
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#values ⇒ Object
readonly
Returns the value of attribute 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.
7 8 9 10 11 12 |
# File 'lib/onlinepayments/sdk/multipart_form_data_object.rb', line 7 def initialize @boundary = SecureRandom.uuid @content_type = 'multipart/form-data; boundary=' + @boundary @values = {} @files = {} end |
Instance Attribute Details
#boundary ⇒ Object (readonly)
Returns the value of attribute boundary.
14 15 16 |
# File 'lib/onlinepayments/sdk/multipart_form_data_object.rb', line 14 def boundary @boundary end |
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
15 16 17 |
# File 'lib/onlinepayments/sdk/multipart_form_data_object.rb', line 15 def content_type @content_type end |
#files ⇒ Object (readonly)
Returns the value of attribute files.
17 18 19 |
# File 'lib/onlinepayments/sdk/multipart_form_data_object.rb', line 17 def files @files end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
16 17 18 |
# File 'lib/onlinepayments/sdk/multipart_form_data_object.rb', line 16 def values @values end |
Instance Method Details
#add_file(parameter_name, uploadable_file) ⇒ Object
Adds a file to the multipart Form Data Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/onlinepayments/sdk/multipart_form_data_object.rb', line 32 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
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/onlinepayments/sdk/multipart_form_data_object.rb', line 19 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 |