lib/i2x/csvdetector.rb in i2x-0.0.4 vs lib/i2x/csvdetector.rb in i2x-0.0.5
- old
+ new
@@ -1,13 +1,7 @@
-#require 'helper'
require 'csv'
require 'open-uri'
-#require 'seedreader'
-#require 'csvseedreader'
-#require 'sqlseedreader'
-#require 'xmlseedreader'
-#require 'jsonseedreader'
module I2X
##
# = CSVDetector
@@ -19,35 +13,49 @@
public
##
# == Detect the changes
#
def detect object
- begin
- CSV.new(open(object[:uri]), :headers => :first_row).each do |row|
+
+ p "[i2x][CSV] Testing #{object[:uri]}"
+ CSV.new(open(object[:uri]), :headers => :first_row).each do |row|
+ begin
unless object[:cache].nil? then
- @cache = Cashier.verify row[object[:cache].to_i], object, row, object[:seed]
+ p "[i2x][CSV] with cache, verifying"
+ @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]
+
end
+ rescue Exception => e
+ p "[i2x][CSVDetector] loading error: #{e.inspect}"
+ end
+
+ begin
+
+ @cache = JSON.parse(@response, {:symbolize_names => true})
+ @templates = @cache[:templates]
# The actual processing
#
- if @cache[:status] == 100 then
+ if @cache[:cache][:status] == 100 then
# 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|
payload[k] = row[v.to_i]
end
end
# add payload object to payloads list
@payloads.push payload
end
+
+ rescue Exception => e
+ p "[i2x][CSVDetector] processing error: #{e.inspect}"
end
- rescue Exception => e
- I2X::Slog.exception e
end
end
-
-
end
end
\ No newline at end of file