Class: WSDiscovery::Response
- Inherits:
-
Object
- Object
- WSDiscovery::Response
- Defined in:
- lib/ws_discovery/response.rb
Overview
Represents the probe response.
Instance Attribute Summary collapse
-
#response ⇒ Object
Returns the value of attribute response.
Instance Method Summary collapse
-
#[](key) ⇒ Hash, String
Shortcut accessor for the SOAP response body Hash.
-
#body ⇒ Hash
(also: #to_hash)
Returns the SOAP response body as a Hash.
-
#doc ⇒ Nokogiri::XML::Document
Returns a Nokogiri::XML::Document for the SOAP response XML.
-
#hash ⇒ Hash
Returns the complete SOAP response XML without normalization.
-
#header ⇒ Hash
Returns the SOAP response header as a Hash.
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
-
#to_xml ⇒ String
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(response) ⇒ Response
Returns a new instance of Response.
13 14 15 |
# File 'lib/ws_discovery/response.rb', line 13 def initialize(response) @response = response end |
Instance Attribute Details
#response ⇒ Object
Returns the value of attribute response.
10 11 12 |
# File 'lib/ws_discovery/response.rb', line 10 def response @response end |
Instance Method Details
#[](key) ⇒ Hash, String
Shortcut accessor for the SOAP response body Hash.
21 22 23 |
# File 'lib/ws_discovery/response.rb', line 21 def [](key) body[key] end |
#body ⇒ Hash Also known as: to_hash
Returns the SOAP response body as a Hash.
41 42 43 44 45 46 47 |
# File 'lib/ws_discovery/response.rb', line 41 def body unless hash.has_key? :envelope raise WSDiscovery::Error, "Unable to parse response body '#{to_xml}'" end hash[:envelope][:body] end |
#doc ⇒ Nokogiri::XML::Document
Returns a Nokogiri::XML::Document for the SOAP response XML.
68 69 70 |
# File 'lib/ws_discovery/response.rb', line 68 def doc @doc ||= Nokogiri::XML(to_xml) end |
#hash ⇒ Hash
Returns the complete SOAP response XML without normalization.
54 55 56 |
# File 'lib/ws_discovery/response.rb', line 54 def hash @hash ||= nori.parse(to_xml) end |
#header ⇒ Hash
Returns the SOAP response header as a Hash.
29 30 31 32 33 34 35 |
# File 'lib/ws_discovery/response.rb', line 29 def header unless hash.has_key? :envelope raise WSDiscovery::Error, "Unable to parse response body '#{to_xml}'" end hash[:envelope][:header] end |
#to_xml ⇒ String
Returns the SOAP response XML.
61 62 63 |
# File 'lib/ws_discovery/response.rb', line 61 def to_xml response 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.
77 78 79 |
# File 'lib/ws_discovery/response.rb', line 77 def xpath(path, namespaces = nil) doc.xpath(path, namespaces || xml_namespaces) end |