Class: OnlinePayments::SDK::MultipartFormDataObject

Inherits:
Object
  • Object
show all
Defined in:
lib/onlinepayments/sdk/multipart_form_data_object.rb

Overview

A representation of a multipart/form-data object

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMultipartFormDataObject

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

#boundaryObject (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_typeObject (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

#filesObject (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

#valuesObject (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

Raises:

  • (ArgumentError)


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

Raises:

  • (ArgumentError)


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