From b64a203ceb51695f9dce8ba5980c6e78f05d4b7e Mon Sep 17 00:00:00 2001 From: brettlangdon Date: Thu, 28 Mar 2013 14:16:28 -0400 Subject: [PATCH] move search method into it's own script --- lib/api/search.js | 6 +++++ lib/api/tag.js | 56 ++++++++++++++++++++++++++++++++++++++++++----- lib/index.js | 4 +++- 3 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 lib/api/search.js diff --git a/lib/api/search.js b/lib/api/search.js new file mode 100644 index 0000000..aca7e98 --- /dev/null +++ b/lib/api/search.js @@ -0,0 +1,6 @@ +var search_api = function(){}; +search_api.prototype.search = function(query, callback){ + this.request('GET', '/search', {query: {'q': query}}, callback); +}; + +return module.exports = search_api; diff --git a/lib/api/tag.js b/lib/api/tag.js index c0be542..7592af0 100644 --- a/lib/api/tag.js +++ b/lib/api/tag.js @@ -3,9 +3,6 @@ var v8type = require('v8type'); var tag_api = function(){}; -tag_api.prototype.search = function(query, callback){ - this.request('GET', '/search', {query: {'q': query}}, callback); -}; tag_api.prototype.all_tags = function(source, callback){ if(arguments.length < 2 && v8type.is(arguments[0], v8type.FUNCTION)){ @@ -50,16 +47,63 @@ tag_api.prototype.host_tags_by_source = function(host, source, callback){ this.request('GET', util.format('/tags/hosts/%s', host), params, callback); }; -tag_api.prototype.add_tags = function(){ +tag_api.prototype.add_tags = function(host, tags, source, callback){ + if(!v8type.is(tags, v8type.ARRAY)){ + throw new Error('`tags` parameter must be an array'); + } + + if(arguments.length < 4 && v8type.is(arguments[2], v8type.FUNCTION)){ + callback = arguments[2]; + source = undefined; + } + params = { + query: { + source: source, + }, + body: { + tags: tags, + } + }; + + this.request('POST', util.format('/tags/hosts/%s', host), params, callback); }; -tag_api.prototype.change_tags = function(){ +tag_api.prototype.update_tags = function(host, tags, source, callback){ + if(!v8type.is(tags, v8type.ARRAY)){ + throw new Error('`tags` parameter must be an array'); + } + + if(arguments.length < 4 && v8type.is(arguments[2], v8type.FUNCTION)){ + callback = arguments[2]; + source = undefined; + } + + params = { + query: { + source: source, + }, + body: { + tags: tags, + } + }; + this.request('PUT', util.format('/tags/hosts/%s', host), params, callback); }; -tag_api.prototype.detach_tags = function(){ +tag_api.prototype.detach_tags = function(host, source, callback){ + if(arguments.length < 3 && v8type.is(arguments[1], v8type.FUNCTION)){ + callback = arguments[1]; + source = undefined; + } + + params = { + query: { + source: source, + }, + }; + this.request('DELETE', util.format('/tags/hosts/%s', host), params, callback); }; return module.exports = tag_api; diff --git a/lib/index.js b/lib/index.js index dc3bbc5..fed130b 100644 --- a/lib/index.js +++ b/lib/index.js @@ -6,6 +6,7 @@ var dash_api = require('./api/dash.js'); var event_api = require('./api/event.js'); var tag_api = require('./api/tag.js'); var metric_api = require('./api/metric.js'); +var search_api = require('./api/search.js'); var dogapi = function(options){ http_client.call(this, options); @@ -17,6 +18,7 @@ extend(dogapi.prototype, dash_api.prototype, event_api.prototype, tag_api.prototype, - metric_api.prototype); + metric_api.prototype, + search_api.prototype); return module.exports = dogapi;