cantino/huginn — pull request #161 by umarsheikh (2014-02-04 10:39:52+00:00)
Title: Code agent

This is a working code agent which works as follows:

1) suppose the agent checks every few minutes for some stuff to happen. The user needs to provide the implementation of Agent.prototype.check method in this case and implement the functionality here. The check() method will then get called periodically to take the action the user has specified.
2) suppose the agent receives an event from some other agent. The user needs to provide the implementation of Agent.prototype.receive in this case. The receive() method will get triggered whenever it receives an event from other sources.

The user can create events using the global js method create_event which accepts json string of attributes or the payload.

The user can access the agent's memory. This is an override method so that agent.memory returns the agent's memory, and agent.memory(key,value) sets the ruby agent's memory at key to the specified value.

###ToDo

The agent doesn't need to be passed events at the time of creation. We can get rid of that. Similarly, we can implement the js method to return the agent options, which will obviate the need to pass the options to the js agent object. Once these are done, we can get rid of the class structure on the js side and implement a much simpler singleton pattern.