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

- old
+ new

@@ -14,37 +14,36 @@ ## # == Detect the changes # def detect object - p "[i2x][CSV] Testing #{object[:uri]}" + I2X::Config.log.debug(self.class.name) {"Monitoring #{object[:uri]}"} CSV.new(open(object[:uri]), :headers => :first_row).each do |row| begin unless object[:cache].nil? then - p "[i2x][CSV] with cache, verifying" - @response = Cashier.verify row[object[:cache].to_i], object, row, object[:seed] - + @response = Cashier.verify row[object[:cache].to_i], object, row, object[:seed] else - p "[i2x][CSV] no cache, verifying" - @cache = Cashier.verify row[0], object, row, object[:seed] - + @response = Cashier.verify row[0], object, row, object[:seed] end rescue Exception => e - p "[i2x][CSVDetector] loading error: #{e.inspect}" + I2X::Config.log.error(self.class.name) {"Loading error: #{e}"} end begin + # Process i2xcache response @cache = JSON.parse(@response, {:symbolize_names => true}) - @cache[:templates].each do |t| - @templates.push t + unless @cache[:templates].nil? then + @cache[:templates].each do |t| + @templates.push t + end end # The actual processing # if @cache[:cache][:status] == 100 then - - # add row data to payload from selectors (key => key, value => column name) + I2X::Config.log.info(self.class.name) {"Not on cache, generating payload"} + payload = Hash.new object[:selectors].each do |selector| selector.each do |k,v| payload[k] = row[v.to_i] @@ -53,10 +52,10 @@ # add payload object to payloads list @payloads.push payload end rescue Exception => e - p "[i2x][CSVDetector] processing error: #{e.inspect}" + I2X::Config.log.error(self.class.name) {"Processing error: #{e}"} end @cache[:templates] end end end \ No newline at end of file