keenlabs/KeenClient-Node — pull request #10 by sebinsua (2014-02-09 16:51:41+00:00)
Title: [FEATURE] Flushing Support for addEvent()/addEvents() 

I thought this should be added to this library.

It should mean that:

1. We lessen the possibility that a developer might call addEvent() or addEvents() too fast causing an out-of-memory error.

2. More control over when and how insert requests are made to Keen.IO.

3. Should make it slightly easier for somebody to implement the not-yet-implemented “batchEventInserts” option that is spoken of in the `README.md`. (You would have to alter the internal structure of the requestData objects I am creating and use these inside `this.flush()` to restructure multiple requests into per event collection addEvents() requests.)

I took a look at an approach another library took on this so it’s hopefully correct, albeit derivative. :)

There were some integration problems as the original library exposed a request method, and as I do not think you ever want to queue/flush anything but `addEvent()` and `addEvents()` calls, I ended up creating a special case. Unfortunately, I can’t be sure that somebody won’t skip the special case by accessing directly through `this.request()`. Also, I think it might make sense to split index.js up a little sooner or later.

So it probably needs a refactor. Maybe somebody sees a need to switch this off, or change the configuration object? Can anybody see any bugs?

Thoughts?

Seb