Skip to content

Commit

Permalink
Add multiple client connection support that only relies on the create…
Browse files Browse the repository at this point in the history
…Client object (not the environment variables)
  • Loading branch information
Eriks committed Mar 26, 2015
1 parent d23c982 commit d4ca61c
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,28 +53,24 @@ exports.createClient = function (options) {

options = store.defaults(options);

if (nconf.get('helpcenter')) {
this.helpcenter = true;
} else if (nconf.get('voice')) {
this.voice = true;
}

if (nconf.get('subdomain')) {
if (this.helpcenter) {
nconf.set('remoteUri', 'https://' + nconf.get('subdomain') + '.zendesk.com/api/v2/help_center');
} else if (this.voice){
nconf.overrides({'remoteUri': 'https://'+nconf.get('subdomain') + '.zendesk.com/api/v2/channels/voice'});
var endpoint;
if (options.stores.defaults.store.helpcenter) {
endpoint = '.zendesk.com/api/v2/help_center';
} else if (options.stores.defaults.store.voice){
endpoint = '.zendesk.com/api/v2/channels/voice';
} else {
nconf.set('remoteUri', 'https://' + nconf.get('subdomain') + '.zendesk.com/api/v2');
endpoint = '.zendesk.com/api/v2';
}
options.stores.defaults.store.remoteUri = 'https://' + nconf.get('subdomain') + endpoint;
}

var client = {}, partsToAdd, clientPath;

if (this.helpcenter) {
if (options.stores.defaults.store.helpcenter) {
partsToAdd = helpcenterParts;
clientPath = './client/helpcenter/';
} else if (this.voice) {
} else if (options.stores.defaults.store.voice) {
partsToAdd = voiceParts;
clientPath = './client/voice/';
} else {
Expand All @@ -98,5 +94,6 @@ exports.createClient = function (options) {
console.log(args);
}
}

return client;
};

0 comments on commit d4ca61c

Please sign in to comment.