Module: MetaProject::HTTP::Multipart

Included in:
Project::XForge::Session, Tracker::XForge::XForgeTracker::SubTracker
Defined in:
lib/meta_project/http/multipart.rb

Overview

TODO make this an extension of Net::HTTP and nicify the API

Constant Summary collapse

BOUNDARY =

:nodoc:

"rubyqMY6QN9bp6e4kS21H4y0zxcvoor"

Instance Method Summary collapse

Instance Method Details

#post_data(*params) ⇒ Object

Converts an Array or Hash into HTTP POST params



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/meta_project/http/multipart.rb', line 13

def post_data(*params)
  form = []
  params.each do |param|
    case param
    when Array
      form << param
    when Hash
      param.each do |key, value|
        form <<
          "--#{BOUNDARY}" <<
          %Q(Content-Disposition: form-data; name="#{key}") <<
          "" << value
      end
    end
  end
  form.flatten.join("\r\n")
end

#post_multipart(http, target, params, headers) ⇒ Object



7
8
9
10
# File 'lib/meta_project/http/multipart.rb', line 7

def post_multipart(http, target, params, headers)
  headers = headers.merge("Content-Type" => "multipart/form-data; boundary=#{BOUNDARY}")
  http.post(target, post_data(params), headers)
end