Skip to content

Commit

Permalink
Merge branch 'davidbanham-promises'
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Walsh committed Mar 8, 2017
2 parents 5d31493 + 7bbd1bf commit 3d6b613
Show file tree
Hide file tree
Showing 25 changed files with 255 additions and 283 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -135,7 +135,7 @@ Print a count of invoices:
xeroClient.core.invoices.getInvoices()
.then(function(invoices) {
console.log("Invoices: " + invoices.length);
}).fail(function(err) {
}).catch(function(err) {
console.error(err);
});
```
Expand All @@ -151,7 +151,7 @@ xeroClient.core.contacts.getContacts({
contacts.forEach(function(contact) {
console.log(contact.Name);
});
}).fail(function(err) {
}).catch(function(err) {
console.error(err);
});
```
Expand All @@ -160,7 +160,7 @@ Efficient paging:

```javascript
xeroClient.core.contacts.getContacts({ pager: {start:1 /* page number */, callback: onContacts}})
.fail(function(err) {
.catch(function(err) {
console.log('Oh no, an error');
});

Expand Down
340 changes: 166 additions & 174 deletions lib/application.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/entities/attachment.js
Expand Up @@ -35,7 +35,7 @@ var Attachment = Entity.extend(AttachmentSchema, {
console.log(ret);
return ret.response.Attachments.Attachment;
})
.fail(function(err) {
.catch(function(err) {
console.log(err);
})

Expand Down
3 changes: 1 addition & 2 deletions lib/entity_helpers/accounts.js
Expand Up @@ -2,7 +2,6 @@ var _ = require('lodash'),
logger = require('../logger'),
EntityHelper = require('./entity_helper'),
Account = require('../entities/account'),
p = require('../misc/promise'),
util = require('util')

var Accounts = EntityHelper.extend({
Expand Down Expand Up @@ -35,4 +34,4 @@ var Accounts = EntityHelper.extend({
}
})

module.exports = Accounts;
module.exports = Accounts;
3 changes: 1 addition & 2 deletions lib/entity_helpers/attachments.js
Expand Up @@ -2,7 +2,6 @@ var _ = require('lodash'),
logger = require('../logger'),
EntityHelper = require('./entity_helper'),
Attachment = require('../entities/attachment'),
p = require('../misc/promise'),
util = require('util')

var Attachments = EntityHelper.extend({
Expand All @@ -26,4 +25,4 @@ var Attachments = EntityHelper.extend({
}
})

module.exports = Attachments;
module.exports = Attachments;
3 changes: 1 addition & 2 deletions lib/entity_helpers/banktransactions.js
Expand Up @@ -2,7 +2,6 @@ var _ = require('lodash'),
logger = require('../logger'),
EntityHelper = require('./entity_helper'),
BankTransaction = require('../entities/banktransaction'),
p = require('../misc/promise'),
util = require('util')

var BankTransactions = EntityHelper.extend({
Expand Down Expand Up @@ -32,4 +31,4 @@ var BankTransactions = EntityHelper.extend({
}
})

module.exports = BankTransactions;
module.exports = BankTransactions;
3 changes: 1 addition & 2 deletions lib/entity_helpers/banktransfers.js
Expand Up @@ -2,7 +2,6 @@ var _ = require('lodash'),
logger = require('../logger'),
EntityHelper = require('./entity_helper'),
BankTransfer = require('../entities/banktransfer'),
p = require('../misc/promise'),
util = require('util')

var BankTransfers = EntityHelper.extend({
Expand Down Expand Up @@ -32,4 +31,4 @@ var BankTransfers = EntityHelper.extend({
}
})

module.exports = BankTransfers;
module.exports = BankTransfers;
3 changes: 1 addition & 2 deletions lib/entity_helpers/contacts.js
Expand Up @@ -2,7 +2,6 @@ var _ = require('lodash'),
logger = require('../logger'),
EntityHelper = require('./entity_helper'),
Contact = require('../entities/contact'),
p = require('../misc/promise'),
util = require('util')

var Contacts = EntityHelper.extend({
Expand Down Expand Up @@ -33,4 +32,4 @@ var Contacts = EntityHelper.extend({
}
})

module.exports = Contacts;
module.exports = Contacts;
3 changes: 1 addition & 2 deletions lib/entity_helpers/entity_helper.js
@@ -1,7 +1,6 @@
var logger = require('../logger'),
extend = require('../misc/extend'),
_ = require('lodash'),
promise = require('../misc/promise'),
util = require('util'),
qs = require('querystring')

Expand Down Expand Up @@ -70,4 +69,4 @@ _.extend(EntityHelper.prototype, {
}

})
module.exports = EntityHelper;
module.exports = EntityHelper;
3 changes: 1 addition & 2 deletions lib/entity_helpers/invoices.js
Expand Up @@ -2,7 +2,6 @@ var _ = require('lodash'),
logger = require('../logger'),
EntityHelper = require('./entity_helper'),
Invoice = require('../entities/invoice'),
p = require('../misc/promise'),
util = require('util')

var Invoices = EntityHelper.extend({
Expand Down Expand Up @@ -39,4 +38,4 @@ var Invoices = EntityHelper.extend({
}
})

module.exports = Invoices;
module.exports = Invoices;
3 changes: 1 addition & 2 deletions lib/entity_helpers/items.js
Expand Up @@ -2,7 +2,6 @@ var _ = require('lodash'),
logger = require('../logger'),
EntityHelper = require('./entity_helper'),
Item = require('../entities/item'),
p = require('../misc/promise'),
util = require('util')

var Items = EntityHelper.extend({
Expand Down Expand Up @@ -32,4 +31,4 @@ var Items = EntityHelper.extend({
}
})

module.exports = Items;
module.exports = Items;
5 changes: 2 additions & 3 deletions lib/entity_helpers/journals.js
Expand Up @@ -2,7 +2,6 @@ var _ = require('lodash'),
logger = require('../logger'),
EntityHelper = require('./entity_helper'),
Journal = require('../entities/journal'),
p = require('../misc/promise'),
util = require('util')

var Journals = EntityHelper.extend({
Expand Down Expand Up @@ -53,11 +52,11 @@ var Journals = EntityHelper.extend({
callback && callback(null, journals);
return journals;
})
.fail(function(err) {
.catch(function(err) {
callback && callback(err);
throw err;
})
}
})

module.exports = Journals;
module.exports = Journals;
5 changes: 2 additions & 3 deletions lib/entity_helpers/organisations.js
Expand Up @@ -2,7 +2,6 @@ var _ = require('lodash'),
logger = require('../logger'),
EntityHelper = require('./entity_helper'),
Organisation = require('../entities/organisation'),
p = require('../misc/promise'),
util = require('util')

var Organisations = EntityHelper.extend({
Expand All @@ -21,11 +20,11 @@ var Organisations = EntityHelper.extend({
callback && callback(null, _.first(organisations));
return _.first(organisations);
})
.fail(function(err) {
.catch(function(err) {
callback && callback(err);
throw err;
})
}
})

module.exports = Organisations;
module.exports = Organisations;
1 change: 0 additions & 1 deletion lib/entity_helpers/payitems.js
Expand Up @@ -7,7 +7,6 @@ var _ = require('lodash')
, DeductionType = require('../entities/payitems').DeductionType
, ReimbursementType = require('../entities/payitems').ReimbursementType
, TimeOffType = require('../entities/payitems').TimeOffType
, p = require('../misc/promise')
, util = require('util')

var PayItems = EntityHelper.extend({
Expand Down
3 changes: 1 addition & 2 deletions lib/entity_helpers/payments.js
Expand Up @@ -2,7 +2,6 @@ var _ = require('lodash'),
logger = require('../logger'),
EntityHelper = require('./entity_helper'),
Payment = require('../entities/payment'),
p = require('../misc/promise'),
util = require('util')

var Payments = EntityHelper.extend({
Expand All @@ -26,4 +25,4 @@ var Payments = EntityHelper.extend({
}
})

module.exports = Payments;
module.exports = Payments;
3 changes: 1 addition & 2 deletions lib/entity_helpers/payroll_employees.js
Expand Up @@ -2,7 +2,6 @@ var _ = require('lodash'),
logger = require('../logger'),
EntityHelper = require('./entity_helper'),
Employee = require('../entities/payroll_employee'),
p = require('../misc/promise'),
util = require('util')

var Employees = EntityHelper.extend({
Expand Down Expand Up @@ -30,4 +29,4 @@ var Employees = EntityHelper.extend({
}
})

module.exports = Employees;
module.exports = Employees;
3 changes: 1 addition & 2 deletions lib/entity_helpers/taxrates.js
Expand Up @@ -2,7 +2,6 @@ var _ = require('lodash'),
logger = require('../logger'),
EntityHelper = require('./entity_helper'),
TaxRate = require('../entities/taxrate'),
p = require('../misc/promise'),
util = require('util')

var TaxRates = EntityHelper.extend({
Expand All @@ -24,4 +23,4 @@ var TaxRates = EntityHelper.extend({
}
})

module.exports = TaxRates;
module.exports = TaxRates;
1 change: 0 additions & 1 deletion lib/entity_helpers/timesheets.js
Expand Up @@ -2,7 +2,6 @@ var _ = require('lodash')
, logger = require('../logger')
, EntityHelper = require('./entity_helper')
, Timesheet = require('../entities/timesheet')
, p = require('../misc/promise')
, util = require('util')

var Timesheets = EntityHelper.extend({
Expand Down
3 changes: 1 addition & 2 deletions lib/entity_helpers/trackingcategories.js
Expand Up @@ -3,7 +3,6 @@ var _ = require('lodash'),
EntityHelper = require('./entity_helper'),
TrackingCategory = require('../entities/trackingcategory'),
TrackingOption = require('../entities/trackingoption.js'),
p = require('../misc/promise'),
util = require('util')

var TrackingCategories = EntityHelper.extend({
Expand Down Expand Up @@ -37,4 +36,4 @@ var TrackingCategories = EntityHelper.extend({
}
})

module.exports = TrackingCategories;
module.exports = TrackingCategories;
3 changes: 1 addition & 2 deletions lib/entity_helpers/users.js
Expand Up @@ -2,7 +2,6 @@ var _ = require('lodash'),
logger = require('../logger'),
EntityHelper = require('./entity_helper'),
User = require('../entities/user'),
p = require('../misc/promise'),
util = require('util')

var Users = EntityHelper.extend({
Expand Down Expand Up @@ -31,4 +30,4 @@ var Users = EntityHelper.extend({
}
})

module.exports = Users;
module.exports = Users;
3 changes: 0 additions & 3 deletions lib/misc/promise.js

This file was deleted.

8 changes: 4 additions & 4 deletions sample_app/sample_app.js
Expand Up @@ -155,7 +155,7 @@ app.get('/employees', function(req, res) {
}
});
})
.fail(function(err) {
.catch(function(err) {
console.log(err)
res.render('employees', {
error: err,
Expand Down Expand Up @@ -306,7 +306,7 @@ app.get('/timesheets', function(req, res) {
}
});
})
.fail(function(err) {
.catch(function(err) {
console.log(err)
res.render('timesheets', {
error: err,
Expand Down Expand Up @@ -337,7 +337,7 @@ app.use('/createtimesheet', function(req, res) {
.then(function(ret) {
res.render('createtimesheet', { timesheets: ret.entities })
})
.fail(function(err) {
.catch(function(err) {
res.render('createtimesheet', { err: err })
})

Expand Down Expand Up @@ -400,7 +400,7 @@ app.use('/createinvoice', function(req, res) {
.then(function(ret) {
res.render('createinvoice', { outcome: 'Invoice created', id: ret.entities[0].InvoiceID })
})
.fail(function(err) {
.catch(function(err) {
res.render('createinvoice', { outcome: 'Error', err: err })
})

Expand Down
6 changes: 3 additions & 3 deletions sample_app/views/index.handlebars
Expand Up @@ -113,7 +113,7 @@ privateApp.core.invoices.getInvoices()
.then(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">invoices</span>) </span>{
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Invoices: "</span> + invoices.length);

}).fail(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">err</span>) </span>{
}).catch(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">err</span>) </span>{
<span class="hljs-built_in">console</span>.error(err);
});
</code></pre>
Expand All @@ -126,13 +126,13 @@ privateApp.core.contacts.getContacts({
contacts.forEach(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">contact</span>) </span>{
<span class="hljs-built_in">console</span>.log(contact.Name);
});
}).fail(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">err</span>) </span>{
}).catch(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">err</span>) </span>{
<span class="hljs-built_in">console</span>.error(err);
});
</code></pre>
<p>Efficient paging:</p>
<pre><code class="language-javascript">privateApp.core.contacts.getContacts({ pager: {start:<span class="hljs-number">1</span> <span class="hljs-comment">/* page number */</span>, callback:onContacts}})
.fail(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">err</span>) </span>{
.catch(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">err</span>) </span>{
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">'Oh no, an error'</span>);
});

Expand Down

0 comments on commit 3d6b613

Please sign in to comment.