Skip to content
Permalink
Browse files

[api] Now able to work with other user's dbs

  • Loading branch information...
pksunkara committed Aug 13, 2012
1 parent cb991fe commit 04d4ee22437ff940481412b61e6716b5d2b38f12
Showing with 40 additions and 12 deletions.
  1. +40 −12 node.js/lib/client/databases.js
@@ -23,14 +23,22 @@ var Databases = exports.Databases = function (options) {
util.inherits(Databases, Client);

//
// ### function create (databaseType, databaseName, callback)
// ### function create (username, databaseType, databaseName, callback)
// #### @username {string} Username
// #### @databaseType {string} Type of database to create, valid values: redis, couch, mongo
// #### @databaseName {string} Name of the database to create
// #### @callback {function} Continuation to pass control to when complete
// Provisions a database for the user
//
Databases.prototype.create = function (databaseType, databaseName, callback) {
this.addons.client.users.databases.create(this.options.get('username'), {
Databases.prototype.create = function (username, databaseType, databaseName, callback) {
if (arguments.length == 3) {
callback = databaseName;
databaseName = databaseType;
databaseType = username;
username = this.options.get('username');
}

this.addons.client.users.databases.create(username, {
type: databaseType,
name: databaseName
}, function(err, res, body){
@@ -39,36 +47,56 @@ Databases.prototype.create = function (databaseType, databaseName, callback) {
};

//
// ### function get (databaseName, callback)
// ### function get (username, databaseName, callback)
// #### @username {String} Username
// #### @databaseName {string} Name of the database to get
// #### @callback {function} Continuation to pass control to when complete
// Gets the metadata for the specified database
//
Databases.prototype.get = function (databaseName, callback) {
this.addons.client.users.databases.get(this.options.get('username'), databaseName, function(err, res, body){
Databases.prototype.get = function (username, databaseName, callback) {
if (arguments.length == 2) {
callback = databaseName;
databaseName = username;
username = this.options.get('username');
}

this.addons.client.users.databases.get(username, databaseName, function(err, res, body){
callback(err, body);
});
};

//
// ### function list (callback)
// ### function list (username, callback)
// #### @username {String} Username
// #### @callback {function} Continuation to pass control to when complete
// Gets the list of databases assigned to the user
//
Databases.prototype.list = function (callback) {
this.addons.client.users.databases(this.options.get('username'), function(err, res, body){
Databases.prototype.list = function (username, callback) {
if (arguments.length == 1) {
callback = username;
username = this.options.get('username');
}

this.addons.client.users.databases(username, function(err, res, body){
callback(err, body);
});
};

//
// ### function destroy (databaseName, callback)
// ### function destroy (username, databaseName, callback)
// #### @username {String} Username
// #### @databaseName {string} Name of the database to delete
// #### @callback {function} Continuation to pass control to when complete
// Deprovisions specified database
//
Databases.prototype.destroy = function (databaseName, callback) {
this.addons.client.users.databases.destroy(this.options.get('username'), databaseName, function(err, res, body){
Databases.prototype.destroy = function (username, databaseName, callback) {
if (arguments.length == 2) {
callback = databaseName;
databaseName = username;
username = this.options.get('username');
}

this.addons.client.users.databases.destroy(username, databaseName, function(err, res, body){
callback(err, body);
});
};

1 comment on commit 04d4ee2

@Marak

This comment has been minimized.

Copy link
Contributor

commented on 04d4ee2 Aug 13, 2012

You should be using utile.args instead of custom argument parsing. https://github.com/flatiron/utile/blob/master/lib/args.js

Checking length of arguments with non-strict equals is not the best idea.

Please sign in to comment.
You can’t perform that action at this time.