Sha256: 06423f1c1ba539256ebdf7fe4a7b79d350d38582eb3875e45a06189669ef1437

Contents?: true

Size: 1.74 KB

Versions: 9

Compression:

Stored size: 1.74 KB

Contents

require 'open-uri'

module ARII

  # = XMLDetector
  #
  # Detect changes in XML files (uses XPath).
  #
  class XMLDetector < Detector

    public
    ##
    # == Detect the changes
    #
    def detect object
      ARII::Config.log.info(self.class.name) {"Monitoring #{object[:uri]}"} unless object[:uri].nil?
      begin
        if object[:uri] == '' then
          @doc = Nokogiri::XML(object[:content])
        else
          @doc = Nokogiri::XML(open(object[:uri]))
        end
        @doc.remove_namespaces!
        @doc.xpath(object[:query]).each do |element|
          element.xpath(object[:cache]).each do |c|
            @response = Cashier.verify c.content, object, c.content, object[:seed]
          end

          # Process ARII cache response
          @cache = JSON.parse(@response, {:symbolize_names => true})
          unless @cache[:templates].nil? then
            @cache[:templates].each do |t|
              @templates.push t
            end
          end

          ##
          # If not on cache, add to payload for processing
          #
          if @cache[:status] == 100 then
            ARII::Config.log.info(self.class.name) {"Not on cache, generating payload"}
            # add row data to payload from selectors (key => key, value => column name)
            payload = Hash.new
            object[:selectors].each do |selector|

              selector.each do |k,v|
                element.xpath(v).each do |el|
                  payload[k] = el.content
                end
              end
            end
            # add payload object to payloads list
            @payloads.push payload

          end
        end
      end
    rescue Exception => e
      ARII::Config.log.error(self.class.name) {"Processing error: #{e}"}
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
arii-1.0.8 lib/arii/xmldetector.rb
arii-1.0.7 lib/arii/xmldetector.rb
arii-1.0.6 lib/arii/xmldetector.rb
arii-1.0.5 lib/arii/xmldetector.rb
arii-1.0.4 lib/arii/xmldetector.rb
arii-1.0.3 lib/arii/xmldetector.rb
arii-1.0.2 lib/arii/xmldetector.rb
arii-1.0.1 lib/arii/xmldetector.rb
arii-1.0 lib/arii/xmldetector.rb