Sha256: 54b5ad2fcb9b685c5e29d569aaf922a69c69ce84454aeca3f427dadc457f254d

Contents?: true

Size: 824 Bytes

Versions: 5

Compression:

Stored size: 824 Bytes

Contents

# -*- encoding : utf-8 -*-
require 'reactor/tools/response_handler/xml_attribute'
require 'reactor/tools/xpath_extractor'
require 'rexml/document'

module Reactor

  module Cm

    class XmlResponse

      attr_reader :xml
      attr_reader :xml_str

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

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

      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

    end

  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
infopark_reactor-1.26.1 lib/reactor/cm/xml_response.rb
infopark_reactor-1.26.0 lib/reactor/cm/xml_response.rb
infopark_reactor-1.25.2 lib/reactor/cm/xml_response.rb
infopark_reactor-1.25.1 lib/reactor/cm/xml_response.rb
infopark_reactor-1.25.0 lib/reactor/cm/xml_response.rb