Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add CompoundPlayer to allow easily trying two or more different metho…

…ds of obtaining data.
  • Loading branch information...
commit 2f4a731aa02ba2992857e1ed6f7806eb73b6fe4a 1 parent e7301f2
@eventualbuddha eventualbuddha authored
View
73 application/chrome/content/wesabe/download/CompoundPlayer.js
@@ -0,0 +1,73 @@
+wesabe.provide('download.CompoundPlayer', function() {});
+
+wesabe.lang.extend(wesabe.download.CompoundPlayer, {
+ register: function(params) {
+ var klass = this.create(params);
+
+ // make sure we put it where wesabe.require expects it
+ wesabe['fi-scripts'][params.fid] = klass;
+
+ return klass;
+ },
+
+ create: function(params) {
+ return function() {
+ // inherit from OFXPlayer
+ wesabe.lang.extend(this, wesabe.download.CompoundPlayer.prototype);
+ // subclass it
+ wesabe.lang.extend(this, params);
+ };
+ },
+});
+
+wesabe.lang.extend(wesabe.download.CompoundPlayer.prototype, {
+ playerIndex: -1,
+ currentJob: null,
+ players: null,
+
+ start: function(answers, browser) {
+ var self = this;
+
+ function startNextPlayer() {
+ self.playerIndex++;
+ self.currentPlayer = new self.players[self.playerIndex]();
+ wesabe.info("Starting player ", self.currentPlayer);
+ self.currentPlayer.job = jobProxy;
+ self.currentPlayer.start(answers, browser);
+ }
+
+ var jobProxy = {
+ update: function(status, result) {
+ // proxy job updates through
+ self.job.update(status, result);
+ },
+
+ fail: function(status, result) {
+ wesabe.info("Could not complete job with ", self.currentJob, " (", status, " ", result, ")");
+
+ if (self.playerIndex+1 < self.players.length) {
+ startNextPlayer();
+ } else {
+ // no more players to try, report the last failure
+ self.job.fail(status, result);
+ }
+ },
+
+ succeed: function() {
+ self.job.succeed();
+ },
+
+ timer: self.job.timer,
+
+ get page() {
+ return self.currentPlayer.page;
+ },
+ };
+
+ startNextPlayer();
+ },
+
+ resume: function() {
+ self.currentPlayer && self.currentPlayer.resume();
+ },
+});
View
1  application/chrome/content/wesabe/download/Controller.js
@@ -1,5 +1,6 @@
wesabe.provide('download.Controller');
wesabe.require('download.Player');
+wesabe.require('download.CompoundPlayer');
wesabe.require('canvas.snapshot');
wesabe.download.Controller = function() {
View
3  application/chrome/content/wesabe/download/Job.js
@@ -54,7 +54,8 @@ wesabe.download.Job.prototype.finish = function(status, result, successful) {
this.version++;
var event = successful ? 'succeed' : 'fail';
this.done = true;
- this.player.finish();
+ if (typeof this.player.finish == 'function')
+ this.player.finish();
this.status = status || (successful ? 200 : 400);
this.result = result || (successful ? 'ok' : 'fail');
wesabe.trigger(this, 'update ' + event + ' complete');
View
16 application/chrome/content/wesabe/download/OFXPlayer.js
@@ -12,12 +12,7 @@ wesabe.download.OFXPlayer = function(fid) {
wesabe.download.OFXPlayer.prototype.DAYS_OF_HISTORY = 365;
wesabe.download.OFXPlayer.register = function(params) {
- var klass = function() {
- // inherit from OFXPlayer
- wesabe.lang.extend(this, wesabe.download.OFXPlayer.prototype);
- // subclass it
- wesabe.lang.extend(this, params);
- };
+ var klass = this.create(params);
// make sure we put it where wesabe.require expects it
wesabe['fi-scripts'][params.fid] = klass;
@@ -25,6 +20,15 @@ wesabe.download.OFXPlayer.register = function(params) {
return klass;
};
+wesabe.download.OFXPlayer.create = function(params) {
+ return function() {
+ // inherit from OFXPlayer
+ wesabe.lang.extend(this, wesabe.download.OFXPlayer.prototype);
+ // subclass it
+ wesabe.lang.extend(this, params);
+ };
+};
+
/**
* Starts retrieving statements from the FI's OFX server.
*/
View
25 application/chrome/content/wesabe/download/Player.js
@@ -1,14 +1,20 @@
-wesabe.provide('download.Player');
wesabe.provide('fi-scripts');
wesabe.require('logger.*');
wesabe.require('dom.*');
wesabe.require('xul.UserAgent');
-wesabe.download.Player = function(answers) {
- this.answers = answers;
-};
+wesabe.provide('download.Player', function() { });
wesabe.download.Player.register = function(params) {
+ var klass = this.create(params);
+
+ // make sure we put it where wesabe.require expects it
+ wesabe['fi-scripts'][klass.fid] = klass;
+
+ return klass;
+};
+
+wesabe.download.Player.create = function(params) {
var klass = function() {
// inherit from Player
wesabe.lang.extend(this, wesabe.download.Player.prototype, false);
@@ -28,6 +34,8 @@ wesabe.download.Player.register = function(params) {
klass.fid = klass.prototype.fid = params.fid;
// the name of the Financial Institution (e.g. Wells Fargo)
klass.org = klass.prototype.org = params.org;
+ // ofx info in case this is a hybrid
+ klass.ofx = params.ofx;
var modules = [params];
@@ -88,9 +96,6 @@ wesabe.download.Player.register = function(params) {
}
});
- // make sure we put it where wesabe.require expects it
- wesabe['fi-scripts'][klass.fid] = klass;
-
return klass;
};
@@ -144,7 +149,7 @@ wesabe.download.Player.prototype.finish = function() {
};
wesabe.download.Player.prototype.runAction = function(name, browser, page, scope) {
- var self = this, module = this.constructor.__module__.name;
+ var self = this, module = this.constructor.fid;
var fn = wesabe.isFunction(name) ? name : this[name];
var name = wesabe.isFunction(name) ? (name.name || '(anonymous)') : name;
@@ -367,7 +372,7 @@ wesabe.download.Player.prototype.clearErrorTimeout = function(type) {
wesabe.download.Player.prototype.onDocumentLoaded = function(browser, page) {
if (this.job.done || this.job.paused) return;
- var self = this, module = this.constructor.__module__.name;
+ var self = this, module = this.constructor.fid;
// log when alert and confirm are called
new wesabe.dom.Bridge(page.proxyTarget, function() {
@@ -470,7 +475,7 @@ wesabe.download.Player.prototype.shouldDispatch = function(browser, page) {
var self = this;
for (var i = 0; i < this.filters.length; i++) {
- var result = wesabe.tryCatch(this.constructor.__module__.name+'#filter('+i+')', function(log) {
+ var result = wesabe.tryCatch(this.constructor.fid+'#filter('+i+')', function(log) {
var r = wesabe.lang.func.callWithScope(self.filters[i], self, {
browser: browser,
page: page,
View
110 application/chrome/content/wesabe/fi-scripts/us-003383.js
@@ -1,79 +1,63 @@
-wesabe.download.Player.register({
+wesabe.download.CompoundPlayer.register({
fid: 'us-003383',
org: 'American Express Cards',
- dispatchFrames: false,
- afterDownload: 'logout',
+ players: [
+ wesabe.download.Player.create({
+ fid: 'us-003383',
+ org: 'American Express Cards',
- includes: [
- 'fi-scripts.us-003383.login',
- 'fi-scripts.us-003383.accounts',
- ],
-
- dispatch: function() {
- if (page.present(e.errors.systemNotResponding)) {
- tmp.systemNotRespondingTTL = tmp.systemNotRespondingTTL || 4;
- tmp.systemNotRespondingTTL--;
-
- if (!tmp.systemNotRespondingTTL) {
- job.fail(503, 'fi.unavailable');
- } else {
- log.warn("Amex system is not responding (retrying, TTL=", tmp.systemNotRespondingTTL, ")");
- // retry again in 5s
- setTimeout(function(){ action.main() }, 15000);
- }
- return false;
- }
- },
+ dispatchFrames: false,
+ afterDownload: 'logout',
- actions: {
- main: function() {
- wesabe.dom.browser.go(browser, "https://www.americanexpress.com/");
- },
- },
-
- elements: {
- errors: {
- systemNotResponding: [
- '//text()[contains(., "Our System is Not Responding")]',
+ includes: [
+ 'fi-scripts.us-003383.login',
+ 'fi-scripts.us-003383.accounts',
],
- },
- },
-
- extensions: {
- start: function(answers, browser) {
- var self = this;
- var jobproxy = {
- update: function(status, result) {
- // proxy job updates through
- self.job.update(status, result);
+ dispatch: function() {
+ if (page.present(e.errors.systemNotResponding)) {
+ tmp.systemNotRespondingTTL = tmp.systemNotRespondingTTL || 4;
+ tmp.systemNotRespondingTTL--;
+
+ if (!tmp.systemNotRespondingTTL) {
+ job.fail(503, 'fi.unavailable');
+ } else {
+ log.warn("Amex system is not responding (retrying, TTL=", tmp.systemNotRespondingTTL, ")");
+ // retry again in 5s
+ setTimeout(function(){ action.main() }, 15000);
+ }
+ return false;
+ }
+ },
+
+ actions: {
+ main: function() {
+ wesabe.dom.browser.go(browser, "https://www.americanexpress.com/");
},
+ },
- fail: function(status, result) {
- wesabe.info("Could not complete job with OFX player (", status, " ", result, ") -- trying web based one");
- wesabe.download.Player.prototype.start.call(self, answers, browser);
+ elements: {
+ errors: {
+ systemNotResponding: [
+ '//text()[contains(., "Our System is Not Responding")]',
+ ],
},
+ },
+ }),
- succeed: function() {
- // the OFX version worked! we're done
- self.job.succeed();
- },
-
- timer: self.job.timer,
- };
+ wesabe.download.OFXPlayer.create({
+ fid: 'us-003383',
+ org: 'American Express Cards',
- wesabe.info("Starting with OFX for American Express Cards");
- var ofxPlayer = new wesabe.download.OFXPlayer(self.fid);
- ofxPlayer.fi = {
+ fi: {
ofxUrl: "https://online.americanexpress.com/myca/ofxdl/desktop/desktopDownload.do?request_type=nl_ofxdownload",
ofxOrg: "AMEX",
ofxFid: "3101",
- };
- ofxPlayer.appId = 'QWIN';
- ofxPlayer.appVersion = '1500';
- ofxPlayer.job = jobproxy;
- ofxPlayer.start(answers);
- },
- },
+ },
+
+ appId: 'QWIN',
+ appVersion: '1500',
+ }),
+ ],
});
View
66 application/chrome/content/wesabe/fi-scripts/us-003396.js
@@ -1,50 +1,34 @@
-wesabe.download.Player.register({
+wesabe.download.CompoundPlayer.register({
fid: 'us-003396',
org: 'Chase',
- dispatchFrames: false,
- afterDownload: 'nextAccount',
+ players: [
+ wesabe.download.OFXPlayer.create({
+ fid: 'us-003396',
+ org: 'Chase',
- includes: [
- 'fi-scripts.us-003396.promos',
- 'fi-scripts.us-003396.login',
- 'fi-scripts.us-003396.identification',
- 'fi-scripts.us-003396.accounts',
- 'fi-scripts.us-003396.errors',
- ],
-
- extensions: {
- start: function(answers, browser) {
- var self = this;
-
- var jobproxy = {
- update: function(status, result) {
- // proxy job updates through
- self.job.update(status, result);
- },
+ fi: {
+ ofxUrl: "https://ofx.chase.com",
+ ofxOrg: "B1",
+ ofxFid: "10898",
+ },
+ }),
- fail: function(status, result) {
- wesabe.info("Could not complete job with OFX player (", status, " ", result, ") -- trying web based one");
- wesabe.download.Player.prototype.start.call(self, answers, browser);
- },
- succeed: function() {
- // the OFX version worked! we're done
- self.job.succeed();
- },
+ wesabe.download.Player.create({
+ fid: 'us-003396',
+ org: 'Chase',
- timer: self.job.timer,
- };
+ dispatchFrames: false,
+ afterDownload: 'nextAccount',
- wesabe.info("Starting with OFX for Chase");
- var ofxPlayer = new wesabe.download.OFXPlayer(self.fid);
- ofxPlayer.fi = {
- ofxUrl: "https://ofx.chase.com",
- ofxOrg: "B1",
- ofxFid: "10898",
- };
- ofxPlayer.job = jobproxy;
- ofxPlayer.start(answers);
- },
- },
+ includes: [
+ 'fi-scripts.us-003396.promos',
+ 'fi-scripts.us-003396.login',
+ 'fi-scripts.us-003396.identification',
+ 'fi-scripts.us-003396.accounts',
+ 'fi-scripts.us-003396.errors',
+ ],
+ }),
+ ],
});
Please sign in to comment.
Something went wrong with that request. Please try again.