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.
28 29 30 31 32 33 34 |
# File 'lib/gdata/http/mime_body.rb', line 28 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.
24 25 26 |
# File 'lib/gdata/http/mime_body.rb', line 24 def boundary @boundary end |
Instance Method Details
#content_type ⇒ Object
Returns the content type of the message including boundary.
55 56 57 |
# File 'lib/gdata/http/mime_body.rb', line 55 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.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/gdata/http/mime_body.rb', line 37 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 |