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.



14
15
16
17
18
# File 'lib/reactor/cm/xml_response.rb', line 14

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

Instance Attribute Details

#xmlObject (readonly)

Returns the value of attribute xml.



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

def xml
  @xml
end

#xml_strObject (readonly)

Returns the value of attribute xml_str.



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

def xml_str
  @xml_str
end

Instance Method Details

#ok?Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
35
36
37
# File 'lib/reactor/cm/xml_response.rb', line 27

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



20
21
22
23
24
25
# File 'lib/reactor/cm/xml_response.rb', line 20

def xpath(expr)
  arr = REXML::XPath.match(@xml, expr)

  return arr.first if arr.length == 1
  return arr
end