From 5c5274e6c2c743784984cea8567ef25a3ff746b0 Mon Sep 17 00:00:00 2001 From: Kevin Fitzgerald Date: Sun, 15 Mar 2015 13:59:00 -0500 Subject: [PATCH 1/2] Added basic implementation for GetAPIKeyInfo and unit tests to support it --- index.js | 22 ++++++++++++++++++++++ test/index.js | 13 +++++++++++++ 2 files changed, 35 insertions(+) diff --git a/index.js b/index.js index e5f39a4..5109f6b 100644 --- a/index.js +++ b/index.js @@ -207,6 +207,28 @@ AlchemyAPI.prototype._getQuery = function(data, opts, method) { }; +/** + * Function to return the API key usage information + * @param {Object} options Options to be passed to the AlchemyAPI (no options are currently supported) + * @param cb + */ +AlchemyAPI.prototype.apiKeyInfo = function(options, cb) { + // Since this request is nothing like the others, build it manually + var opts = extend(this.options, opts), + query = { + data: "", + post: {}, + apimethod: "info/GetAPIKeyInfo", + headers: { + "content-length": 0 + } + }; + query.nice = this._generateNiceUrl(null, opts, query.apimethod) + query.nice.method = "GET"; + query.nice.headers = query.headers; + this._doRequest(query, cb) +}; + /** * Function to return sentiment of the data passed in * @param {String} data The text to be passed to Alchemy can either a url, html text or plain text diff --git a/test/index.js b/test/index.js index b21b13f..3f1241a 100644 --- a/test/index.js +++ b/test/index.js @@ -23,6 +23,19 @@ module.exports = { test.equal(alchemy._urlCheck('http://google.com is my favorite site ever'), false); test.done(); }, + 'get api key info': function(test) { + var alchemy = new Alchemy(apikey); + alchemy.apiKeyInfo({}, function(error, result) { + test.ifError(error); + test.ok(result); + test.ok(result.hasOwnProperty('status')); + test.ok(result.hasOwnProperty('consumedDailyTransactions')); + test.ok(result.hasOwnProperty('dailyTransactionLimit')); + //console.log(result.docSentiment); + //test.deepEqual(result.status, "OK"); + test.done(); + }); + }, 'get sentiment': function(test) { var alchemy = new Alchemy(apikey); alchemy.sentiment(testURL, {}, function(error, result) { From 1cd10bc54c6d22fe2eb62a2480f87f91074b56b8 Mon Sep 17 00:00:00 2001 From: Kevin Fitzgerald Date: Sun, 15 Mar 2015 14:04:36 -0500 Subject: [PATCH 2/2] Added example for apiKeyInfo to the docs --- README.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f6a4212..f45fd87 100644 --- a/README.md +++ b/README.md @@ -237,4 +237,16 @@ Publication Date var publicationDate = response.publicationDate; //YYYYMMDDTHHMMSS string // Do something with data - }); \ No newline at end of file + }); + +API Key Information +---------- + var AlchemyAPI = require('alchemy-api'); + var alchemy = new AlchemyAPI(''); + alchemy.apiKeyInfo({}, function(err, response) { + if (err) throw err; + + // Do something with data + console.log('Status:', response.status, 'Consumed:', response.consumedDailyTransactions, 'Limit:', response.dailyTransactionLimit); + + });