Class: Savon::SOAP::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/savon/soap/response.rb

Overview

Savon::SOAP::Response

Represents the SOAP response and contains the HTTP response.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Expects an HTTPI::Response and handles errors.



14
15
16
17
# File 'lib/savon/soap/response.rb', line 14

def initialize(response)
  self.http = response
  raise_errors if Savon.raise_errors?
end

Instance Attribute Details

#httpObject

Returns the value of attribute http.



19
20
21
# File 'lib/savon/soap/response.rb', line 19

def http
  @http
end

Instance Method Details

#[](key) ⇒ Object

Shortcut accessor for the SOAP response body Hash.



47
48
49
# File 'lib/savon/soap/response.rb', line 47

def [](key)
  body[key]
end

#bodyObject Also known as: to_hash

Returns the SOAP response body as a Hash.



57
58
59
# File 'lib/savon/soap/response.rb', line 57

def body
  hash[:envelope][:body]
end

#docObject

Returns a Nokogiri::XML::Document for the SOAP response XML.



86
87
88
# File 'lib/savon/soap/response.rb', line 86

def doc
  @doc ||= Nokogiri::XML(to_xml)
end

#hashObject

Returns the complete SOAP response XML without normalization.



76
77
78
# File 'lib/savon/soap/response.rb', line 76

def hash
  @hash ||= Nori.parse(to_xml)
end

#headerObject

Returns the SOAP response header as a Hash.



52
53
54
# File 'lib/savon/soap/response.rb', line 52

def header
  hash[:envelope][:header]
end

#http_errorObject

Returns the Savon::HTTP::Error.



42
43
44
# File 'lib/savon/soap/response.rb', line 42

def http_error
  @http_error ||= HTTP::Error.new http
end

#http_error?Boolean

Returns whether there was an HTTP error.

Returns:

  • (Boolean)


37
38
39
# File 'lib/savon/soap/response.rb', line 37

def http_error?
  http_error.present?
end

#soap_faultObject

Returns the Savon::SOAP::Fault.



32
33
34
# File 'lib/savon/soap/response.rb', line 32

def soap_fault
  @soap_fault ||= Fault.new http
end

#soap_fault?Boolean

Returns whether there was a SOAP fault.

Returns:

  • (Boolean)


27
28
29
# File 'lib/savon/soap/response.rb', line 27

def soap_fault?
  soap_fault.present?
end

#success?Boolean

Returns whether the request was successful.

Returns:

  • (Boolean)


22
23
24
# File 'lib/savon/soap/response.rb', line 22

def success?
  !soap_fault? && !http_error?
end

#to_array(*path) ⇒ Object

Traverses the SOAP response body Hash for a given path of Hash keys and returns the value as an Array. Defaults to return an empty Array in case the path does not exist or returns nil.



66
67
68
69
70
71
72
73
# File 'lib/savon/soap/response.rb', line 66

def to_array(*path)
  result = path.inject body do |memo, key|
    return [] unless memo[key]
    memo[key]
  end

  result.kind_of?(Array) ? result.compact : [result].compact
end

#to_xmlObject

Returns the SOAP response XML.



81
82
83
# File 'lib/savon/soap/response.rb', line 81

def to_xml
  http.body
end

#xpath(path, namespaces = nil) ⇒ Object

Returns an Array of Nokogiri::XML::Node objects retrieved with the given path. Automatically adds all of the document’s namespaces unless a namespaces hash is provided.



92
93
94
# File 'lib/savon/soap/response.rb', line 92

def xpath(path, namespaces = nil)
  doc.xpath(path, namespaces || xml_namespaces)
end