Created
April 8, 2011 01:38
-
-
Save kuahyeow/909137 to your computer and use it in GitHub Desktop.
Savon SOAP Response monkey patch to parse soap attachments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mail' | |
module Savon | |
module SOAP | |
class Response | |
def multipart? | |
http.headers["Content-Type"] =~ /^multipart/ | |
end | |
def boundary | |
@boundary ||= Mail::Field.new("Content-Type", http.headers["Content-Type"]).parameters['boundary'] | |
end | |
def parts | |
return [] unless multipart? | |
return @parts if @parts | |
part_of_parts = Mail::Part.new(:headers => http.headers, :body => http.body) | |
part_of_parts.body.split!(boundary) | |
@parts = part_of_parts.parts | |
end | |
def attachments | |
parts.attachments | |
end | |
def raw | |
http.body | |
end | |
def to_xml | |
if multipart? | |
parts.first.body.encoded # we just assume the first part is the XML | |
else | |
http.body | |
end | |
end | |
def basic_hash | |
@basic_hash ||= Savon::SOAP::XML.parse to_xml | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment