Class: VoiceBase::Request::MultipartBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/voicebase/request/multipart_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(headers:) ⇒ MultipartBuilder

Returns a new instance of MultipartBuilder.



7
8
9
10
11
# File 'lib/voicebase/request/multipart_builder.rb', line 7

def initialize(headers:)
  @headers = headers
  @parts = []
  @boundary = SecureRandom.hex
end

Instance Attribute Details

#boundaryObject

Returns the value of attribute boundary.



6
7
8
# File 'lib/voicebase/request/multipart_builder.rb', line 6

def boundary
  @boundary
end

#partsObject

Returns the value of attribute parts.



6
7
8
# File 'lib/voicebase/request/multipart_builder.rb', line 6

def parts
  @parts
end

Instance Method Details

#add(part) ⇒ Object



13
14
15
# File 'lib/voicebase/request/multipart_builder.rb', line 13

def add(part)
  parts << part
end

#bodyObject



17
18
19
# File 'lib/voicebase/request/multipart_builder.rb', line 17

def body
  "--#{boundary}\r\n#{multiparts}--#{boundary}--"
end

#headersObject



21
22
23
# File 'lib/voicebase/request/multipart_builder.rb', line 21

def headers
  @headers.merge({"Content-Type" => "multipart/form-data; boundary=#{boundary}"})
end