diff --git a/oauth_test/sample_app.js b/oauth_test/sample_app.js index 8c55a2ca..09f37935 100644 --- a/oauth_test/sample_app.js +++ b/oauth_test/sample_app.js @@ -23,13 +23,45 @@ function getXeroApp(session) { var app = express(); -app.engine('handlebars', exphbs({ +var exphbs = exphbs.create({ defaultLayout: 'main', layoutsDir: __dirname + '/views/layouts', partialsDir: [ __dirname + '/views/partials/' - ] -})); + ], + helpers: { + ifCond: function(v1, operator, v2, options) { + + switch (operator) { + case '==': + return (v1 == v2) ? options.fn(this) : options.inverse(this); + case '===': + return (v1 === v2) ? options.fn(this) : options.inverse(this); + case '!=': + return (v1 != v2) ? options.fn(this) : options.inverse(this); + case '!==': + return (v1 !== v2) ? options.fn(this) : options.inverse(this); + case '<': + return (v1 < v2) ? options.fn(this) : options.inverse(this); + case '<=': + return (v1 <= v2) ? options.fn(this) : options.inverse(this); + case '>': + return (v1 > v2) ? options.fn(this) : options.inverse(this); + case '>=': + return (v1 >= v2) ? options.fn(this) : options.inverse(this); + case '&&': + return (v1 && v2) ? options.fn(this) : options.inverse(this); + case '||': + return (v1 || v2) ? options.fn(this) : options.inverse(this); + default: + return options.inverse(this); + } + } + } +}); + +app.engine('handlebars', exphbs.engine); + app.set('view engine', 'handlebars'); app.set('views', __dirname + '/views'); @@ -126,6 +158,45 @@ app.get('/contacts', function(req, res) { }) }); +app.get('/banktransactions', function(req, res) { + authorizedOperation(req, res, '/banktransactions', function(xeroApp) { + var bankTransactions = []; + xeroApp.core.bankTransactions.getBankTransactions({ pager: { callback: pagerCallback } }) + .then(function() { + res.render('banktransactions', { bankTransactions: bankTransactions }); + }) + + function pagerCallback(err, response, cb) { + bankTransactions.push.apply(bankTransactions, response.data); + cb() + } + }) +}); + +app.get('/banktransfers', function(req, res) { + authorizedOperation(req, res, '/banktransfers', function(xeroApp) { + var bankTransfers = []; + xeroApp.core.bankTransfers.getBankTransfers({ pager: { callback: pagerCallback } }) + .then(function() { + res.render('banktransfers', { bankTransfers: bankTransfers }); + }) + + function pagerCallback(err, response, cb) { + bankTransfers.push.apply(bankTransfers, response.data); + cb() + } + }) +}); + +app.get('/accounts', function(req, res) { + authorizedOperation(req, res, '/accounts', function(xeroApp) { + xeroApp.core.accounts.getAccounts() + .then(function(accounts) { + res.render('accounts', { accounts: accounts }); + }) + }) +}); + app.get('/timesheets', function(req, res) { authorizedOperation(req, res, '/timesheets', function(xeroApp) { diff --git a/oauth_test/views/accounts.handlebars b/oauth_test/views/accounts.handlebars new file mode 100644 index 00000000..45700595 --- /dev/null +++ b/oauth_test/views/accounts.handlebars @@ -0,0 +1,27 @@ +
Name | +Code | +Type | +BankAccountNumber | +BankAccountType | +CurrencyCode | +|
{{this.Name}} | + {{else}} +{{this.Name}} | + {{/ifCond}} +{{ this.Code }} | +{{ this.Type }} | +{{ this.BankAccountNumber }} | +{{ this.BankAccountType }} | +{{ this.CurrencyCode }} | +
Contact Name | +Transaction Date | +# Line Items | +SubTotal | +Tax | +Total | +
{{this.Contact.Name}} | +{{ this.Date }} | +{{ this.LineItems.length }} | +{{ this.SubTotal }} | +{{ this.TotalTax }} | +{{ this.Total }} | +
ID | +Transfer Date | +From Acct Name | +To Acct Name | +Amount | +
{{ this.BankTransferID }} | +{{ this.Date }} | +{{ this.FromBankAccount.Name }} (ref) | +{{ this.ToBankAccount.Name }} (ref) | +{{ this.Amount }} | +
ID | Name | First name | Last name | @@ -10,8 +9,7 @@||||
{{ this.ContactID }} | -{{ this.Name }} | +{{ this.Name }} | {{ this.FirstName }} | {{ this.LastName }} |
Parameter | +Description | +Mandatory | +
---|---|---|
UserAgent | +The useragent that should be used with all calls to the Xero API | +True | +
ConsumerKey | +The consumer key that is required with all calls to the Xero API., | +True | +
ConsumerSecret | +The secret key from the developer portal that is required to authenticate your API calls | +True | +
PrivateKeyPath | +The filesystem path to your privatekey.pem file to sign the API calls | +True | +
RunscopeBucketId | +Your personal runscope bucket for debugging API calls | +False | +
RunscopeBucketId
has been added to support debugging the SDK. Runscope is a simple tool for Testing Complex
+ APIs. You can use Runscope to verify that the structure and content of your API calls meets your expectations.
Sign up for a free runscope account at runscope.com and place your bucket ID in the config + file to see API calls in real time.
+Runscope is not endorsed by or affiliated with Xero. This tool was used by the SDK creator when authoring the code only.
+var PrivateApplication = require('xero-node').PrivateApplication;
+var privateApp = new PrivateApplication();
+
+// This checks the ~/.xero/config.json directory by default looking for a config file.
+// Alternatively a path to a JSON file can be provided as a parameter:
+
+var myConfigFile = "/tmp/config.json";
+var privateApp = new PrivateApplication(myConfigFile);
+
+var PublicApplication = require('xero-node').PublicApplication;
+var publicApp = new PublicApplication(myConfigFile);
+
+var ParnetApplication = require('xero-node').PartnerApplication;
+var partnerApp = new PartnerApplication(myConfigFile);
+
+Print a count of invoices:
+//Print a count of invoices
+privateApp.core.invoices.getInvoices()
+.then(function(invoices) {
+ console.log("Invoices: " + invoices.length);
+
+}).fail(function(err) {
+ console.error(err);
+});
+
+Print the name of some filtered contacts:
+//Print the name of a contact
+privateApp.core.contacts.getContacts({
+ where: 'Name.Contains("Bayside")'
+})
+.then(function(contacts) {
+ contacts.forEach(function(contact) {
+ console.log(contact.Name);
+ });
+}).fail(function(err) {
+ console.error(err);
+});
+
+Efficient paging:
+privateApp.core.contacts.getContacts({ pager: {start:1 /* page number */, callback:onContacts}})
+ .fail(function(err) {
+ console.log('Oh no, an error');
+ });
+
+/* Called per page */
+function onContacts(err, response, cb) {
+ var contacts = response.data;
+ if (response.finished) // finished paging
+ ....
+ cb(); // Async support
+}
+
+Filter support: Modified After
+// No paging
+publicApp.core.contacts.getContacts({
+ modifiedAfter: new Date(2013,1,1)
+})
+.then(function(contacts) {
+ _.each(contacts, function(contact) {
+ // Do something with contact
+ })
+})
+
+
+npm test
+Copyright © 2017 Tim Shnaider, Guillermo Gette, Andrew Connell, Elliot Shepherd and Jordan Walsh
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation + files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, + modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software + is furnished to do so, subject to the following conditions:
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\ No newline at end of file diff --git a/oauth_test/views/invoices.handlebars b/oauth_test/views/invoices.handlebars index 58b5a39a..6e9d1695 100644 --- a/oauth_test/views/invoices.handlebars +++ b/oauth_test/views/invoices.handlebars @@ -1,20 +1,36 @@ID | -Invoice Number | -Date | -Due Date | -Status | -Total | -- | |
Invoice Number | +Date | +Due Date | +Status | +Total | ++ | ||
{{ this.InvoiceID }} | -{{ this.InvoiceNumber}} | + {{#ifCond this.Type '==' 'ACCREC'}} ++ {{#if this.InvoiceNumber}} + {{this.InvoiceNumber}} + {{else}} + {{this.InvoiceID}} + {{/if}} + + | + {{else}} ++ {{#if this.InvoiceNumber}} + {{this.InvoiceNumber}} + {{else}} + {{this.InvoiceID}} + {{/if}} + + | + {{/ifCond}}{{ this.Date }} | {{ this.DueDate }} | {{ this.Status}} | @@ -22,4 +38,4 @@