def atsym(name) ("@"+(name.to_s)).to_sym end module SOAP::MultiService # Generic error provides base class for more specific errors # while still allowing a blanket rescue for any multiservice error. class Error < StandardError; end # Raised if a call is made to a method that does not exist in the multiservice API class UnknownAPICall < Error; end # Raised if an attempt is made to instantiate a type that does not exist in # the multiservice SOAP API class UnknownType < Error; end # Raised if a call returns with a SOAP error class ApiError < Error (Attrs = [ :soap_faultcode, :soap_faultstring, :code, :internal, :message, :trigger, :violations ]).each {|a|attr(a)} def initialize(fault) @soap_faultcode = getOrNil(fault, 'faultcode') @soap_faultstring = getOrNil(fault, 'faultstring') @code = getOrNil(fault.detail, 'code') @internal = getOrNil(fault.detail,'internal') @message = getOrNil(fault.detail,'message') @trigger = getOrNil(fault.detail,'trigger') @violations = getOrNil(fault.detail,'violations') end def inspect "#" end def message Attrs.map{|a| [a, instance_variable_get(atsym(a))] }. select{|p| p[1] }. map{|p| "#{p[0]}: #{p[1].inspect}" }.join(', ') end def to_s message end private def getOrNil(obj, meth) obj.respond_to?(meth) ? eval("obj.#{meth}") : nil end end end