Class: Multipart::Post
- Inherits:
-
Object
- Object
- Multipart::Post
- Defined in:
- lib/common/http/multipart.rb
Overview
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
Constant Summary collapse
- USERAGENT =
We have to pretend like we’re a web browser…
"Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/523.10.6 (KHTML, like Gecko) Version/3.0.4 Safari/523.10.6"
- BOUNDARY =
BOUNDARY = “0123456789ABLEWASIEREISAWELBA9876543210” unless const_defined?(:BOUNDARY)
"--------------01234HELLOSPACE56789"
- CONTENT_TYPE =
"multipart/form-data; boundary=#{ BOUNDARY }"
- HEADER =
{ "Content-Type" => CONTENT_TYPE, "User-Agent" => USERAGENT }
Class Method Summary collapse
Class Method Details
.prepare_query(params) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/common/http/multipart.rb', line 27 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 + "--\r\n" return query, HEADER end |