Module: HTTPMultipart

Included in:
Net::HTTPOK, Net::HTTPResponse
Defined in:
lib/jasper-client/http_multipart.rb

Overview

A mixin to add basic RFC 2387 MIME Multipart/Related response support.

A multipart http response has several sections which are intended to be treated as indpendent objects. The Multipart/Related response is used when all of the objects are related to one another. Typcially multipart is used to have alternative versions of the same content. This is not the case with multipart related.

This mixen was written while using the Savon SOAP API, but it’s intended to be mixed in to Net::HTTP and does not have any known dependencies on Savon.

www.faqs.org/rfcs/rfc2387.html

Defined Under Namespace

Classes: Part

Instance Method Summary collapse

Instance Method Details

#each_part(&block) ⇒ Object

Iterate through each part calling the block. A Part is yielded to the block.



98
99
100
101
102
103
104
105
106
# File 'lib/jasper-client/http_multipart.rb', line 98

def each_part(&block)
  if multipart?
    parts.each do |part|
      yield part
    end
  else
    yield self
  end
end

#multipart?Boolean

Am I multipart?

Returns:

  • (Boolean)


69
70
71
# File 'lib/jasper-client/http_multipart.rb', line 69

def multipart?
  %w{multipart/related}.include? content_type
end

#multipart_boundaryObject

Fetch the multipart boundary.



74
75
76
# File 'lib/jasper-client/http_multipart.rb', line 74

def multipart_boundary
  content_type_fields['boundary']
end

#partsObject

return an array of parts.



90
91
92
93
94
# File 'lib/jasper-client/http_multipart.rb', line 90

def parts
    pts = body.split("--%s" % [ multipart_boundary ])
    pts.shift
    pts.reject { |part| part == "--\r\n" }.map { |part| Part.new(part) }
end

#startObject

The ID of the “start part” or initial part of the multipart related response.



80
81
82
# File 'lib/jasper-client/http_multipart.rb', line 80

def start
  content_type_fields['start']
end

#start_partObject

Return the start part.



85
86
87
# File 'lib/jasper-client/http_multipart.rb', line 85

def start_part
  parts.select { |p| p.content_id.first == start }.first.body
end