Permalink
Browse files

refactor

  • Loading branch information...
1 parent 0ddb331 commit ac5f0ace35b54a7c81d8fc4b8b2d85c59d8fa01b @AlgoTrader committed Dec 14, 2012
@@ -8,28 +8,27 @@ var v6 = require('betfair-sports-api');
var invocation = require('./betfair_invocation.js');
exports.newSession = newSession;
-function newSession() {
- return new BetfairSession();
+function newSession(appKey) {
+ return new BetfairSession(appKey);
}
-function BetfairSession() {
+function BetfairSession(appKey) {
var self = this;
+ self.applicationKey = appKey;
+ invocation.applicationKey = appKey;
}
// expose setCurrentExchange via session
//BetfairSession.prototype.setCurrentExchange = exchangeService.setCurrentExchange;
// Open current session
-BetfairSession.prototype.open = function(login, password, appKey, cb) {
+BetfairSession.prototype.login = function(login, password, cb) {
var self = this;
self.login = login;
self.password = password;
- self.applicationKey = appKey;
cb = cb || function() {};
- invocation.applicationKey = self.applicationKey;
-
// Compatibility mode, use old V6 login
self.v6Session = v6.newSession(login, password);
self.v6Session.open(function(err,v6res) {
@@ -47,7 +46,7 @@ BetfairSession.prototype.open = function(login, password, appKey, cb) {
}
// Close current session
-BetfairSession.prototype.close = function(cb) {
+BetfairSession.prototype.logout = function(cb) {
var self = this;
cb = cb || function() {};
View
@@ -5,7 +5,6 @@ var util = require('util');
exports.session = null;
exports.loginName = null;
exports.password = null;
-exports.applicationKey = null;
// login to Betfair
exports.login = function(par, cb) {
@@ -15,7 +14,7 @@ exports.login = function(par, cb) {
console.log('===== Logging in to Betfair =====');
var session = exports.session;
- session.open(exports.loginName, exports.password, exports.applicationKey, function(err, res) {
+ session.login(exports.loginName, exports.password, function(err, res) {
if (err) {
console.log('Login error', err);
} else {
@@ -34,7 +33,7 @@ exports.logout = function(par, cb) {
console.log('===== Logging out... =====');
var session = exports.session;
- session.close(function(err, res) {
+ session.logout(function(err, res) {
if (err) {
console.log('Logout error', err);
} else {
@@ -4,11 +4,10 @@ var async = require('async');
var common = require('./common.js');
// Create session to Betfair
-var session = betfair.newSession();
-common.session = session;
+var appKey = process.env['BF_APPLICATION_KEY']|| "invalid";
+var session = common.session = betfair.newSession(appKey);
common.loginName = process.env['BF_LOGIN'] || "nobody";
common.password = process.env['BF_PASSWORD'] || "password";
-common.applicationKey = process.env['BF_APPLICATION_KEY'] || "invalid";
// list countries
function listCompetitions(data, cb) {
@@ -4,11 +4,10 @@ var async = require('async');
var common = require('./common.js');
// Create session to Betfair
-var session = betfair.newSession();
-common.session = session;
+var appKey = process.env['BF_APPLICATION_KEY']|| "invalid";
+var session = common.session = betfair.newSession(appKey);
common.loginName = process.env['BF_LOGIN'] || "nobody";
common.password = process.env['BF_PASSWORD'] || "password";
-common.applicationKey = process.env['BF_APPLICATION_KEY'] || "invalid";
// list countries
function listCountries(data, cb) {
@@ -4,11 +4,10 @@ var async = require('async');
var common = require('./common.js');
// Create session to Betfair
-var session = betfair.newSession();
-common.session = session;
+var appKey = process.env['BF_APPLICATION_KEY']|| "invalid";
+var session = common.session = betfair.newSession(appKey);
common.loginName = process.env['BF_LOGIN'] || "nobody";
common.password = process.env['BF_PASSWORD'] || "password";
-common.applicationKey = process.env['BF_APPLICATION_KEY'] || "invalid";
// list countries
function listEventTypes(data, cb) {
View
@@ -4,11 +4,10 @@ var async = require('async');
var common = require('./common.js');
// Create session to Betfair
-var session = betfair.newSession();
-common.session = session;
+var appKey = process.env['BF_APPLICATION_KEY']|| "invalid";
+var session = common.session = betfair.newSession(appKey);
common.loginName = process.env['BF_LOGIN'] || "nobody";
common.password = process.env['BF_PASSWORD'] || "password";
-common.applicationKey = process.env['BF_APPLICATION_KEY'] || "invalid";
// list countries
function listEvents(data, cb) {
@@ -4,11 +4,10 @@ var async = require('async');
var common = require('./common.js');
// Create session to Betfair
-var session = betfair.newSession();
-common.session = session;
+var appKey = process.env['BF_APPLICATION_KEY']|| "invalid";
+var session = common.session = betfair.newSession(appKey);
common.loginName = process.env['BF_LOGIN'] || "nobody";
common.password = process.env['BF_PASSWORD'] || "password";
-common.applicationKey = process.env['BF_APPLICATION_KEY'] || "invalid";
// list market catalogue
function listMarketCatalogue(data, cb) {
@@ -4,11 +4,10 @@ var async = require('async');
var common = require('./common.js');
// Create session to Betfair
-var session = betfair.newSession();
-common.session = session;
+var appKey = process.env['BF_APPLICATION_KEY']|| "invalid";
+var session = common.session = betfair.newSession(appKey);
common.loginName = process.env['BF_LOGIN'] || "nobody";
common.password = process.env['BF_PASSWORD'] || "password";
-common.applicationKey = process.env['BF_APPLICATION_KEY'] || "invalid";
// list market catalogue
function listMarketCatalogue(data, cb) {
@@ -4,11 +4,10 @@ var async = require('async');
var common = require('./common.js');
// Create session to Betfair
-var session = betfair.newSession();
-common.session = session;
+var appKey = process.env['BF_APPLICATION_KEY']|| "invalid";
+var session = common.session = betfair.newSession(appKey);
common.loginName = process.env['BF_LOGIN'] || "nobody";
common.password = process.env['BF_PASSWORD'] || "password";
-common.applicationKey = process.env['BF_APPLICATION_KEY'] || "invalid";
// list
function listMarketTypes(data, cb) {
@@ -4,11 +4,10 @@ var async = require('async');
var common = require('./common.js');
// Create session to Betfair
-var session = betfair.newSession();
-common.session = session;
+var appKey = process.env['BF_APPLICATION_KEY']|| "invalid";
+var session = common.session = betfair.newSession(appKey);
common.loginName = process.env['BF_LOGIN'] || "nobody";
common.password = process.env['BF_PASSWORD'] || "password";
-common.applicationKey = process.env['BF_APPLICATION_KEY'] || "invalid";
// list
function listTimeRanges(data, cb) {
View
@@ -4,11 +4,10 @@ var async = require('async');
var common = require('./common.js');
// Create session to Betfair
-var session = betfair.newSession();
-common.session = session;
+var appKey = process.env['BF_APPLICATION_KEY']|| "invalid";
+var session = common.session = betfair.newSession(appKey);
common.loginName = process.env['BF_LOGIN'] || "nobody";
common.password = process.env['BF_PASSWORD'] || "password";
-common.applicationKey = process.env['BF_APPLICATION_KEY'] || "invalid";
// list
function listVenues(data, cb) {
View
@@ -4,11 +4,10 @@ var async = require('async');
var common = require('./common.js');
// Create session to Betfair
-var session = betfair.newSession();
-common.session = session;
+var appKey = process.env['BF_APPLICATION_KEY']|| "invalid";
+var session = common.session = betfair.newSession(appKey);
common.loginName = process.env['BF_LOGIN'] || "nobody";
common.password = process.env['BF_PASSWORD'] || "password";
-common.applicationKey = process.env['BF_APPLICATION_KEY']|| "invalid";
async.waterfall([common.login, common.logout], function(err,res) {
console.log("Done");

0 comments on commit ac5f0ac

Please sign in to comment.