lib/i2x/detector.rb in i2x-0.0.4 vs lib/i2x/detector.rb in i2x-0.0.5
- old
+ new
@@ -11,37 +11,38 @@
# = Detector
#
# Main change detection class, to be inherited by SQL, CSV, JSON and XML detectors (and others to come).
#
class Detector
- attr_accessor :identifier, :agent, :objects, :payloads, :content
+ attr_accessor :identifier, :agent, :objects, :payloads, :content, :templates
- def initialize identifier
+ def initialize agent
begin
- @agent = Agent.find_by! identifier: identifier
+ @agent = agent
@payloads = Array.new
@objects = Array.new
@help = I2X::Helper.new
+ @templates = {}
+ puts "Loaded new detector: #{agent.identifier}"
rescue Exception => e
end
end
##
# == Start original source detection process
#
def checkup
- # update checkup time
- @agent.update_check_at @help.datetime
begin
+
##
# => Process seed data, if available.
#
- if @agent.seeds.size != 0 then
+ unless @agent.seeds.nil? then
@agent.seeds.each do |seed|
case seed[:publisher]
when 'csv'
begin
@sr = I2X::CSVSeedReader.new(@agent, seed)
@@ -71,36 +72,39 @@
@reads = @sr.read
@reads.each do |read|
@objects.push read
end
rescue Exception => e
-
+ p "[i2x] error: #{e}"
end
end
else
##
# no seeds, simply copy agent data
- object = @help.deep_copy @agent[:payload]
- object[:identifier] = @agent[:identifier]
+ object = @help.deep_copy @agent.payload
+ object[:identifier] = @agent.identifier
+ object[:cache] = @agent.cache
object[:seed] = object[:identifier]
- unless self.content.nil? then
+ object[:selectors] = @agent.selectors
+ p "\n\tSelectors: #{object[:selectors]}"
+ unless self.content.nil? then
object[:content] = self.content
end
@objects.push object
end
rescue Exception => e
@response = {:status => 404, :message => "[i2x][Detector] failed to load doc, #{e}"}
- I2X::Slog.exception e
+ p "[i2x] error: #{e}"
end
begin
# increase detected events count
- @agent.increment!(:events_count, @payloads.size)
- @response = { :payload => @payloads, :status => 100}
+
+ @response = { :payload => @payloads, :templates => @templates, :status => 100}
rescue Exception => e
@response = {:status => 404, :message => "[i2x][Detector] failed to process queries, #{e}"}
- I2X::Slog.exception e
+ p "[i2x] error: #{e}"
end
@response
end
\ No newline at end of file