class VoiceBase::Request::MultipartBuilder

Attributes

boundary[RW]
parts[RW]

Public Class Methods

new(headers:) click to toggle source
# File lib/voicebase/request/multipart_builder.rb, line 7
def initialize(headers:)
  @headers = headers
  @parts = []
  @boundary = SecureRandom.hex
end

Public Instance Methods

add(part) click to toggle source
# File lib/voicebase/request/multipart_builder.rb, line 13
def add(part)
  parts << part
end
body() click to toggle source
# File lib/voicebase/request/multipart_builder.rb, line 17
def body
  "--#{boundary}\r\n#{multiparts}--#{boundary}--"
end
headers() click to toggle source
# File lib/voicebase/request/multipart_builder.rb, line 21
def headers
  @headers.merge({"Content-Type" => "multipart/form-data; boundary=#{boundary}"})
end

Private Instance Methods

multiparts() click to toggle source
# File lib/voicebase/request/multipart_builder.rb, line 27
def multiparts
  parts.map(&:multipart).join("--#{boundary}\r\n")
end