Last active
December 15, 2015 04:09
-
-
Save kenperkins/5199162 to your computer and use it in GitHub Desktop.
Factory methods with and without implicit authorization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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