Skip to content

Commit

Permalink
if no testingbot_key environment of key passed, try to check the ~/.t…
Browse files Browse the repository at this point in the history
…estingbot file
  • Loading branch information
jochen-testingbot committed Oct 30, 2015
1 parent 5754653 commit 8c0e208
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,25 @@ function TestingBot(options) {
this.options = options || {};
this.options.api_key = process.env.TESTINGBOT_KEY || this.options.api_key || null;
this.options.api_secret = process.env.TESTINGBOT_SECRET || this.options.api_secret || null;

if (!this.options.api_key || !this.options.api_secret) {
var fs = require('fs');
var path = require('path');

try {
var tbFile = path.join(process.env[(process.platform == 'win32') ? 'USERPROFILE' : 'HOME'], '.testingbot');
if (fs.statSync(tbFile).isFile() === true) {
var data = fs.readFileSync(tbFile);
if (data !== null) {
var arr = data.toString().replace('\n', '').split(':');
this.options.api_key = arr[0];
this.options.api_secret = arr[1];
}
}
} catch (e) {

}
}
}

TestingBot.prototype.getTestDetails = function(testID, callback) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "TestingBot <[email protected]> (testingbot.com)",
"name": "testingbot-api",
"description": "A wrapper around TestingBot's REST API",
"version": "1.0.0",
"version": "1.0.1",
"homepage": "https://github.com/testingbot/testingbot-api",
"repository": {
"type": "git",
Expand Down

0 comments on commit 8c0e208

Please sign in to comment.