Sha256: a57dd7e2608773c88ce6b6f7b31674f21eddfdaca275512d4826f3bab7440a02
Contents?: true
Size: 946 Bytes
Versions: 14
Compression:
Stored size: 946 Bytes
Contents
module Vzaar module Request class Multipart < Struct.new(:path, :file) CRLF = "\r\n" def request req = Net::HTTP::Post.new(path) req.body = build_body req["Content-Type"] = "multipart/form-data; boundary=#{boundary}" req["Content-Length"] = req.body.size req end private def build_body body = "" body << "--#{boundary}#{CRLF}" body << "Content-Disposition: form-data;"\ " name=\"vzaar-api[thumbnail]\"; filename=\"#{filename}\"#{CRLF}" body << "Content-Type: image/#{file_format}#{CRLF*2}" body << file.read body << CRLF body << "--#{boundary}--#{CRLF*2}" body end def boundary @boundary ||= Time.now.to_i.to_s(16) end def filename File.basename(file.path) end def file_format filename.split(/\./).last end end end end
Version data entries
14 entries across 14 versions & 1 rubygems