8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/salesfly/multipart.rb', line 8
def encode(params, files)
boundary = self.get_random_string()
lines = []
params.each do |key, value|
if value.kind_of?(Array)
value.each do |v|
lines.push(StringParam.new(key, v))
end
else
lines.push(StringParam.new(key, value))
end
end
files.each do |fn|
lines.push(FileParam.new(fn))
end
content = lines.collect {|p| "--" + boundary + "\r\n" + p.to_multipart }.join("") + "--" + boundary + "--"
= {
"Content-Type" => "multipart/form-data; boundary=#{ boundary }",
"Content-Length" => content.length.to_s
}
return content,
end
|