class Savon::Response

Attributes

globals[R]
http[R]
http_error[R]
locals[R]
soap_fault[R]

Public Class Methods

new(http, globals, locals) click to toggle source
# File lib/savon/response.rb, line 8
def initialize(http, globals, locals)
  @http    = http
  @globals = globals
  @locals  = locals

  build_soap_and_http_errors!
  raise_soap_and_http_errors! if @globals[:raise_errors]
end

Public Instance Methods

body() click to toggle source
# File lib/savon/response.rb, line 36
def body
  find('Body')
end
Also aliased as: to_hash
doc() click to toggle source
# File lib/savon/response.rb, line 62
def doc
  @doc ||= Nokogiri.XML(xml)
end
find(*path) click to toggle source
# File lib/savon/response.rb, line 70
def find(*path)
  envelope = nori.find(hash, 'Envelope')
  raise_invalid_response_error! unless envelope

  nori.find(envelope, *path)
end
hash() click to toggle source
# File lib/savon/response.rb, line 51
def hash
  @hash ||= nori.parse(xml)
end
header() click to toggle source
# File lib/savon/response.rb, line 32
def header
  find('Header')
end
http_error?() click to toggle source
# File lib/savon/response.rb, line 28
def http_error?
  HTTPError.present? @http
end
soap_fault?() click to toggle source
# File lib/savon/response.rb, line 24
def soap_fault?
  SOAPFault.present?(@http, xml)
end
success?() click to toggle source
# File lib/savon/response.rb, line 19
def success?
  !soap_fault? && !http_error?
end
Also aliased as: successful?
successful?()
Alias for: success?
to_array(*path) click to toggle source
# File lib/savon/response.rb, line 42
def to_array(*path)
  result = path.inject body do |memo, key|
    return [] if memo[key].nil?
    memo[key]
  end

  result.kind_of?(Array) ? result.compact : [result].compact
end
to_hash()
Alias for: body
to_s()
Alias for: xml
to_xml()
Alias for: xml
xml() click to toggle source
# File lib/savon/response.rb, line 55
def xml
  @http.body
end
Also aliased as: to_xml, to_s
xpath(path, namespaces = nil) click to toggle source
# File lib/savon/response.rb, line 66
def xpath(path, namespaces = nil)
  doc.xpath(path, namespaces || xml_namespaces)
end

Private Instance Methods

build_soap_and_http_errors!() click to toggle source
# File lib/savon/response.rb, line 79
def build_soap_and_http_errors!
  @soap_fault = SOAPFault.new(@http, nori, xml) if soap_fault?
  @http_error = HTTPError.new(@http) if http_error?
end
nori() click to toggle source
# File lib/savon/response.rb, line 97
def nori
  return @nori if @nori

  nori_options = {
    :strip_namespaces      => @globals[:strip_namespaces],
    :convert_tags_to       => @globals[:convert_response_tags_to],
    :convert_attributes_to => @globals[:convert_attributes_to],
    :advanced_typecasting  => @locals[:advanced_typecasting],
    :parser                => @locals[:response_parser]
  }

  non_nil_nori_options = nori_options.reject { |_, value| value.nil? }
  @nori = Nori.new(non_nil_nori_options)
end
raise_invalid_response_error!() click to toggle source
# File lib/savon/response.rb, line 89
def raise_invalid_response_error!
  raise InvalidResponseError, "Unable to parse response body:\n" + xml.inspect
end
raise_soap_and_http_errors!() click to toggle source
# File lib/savon/response.rb, line 84
def raise_soap_and_http_errors!
  raise soap_fault if soap_fault?
  raise http_error if http_error?
end
xml_namespaces() click to toggle source
# File lib/savon/response.rb, line 93
def xml_namespaces
  @xml_namespaces ||= doc.collect_namespaces
end