Class: WSDiscovery::Response

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

Overview

Represents the probe response.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Returns a new instance of Response.

Parameters:

  • response (String)

    Text of the response to a WSDiscovery probe.



13
14
15
# File 'lib/ws_discovery/response.rb', line 13

def initialize(response)
  @response = response
end

Instance Attribute Details

#responseObject

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.

Parameters:

  • key (Symbol)

    The key to access in the body Hash.

Returns:

  • (Hash, String)

    The accessed value.



21
22
23
# File 'lib/ws_discovery/response.rb', line 21

def [](key)
  body[key]
end

#bodyHash Also known as: to_hash

Returns the SOAP response body as a Hash.

Returns:

  • (Hash)

    SOAP response body.

Raises:



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

#docNokogiri::XML::Document

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

Returns:

  • (Nokogiri::XML::Document)

    Document for the SOAP response.



68
69
70
# File 'lib/ws_discovery/response.rb', line 68

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

#hashHash

Returns the complete SOAP response XML without normalization.

Returns:

  • (Hash)

    Complete SOAP response Hash.



54
55
56
# File 'lib/ws_discovery/response.rb', line 54

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

#headerHash

Returns the SOAP response header as a Hash.

Returns:

  • (Hash)

    SOAP response header.

Raises:



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_xmlString

Returns the SOAP response XML.

Returns:

  • (String)

    Raw 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.

Parameters:

  • path (String)

    XPath to search.

  • namespaces (Hash<String>) (defaults to: nil)

    Namespaces to append.



77
78
79
# File 'lib/ws_discovery/response.rb', line 77

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