Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[fix] Changed options so that nconf objects can be passed in as well …

…as options.
  • Loading branch information...
commit d0de99409d10dda5b5766f88b31ccd5005add90f 1 parent 661b4d9
@AvianFlu AvianFlu authored
View
18 node.js/lib/client/apps.js
@@ -28,7 +28,7 @@ util.inherits(Apps, Client);
// Lists all applications for the authenticated user
//
Apps.prototype.list = function (callback) {
- var username = this.options.username;
+ var username = this.options.get('username');
this.request('GET', ['apps', username], callback, function (res, result) {
callback(null, result.apps || res.statusCode);
})
@@ -41,7 +41,7 @@ Apps.prototype.list = function (callback) {
// Creates an application with the specified package.json manifest in `app`.
//
Apps.prototype.create = function (app, callback) {
- var username = this.options.username;
+ var username = this.options.get('username');
this.request('POST', ['apps', username, app.name], app, callback, function (res, result) {
callback(null, result || res.statusCode);
})
@@ -54,7 +54,7 @@ Apps.prototype.create = function (app, callback) {
// Views the application specified by `name`.
//
Apps.prototype.view = function (name, callback) {
- var username = this.options.username;
+ var username = this.options.get('username');
this.request('GET', ['apps', username, name], callback, function (res, result) {
callback(null, result.app || res.statusCode);
})
@@ -68,7 +68,7 @@ Apps.prototype.view = function (name, callback) {
// Updates the application with `name` with the specified attributes in `attrs`
//
Apps.prototype.update = function (name, attrs, callback) {
- var username = this.options.username;
+ var username = this.options.get('username');
this.request('PUT', ['apps', username, name], attrs, callback, function (res, result) {
callback(null, result || res.statusCode);
});
@@ -81,7 +81,7 @@ Apps.prototype.update = function (name, attrs, callback) {
// Destroys the application with `name` for the authenticated user.
//
Apps.prototype.destroy = function (name, callback) {
- var username = this.options.username;
+ var username = this.options.get('username');
this.request('DELETE', ['apps', username, name], callback, function (res, result) {
callback(null, result || res.statusCode);
})
@@ -94,7 +94,7 @@ Apps.prototype.destroy = function (name, callback) {
// Starts the application with `name` for the authenticated user.
//
Apps.prototype.start = function (name, callback) {
- var username = this.options.username;
+ var username = this.options.get('username');
this.request('POST', ['apps', username, name, 'start'], callback, function (res, result) {
callback(null, result || res.statusCode);
});
@@ -107,7 +107,7 @@ Apps.prototype.start = function (name, callback) {
// Starts the application with `name` for the authenticated user.
//
Apps.prototype.restart = function (name, callback) {
- var username = this.options.username;
+ var username = this.options.get('username');
this.request('POST', ['apps', username, name, 'restart'], callback, function (res, result) {
callback(null, result || res.statusCode);
});
@@ -120,7 +120,7 @@ Apps.prototype.restart = function (name, callback) {
// Stops the application with `name` for the authenticated user.
//
Apps.prototype.stop = function (name, callback) {
- var username = this.options.username;
+ var username = this.options.get('username');
this.request('POST', ['apps', username, name, 'stop'], callback, function (res, result) {
callback(null, result || res.statusCode);
});
@@ -134,7 +134,7 @@ Apps.prototype.stop = function (name, callback) {
// in the current Nodejitsu environment.
//
Apps.prototype.available = function (app, callback) {
- var username = this.options.username;
+ var username = this.options.get('username');
this.request('POST', ['apps', username, app.name, 'available'], app, callback, function (res, result) {
callback(null, result || res.statusCode);
});
View
13 node.js/lib/client/client.js
@@ -19,6 +19,13 @@ var eyes = require('eyes'),
var Client = exports.Client = function (options) {
this.options = options;
this._request = request;
+
+ if (typeof this.options.get !== 'function') {
+ this.options.get = function (key) {
+ return this[key];
+ }
+ }
+
};
//
@@ -37,12 +44,12 @@ Client.prototype.request = function (method, uri /* variable arguments */) {
success = args.pop(),
callback = args.pop(),
body = typeof args[args.length - 1] === 'object' && !Array.isArray(args[args.length - 1]) && args.pop(),
- encoded = new Buffer(this.options.username + ':' + this.options.password).toString('base64'),
+ encoded = new Buffer(this.options.get('username') + ':' + this.options.get('password')).toString('base64'),
proxy = this.proxy;
options = {
method: method || 'GET',
- uri: this.options.remoteUri + '/' + uri.join('/'),
+ uri: this.options.get('remoteUri') + '/' + uri.join('/'),
headers: {
'Authorization': 'Basic ' + encoded,
'Content-Type': 'application/json'
@@ -112,7 +119,7 @@ Client.prototype.upload = function (uri, contentType, file, callback, success) {
encoded,
proxy = self.options.proxy;
- encoded = new Buffer(this.options.username + ':' + this.options.password).toString('base64');
+ encoded = new Buffer(this.options.get('username') + ':' + this.options.get('password')).toString('base64');
fs.readFile(file, function (err, data) {
options = {
View
8 node.js/lib/client/databases.js
@@ -30,7 +30,7 @@ util.inherits(Databases, Client);
// Provisions a database for the user
//
Databases.prototype.create = function (databaseType, databaseName, callback) {
- this.request('POST', ['databases', this.options.username, databaseName], {type:databaseType}, callback, function (res, result) {
+ this.request('POST', ['databases', this.options.get('username'), databaseName], {type:databaseType}, callback, function (res, result) {
callback(null, result, res);
});
};
@@ -42,7 +42,7 @@ Databases.prototype.create = function (databaseType, databaseName, callback) {
// Gets the metadata for the specified database
//
Databases.prototype.get = function (databaseName, callback) {
- this.request('GET', ['databases', this.options.username, databaseName], callback, function (res, result) {
+ this.request('GET', ['databases', this.options.get('username'), databaseName], callback, function (res, result) {
callback(null, result);
});
};
@@ -53,7 +53,7 @@ Databases.prototype.get = function (databaseName, callback) {
// Gets the list of databases assigned to the user
//
Databases.prototype.list = function (callback) {
- this.request('GET', ['databases', this.options.username], callback, function (res, result) {
+ this.request('GET', ['databases', this.options.get('username')], callback, function (res, result) {
callback(null, result);
});
};
@@ -65,7 +65,7 @@ Databases.prototype.list = function (callback) {
// Deprovisions specified database
//
Databases.prototype.destroy = function (databaseName, callback) {
- this.request('DELETE', ['databases', this.options.username, databaseName], callback, function (res, result) {
+ this.request('DELETE', ['databases', this.options.get('username'), databaseName], callback, function (res, result) {
callback(null, result);
});
}
View
4 node.js/lib/client/logs.js
@@ -36,7 +36,7 @@ Logs.prototype.byApp = function (appId, amount, callback) {
rows: amount
};
- this.request('POST', ['logs', this.options.username , appId], options, callback, function (res, result) {
+ this.request('POST', ['logs', this.options.get('username') , appId], options, callback, function (res, result) {
callback(null, result);
});
};
@@ -54,7 +54,7 @@ Logs.prototype.byUser = function (amount, callback) {
rows: amount
};
- this.request('POST', ['logs', this.options.username], options, callback, function (res, result) {
+ this.request('POST', ['logs', this.options.get('username')], options, callback, function (res, result) {
callback(null, result);
});
};
View
8 node.js/lib/client/snapshots.js
@@ -31,7 +31,7 @@ util.inherits(Snapshots, Client);
//
Snapshots.prototype.list = function (name, callback) {
winston.info('Listing snapshots for ' + name.magenta);
- var username = this.options.username;
+ var username = this.options.get('username');
this.request('GET', ['apps', username, name, 'snapshots'], callback, function (res, result) {
callback(null, result.snapshots);
});
@@ -46,7 +46,7 @@ Snapshots.prototype.list = function (name, callback) {
// the `*.tgz` package data in `snapshot`.
//
Snapshots.prototype.create = function (appName, snapshotName, filename, callback) {
- var username = this.options.username;
+ var username = this.options.get('username');
var url = ['apps', username, appName, 'snapshots', snapshotName];
var that = this;
@@ -74,7 +74,7 @@ Snapshots.prototype.create = function (appName, snapshotName, filename, callback
// `snapshot.id === snapshotName`.
//
Snapshots.prototype.destroy = function (appName, snapshotName, callback) {
- var username = this.options.username,
+ var username = this.options.get('username'),
url = ['apps', username, appName, 'snapshots', snapshotName];
this.request('DELETE', url, callback, function (res, body) {
@@ -91,7 +91,7 @@ Snapshots.prototype.destroy = function (appName, snapshotName, callback) {
// `snapshot.id === snapshotName`.
//
Snapshots.prototype.activate = function (appName, snapshotName, callback) {
- var username = this.options.username,
+ var username = this.options.get('username'),
url = ['apps', username, appName, 'snapshots', snapshotName, 'activate'];
this.request('POST', url, callback, function (res, body) {
Please sign in to comment.
Something went wrong with that request. Please try again.