diff --git a/lib/api/event.js b/lib/api/event.js index ffa143b..9839bd2 100644 --- a/lib/api/event.js +++ b/lib/api/event.js @@ -57,6 +57,25 @@ event_api.prototype.stream = function(start, end, filter, callback){ this.request('GET', '/events', params, callback); }; +event_api.prototype.polling_stream = function(interval, filter, callback){ + if(arguments.length < 3 && v8type.is(arguments[1], v8type.FUNCTION)){ + callback = arguments[1]; + filter = {}; + } + if(!v8type.is(filter, v8type.OBJECT)){ + throw new Error('`filter` parameter must be an object'); + } + + var last_run = new Date().getTime() / 1000; + var self = this; + setInterval(function(){ + var start = last_run; + var end = last_run = new Date().getTime() / 1000; + self.stream(start, end, filter, callback); + }, interval * 1000); + +}; + event_api.prototype.get_event = function(event_id, callback){ /* * event_api.get_event(event_id, callback)