|
|
@ -23,11 +23,11 @@ event_api.prototype.stream = function(start, end, filter, callback){ |
|
|
* callback(error, result, status_code) |
|
|
* callback(error, result, status_code) |
|
|
*/ |
|
|
*/ |
|
|
if(arguments.length < 2){ |
|
|
if(arguments.length < 2){ |
|
|
throw new Error('parameters `start` and `end` are required'); |
|
|
|
|
|
|
|
|
throw new Error('parameters `start` and `end` are required'); |
|
|
} |
|
|
} |
|
|
query = { |
|
|
query = { |
|
|
start: parseInt(start), |
|
|
|
|
|
end: parseInt(end), |
|
|
|
|
|
|
|
|
start: parseInt(start), |
|
|
|
|
|
end: parseInt(end), |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
// this is the only case we have to check
|
|
|
// this is the only case we have to check
|
|
|
@ -41,7 +41,7 @@ event_api.prototype.stream = function(start, end, filter, callback){ |
|
|
// validate the filters we were given and append to `query`
|
|
|
// validate the filters we were given and append to `query`
|
|
|
// if they exist and meet their requirements
|
|
|
// if they exist and meet their requirements
|
|
|
if(filter['priority'] && ['low', 'normal'].indexOf(filter['priority'].toLowerCase()) >= 0){ |
|
|
if(filter['priority'] && ['low', 'normal'].indexOf(filter['priority'].toLowerCase()) >= 0){ |
|
|
query['priority'] = filter['priority'].toLowerCase(); |
|
|
|
|
|
|
|
|
query['priority'] = filter['priority'].toLowerCase(); |
|
|
} |
|
|
} |
|
|
if(filter['sources'] && typeof filter['sources'] == 'object'){ |
|
|
if(filter['sources'] && typeof filter['sources'] == 'object'){ |
|
|
query['sources'] = filter['sources'].join(); |
|
|
query['sources'] = filter['sources'].join(); |
|
|
@ -51,7 +51,7 @@ event_api.prototype.stream = function(start, end, filter, callback){ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
params = { |
|
|
params = { |
|
|
query: query, |
|
|
|
|
|
|
|
|
query: query, |
|
|
}; |
|
|
}; |
|
|
this.request('GET', '/events', params, callback); |
|
|
this.request('GET', '/events', params, callback); |
|
|
}; |
|
|
}; |
|
|
@ -67,20 +67,20 @@ event_api.prototype.polling_stream = function(interval, filter, callback){ |
|
|
* `callback` is an optional function called with the results of the api call |
|
|
* `callback` is an optional function called with the results of the api call |
|
|
* callback(error, result, status_code) |
|
|
* callback(error, result, status_code) |
|
|
*/ |
|
|
*/ |
|
|
if(arguments.length < 3 && v8type.is(arguments[1], v8type.FUNCTION)){ |
|
|
|
|
|
callback = arguments[1]; |
|
|
|
|
|
filter = {}; |
|
|
|
|
|
|
|
|
if(arguments.length < 3 && typeof arguments[1] == 'function'){ |
|
|
|
|
|
callback = arguments[1]; |
|
|
|
|
|
filter = {}; |
|
|
} |
|
|
} |
|
|
if(!v8type.is(filter, v8type.OBJECT)){ |
|
|
|
|
|
throw new Error('`filter` parameter must be an object'); |
|
|
|
|
|
|
|
|
if(typeof filter != 'object'){ |
|
|
|
|
|
throw new Error('`filter` parameter must be an object'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var last_run = new Date().getTime() / 1000; |
|
|
var last_run = new Date().getTime() / 1000; |
|
|
var self = this; |
|
|
var self = this; |
|
|
setInterval(function(){ |
|
|
setInterval(function(){ |
|
|
var start = last_run; |
|
|
|
|
|
var end = last_run = new Date().getTime() / 1000; |
|
|
|
|
|
self.stream(start, end, filter, callback); |
|
|
|
|
|
|
|
|
var start = last_run; |
|
|
|
|
|
last_run = new Date().getTime() / 1000; |
|
|
|
|
|
self.stream(start, last_run, filter, callback); |
|
|
}, interval * 1000); |
|
|
}, interval * 1000); |
|
|
|
|
|
|
|
|
}; |
|
|
}; |
|
|
@ -96,7 +96,7 @@ event_api.prototype.get_event = function(event_id, callback){ |
|
|
* callback(error, result, status_code) |
|
|
* callback(error, result, status_code) |
|
|
*/ |
|
|
*/ |
|
|
if(!event_id){ |
|
|
if(!event_id){ |
|
|
throw new Error('`event_id` parameter is required'); |
|
|
|
|
|
|
|
|
throw new Error('`event_id` parameter is required'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
this.request('GET', util.format('/events/%s', event_id), callback); |
|
|
this.request('GET', util.format('/events/%s', event_id), callback); |
|
|
@ -123,30 +123,30 @@ event_api.prototype.add_event = function(event, callback){ |
|
|
* `callback` is an optional function for the result |
|
|
* `callback` is an optional function for the result |
|
|
* callback(error, result, status_code) |
|
|
* callback(error, result, status_code) |
|
|
*/ |
|
|
*/ |
|
|
if(!v8type.is(event, v8type.OBJECT)){ |
|
|
|
|
|
throw new Error('`event` parameter must be an object'); |
|
|
|
|
|
|
|
|
if(typeof event != 'object'){ |
|
|
|
|
|
throw new Error('`event` parameter must be an object'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if(!event['title']){ |
|
|
if(!event['title']){ |
|
|
throw new Error('`title` property of `event` parameter is required'); |
|
|
|
|
|
|
|
|
throw new Error('`title` property of `event` parameter is required'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if(!event['text']){ |
|
|
if(!event['text']){ |
|
|
throw new Error('`text` property of `event` parameter is required'); |
|
|
|
|
|
|
|
|
throw new Error('`text` property of `event` parameter is required'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if(!event['date_happened']){ |
|
|
if(!event['date_happened']){ |
|
|
event['date_happened'] = (new Date().getTime()) / 1000; |
|
|
|
|
|
|
|
|
event['date_happened'] = (new Date().getTime()) / 1000; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if(event['priority']){ |
|
|
if(event['priority']){ |
|
|
if(['normal', 'low'].indexOf(event['priority'].toLowerCase()) == -1){ |
|
|
|
|
|
event['priority'] = undefined; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if(['normal', 'low'].indexOf(event['priority'].toLowerCase()) == -1){ |
|
|
|
|
|
event['priority'] = undefined; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if(event['tags']){ |
|
|
if(event['tags']){ |
|
|
event['tags'] = event['tags'].join(); |
|
|
|
|
|
|
|
|
event['tags'] = event['tags'].join(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
this.request('POST', '/events', {body: event}, callback); |
|
|
this.request('POST', '/events', {body: event}, callback); |
|
|
@ -166,12 +166,12 @@ event_api.prototype.add_comment = function(comment, callback){ |
|
|
* `callback` is an optional function for the result of the call |
|
|
* `callback` is an optional function for the result of the call |
|
|
* callback(error, result, status_code) |
|
|
* callback(error, result, status_code) |
|
|
*/ |
|
|
*/ |
|
|
if(!v8type.is(comment, v8type.OBJECT)){ |
|
|
|
|
|
throw new Error('`comment` parameter must be an object'); |
|
|
|
|
|
|
|
|
if(typeof comment != 'object'){ |
|
|
|
|
|
throw new Error('`comment` parameter must be an object'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if(!comment['message']){ |
|
|
if(!comment['message']){ |
|
|
throw new Error('`message` property of `comment` paramter is required'); |
|
|
|
|
|
|
|
|
throw new Error('`message` property of `comment` paramter is required'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
this.request('POST', '/comments', {body: comment}, callback); |
|
|
this.request('POST', '/comments', {body: comment}, callback); |
|
|
|