Skip to content

Commit

Permalink
[new] Auth and listApplications examples
Browse files Browse the repository at this point in the history
  • Loading branch information
johanfirebase committed May 28, 2012
1 parent 10878d2 commit 3706a80
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/.gitignore
@@ -0,0 +1 @@
credentials.json
14 changes: 14 additions & 0 deletions examples/auth-example.js
@@ -0,0 +1,14 @@
/* This example shows you how to login into a VCAP cloud, put your
* credentials into credentials.json file.*/

var vcap = require('../index');
var credentials = require('./credentials');

// Create the client using the given endpoint.
var client = new vcap.Client(credentials.endpoint);

// Login with the given credentials
client.login(credentials.user, credentials.password, function(err, token) {
if(err) return console.log('Login error:', err);
console.log('Auth success, token is', token);
});
5 changes: 5 additions & 0 deletions examples/credentials-sample.json
@@ -0,0 +1,5 @@
{
"user": "your-email@example.com",
"password": "Your - Password",
"endpoint": "http://api.cloudfoundry.com"
}
9 changes: 9 additions & 0 deletions examples/credentials.js
@@ -0,0 +1,9 @@
var fs = require('fs');
var path = require('path');

var credentialsFilePath = path.join(__dirname, 'credentials.json');
if(!path.existsSync(credentialsFilePath)) {
throw "Before running any example, be sure to put your cloud credentials in the examples/credentials.json file. Use examples/credentials-sample.json as an guide";
}
var credentials = JSON.parse(fs.readFileSync(credentialsFilePath));
module.exports = credentials;
16 changes: 16 additions & 0 deletions examples/listApplications-example.js
@@ -0,0 +1,16 @@
/** This example shows you how to list the applications from a VCAP
* cloud */

var vcap = require('../index');
var credentials = require('./credentials');

var client = new vcap.Client(credentials.endpoint);

// List all my current applications
client.login(credentials.user, credentials.password, function(err, token) {
if(err) return console.log('Login error: ' + err);
client.listApplications(function(err, apps) {
if(err) return console.log('An error occurred while listing the applications: ', err);
console.log(apps);
});
});

0 comments on commit 3706a80

Please sign in to comment.