auth10/node-waad — pull request #2 by jfromaniello (2012-12-19 19:36:26+00:00)
Title: add pagination and some refactorings

Hi Matías, I added pagination to the users query and did some refactorings.

There are two ways to access the graph client now, first one is by doing:

~~~javascript
var waad = require('node-waad');

waad.getAccessToken('auth10dev.onmicrosoft.com', 'spn-appprincipal', 'symmetric-key-base64', function(err, token) {
var client = new waad.GraphClient({tenant: 'auth10dev.onmicrosoft.com', accessToken: token});

// query the graph
client.getUserByEmail('matias@auth10dev.onmicrosoft.com', function(err, user) {
// get user properties (user.DisplayName, user.Mail, etc.)
});
});
~~~

the second one is by using the ```getGraphClient``` method:

~~~javascript
var waad = require('node-waad');

waad.getGraphClient('auth10dev.onmicrosoft.com', 'spn-appprincipal', 'symmetric-key-base64', function(err, client) {
client.getUserByEmail('matias@auth10dev.onmicrosoft.com', function(err, user) {
// get user properties (user.DisplayName, user.Mail, etc.)
});
});
~~~

The same happen with ```getAccessTokenWithClientCredentials``` and ```getGraphClientWithClientCredentials```.

## Pagination

I added pagination to the getUsers method, so now we can do:

~~~javascript
client.getUsers({top: 10}, function (err, users) {
if (users.hasMorePages) {
users.nextPage(function(err, users) {
//this fetch the second page
});
}
});
~~~

This syntax is also possible:

~~~javascript
client.getUsers({top: 10}, function (err, users) {
client.getUsers({top: 10, skiptoken: users.skiptoken}, function(err, users) {
//this fetch the second page
});
});
~~~