class DoneDone::Multipart::Post
Formats a given hash as a multipart form post If determine if the params are Files or Strings and process appropriately
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
HEADER = { “Content-Type” => CONTENT_TYPE
, “User-Agent” => USERAGENT
} unless const_defined?(:HEADER)
# File lib/donedone/multipart.rb, line 22 def self.prepare_query(params) fp = [] params.each do |k, v| if File.exists?(v) # must be a file path = File.path(v) content = File.binread(v) fp.push(FileParam.new(k, path, content)) else # must be a string 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, CONTENT_TYPE, USERAGENT end