Class: Candid::Internal::Multipart::FormDataPart Private

Inherits:
Object
  • Object
show all
Defined in:
lib/candid/internal/multipart/multipart_form_data_part.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, value:, filename: nil, headers: nil) ⇒ FormDataPart

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of FormDataPart.

Parameters:

  • name (String)

    The name of the form field

  • value (String, Integer, Float, Boolean, File, #read)

    The value of the field

  • filename (String, nil) (defaults to: nil)

    Optional filename for file uploads

  • headers (Hash<String, String>, nil) (defaults to: nil)

    Optional additional headers



16
17
18
19
20
21
# File 'lib/candid/internal/multipart/multipart_form_data_part.rb', line 16

def initialize(name:, value:, filename: nil, headers: nil)
  @name = name
  @contents = convert_to_content(value)
  @filename = filename
  @headers = headers
end

Instance Attribute Details

#contentsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
# File 'lib/candid/internal/multipart/multipart_form_data_part.rb', line 10

def contents
  @contents
end

#filenameObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
# File 'lib/candid/internal/multipart/multipart_form_data_part.rb', line 10

def filename
  @filename
end

#headersObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
# File 'lib/candid/internal/multipart/multipart_form_data_part.rb', line 10

def headers
  @headers
end

#nameObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



10
11
12
# File 'lib/candid/internal/multipart/multipart_form_data_part.rb', line 10

def name
  @name
end

Instance Method Details

#to_hashHash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Converts the part to a hash suitable for serialization.

Returns:

  • (Hash)

    A hash representation of the part



26
27
28
29
30
31
32
33
34
# File 'lib/candid/internal/multipart/multipart_form_data_part.rb', line 26

def to_hash
  result = {
    name: @name,
    contents: @contents
  }
  result[:filename] = @filename if @filename
  result[:headers] = @headers if @headers
  result
end