class Savon::SOAPFault

Attributes

http[R]
nori[R]

Public Class Methods

new(http, nori) click to toggle source
# File lib/savon/soap_fault.rb, line 14
def initialize(http, nori)
  @http = http
  @nori = nori
end
present?(http) click to toggle source
# File lib/savon/soap_fault.rb, line 6
def self.present?(http)
  fault_node  = http.body.include?("Fault>")
  soap1_fault = http.body.include?("faultcode>") && http.body.include?("faultstring>")
  soap2_fault = http.body.include?("Code>") && http.body.include?("Reason>")

  fault_node && (soap1_fault || soap2_fault)
end

Public Instance Methods

to_hash() click to toggle source
# File lib/savon/soap_fault.rb, line 26
def to_hash
  parsed = nori.parse(@http.body)
  nori.find(parsed, 'Envelope', 'Body')
end
to_s() click to toggle source
# File lib/savon/soap_fault.rb, line 21
def to_s
  fault = nori.find(to_hash, 'Fault')
  message_by_version(fault)
end

Private Instance Methods

message_by_version(fault) click to toggle source
# File lib/savon/soap_fault.rb, line 33
def message_by_version(fault)
  if nori.find(fault, 'faultcode')
    code = nori.find(fault, 'faultcode')
    text = nori.find(fault, 'faultstring')

    "(#{code}) #{text}"
  elsif nori.find(fault, 'Code')
    code = nori.find(fault, 'Code', 'Value')
    text = nori.find(fault, 'Reason', 'Text')

    "(#{code}) #{text}"
  end
end