class GData::HTTP::MimeBody
Class acts as a virtual file handle to a MIME multipart message body
Attributes
boundary[R]
The MIME boundary being used.
Public Class Methods
new(entry, file, file_mime_type)
click to toggle source
All fields are required, the entry should be a string and is assumed to be XML.
# File lib/gdata/http/mime_body.rb, line 27 def initialize(entry, file, file_mime_type) @boundary = "END_OF_PART_#{rand(64000)}" entry = wrap_entry(entry, file_mime_type) closing_boundary = MimeBodyString.new("\r\n--#{@boundary}--") @parts = [entry, file, closing_boundary] @current_part = 0 end
Public Instance Methods
content_type()
click to toggle source
Returns the content type of the message including boundary.
# File lib/gdata/http/mime_body.rb, line 54 def content_type return "multipart/related; boundary=\"#{@boundary}\"" end
read(bytes_requested)
click to toggle source
Implement read so that this class can be treated as a stream.
# File lib/gdata/http/mime_body.rb, line 36 def read(bytes_requested) if @current_part >= @parts.length return false end buffer = @parts[@current_part].read(bytes_requested) until buffer.length == bytes_requested @current_part += 1 next_buffer = self.read(bytes_requested - buffer.length) break if not next_buffer buffer += next_buffer end return buffer end
Private Instance Methods
wrap_entry(entry, file_mime_type)
click to toggle source
Sandwiches the entry body into a MIME message
# File lib/gdata/http/mime_body.rb, line 61 def wrap_entry(entry, file_mime_type) wrapped_entry = "--#{@boundary}\r\n" wrapped_entry += "Content-Type: application/atom+xml\r\n\r\n" wrapped_entry += entry wrapped_entry += "\r\n--#{@boundary}\r\n" wrapped_entry += "Content-Type: #{file_mime_type}\r\n\r\n" return MimeBodyString.new(wrapped_entry) end