Skip to content

Instantly share code, notes, and snippets.

@kuahyeow
Created April 8, 2011 01:38
Show Gist options
  • Save kuahyeow/909137 to your computer and use it in GitHub Desktop.
Save kuahyeow/909137 to your computer and use it in GitHub Desktop.
Savon SOAP Response monkey patch to parse soap attachments
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