class 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
- HEADER
- USERAGENT
We have to pretend like we’re a web browser…
Public Class Methods
prepare_query(params)
click to toggle source
# File lib/pamfaxr/multipart.rb, line 22 def self.prepare_query(params) fp = [] params.each do |k, v| # Are we trying to make a file parameter? if v.respond_to?(:path) and v.respond_to?(:read) then fp.push(FileParam.new(k, v.path, v.read)) # We must be trying to make a regular parameter else fp.push(StringParam.new(k, v)) end end # Assemble the request body using the special multipart format query = fp.collect {|p| "--" + BOUNDARY + "\r\n" + p.to_multipart }.join("") + "--" + BOUNDARY + "--" return query, HEADER end