Class: MEACControl::XML::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml, request = nil) ⇒ Response

Returns a new instance of Response.



9
10
11
12
13
# File 'lib/meac_control/xml/response.rb', line 9

def initialize(xml, request = nil)
  @xml = ::Nokogiri::XML(xml)
  @request = request
  raise(MEACControl::XML::InvalidResponse, @xml.to_s) if @xml.root.nil?
end

Instance Attribute Details

#requestObject (readonly)

Returns the value of attribute request.



7
8
9
# File 'lib/meac_control/xml/response.rb', line 7

def request
  @request
end

#xmlObject (readonly)

Returns the value of attribute xml.



7
8
9
# File 'lib/meac_control/xml/response.rb', line 7

def xml
  @xml
end

Instance Method Details

#error_messagesObject



37
38
39
40
41
# File 'lib/meac_control/xml/response.rb', line 37

def error_messages
  errors.map do |error|
    error['Message']
  end
end

#errorsObject



27
28
29
30
31
32
33
34
35
# File 'lib/meac_control/xml/response.rb', line 27

def errors
  @xml.xpath('/Packet/DatabaseManager/ERROR').map do |error|
    data = {}
    error.each do |key, value|
      data[key] = value
    end
    data
  end
end

#errors?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/meac_control/xml/response.rb', line 23

def errors?
  !@xml.xpath('/Packet/DatabaseManager/ERROR').empty?
end

#ok?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/meac_control/xml/response.rb', line 19

def ok?
  !errors?
end

#to_xmlObject



15
16
17
# File 'lib/meac_control/xml/response.rb', line 15

def to_xml
  @xml.to_s
end