Class: HTTP::Post

Inherits:
Object
  • Object
show all
Defined in:
lib/divshare/multipart.rb

Instance Method Summary collapse

Instance Method Details

#multipart_params=(param_hash = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/divshare/multipart.rb', line 9

def multipart_params=(param_hash={})
  boundary_token = [Array.new(8) {rand(256)}].join
  self.content_type = "multipart/form-data; boundary=#{boundary_token}"
  boundary_marker = "--#{boundary_token}\r\n"
  self.body = param_hash.map { |param_name, param_value|
    boundary_marker + case param_value
    when File
      file_to_multipart(param_name, param_value)
    else
      text_to_multipart(param_name, param_value.to_s)
    end
  }.join('') + "--#{boundary_token}--\r\n"
end