lib/i2x/agent.rb in i2x-0.0.5 vs lib/i2x/agent.rb in i2x-0.0.6
- old
+ new
@@ -1,10 +1,6 @@
-#require 'detector'
-#require 'csvdetector'
-#require 'jsondetector'
-#require 'xmldetector'
-#require 'sqldetector'
+require 'rest_client'
module I2X
class Agent
attr_accessor :content, :identifier, :publisher, :payload, :templates, :seeds, :cache, :selectors
@@ -47,11 +43,11 @@
when 'xml'
begin
@d = I2X::XMLDetector.new(self)
rescue Exception => e
@response = {:status => 400, :error => e}
- p "[i2x] error: #{e}"
+ p "[i2x] error: #{e}"
end
when 'json'
begin
@d = I2X::JSONDetector.new(self)
rescue Exception => e
@@ -74,10 +70,12 @@
# Start detection
begin
@d.objects.each do |object|
@d.detect object
end
+
+ @checkup[:templates] = @d.templates.uniq
rescue Exception => e
p "[i2x] error: #{e}"
end
begin
@@ -94,10 +92,27 @@
##
# => Process agent checks.
#
def process checkup
- p checkup
+ begin
+ checkup[:templates].each do |template|
+ p "[i2x][Agent] Processing #{template}"
+ checkup[:payload].each do |payload|
+ puts "\t[i2x][Agent] Processing #{payload}"
+ response = RestClient.post "#{I2X::Config.host}postman/deliver/#{template}.js", payload
+ case response.code
+ when 200
+
+ else
+ puts "[i2x][Agent] unable to deliver \"#{payload}\" to \"#{template}\""
+ end
+ end
+ end
+ rescue Exception => e
+ p "[i2x][Agent] error: #{e}"
+ end
+
end
end
end
\ No newline at end of file