class MIME::Multipart::Builder
inherits Reference
¶
Builds a multipart MIME message.
Example¶
require "mime/multipart"
io = IO::Memory.new # This is a stub. Actually, any IO can be used.
multipart = MIME::Multipart::Builder.new(io)
multipart.body_part HTTP::Headers{"Content-Type" => "text/plain"}, "hello!"
multipart.finish
io.to_s # => "----------------------------DTf61dRTHYzprx7rwVQhTWr7\r\nContent-Type: text/plain\r\n\r\nhello!\r\n----------------------------DTf61dRTHYzprx7rwVQhTWr7--"
Class methods¶
.new(io : IO, boundary = Multipart.generate_boundary)
¶
(io : IO, boundary = Multipart.generate_boundary)
Creates a new Multipart::Builder
which writes the generated multipart
message to io, using the multipart boundary boundary.
Methods¶
#body_part(headers : HTTP::Headers, string : String)
¶
(headers : HTTP::Headers, string : String)
Appends a body part to the multipart message with the given headers
and string. Throws if #finish
or #epilogue
is called before this
method.
#body_part(headers : HTTP::Headers, data : Bytes)
¶
(headers : HTTP::Headers, data : Bytes)
Appends a body part to the multipart message with the given headers
and data. Throws if #finish
or #epilogue
is called before this
method.
#body_part(headers : HTTP::Headers, body_io : IO)
¶
(headers : HTTP::Headers, body_io : IO)
Appends a body part to the multipart message with the given headers
and data from body_io. Throws if #finish
or #epilogue
is called
before this method.
#body_part(headers : HTTP::Headers
¶
(headers : HTTP::Headers
Yields an IO that can be used to write to a body part which is appended
to the multipart message with the given headers. Throws if #finish
or
#epilogue
is called before this method.
#body_part(headers : HTTP::Headers)
¶
(headers : HTTP::Headers)
Appends a body part to the multipart message with the given headers
and no body data. Throws is #finish
or #epilogue
is called before
this method.
#content_type(subtype = "mixed")
¶
(subtype = "mixed")
Returns a content type header with multipart subtype subtype, and boundary parameter added.
require "mime/multipart"
io = IO::Memory.new # This is a stub. Actually, any IO can be used.
builder = MIME::Multipart::Builder.new(io, "a4VF")
builder.content_type("mixed") # => "multipart/mixed; boundary=a4VF"
#epilogue(string : String)
¶
(string : String)
Appends string to the epilogue segment of the multipart message. Throws
if #finish
is called before this method, or no body parts have been
appended.
Can be called multiple times to append to the epilogue multiple times.
#epilogue(data : Bytes)
¶
(data : Bytes)
Appends data to the epilogue segment of the multipart message. Throws
if #finish
is called before this method, or no body parts have been
appended.
Can be called multiple times to append to the epilogue multiple times.
#epilogue(epilogue_io : IO)
¶
(epilogue_io : IO)
Appends preamble_io to the epilogue segment of the multipart message.
Throws if #finish
is called before this method, or no body parts have
been appended.
Can be called multiple times to append to the epilogue multiple times.
#epilogue
¶
Yields an IO that can be used to append to the epilogue of the multipart
message. Throws if #finish
is called before this method, or no body
parts have been appended.
Can be called multiple times to append to the preamble multiple times.
#finish
¶
Finalizes the multipart message, this method must be called to properly end the multipart message.
#preamble(string : String)
¶
(string : String)
Appends string to the preamble segment of the multipart message. Throws
if #body_part
is called before this method.
Can be called multiple times to append to the preamble multiple times.
#preamble(data : Bytes)
¶
(data : Bytes)
Appends data to the preamble segment of the multipart message. Throws
if #body_part
is called before this method.
Can be called multiple times to append to the preamble multiple times.
#preamble(preamble_io : IO)
¶
(preamble_io : IO)
Appends preamble_io to the preamble segment of the multipart message.
Throws if #body_part
is called before this method.
Can be called multiple times to append to the preamble multiple times.
#preamble
¶
Yields an IO that can be used to append to the preamble of the multipart
message. Throws if #body_part
is called before this method.
Can be called multiple times to append to the preamble multiple times.