Sha256: d1777ff4a015dbc571d1bc09c83c5e2636dc1cad1d52c0d70a702368b5bfff25

Contents?: true

Size: 622 Bytes

Versions: 1

Compression:

Stored size: 622 Bytes

Contents

require "securerandom"

module VoiceBase
  module Request
    class MultipartBuilder
      attr_accessor :parts, :boundary
      def initialize(headers:)
        @headers = headers
        @parts = []
        @boundary = SecureRandom.hex
      end

      def add(part)
        parts << part
      end

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

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

      private

      def multiparts
        parts.map(&:multipart).join("--#{boundary}\r\n")
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
voicebase-client-ruby-1.3.0 lib/voicebase/request/multipart_builder.rb