class Jdoc::Request::Multipart

Constants

MULTIPART_BOUNDARY

Public Class Methods

boundary() click to toggle source

@return [String] returns boundary parameter for multipart content-type

# File lib/jdoc/request/multipart.rb, line 7
def self.boundary
  "boundary=#{MULTIPART_BOUNDARY}"
end
new(params) click to toggle source

@param params [Hash] request parameters

# File lib/jdoc/request/multipart.rb, line 12
def initialize(params)
  @params = params
end

Public Instance Methods

dump() click to toggle source

@return [String] request body of multipart/form-data request. @example

-----BoundaryX
Content-Disposition: form-data; name="file"

... contents of file ...
-----BoundaryX--
# File lib/jdoc/request/multipart.rb, line 23
def dump
  contents = Rack::Multipart::Generator.new(@params, false).dump.map do |name, content|
    content_part(content, name)
  end.join
  "#{contents}\r--#{MULTIPART_BOUNDARY}--\r"
end

Private Instance Methods

content_part(content, name) click to toggle source

return [String] content part of multipart/form-data request

# File lib/jdoc/request/multipart.rb, line 33
      def content_part(content, name)
<<-EOF
--#{MULTIPART_BOUNDARY}\r
Content-Disposition: form-data; name="#{name}"\r
\r
#{content}
EOF
      end