Skip to content

Commit

Permalink
Merge pull request #20 from davidbanham/events
Browse files Browse the repository at this point in the history
Cleanup event emission and object assignment.
  • Loading branch information
jordanwalsh23 authored Mar 15, 2017
2 parents 7f0199d + ea168eb commit 16c5b96
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions lib/application.js
Original file line number Diff line number Diff line change
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,21 +593,19 @@ 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");
options.accessToken ? this.options.accessToken = options.accessToken : false;
options.accessSecret ? this.options.accessSecret = options.accessSecret : false;
options.sessionHandle ? this.options.sessionHandle = options.sessionHandle : false;
options.tokenExpiry ? this.options.tokenExpiry = options.tokenExpiry : false;

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");
this.eventEmitter.emit('xeroTokenUpdate', options);
}
}
}

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

Expand Down

0 comments on commit 16c5b96

Please sign in to comment.