Skip to content

Instantly share code, notes, and snippets.

@kenperkins
Last active December 15, 2015 04:09
Show Gist options
  • Save kenperkins/5199162 to your computer and use it in GitHub Desktop.
Save kenperkins/5199162 to your computer and use it in GitHub Desktop.
Factory methods with and without implicit authorization
// Approach one is a synchronous factory method, with explicit authorization
var service = require('service'),
client = service.createClient('username', 'password');
client.authorize(function(err) {
client.servers.getServers(function(err, servers) {
// do stuff with your servers here
});
});
// Approach two includes implicit authorization as part of an asynchronous createClient method
var service = require('service');
service.createClient('username', 'password', function(err, client) {
client.getServers(function(err, servers) {
// do stuff with your servers here
});
});
// A third approach uses a synchronous createClient factory method and implicit on-demand authorization
var server = require('service'),
client = service.createClient('username', 'password');
// implicitly authorize when the user tries to do something.
client.servers.getServers(function(err, servers) {
// do stuff with your servers here
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment