Class: Savon::SOAP::Response
- Inherits:
-
Object
- Object
- Savon::SOAP::Response
- Defined in:
- lib/savon/soap/response.rb
Overview
Savon::SOAP::Response
Represents the SOAP response and contains the HTTP response.
Instance Attribute Summary collapse
-
#http ⇒ Object
Returns the value of attribute http.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Shortcut accessor for the SOAP response body Hash.
-
#body ⇒ Object
(also: #to_hash)
Returns the SOAP response body as a Hash.
-
#doc ⇒ Object
Returns a
Nokogiri::XML::Document
for the SOAP response XML. -
#hash ⇒ Object
Returns the complete SOAP response XML without normalization.
-
#header ⇒ Object
Returns the SOAP response header as a Hash.
-
#http_error ⇒ Object
Returns the
Savon::HTTP::Error
. -
#http_error? ⇒ Boolean
Returns whether there was an HTTP error.
-
#initialize(response) ⇒ Response
constructor
Expects an
HTTPI::Response
and handles errors. -
#soap_fault ⇒ Object
Returns the
Savon::SOAP::Fault
. -
#soap_fault? ⇒ Boolean
Returns whether there was a SOAP fault.
-
#success? ⇒ Boolean
Returns whether the request was successful.
-
#to_array(*path) ⇒ Object
Traverses the SOAP response body Hash for a given
path
of Hash keys and returns the value as an Array. -
#to_xml ⇒ Object
Returns the SOAP response XML.
-
#xpath(path, namespaces = nil) ⇒ Object
Returns an Array of
Nokogiri::XML::Node
objects retrieved with the givenpath
.
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
#http ⇒ Object
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 |
#body ⇒ Object 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 |
#doc ⇒ Object
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 |
#hash ⇒ Object
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 |
#header ⇒ Object
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_error ⇒ Object
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.
37 38 39 |
# File 'lib/savon/soap/response.rb', line 37 def http_error? http_error.present? end |
#soap_fault ⇒ Object
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.
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.
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_xml ⇒ Object
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 |