From 90c86336a85acf6abf50a97c5fb009469eff252a Mon Sep 17 00:00:00 2001 From: brettlangdon Date: Thu, 28 Mar 2013 17:06:23 -0400 Subject: [PATCH] finish alert api --- lib/api/alert.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/api/alert.js b/lib/api/alert.js index 3c2919f..e73d45a 100644 --- a/lib/api/alert.js +++ b/lib/api/alert.js @@ -1,16 +1,31 @@ var util = require('util'); +var v8type = require('v8type'); -var alert_api = function(){ +var alert_api = function(){}; -}; +alert_api.prototype.add_alert = function(alert, callback){ + if(!v8type.is(alert, v8type.OBJECT)){ + throw new Error('`alert` parameter must be an object'); + } -alert_api.prototype.add_alert = function(){ + if(!alert['query']){ + throw new Error('`alert["query"]` is required'); + } + this.request('POST', '/alert', {body: alert}, callback); }; -alert_api.prototype.update_alert = function(){ +alert_api.prototype.update_alert = function(alert_id, alert, callback){ + if(!v8type.is(alert, v8type.OBJECT)){ + throw new Error('`alert` parameter must be an object'); + } + + if(!alert['query']){ + throw new Error('`alert["query"]` is required'); + } + this.request('PUT', util.format('/alert/%s', alert_id), {body: alert}, callback); }; alert_api.prototype.get_alert = function(alert_id, callback){ @@ -21,7 +36,7 @@ alert_api.prototype.delete_alert = function(){ this.request('DELETE', util.format('/alert/%s', alert_id), callback) }; -alert_api.prototype.get_all_alerts = function(){ +alert_api.prototype.get_all_alerts = function(callback){ this.request('GET', '/alert', callback) };