Skip to content

Commit

Permalink
Clean up setOptions API
Browse files Browse the repository at this point in the history
This moves the concern of whether or not to emit an event to be internal to setOptions. No need for the calling functions to make that decision.
  • Loading branch information
davidbanham committed Mar 15, 2017
1 parent 0f0525f commit 12c5b81
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions lib/application.js
Expand Up @@ -559,7 +559,7 @@ var RequireAuthorizationApplication = Application.extend({
accessSecret: results.oauth_token_secret,
sessionHandle: results.oauth_session_handle,
tokenExpiry: exp.toString()
}, false);
});
resolve({ results: results });
}
callback && callback.apply(callback, arguments);
Expand All @@ -581,7 +581,7 @@ var RequireAuthorizationApplication = Application.extend({
accessSecret: results.oauth_token_secret,
sessionHandle: results.oauth_session_handle,
tokenExpiry: exp.toString()
}, true);
});
resolve({ results: results });
}

Expand All @@ -593,18 +593,23 @@ var RequireAuthorizationApplication = Application.extend({
var q = Object.assign({}, { oauth_token: requestToken }, other);
return this.options.baseUrl + this.options.authorizeUrl + '?' + querystring.stringify(q);
},
setOptions: function(options, emitThisEvent) {
setOptions: function(options) {
logger.debug("Setting options");
this.options = Object.assign(this.options, options);

if (emitThisEvent && this.eventEmitter) {
logger.debug("Emitting event");
try {
this.eventEmitter.emit('xeroTokenUpdate', options);
} catch (e) {
logger.error(e);
if (this.options.accessToken) {
if (options.accessToken !== this.options.accessToken) {
if (this.eventEmitter) {
logger.debug("Emitting event");
try {
this.eventEmitter.emit('xeroTokenUpdate', options);
} catch (e) {
logger.error(e);
}
}
}
}

this.options = Object.assign(this.options, options);
}
});

Expand Down

0 comments on commit 12c5b81

Please sign in to comment.