Class: Worldline::Connect::SDK::Communication::MultipartFormDataObject

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeMultipartFormDataObject

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

#boundaryString (readonly)

Returns the current value of boundary.

Returns:

  • (String)

    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_typeString (readonly)

Returns the current value of content_type.

Returns:

  • (String)

    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

#filesHash (readonly)

Returns the current value of files.

Returns:

  • (Hash)

    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

#valuesHash (readonly)

Returns the current value of values.

Returns:

  • (Hash)

    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

Raises:

  • (ArgumentError)


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

Raises:

  • (ArgumentError)


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