From dcddd7862fc85acb4ab41c698e5317042b5df5c6 Mon Sep 17 00:00:00 2001 From: Colin Jones Date: Wed, 9 Oct 2013 19:37:50 +0100 Subject: [PATCH 1/3] 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", From d21a3834ee8ff24d64111abdf2be4085c7591244 Mon Sep 17 00:00:00 2001 From: Colin Jones Date: Thu, 10 Oct 2013 19:48:50 +0100 Subject: [PATCH 2/3] Correction to the HTTP method to posting snapshot requests --- lib/api/snapshot.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/api/snapshot.js b/lib/api/snapshot.js index a24a6bf..890f06b 100644 --- a/lib/api/snapshot.js +++ b/lib/api/snapshot.js @@ -1,5 +1,3 @@ -snapshot.js - var extend = require('extend'); var util = require('util'); var v8type = require('v8type'); @@ -42,7 +40,7 @@ snapshot_api.prototype.add_snapshot = function(snapshot, callback){ - this.request('POST', '/graph/snapshot', {body: snapshot}, callback); + this.request('GET', '/graph/snapshot', {query: snapshot}, callback); }; From 9ddad29e1852a6b8fc0fa0192e4f86d54116a7f6 Mon Sep 17 00:00:00 2001 From: Colin Jones Date: Thu, 10 Oct 2013 20:44:31 +0100 Subject: [PATCH 3/3] Amendments to package.json --- package.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 32e2841..32882ee 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ }, "repository": { "type": "git", - "url": "git://github.com/thetestpeople/node-dogapi" + "url": "git://github.com/brettlangdon/node-dogapi" }, "keywords": [ "datadog", @@ -19,6 +19,9 @@ "dog api" ], "author": "Brett Langdon (http://brett.is)", + "contributors":[ + "colinjonesx (http://www.thetestpeople.com)" + ], "license": "MIT", "readmeFilename": "README.md", "gitHead": "f388635a5ab4f4da25702dc0999385d437bdf2bc",