Class: Multipart::Post
- Inherits:
-
Object
- Object
- Multipart::Post
- Defined in:
- lib/mls/models/document.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
Class Method Summary collapse
Class Method Details
.prepare_query(params) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/mls/models/document.rb', line 89 def self.prepare_query(params) boundary = "-----RubyMultipartClient~#{SecureRandom.hex(32)}" parts = params.map do |k, v| if v.respond_to?(:path) && v.respond_to?(:read) FileParam.new(k, v) else StringParam.new(k, v) end end query = parts.map {|p| "--#{boundary}\r\n#{p.to_multipart}" }.join('') + "--#{boundary}--" return query, { "Content-Type" => "multipart/form-data; boundary=#{boundary}" } end |