Class: Wrike3::Helper
- Inherits:
-
Object
- Object
- Wrike3::Helper
- Defined in:
- lib/wrike3/utils.rb
Constant Summary collapse
- CRLF =
"\r\n"
Class Method Summary collapse
Class Method Details
.http_multipart_data(params) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/wrike3/utils.rb', line 6 def http_multipart_data(params) body = '' headers = {} boundary = Time.now.to_i.to_s(16) headers["Content-Type"] = "multipart/form-data; boundary=#{boundary}" # params.each do |key, value| # esc_key = OAuth::Helper.escape(key.to_s) # body << "--#{boundary}#{CRLF}" # # if value.respond_to?(:read) # mime_type = MIME::Types.type_for(value.path)[0] || MIME::Types["application/octet-stream"][0] # body << "Content-Disposition: form-data; name=\"#{esc_key}\"; filename=\"#{File.basename(value.path)}\"#{CRLF}" # body << "Content-Type: #{mime_type.simplified}#{CRLF*2}" # body << value.read # else # body << "Content-Disposition: form-data; name=\"#{esc_key}\"#{CRLF*2}#{value}" # end # end body << "--#{boundary}--#{CRLF*2}" headers["Content-Length"] = body.size.to_s return [body, headers] end |