lib/i2x/xmldetector.rb in i2x-0.0.6 vs lib/i2x/xmldetector.rb in i2x-0.0.7

- old
+ new

@@ -1,10 +1,6 @@ -#require 'helper' -#require 'cashier' require 'open-uri' -#require 'raven' -#require 'slog' module I2X # = XMLDetector # @@ -15,30 +11,39 @@ public ## # == Detect the changes # def detect object + I2X::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| - @cache = Cashier.verify c.content, object, c.content, object[:seed] + @response = Cashier.verify c.content, object, c.content, object[:seed] end + # Process i2x 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 - + I2X::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 - JSON.parse(object[:selectors]).each do |selector| + object[:selectors].each do |selector| selector.each do |k,v| element.xpath(v).each do |el| payload[k] = el.content end @@ -49,9 +54,9 @@ end end end rescue Exception => e - + I2X::Config.log.error(self.class.name) {"Processing error: #{e}"} end end end \ No newline at end of file