diff --git a/lib/api/alert.js b/lib/api/alert.js index 1e392a2..197b086 100644 --- a/lib/api/alert.js +++ b/lib/api/alert.js @@ -1,5 +1,4 @@ var util = require('util'); -var v8type = require('v8type'); var alert_api = function(){}; @@ -19,8 +18,8 @@ alert_api.prototype.add_alert = function(alert, callback){ * `callback` an optional function to get called with the results of the api call * callback(error, result, status_code) */ - if(!v8type.is(alert, v8type.OBJECT)){ - throw new Error('`alert` parameter must be an object'); + if(typeof alert != 'object'){ + throw new Error('`alert` parameter must be an object'); } if(!alert['query']){ @@ -46,8 +45,8 @@ alert_api.prototype.update_alert = function(alert_id, alert, callback){ * `callback` an optional function to get called with the results of the api call * callback(error, result, status_code) */ - if(!v8type.is(alert, v8type.OBJECT)){ - throw new Error('`alert` parameter must be an object'); + if(typeof alert != 'object'){ + throw new Error('`alert` parameter must be an object'); } if(!alert['query']){ diff --git a/lib/api/dash.js b/lib/api/dash.js index b59505e..e6b76a3 100644 --- a/lib/api/dash.js +++ b/lib/api/dash.js @@ -1,21 +1,20 @@ var util = require('util'); -var v8type = require('v8type'); var validate_dashboard = function(dashboard){ - if(!v8type.of(dashboard, v8type.OBJECT)){ - throw new Error('`dashboard` parameter must be an object'); + if(typeof dashboard != 'object'){ + throw new Error('`dashboard` parameter must be an object'); } - if(!v8type.of(dashboard['title'], v8type.STRING)){ - throw new Error('`dashboard["title"]` must be a string'); + if(dashboard['title'] != 'string'){ + throw new Error('`dashboard["title"]` must be a string'); } - if(!v8type.of(dashboard['description'], v8type.STRING)){ - throw new Error('`dashboard["description"]` must be a string'); + if(typeof dashboard['description'] != 'string'){ + throw new Error('`dashboard["description"]` must be a string'); } - if(!v8type.of(dashboard['graphs'], v8type.ARRAY)){ - throw new Error('`dashboard["graphs"]` must be an array'); + if(typeof dashboard['graphs'] != 'object'){ + throw new Error('`dashboard["graphs"]` must be an array'); } for(var i in dashboard['graphs']){ diff --git a/lib/api/event.js b/lib/api/event.js index 17f280e..ed33c36 100644 --- a/lib/api/event.js +++ b/lib/api/event.js @@ -1,6 +1,5 @@ var extend = require('extend'); var util = require('util'); -var v8type = require('v8type'); var event_api = function(){}; @@ -34,9 +33,9 @@ event_api.prototype.stream = function(start, end, filter, callback){ // this is the only case we have to check // if we have `event_api(1234, 5678, callback)` then // we want to push callback back - if(arguments.length == 3 && v8type.is(arguments[2], v8type.FUNCTION)){ - callback = arguments[2]; - filter = {}; + if(arguments.length == 3 && typeof arguments[2] == 'function'){ + callback = arguments[2]; + filter = {}; } // validate the filters we were given and append to `query` @@ -44,11 +43,11 @@ event_api.prototype.stream = function(start, end, filter, callback){ if(filter['priority'] && ['low', 'normal'].indexOf(filter['priority'].toLowerCase()) >= 0){ query['priority'] = filter['priority'].toLowerCase(); } - if(filter['sources'] && v8type.is(filter['sources'], v8type.ARRAY)){ - query['sources'] = filter['sources'].join(); + if(filter['sources'] && typeof filter['sources'] == 'object'){ + query['sources'] = filter['sources'].join(); } - if(filter['tags'] && v8type.is(filter['tags'], v8type.ARRAY)){ - query['tags'] = filter['tags'].join(); + if(filter['tags'] && typeof filter['tags'] == 'object'){ + query['tags'] = filter['tags'].join(); } params = { @@ -192,8 +191,8 @@ event_api.prototype.update_comment = function(comment_id, comment, callback){ * `callback` an optional callback to call with the result * 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'); } this.request('PUT', util.format('/comments/%s', comment_id), {body: comment}, callback); diff --git a/lib/api/metric.js b/lib/api/metric.js index 7e391a3..2ff0640 100644 --- a/lib/api/metric.js +++ b/lib/api/metric.js @@ -1,6 +1,3 @@ -var v8type = require('v8type'); - - var metric_api = function(){}; metric_api.prototype.add_metric = function(metric, callback){ @@ -37,12 +34,12 @@ metric_api.prototype.add_metrics = function(metrics, callback){ * `callback` an optional function to call with the results * callback(metric, [callback]) */ - if(!v8type.is(metrics, v8type.OBJECT)){ - throw new Error('`metrics` parameter must be an object'); + if(typeof metrics != 'object'){ + throw new Error('`metrics` parameter must be an object'); } - if(!metrics['series'] || !v8type.is(metrics['series'], v8type.ARRAY)){ - throw new Error('`metrics["series"]` parameter must be an array'); + if(!metrics['series'] || typeof metrics['series'] != 'object'){ + throw new Error('`metrics["series"]` parameter must be an array'); } for(var i in metrics['series']){ @@ -51,9 +48,9 @@ metric_api.prototype.add_metrics = function(metrics, callback){ throw new Error('metric["metric"] is required'); } - if(!metric['points'] || !v8type.is(metric['points'], v8type.ARRAY)){ - throw new Error('metric["points"] must be an array'); - } + if(!metric['points'] || typeof metric['points'] != 'object'){ + throw new Error('metric["points"] must be an array'); + } } this.request('POST', '/series', {body: metrics}, callback); diff --git a/lib/api/screen.js b/lib/api/screen.js index a379482..4845e1c 100644 --- a/lib/api/screen.js +++ b/lib/api/screen.js @@ -1,24 +1,23 @@ var util = require('util'); -var v8type = require('v8type'); var validate_screenboard = function(screenboard){ - if(!v8type.of(screenboard, v8type.OBJECT)){ + if(typeof screenboard != 'object'){ throw new Error('`screenboard` parameter must be an object'); } - if(!v8type.of(screenboard['board_title'], v8type.STRING)){ + if(typeof screenboard['board_title'] != 'string'){ throw new Error('`screenboard["board_title"]` must be a string'); } - if(screenboard['width'] != undefined && !v8type.of(screenboard['width'], v8type.NUMBER)){ + if(screenboard['width'] != undefined && typeof screenboard['width'] != 'number'){ throw new Error('`screenboard["width"]` must be a number'); } - if(screenboard['height'] != undefined && !v8type.of(screenboard['height'], v8type.NUMBER)){ + if(screenboard['height'] != undefined && typeof screenboard['height'] != 'number'){ throw new Error('`screenboard["height"]` must be a number'); } - if(!v8type.of(screenboard['widgets'], v8type.ARRAY)){ + if(typeof screenboard['widgets'] != 'object'){ throw new Error('`screenboard["widgets"]` must be an array'); } diff --git a/lib/api/snapshot.js b/lib/api/snapshot.js index a2cabed..d96c80d 100644 --- a/lib/api/snapshot.js +++ b/lib/api/snapshot.js @@ -1,6 +1,5 @@ var extend = require('extend'); var util = require('util'); -var v8type = require('v8type'); var snapshot_api = function(){}; @@ -22,7 +21,7 @@ snapshot_api.prototype.add_snapshot = function(snapshot, callback){ * `callback` is an optional function for the result * callback(error, result, status_code) */ - if(!v8type.is(snapshot, v8type.OBJECT)){ + if(typeof snapshot != 'object'){ throw new Error('`snapshot` parameter must be an object'); } diff --git a/lib/api/tag.js b/lib/api/tag.js index 8eeb906..e9213f8 100644 --- a/lib/api/tag.js +++ b/lib/api/tag.js @@ -1,5 +1,4 @@ var util = require('util'); -var v8type = require('v8type'); var tag_api = function(){}; @@ -14,9 +13,9 @@ tag_api.prototype.all_tags = function(source, callback){ * `callback` is an optional function to call with the results of the api call * callback(error, result, status_code) */ - if(arguments.length < 2 && v8type.is(arguments[0], v8type.FUNCTION)){ - callback = arguments[0]; - source = undefined; + if(arguments.length < 2 && typeof arguments[0] == 'function'){ + callback = arguments[0]; + source = undefined; } params = { @@ -38,9 +37,9 @@ tag_api.prototype.host_tags = function(host, source, callback){ * `callback` is an optional function to call with the results of the api call * callback(error, result, status_code) */ - if(arguments.length < 3 && v8type.is(arguments[1], v8type.FUNCTION)){ - callback = arguments[1]; - source = undefined; + if(arguments.length < 3 && typeof arguments[1] == 'function'){ + callback = arguments[1]; + source = undefined; } params = { @@ -62,9 +61,9 @@ tag_api.prototype.host_tags_by_source = function(host, source, callback){ * `callback` is an optional function to call with the results of the api call * callback(error, result, status_code) */ - if(arguments.length < 3 && v8type.is(arguments[1], v8type.FUNCTION)){ - callback = arguments[1]; - source = undefined; + if(arguments.length < 3 && typeof arguments[1] == 'function'){ + callback = arguments[1]; + source = undefined; } params = { @@ -88,13 +87,13 @@ tag_api.prototype.add_tags = function(host, tags, source, callback){ * `callback` is an optional function to call with the results of the api call * callback(error, result, status_code) */ - if(!v8type.is(tags, v8type.ARRAY)){ - throw new Error('`tags` parameter must be an array'); + if(typeof tags != 'object'){ + throw new Error('`tags` parameter must be an array'); } - if(arguments.length < 4 && v8type.is(arguments[2], v8type.FUNCTION)){ - callback = arguments[2]; - source = undefined; + if(arguments.length < 4 && typeof arguments[2] == 'function'){ + callback = arguments[2]; + source = undefined; } params = { @@ -121,13 +120,13 @@ tag_api.prototype.update_tags = function(host, tags, source, callback){ * `callback` is an optional function to call with the results of the api call * callback(error, result, status_code) */ - if(!v8type.is(tags, v8type.ARRAY)){ - throw new Error('`tags` parameter must be an array'); + if(typeof tags != 'object'){ + throw new Error('`tags` parameter must be an array'); } - if(arguments.length < 4 && v8type.is(arguments[2], v8type.FUNCTION)){ - callback = arguments[2]; - source = undefined; + if(arguments.length < 4 && typeof arguments[2] == 'function'){ + callback = arguments[2]; + source = undefined; } params = { @@ -153,9 +152,9 @@ tag_api.prototype.detach_tags = function(host, source, callback){ * `callback` is an optional function to call with the results of the api call * callback(error, result, status_code) */ - if(arguments.length < 3 && v8type.is(arguments[1], v8type.FUNCTION)){ - callback = arguments[1]; - source = undefined; + if(arguments.length < 3 && typeof arguments[1] == 'function'){ + callback = arguments[1]; + source = undefined; } params = { diff --git a/lib/http_client.js b/lib/http_client.js index 699ad87..3d759d5 100644 --- a/lib/http_client.js +++ b/lib/http_client.js @@ -2,7 +2,6 @@ var extend = require('extend'); var https = require('https'); var url = require('url'); var util = require('util'); -var v8type = require('v8type'); var client = function(options){ @@ -68,20 +67,20 @@ client.prototype.request = function(method, path, params, callback){ * `callback` an optional function to obtain the results of the api call * callback(error, result) */ - if(arguments.length == 3 && v8type.is(arguments[2], v8type.FUNCTION)){ - callback = arguments[2]; - params = {}; + if(arguments.length == 3 && typeof arguments[2] == 'function'){ + callback = arguments[2]; + params = {}; } params = params || {}; - var body = v8type.is(params['body'], v8type.OBJECT)? JSON.stringify(params['body']) : params['body']; + var body = (typeof params['body'] == 'object')? JSON.stringify(params['body']) : params['body']; var query = { 'api_key': this.api_key, 'application_key': this.app_key, }; - if(v8type.is(params['query'], v8type.OBJECT)){ - extend(query, params['query']); + if(typeof params['query'] == 'object'){ + extend(query, params['query']); } path = url.format({ @@ -104,11 +103,11 @@ client.prototype.request = function(method, path, params, callback){ } var req = https.request(http_options, function(res){ - res.on('error', function(err){ - if(v8type.is(callback, v8type.FUNCTION)){ - callback(err, null, res.statusCode); - } - }); + res.on('error', function(err){ + if(typeof callback == 'function'){ + callback(err, null, res.statusCode); + } + }); var data = ''; res.on('data', function(chunk){ @@ -123,10 +122,10 @@ client.prototype.request = function(method, path, params, callback){ data = null; } - if(v8type.is(callback, v8type.FUNCTION)){ - callback(error, data, res.statusCode); - } - }); + if(typeof callback == 'function'){ + callback(error, data, res.statusCode); + } + }); }); if(['POST', 'PUT'].indexOf(http_options['method']) >= 0){ diff --git a/package.json b/package.json index 32882ee..5954eee 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,6 @@ "readmeFilename": "README.md", "gitHead": "f388635a5ab4f4da25702dc0999385d437bdf2bc", "dependencies": { - "extend": "~1.1.3", - "v8type": "~0.1.0" + "extend": "~1.1.3" } }