Class: Reactor::Cm::XmlResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/reactor/cm/xml_response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ XmlResponse

Returns a new instance of XmlResponse.



10
11
12
13
14
15
# File 'lib/reactor/cm/xml_response.rb', line 10

def initialize(xml)
  @xml_str = xml
  @xml = REXML::Document.new(xml)
  @handler = Reactor::ResponseHandler::XmlAttribute.new
  @xpath = Reactor::XPathExtractor.new(@xml)
end

Instance Attribute Details

#xmlObject (readonly)

Returns the value of attribute xml.



8
9
10
# File 'lib/reactor/cm/xml_response.rb', line 8

def xml
  @xml
end

#xml_strObject (readonly)

Returns the value of attribute xml_str.



8
9
10
# File 'lib/reactor/cm/xml_response.rb', line 8

def xml_str
  @xml_str
end

Instance Method Details

#ok?Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
29
30
31
# File 'lib/reactor/cm/xml_response.rb', line 21

def ok?
  xp = xpath("//cm-code")

  if xp.is_a?(Array)
    codes = xp.map { |result| result.attribute("numeric").value }.uniq

    return codes.size == 1 && codes.first == "200"
  end

  xp.attribute("numeric").value == "200"
end

#xpath(expr) ⇒ Object



17
18
19
# File 'lib/reactor/cm/xml_response.rb', line 17

def xpath(expr)
  @xpath.match(expr)
end