Class: GData::HTTP::MimeBody
- Inherits:
-
Object
- Object
- GData::HTTP::MimeBody
- Defined in:
- lib/gdata/http/mime_body.rb
Overview
Class acts as a virtual file handle to a MIME multipart message body
Instance Attribute Summary collapse
-
#boundary ⇒ Object
readonly
The MIME boundary being used.
Instance Method Summary collapse
-
#content_type ⇒ Object
Returns the content type of the message including boundary.
-
#initialize(entry, file, file_mime_type) ⇒ MimeBody
constructor
All fields are required, the entry should be a string and is assumed to be XML.
-
#read(bytes_requested) ⇒ Object
Implement read so that this class can be treated as a stream.
Constructor Details
#initialize(entry, file, file_mime_type) ⇒ MimeBody
All fields are required, the entry should be a string and is assumed to be XML.
27 28 29 30 31 32 33 |
# 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 |
Instance Attribute Details
#boundary ⇒ Object (readonly)
The MIME boundary being used.
23 24 25 |
# File 'lib/gdata/http/mime_body.rb', line 23 def boundary @boundary end |
Instance Method Details
#content_type ⇒ Object
Returns the content type of the message including boundary.
54 55 56 |
# File 'lib/gdata/http/mime_body.rb', line 54 def content_type return "multipart/related; boundary=\"#{@boundary}\"" end |
#read(bytes_requested) ⇒ Object
Implement read so that this class can be treated as a stream.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# 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 |