diff --git a/src/appbase.js b/src/appbase.js index da1c8a7..bcec840 100644 --- a/src/appbase.js +++ b/src/appbase.js @@ -21,10 +21,6 @@ var appbaseClient = function appbaseClient(args) { return new appbaseClient(args) } - if (typeof args.appname !== 'string' || args.appname === '') { - throw new Error('Appname not present in options.') - } - if (typeof args.url !== 'string' || args.url === '') { throw new Error('URL not present in options.') } @@ -34,18 +30,28 @@ var appbaseClient = function appbaseClient(args) { this.url = parsedUrl.host this.protocol = parsedUrl.protocol this.credentials = parsedUrl.auth - this.appname = args.appname + this.appname = args.appname || args.app + + if (typeof this.appname !== 'string' || this.appname === '') { + throw new Error('App name is not present in options.') + } if (typeof this.protocol !== 'string' || this.protocol === '') { - throw new Error('Protocol not present in url. URL should be of the form https://scalr.api.appbase.io') + throw new Error('Protocol is not present in url. URL should be of the form https://scalr.api.appbase.io') } if (typeof args.username === 'string' && args.username !== '' && typeof args.password === 'string' && args.password !== '') { this.credentials = args.username + ':' + args.password } + // credentials can be provided as a part of the URL, as username, password args or + // as a credentials argument directly + if (typeof args.credentials === 'string' && args.credentials !== '') { + this.credentials = args.credentials + } + if (typeof this.credentials !== 'string' || this.credentials === '') { - throw new Error('Authentication information not present.') + throw new Error('Authentication information is not present. Did you add credentials?') } if (parsedUrl.protocol === 'https:') { diff --git a/test/test.js b/test/test.js index ee66390..e864b32 100644 --- a/test/test.js +++ b/test/test.js @@ -16,8 +16,9 @@ describe('Appbase', function() { before(function() { streamingClient = new appbase({ - url: 'http://QEVrcElba:5c13d943-a5d1-4b05-92f3-42707d49fcbb@scalr.api.appbase.io', - appname: 'es2test1' + url: 'https://scalr.api.appbase.io', + app: 'es2test1', + credentials: 'QEVrcElba:5c13d943-a5d1-4b05-92f3-42707d49fcbb' }) }) @@ -99,4 +100,4 @@ describe('Appbase', function() { } }) }) -}) \ No newline at end of file +})