class Itrp::Multipart::Post

Formats a given hash as a multipart form post If a hash value responds to :string or :read messages, then it is interpreted as a file and processed accordingly; otherwise, it is assumed to be a string

Constants

BOUNDARY
CONTENT_TYPE
USERAGENT

We have to pretend like we're a web browser…

Public Class Methods

prepare_query(params) click to toggle source
# File lib/itrp/client/multipart.rb, line 24
def self.prepare_query(params)
  fp = []

  params.each do |k, v|
    if v.respond_to?(:path) && v.respond_to?(:read)
      fp.push(FileParam.new(k, v.path, v.read))
    else
      fp.push(StringParam.new(k, v))
    end
  end

  # Assemble the request body using the special multipart format
  query = fp.map{ |p| "--#{BOUNDARY}\r\n#{p.to_multipart}" }.join  + "--#{BOUNDARY}--"
  return query, HEADER
end