class RestClient::Payload::Multipart

Public Instance Methods

build_stream(params) click to toggle source
# File lib/report_portal/patches/rest_client.rb, line 24
def build_stream(params)
  content_type = params.delete(:content_type)
  b = '--' + boundary

  @stream = Tempfile.new("RESTClient.Stream.#{rand(1000)}")
  @stream.binmode
  @stream.write(b + EOL)

  case params
  when Hash, ParamsArray
    x = Utils.flatten_params(params)
  else
    x = params
  end

  last_index = x.length - 1
  x.each_with_index do |a, index|
    k, v = * a
    if v.respond_to?(:read) && v.respond_to?(:path)
      create_file_field(@stream, k, v)
    else
      create_regular_field(@stream, k, v, content_type)
    end
    @stream.write(EOL + b)
    @stream.write(EOL) unless last_index == index
  end
  @stream.write('--')
  @stream.write(EOL)
  @stream.seek(0)
end
create_regular_field(s, k, v, type = nil) click to toggle source
# File lib/report_portal/patches/rest_client.rb, line 55
def create_regular_field(s, k, v, type = nil)
  s.write("Content-Disposition: form-data; name=\"#{k}\"")
  s.write("#{EOL}Content-Type: #{type}#{EOL}") if type
  s.write(EOL)
  s.write(v)
end