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
-
#config ⇒ Object
Returns the value of attribute config.
-
#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(config, 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 given +path+.
Constructor Details
#initialize(config, response) ⇒ Response
Expects an HTTPI::Response and handles errors.
15 16 17 18 19 |
# File 'lib/savon/soap/response.rb', line 15 def initialize(config, response) self.config = config self.http = response raise_errors if config.raise_errors end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
21 22 23 |
# File 'lib/savon/soap/response.rb', line 21 def config @config end |
#http ⇒ Object
Returns the value of attribute http.
21 22 23 |
# File 'lib/savon/soap/response.rb', line 21 def http @http end |
Instance Method Details
#[](key) ⇒ Object
Shortcut accessor for the SOAP response body Hash.
49 50 51 |
# File 'lib/savon/soap/response.rb', line 49 def [](key) body[key] end |
#body ⇒ Object Also known as: to_hash
Returns the SOAP response body as a Hash.
62 63 64 65 66 67 |
# File 'lib/savon/soap/response.rb', line 62 def body if !hash.has_key? :envelope raise Savon::SOAP::InvalidResponseError, "Unable to parse response body '#{to_xml}'" end hash[:envelope][:body] end |
#doc ⇒ Object
Returns a Nokogiri::XML::Document for the SOAP response XML.
94 95 96 |
# File 'lib/savon/soap/response.rb', line 94 def doc @doc ||= Nokogiri::XML(to_xml) end |
#hash ⇒ Object
Returns the complete SOAP response XML without normalization.
84 85 86 |
# File 'lib/savon/soap/response.rb', line 84 def hash @hash ||= Nori.parse(to_xml) end |
#header ⇒ Object
Returns the SOAP response header as a Hash.
54 55 56 57 58 59 |
# File 'lib/savon/soap/response.rb', line 54 def header if !hash.has_key? :envelope raise Savon::SOAP::InvalidResponseError, "Unable to parse response body '#{to_xml}'" end hash[:envelope][:header] end |
#http_error ⇒ Object
Returns the Savon::HTTP::Error.
44 45 46 |
# File 'lib/savon/soap/response.rb', line 44 def http_error @http_error ||= HTTP::Error.new http end |
#http_error? ⇒ Boolean
Returns whether there was an HTTP error.
39 40 41 |
# File 'lib/savon/soap/response.rb', line 39 def http_error? http_error.present? end |
#soap_fault ⇒ Object
Returns the Savon::SOAP::Fault.
34 35 36 |
# File 'lib/savon/soap/response.rb', line 34 def soap_fault @soap_fault ||= Fault.new http end |
#soap_fault? ⇒ Boolean
Returns whether there was a SOAP fault.
29 30 31 |
# File 'lib/savon/soap/response.rb', line 29 def soap_fault? soap_fault.present? end |
#success? ⇒ Boolean
Returns whether the request was successful.
24 25 26 |
# File 'lib/savon/soap/response.rb', line 24 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.
74 75 76 77 78 79 80 81 |
# File 'lib/savon/soap/response.rb', line 74 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.
89 90 91 |
# File 'lib/savon/soap/response.rb', line 89 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.
100 101 102 |
# File 'lib/savon/soap/response.rb', line 100 def xpath(path, namespaces = nil) doc.xpath(path, namespaces || xml_namespaces) end |