Class: Candid::Internal::Multipart::FormData Private

Inherits:
Object
  • Object
show all
Defined in:
lib/candid/internal/multipart/multipart_form_data.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

#initializeFormData

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 FormData.



14
15
16
17
# File 'lib/candid/internal/multipart/multipart_form_data.rb', line 14

def initialize
  @encoder = Encoder.new
  @parts = []
end

Instance Attribute Details

#partsArray<FormDataPart> (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.

Returns The parts in this multipart form data.



9
10
11
# File 'lib/candid/internal/multipart/multipart_form_data.rb', line 9

def parts
  @parts
end

Instance Method Details

#add(name:, value:, content_type: nil) ⇒ self

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.

Adds a new part to the multipart form data.



25
26
27
28
# File 'lib/candid/internal/multipart/multipart_form_data.rb', line 25

def add(name:, value:, content_type: nil)
  headers = content_type ? { "Content-Type" => content_type } : nil
  add_part(FormDataPart.new(name:, value:, headers:))
end

#add_file(name:, file:, filename: nil, content_type: nil) ⇒ self

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.

Adds a file to the multipart form data.



37
38
39
40
41
# File 'lib/candid/internal/multipart/multipart_form_data.rb', line 37

def add_file(name:, file:, filename: nil, content_type: nil)
  headers = content_type ? { "Content-Type" => content_type } : nil
  filename ||= filename_for(file)
  add_part(FormDataPart.new(name:, value: file, filename:, headers:))
end

#add_part(part) ⇒ self

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.

Adds a pre-created part to the multipart form data.



47
48
49
50
# File 'lib/candid/internal/multipart/multipart_form_data.rb', line 47

def add_part(part)
  @parts << part
  self
end

#content_typeString

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.

Gets the content type string including the boundary.



55
56
57
# File 'lib/candid/internal/multipart/multipart_form_data.rb', line 55

def content_type
  @encoder.content_type
end

#encodeString

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.

Encode the multipart form data into a multipart/form-data payload.



62
63
64
# File 'lib/candid/internal/multipart/multipart_form_data.rb', line 62

def encode
  @encoder.encode(self)
end