Method: I2X::Detector#checkup

Defined in:
lib/i2x/detector.rb

#checkupObject

Start original source detection process



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/i2x/detector.rb', line 34

def checkup

  begin


    ##
    # => Process seed data, if available.
    #
    unless @agent.seeds.nil? then
      @agent.seeds.each do |seed|
        case seed[:publisher]
        when 'csv'
          begin
            @sr = I2X::CSVSeedReader.new(@agent, seed)
          rescue Exception => e
            I2X::Config.log.error(self.class.name) {"#{e}"}
          end
        when 'sql'
          begin
            @sr = I2X::SQLSeedReader.new(@agent, seed)
          rescue Exception => e
            I2X::Config.log.error(self.class.name) {"#{e}"}
          end
        when 'xml'
          begin
            @sr = I2X::XMLSeedReader.new(@agent, seed)
          rescue Exception => e
            I2X::Config.log.error(self.class.name) {"#{e}"}
          end
        when 'json'
          begin
            @sr = I2X::JSONSeedReader.new(@agent, seed)
          rescue Exception => e
            I2X::Config.log.error(self.class.name) {"#{e}"}
          end
        end
        begin
          @reads = @sr.read
          @reads.each do |read|
            @objects.push read
          end
        rescue Exception => e
          I2X::Config.log.error(self.class.name) {"#{e}"}
        end
      end

    else
      ##
      # no seeds, simply copy agent data
      object = @help.deep_copy @agent.payload 
      object[:identifier] = @agent.identifier
      object[:cache] = @agent.cache
      object[:seed] = object[:identifier]
      object[:selectors] = @agent.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::Config.log.error(self.class.name) {"#{e}"}
  end

  begin
    # increase detected events count


    @templates = Array.new
    @response = { :payload => @payloads, :templates => @templates, :status => 100}
  rescue Exception => e
    @response = {:status => 404, :message => "[i2x][Detector] failed to process queries, #{e}"}
    I2X::Config.log.error(self.class.name) {"#{e}"}
  end
  @response
end