From dcddd7862fc85acb4ab41c698e5317042b5df5c6 Mon Sep 17 00:00:00 2001 From: Colin Jones Date: Wed, 9 Oct 2013 19:37:50 +0100 Subject: [PATCH] Naive implementation of the snapshot part of the API --- lib/api/snapshot.js | 49 +++++++++++++++++++++++++++++++++++++++++++++ lib/index.js | 5 ++++- package.json | 4 ++-- 3 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 lib/api/snapshot.js diff --git a/lib/api/snapshot.js b/lib/api/snapshot.js new file mode 100644 index 0000000..a24a6bf --- /dev/null +++ b/lib/api/snapshot.js @@ -0,0 +1,49 @@ +snapshot.js + +var extend = require('extend'); +var util = require('util'); +var v8type = require('v8type'); + + +var snapshot_api = function(){}; + + + +snapshot_api.prototype.add_snapshot = function(snapshot, callback){ + /* + * snapshot_api.add_snapshot(snapshot, callback) + * + * method used to add a new snapshot to datadog + * + * `snapshot` is an object containing any of the following: + * metric_query: *required*, The metric query. + * start: *required*, int, Start of the query.(POSIX timestamp) + * end: *required*, int, End of the query.(POSIX timestamp) + * event_query: A query that will add event bands to the graph. + * + * `callback` is an optional function for the result + * callback(error, result, status_code) + */ + if(!v8type.is(snapshot, v8type.OBJECT)){ + throw new Error('`snapshot` parameter must be an object'); + } + + if(!snapshot['metric_query']){ + throw new Error('`metric_query` property of `snapshot` parameter is required'); + } + + if(!snapshot['start']){ + throw new Error('`start` property of `snapshot` parameter is required'); + } + + if(!snapshot['end']){ + throw new Error('`end` property of `snapshot` parameter is required'); + } + + + + this.request('POST', '/graph/snapshot', {body: snapshot}, callback); +}; + + +return module.exports = snapshot_api; diff --git a/lib/index.js b/lib/index.js index f92fe96..1089c73 100644 --- a/lib/index.js +++ b/lib/index.js @@ -8,6 +8,8 @@ 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 snapshot_api = require('./api/snapshot.js'); + var dogapi = function(options){ http_client.call(this, options); @@ -21,6 +23,7 @@ extend(dogapi.prototype, event_api.prototype, tag_api.prototype, metric_api.prototype, - search_api.prototype); + search_api.prototype, + snapshot_api.prototype); return module.exports = dogapi; diff --git a/package.json b/package.json index 2a56ee7..32e2841 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dogapi", - "version": "0.1.2", + "version": "0.1.3", "description": "Datadog API Node.JS Client", "main": "lib/index.js", "scripts": { @@ -8,7 +8,7 @@ }, "repository": { "type": "git", - "url": "git://github.com/brettlangdon/node-dogapi.git" + "url": "git://github.com/thetestpeople/node-dogapi" }, "keywords": [ "datadog",