diff options
Diffstat (limited to 'lib/fake_agent.rb')
| -rw-r--r-- | lib/fake_agent.rb | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/fake_agent.rb b/lib/fake_agent.rb index a3b4002..f5ce3db 100644 --- a/lib/fake_agent.rb +++ b/lib/fake_agent.rb @@ -2,13 +2,20 @@ require 'socket' class FakeAgent include PacketFu + DEFAULT_ENDPOINT='http://localhost:3000' attr_reader :id, :endpoint - def initialize(id, endpoint) - @id = id + def initialize(endpoint = DEFAULT_ENDPOINT) @endpoint = endpoint end + def register + url = "#{endpoint}/agents.json" + response = Typhoeus.post(url, body: { agent: { hostname: Socket.gethostname } }) + json = JSON.parse(response.body) + @id = json["id"] + end + def watch(directory) listener = Listen.to(directory, debug: true) do |modified, added, removed| publish_event(:modified, modified) |
