Class: Parts::FilePart

Inherits:
Object
  • Object
show all
Defined in:
lib/apple-news/multipart_post_patch.rb

Instance Method Summary collapse

Instance Method Details

#build_head(boundary, name, filename, type, content_len, opts = {}, headers = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/apple-news/multipart_post_patch.rb', line 7

def build_head(boundary, name, filename, type, content_len, opts = {}, headers = {})
  trans_encoding = opts["Content-Transfer-Encoding"] || "binary"
  content_disposition = opts["Content-Disposition"] || "form-data"

  part = ''
  part << "--#{boundary}\r\n"
  part << "Content-Disposition: #{content_disposition}; name=#{name}; filename=\"#{filename}\"; size=#{content_len}\r\n"
  part << "Content-Length: #{content_len}\r\n"
  if content_id = opts["Content-ID"]
    part << "Content-ID: #{content_id}\r\n"
  end

  if headers["Content-Type"] != nil
    part <<  "Content-Type: " + headers["Content-Type"] + "\r\n"
  else
    part << "Content-Type: #{type}\r\n"
  end

  part << "Content-Transfer-Encoding: #{trans_encoding}\r\n"
  part << "\r\n"
end