Sha256: e253036e72e2abea0a995593fa3ff6d206a3f3171fbdec84ae73915dba9dd91b

Contents?: true

Size: 858 Bytes

Versions: 1

Compression:

Stored size: 858 Bytes

Contents

require 'nokogiri'
require 'meac_control/xml/exceptions'

module MEACControl
  module XML
    class Response
      attr_reader :xml, :request

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

      def to_xml
        @xml.to_s
      end

      def ok?
        !errors?
      end

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

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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
meac_control-1.0.0 lib/meac_control/xml/response.rb