Skip to content

Commit

Permalink
don't require new
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew McClure committed Oct 21, 2013
1 parent 9262179 commit e7e2c41
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
5 changes: 4 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ var request = require('request')


function initializer(key, base_url, options) {
// Just in case they forgot new.
if (!(this instanceof initializer)) return new initializer(key, base_url, options);

// Required client config
if (!key){
if (process.env.ZENCODER_API_KEY){
Expand Down Expand Up @@ -105,4 +108,4 @@ initializer.prototype.put = function(path, callback, body) {
return this._request('PUT', path, null, body, callback);
};

module.exports = initializer;
module.exports = initializer;
14 changes: 12 additions & 2 deletions test/setup_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,21 @@ var apiKey = '1234567abcde';

var scope = nock('https://app.zencoder.com')
.matchHeader('Zencoder-Api-Key', apiKey)
.get('/api/v2/account')
.get('/api/v2/account').times(2)
.reply(200, scopes.accounts.details);

describe('The Zencoder REST Client setup', function () {

it('should not require new', function(done) {
process.env.ZENCODER_API_KEY = apiKey;
var client = Zencoder();
expect(client.apiKey).to.equal(apiKey);
client.Account.details(function(err, data, response) {
expect(response.statusCode).to.equal(200);
done();
});
});

it('should use an environment variable if API key is not included', function(done) {
process.env.ZENCODER_API_KEY = apiKey;
var client = new Zencoder();
Expand Down Expand Up @@ -39,4 +49,4 @@ describe('The Zencoder REST Client setup', function () {
expect(client.options.timeout).to.equal(5000);
});

});
});

0 comments on commit e7e2c41

Please sign in to comment.