Browse Source

remove v8type dependency

pull/4/head
Brett Langdon 12 years ago
parent
commit
aeee2d4fdc
9 changed files with 72 additions and 83 deletions
  1. +4
    -5
      lib/api/alert.js
  2. +8
    -9
      lib/api/dash.js
  3. +9
    -10
      lib/api/event.js
  4. +7
    -10
      lib/api/metric.js
  5. +5
    -6
      lib/api/screen.js
  6. +1
    -2
      lib/api/snapshot.js
  7. +22
    -23
      lib/api/tag.js
  8. +15
    -16
      lib/http_client.js
  9. +1
    -2
      package.json

+ 4
- 5
lib/api/alert.js View File

@ -1,5 +1,4 @@
var util = require('util'); var util = require('util');
var v8type = require('v8type');
var alert_api = function(){}; 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` an optional function to get called with the results of the api call
* callback(error, result, status_code) * 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']){ 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` an optional function to get called with the results of the api call
* callback(error, result, status_code) * 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']){ if(!alert['query']){


+ 8
- 9
lib/api/dash.js View File

@ -1,21 +1,20 @@
var util = require('util'); var util = require('util');
var v8type = require('v8type');
var validate_dashboard = function(dashboard){ 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']){ for(var i in dashboard['graphs']){


+ 9
- 10
lib/api/event.js View File

@ -1,6 +1,5 @@
var extend = require('extend'); var extend = require('extend');
var util = require('util'); var util = require('util');
var v8type = require('v8type');
var event_api = function(){}; 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 // this is the only case we have to check
// if we have `event_api(1234, 5678, callback)` then // if we have `event_api(1234, 5678, callback)` then
// we want to push callback back // 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` // 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){ if(filter['priority'] && ['low', 'normal'].indexOf(filter['priority'].toLowerCase()) >= 0){
query['priority'] = filter['priority'].toLowerCase(); 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 = { 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` an optional callback to call with the result
* 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');
} }
this.request('PUT', util.format('/comments/%s', comment_id), {body: comment}, callback); this.request('PUT', util.format('/comments/%s', comment_id), {body: comment}, callback);


+ 7
- 10
lib/api/metric.js View File

@ -1,6 +1,3 @@
var v8type = require('v8type');
var metric_api = function(){}; var metric_api = function(){};
metric_api.prototype.add_metric = function(metric, callback){ 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` an optional function to call with the results
* callback(metric, [callback]) * 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']){ 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'); 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); this.request('POST', '/series', {body: metrics}, callback);


+ 5
- 6
lib/api/screen.js View File

@ -1,24 +1,23 @@
var util = require('util'); var util = require('util');
var v8type = require('v8type');
var validate_screenboard = function(screenboard){ var validate_screenboard = function(screenboard){
if(!v8type.of(screenboard, v8type.OBJECT)){
if(typeof screenboard != 'object'){
throw new Error('`screenboard` parameter must be an 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'); 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'); 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'); 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'); throw new Error('`screenboard["widgets"]` must be an array');
} }


+ 1
- 2
lib/api/snapshot.js View File

@ -1,6 +1,5 @@
var extend = require('extend'); var extend = require('extend');
var util = require('util'); var util = require('util');
var v8type = require('v8type');
var snapshot_api = function(){}; 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` is an optional function for the result
* callback(error, result, status_code) * callback(error, result, status_code)
*/ */
if(!v8type.is(snapshot, v8type.OBJECT)){
if(typeof snapshot != 'object'){
throw new Error('`snapshot` parameter must be an object'); throw new Error('`snapshot` parameter must be an object');
} }


+ 22
- 23
lib/api/tag.js View File

@ -1,5 +1,4 @@
var util = require('util'); var util = require('util');
var v8type = require('v8type');
var tag_api = function(){}; 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` is an optional function to call with the results of the api call
* callback(error, result, status_code) * 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 = { 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` is an optional function to call 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];
source = undefined;
if(arguments.length < 3 && typeof arguments[1] == 'function'){
callback = arguments[1];
source = undefined;
} }
params = { 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` is an optional function to call 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];
source = undefined;
if(arguments.length < 3 && typeof arguments[1] == 'function'){
callback = arguments[1];
source = undefined;
} }
params = { 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` is an optional function to call with the results of the api call
* callback(error, result, status_code) * 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 = { 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` is an optional function to call with the results of the api call
* callback(error, result, status_code) * 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 = { 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` is an optional function to call 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];
source = undefined;
if(arguments.length < 3 && typeof arguments[1] == 'function'){
callback = arguments[1];
source = undefined;
} }
params = { params = {


+ 15
- 16
lib/http_client.js View File

@ -2,7 +2,6 @@ var extend = require('extend');
var https = require('https'); var https = require('https');
var url = require('url'); var url = require('url');
var util = require('util'); var util = require('util');
var v8type = require('v8type');
var client = function(options){ 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` an optional function to obtain the results of the api call
* callback(error, result) * 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 || {}; 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 = { var query = {
'api_key': this.api_key, 'api_key': this.api_key,
'application_key': this.app_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({ path = url.format({
@ -104,11 +103,11 @@ client.prototype.request = function(method, path, params, callback){
} }
var req = https.request(http_options, function(res){ 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 = ''; var data = '';
res.on('data', function(chunk){ res.on('data', function(chunk){
@ -123,10 +122,10 @@ client.prototype.request = function(method, path, params, callback){
data = null; 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){ if(['POST', 'PUT'].indexOf(http_options['method']) >= 0){


+ 1
- 2
package.json View File

@ -26,7 +26,6 @@
"readmeFilename": "README.md", "readmeFilename": "README.md",
"gitHead": "f388635a5ab4f4da25702dc0999385d437bdf2bc", "gitHead": "f388635a5ab4f4da25702dc0999385d437bdf2bc",
"dependencies": { "dependencies": {
"extend": "~1.1.3",
"v8type": "~0.1.0"
"extend": "~1.1.3"
} }
} }

Loading…
Cancel
Save