Skip to content

Commit

Permalink
[minor] Some cleanup of code
Browse files Browse the repository at this point in the history
  • Loading branch information
pksunkara committed Aug 9, 2012
1 parent a5f08d2 commit acaa22f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 24 deletions.
4 changes: 2 additions & 2 deletions node.js/examples/create-a-database.js
Expand Up @@ -4,11 +4,11 @@ var nj = require('../lib/client'),
var client = nj.createClient({
username: 'marak',
password: 'foofoo',
remoteUri: 'http://api.nodejitsu.com'
remoteUri: 'https://api.nodejitsu.com'
});


client.databases.create('marak', 'new-database-55558', { type: 'couch' }, function(err, result){
client.databases.create('new-database-55558', 'couch', function(err, result){
if (err) {
console.log(err);
return;
Expand Down
2 changes: 1 addition & 1 deletion node.js/examples/get-a-database.js
Expand Up @@ -8,7 +8,7 @@ var client = nj.createClient({
});


client.databases.get('marak/new-database-55558', function(err, result){
client.databases.get('new-database-55558', function(err, result){
if (err) {
console.log(err);
return;
Expand Down
5 changes: 1 addition & 4 deletions node.js/lib/client/addons/index.js
Expand Up @@ -10,17 +10,14 @@ var util = require('util'),
defaultUser = require('../helpers').defaultUser;

var Addons = exports.Addons = function (options) {

this.router = JSON.parse(fs.readFileSync(__dirname + '/router.json').toString());
this.client = dr.createClient(this.router);
console.log(this.router)
console.log(this.client)
Client.call(this, options);
};

// Inherit from Client base object
util.inherits(Addons, Client);

Addons.prototype.list = function (username, callback) {
console.log('sup')
callback();
};
8 changes: 4 additions & 4 deletions node.js/lib/client/client.js
Expand Up @@ -19,9 +19,9 @@ var fs = require('fs'),
// for communicating with Nodejitsu's API
//
var Client = exports.Client = function (options) {

var self = this;

self.options = options;
self._request = request;

Expand All @@ -36,9 +36,9 @@ var Client = exports.Client = function (options) {
//
self.addons = {}
self.addons.router = JSON.parse(fs.readFileSync(__dirname + '/addons/router.json').toString());
self.addons.client = dr.createClient(self.addons.router, {
self.addons.client = dr.createClient(self.addons.router, {
port: 80,
host: "addons.mockjitsu.com",
host: "addons.nodejitsu.com",
username: self.options.get('username'),
password: self.options.get('password')
});
Expand Down
23 changes: 10 additions & 13 deletions node.js/lib/client/databases.js
Expand Up @@ -29,14 +29,11 @@ util.inherits(Databases, Client);
// #### @callback {function} Continuation to pass control to when complete
// Provisions a database for the user
//


Databases.prototype.create = function (/* user, database, attrs, callback */) {
var args = utile.args(arguments);

console.log('warg', args)
var self = this;
self.addons.client.users.databases.create(user, database, { type: attrs.type, name: database }, function(err, res, body){
Databases.prototype.create = function (databaseType, databaseName, callback) {
this.addons.client.users.databases.create(this.options.get('username'), {
type: databaseType,
name: databaseName
}, function(err, res, body){
callback(err, body);
});
};
Expand All @@ -47,8 +44,8 @@ Databases.prototype.create = function (/* user, database, attrs, callback */) {
// #### @callback {function} Continuation to pass control to when complete
// Gets the metadata for the specified database
//
Databases.prototype.get = function (user, database, callback) {
self.addons.client.users.databases.get(user, database, function(err, res, body){
Databases.prototype.get = function (databaseName, callback) {
this.addons.client.users.databases.get(this.options.get('username'), databaseName, function(err, res, body){
callback(err, body);
});
};
Expand All @@ -59,7 +56,7 @@ Databases.prototype.get = function (user, database, callback) {
// Gets the list of databases assigned to the user
//
Databases.prototype.list = function (callback) {
self.addons.client.users.databases(user, function(err, res, body){
this.addons.client.users.databases(this.options.get('username'), function(err, res, body){
callback(err, body);
});
};
Expand All @@ -70,8 +67,8 @@ Databases.prototype.list = function (callback) {
// #### @callback {function} Continuation to pass control to when complete
// Deprovisions specified database
//
Databases.prototype.destroy = function (user, database, callback) {
self.addons.client.users.databases.destroy(user, database, function(err, res, body){
Databases.prototype.destroy = function (databaseName, callback) {
this.addons.client.users.databases.destroy(this.options.get('username'), databaseName, function(err, res, body){
callback(err, body);
});
};

1 comment on commit acaa22f

@Marak
Copy link
Contributor

@Marak Marak commented on acaa22f Aug 13, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pksunkara - You un-did the previous de-coupling of user to database in this commit.

The client api should provide access to modify databases that are not owned by the current user returned by this.options.get('username').

I can understand the confusion, since in the jitsu cli, we have this action bound more towards the locally configured user.

Can you please change this back and finish up the tests? Aside from that, I think we've got everything we need.

Please sign in to comment.