Skip to content

Commit

Permalink
externalised the runscope bucket ID to the config file
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Walsh committed Feb 22, 2017
1 parent 5a64852 commit efed46b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
38 changes: 23 additions & 15 deletions lib/application.js
Expand Up @@ -42,6 +42,9 @@ _.extend(Batch.prototype, {
function Application(options) {
logger.debug('Application::constructor');
this.options = _.merge(_.clone(Application.defaults), options);

console.log(this.options);

this.init();

var core = new Core(this);
Expand All @@ -64,14 +67,15 @@ Application.extend = extend;

_.extend(Application, {
defaults: {
baseUrl: 'https://api.xero.com',
consumerSecret: '',
consumerKey: '',
requestTokenUrl: 'https://api-xero-com-ei635hnc0fem.runscope.net/oauth/RequestToken',
accessTokenUrl: 'https://api-xero-com-ei635hnc0fem.runscope.net/oauth/AccessToken',
authorizeUrl: 'https://api-xero-com-ei635hnc0fem.runscope.net/oauth/Authorize',
requestTokenUrl: '/oauth/RequestToken',
accessTokenUrl: '/oauth/AccessToken',
authorizeUrl: '/oauth/Authorize',
authorizeCallbackUrl: '',
coreAPIEndPointUrl: 'https://api-xero-com-ei635hnc0fem.runscope.net/api.xro/2.0/',
payrollAPIEndPointUrl: 'https://api-xero-com-ei635hnc0fem.runscope.net/payroll.xro/1.0/',
coreAPIEndPointUrl: '/api.xro/2.0/',
payrollAPIEndPointUrl: '/payroll.xro/1.0/',
pageMaxRecords: 100
}
})
Expand Down Expand Up @@ -102,7 +106,7 @@ _.extend(Application.prototype, {
params.unitdp = options.unitdp;

var endPointUrl = options.api === 'payroll' ? this.options.payrollAPIEndPointUrl : this.options.coreAPIEndPointUrl;
var url = endPointUrl + path;
var url = this.options.baseUrl + endPointUrl + path;
if (!_.isEmpty(params))
url += '?' + querystring.stringify(params);
this.oa[method](url, this.options.accessToken, this.options.accessSecret, { xml: body }, function(err, data, res) {
Expand Down Expand Up @@ -153,7 +157,7 @@ _.extend(Application.prototype, {

function deleteResource() {
var endPointUrl = options.api === 'payroll' ? self.options.payrollAPIEndPointUrl : self.options.coreAPIEndPointUrl;
var url = endPointUrl + path;
var url = self.options.baseUrl + endPointUrl + path;

self.oa.delete(url, self.options.accessToken, self.options.accessSecret, function(err, data, res) {
if (options.stream && !err) {
Expand Down Expand Up @@ -214,7 +218,7 @@ _.extend(Application.prototype, {

function getResource(offset) {
var endPointUrl = options.api === 'payroll' ? self.options.payrollAPIEndPointUrl : self.options.coreAPIEndPointUrl;
var url = endPointUrl + path;
var url = self.options.baseUrl + endPointUrl + path;
var params = {};
if (offset) {
params[options.pager.paramName || 'page'] = offset;
Expand Down Expand Up @@ -425,7 +429,11 @@ populateOptions = function(configFilePath) {
options["consumerSecret"] = config.ConsumerSecret;
options["privateKeyPath"] = config.PrivateKeyPath;
options["userAgent"] = config.UserAgent || "Xero Node.js SDK";
options["runscopeBucketId"] = config.runscopeBucketId;
options["runscopeBucketId"] = config.RunscopeBucketId;

if (options["runscopeBucketId"] && options["runscopeBucketId"] !== "") {
options.baseUrl = "https://api-xero-com-" + options["runscopeBucketId"] + ".runscope.net";
}
} catch (e) {
var err = 'Couldn\'t read config.json from [' + configFilePath + ']. Exiting...';
console.error(err);
Expand Down Expand Up @@ -498,7 +506,7 @@ var RequireAuthorizationApplication = Application.extend({
},
buildAuthorizeUrl: function(requestToken, other) {
var q = _.extend({}, { oauth_token: requestToken }, other);
return this.options.authorizeUrl + '?' + querystring.stringify(q);
return this.options.baseUrl + this.options.authorizeUrl + '?' + querystring.stringify(q);
},
setOptions: function(options) {
this.options.accessToken = options.accessToken;
Expand All @@ -515,8 +523,8 @@ var PublicApplication = RequireAuthorizationApplication.extend({
init: function() {
RequireAuthorizationApplication.prototype.init.apply(this, arguments);
this.oa = new OAuth(
this.options.requestTokenUrl,
this.options.accessTokenUrl,
this.options.baseUrl + this.options.requestTokenUrl,
this.options.baseUrl + this.options.accessTokenUrl,
this.options.consumerKey,
this.options.consumerSecret,
"1.0a",
Expand All @@ -532,7 +540,7 @@ var PartnerApplication = RequireAuthorizationApplication.extend({
constructor: function(options) {
logger.debug('PartnerApplication::constructor');
options = options || {};
options.coreAPIEndPointUrl = 'https://api-partner.network.xero.com/api.xro/2.0/';
//options.coreAPIEndPointUrl = 'https://api-partner.network.xero.com/api.xro/2.0/';

RequireAuthorizationApplication.call(this, _.extend({}, options, { type: 'partner' }));
},
Expand All @@ -541,8 +549,8 @@ var PartnerApplication = RequireAuthorizationApplication.extend({
RequireAuthorizationApplication.prototype.init.apply(this, arguments);
var rsaPrivateKey = fs.readFileSync(this.options.privateKeyPath, "utf8");
this.oa = new OAuth(
'https://api-partner.network.xero.com/oauth/RequestToken',
'https://api-partner.network.xero.com/oauth/AccessToken',
this.options.baseUrl + this.options.requestTokenUrl,
this.options.baseUrl + this.options.accessTokenUrl,
this.options.consumerKey,
rsaPrivateKey,
"1.0a",
Expand Down
1 change: 0 additions & 1 deletion lib/entities/item.js
Expand Up @@ -26,7 +26,6 @@ var ItemSchema = new Entity.SchemaObject({
ItemID: { type: String, toObject: 'always' }
});


var Item = Entity.extend(ItemSchema, {
constructor: function(application, data, options) {
logger.debug('Item::constructor');
Expand Down
4 changes: 2 additions & 2 deletions test/accountingtests.js
Expand Up @@ -259,7 +259,7 @@ describe('regression tests', function() {
})
})

describe.skip('accounts', function() {
describe('accounts', function() {

//Accounts supporting data
var accountClasses = ["ASSET", "EQUITY", "EXPENSE", "LIABILITY", "REVENUE"];
Expand Down Expand Up @@ -758,7 +758,7 @@ describe('regression tests', function() {

describe.skip('tracking categories', function() {});

describe('items', function() {
describe.skip('items', function() {
this.timeout(10000);

var sampleItem = {
Expand Down

0 comments on commit efed46b

Please sign in to comment.