Class: I2X::Client
- Inherits:
-
Object
- Object
- I2X::Client
- Defined in:
- lib/i2x/client.rb
Instance Method Summary collapse
-
#initialize(config, log) ⇒ Client
constructor
> Load configuration properties from client/script code.
-
#process ⇒ Object
> Start processing agents from configuration properties.
-
#validate ⇒ Object
> Validate API key.
Constructor Details
#initialize(config, log) ⇒ Client
> Load configuration properties from client/script code
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/i2x/client.rb', line 9 def initialize config, log begin @config = config I2X::Config.set_access_token config[:server][:api_key] I2X::Config.set_host config[:server][:host] I2X::Config.set_log log I2X::Config.log.info(self.class.name) {'Configuration loaded successfully.'} rescue Exception => e I2X::Config.log.error(self.class.name) {"Failed to load configuration: #{e}"} end end |
Instance Method Details
#process ⇒ Object
> Start processing agents from configuration properties.
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/i2x/client.rb', line 41 def process I2X::Config.log.info(self.class.name) {'Starting agent processing.'} begin @config[:agents].each do |agent| a = I2X::Agent.new agent a.execute end rescue Exception => e I2X::Config.log.error(self.class.name) {"Failed agent processing: #{e}"} end end |
#validate ⇒ Object
> Validate API key.
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/i2x/client.rb', line 26 def validate begin I2X::Config.log.info(self.class.name) {'Launching validation.'} out = RestClient.post "#{I2X::Config.host}fluxcapacitor/validate_key.json", {:access_token => I2X::Config.access_token} response = {:status => 100, :response => out.to_str} rescue Exception => e I2X::Config.log.error(self.class.name) {"Failed validation: #{e}"} end response end |