Skip to content

Commit

Permalink
Merge pull request #10 from kfitzgerald/add-get-api-key-info-method
Browse files Browse the repository at this point in the history
Basic Implementation for GetAPIKeyInfo
  • Loading branch information
Jason Morgan committed Mar 15, 2015
2 parents 430f534 + 1cd10bc commit ed2281f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,16 @@ Publication Date
var publicationDate = response.publicationDate; //YYYYMMDDTHHMMSS string

// Do something with data
});
});

API Key Information
----------
var AlchemyAPI = require('alchemy-api');
var alchemy = new AlchemyAPI('<YOUR API KEY>');
alchemy.apiKeyInfo({}, function(err, response) {
if (err) throw err;

// Do something with data
console.log('Status:', response.status, 'Consumed:', response.consumedDailyTransactions, 'Limit:', response.dailyTransactionLimit);
});
22 changes: 22 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit ed2281f

Please sign in to comment.