Class: GData::HTTP::MimeBody

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#boundaryObject (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_typeObject

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