Skip to content

Commit

Permalink
[fix] Various fixes to apps & snapshots methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
AvianFlu committed Oct 19, 2011
1 parent 24dba3a commit 9cea327
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
18 changes: 9 additions & 9 deletions node.js/lib/client/apps.js
Expand Up @@ -30,7 +30,7 @@ util.inherits(Apps, Client);
Apps.prototype.list = function (callback) {
var username = this.options.username;
this.request('GET', ['apps', username], callback, function (res, result) {
callback(null, result.apps);
callback(null, result.apps || res.statusCode);
})
};

Expand All @@ -43,7 +43,7 @@ Apps.prototype.list = function (callback) {
Apps.prototype.create = function (app, callback) {
var username = this.options.username;
this.request('POST', ['apps', username, app.name], app, callback, function (res, result) {
callback();
callback(null, result || res.statusCode);
})
};

Expand All @@ -56,7 +56,7 @@ Apps.prototype.create = function (app, callback) {
Apps.prototype.view = function (name, callback) {
var username = this.options.username;
this.request('GET', ['apps', username, name], callback, function (res, result) {
callback(null, result.app);
callback(null, result.app || res.statusCode);
})
};

Expand All @@ -70,7 +70,7 @@ Apps.prototype.view = function (name, callback) {
Apps.prototype.update = function (name, attrs, callback) {
var username = this.options.username;
this.request('PUT', ['apps', username, name], attrs, callback, function (res, result) {
callback();
callback(null, result || res.statusCode);
});
};

Expand All @@ -83,7 +83,7 @@ Apps.prototype.update = function (name, attrs, callback) {
Apps.prototype.destroy = function (name, callback) {
var username = this.options.username;
this.request('DELETE', ['apps', username, name], callback, function (res, result) {
callback();
callback(null, result || res.statusCode);
})
};

Expand All @@ -96,7 +96,7 @@ Apps.prototype.destroy = function (name, callback) {
Apps.prototype.start = function (name, callback) {
var username = this.options.username;
this.request('POST', ['apps', username, name, 'start'], callback, function (res, result) {
callback();
callback(null, result || res.statusCode);
});
};

Expand All @@ -109,7 +109,7 @@ Apps.prototype.start = function (name, callback) {
Apps.prototype.restart = function (name, callback) {
var username = this.options.username;
this.request('POST', ['apps', username, name, 'restart'], callback, function (res, result) {
callback();
callback(null, result || res.statusCode);
});
};

Expand All @@ -122,7 +122,7 @@ Apps.prototype.restart = function (name, callback) {
Apps.prototype.stop = function (name, callback) {
var username = this.options.username;
this.request('POST', ['apps', username, name, 'stop'], callback, function (res, result) {
callback();
callback(null, result || res.statusCode);
});
};

Expand All @@ -136,6 +136,6 @@ Apps.prototype.stop = function (name, callback) {
Apps.prototype.available = function (app, callback) {
var username = this.options.username;
this.request('POST', ['apps', username, app.name, 'available'], app, callback, function (res, result) {
callback(null, result);
callback(null, result || res.statusCode);
});
};
10 changes: 5 additions & 5 deletions node.js/lib/client/snapshots.js
Expand Up @@ -61,7 +61,7 @@ Snapshots.prototype.create = function (appName, snapshotName, filename, callback
}

that.upload(url, 'application/octet-stream', filename, callback, function (res, body) {
callback(null);
callback(null, body || res.statusCode);
});
});
};
Expand All @@ -74,11 +74,11 @@ Snapshots.prototype.create = function (appName, snapshotName, filename, callback
// `snapshot.id === snapshotName`.
//
Snapshots.prototype.destroy = function (appName, snapshotName, callback) {
var username = jitsu.config.get('username'),
var username = this.options.username,
url = ['apps', username, appName, 'snapshots', snapshotName];

this.request('DELETE', url, callback, function (res, body) {
callback();
callback(null, body || res.statusCode);
});
};

Expand All @@ -91,10 +91,10 @@ Snapshots.prototype.destroy = function (appName, snapshotName, callback) {
// `snapshot.id === snapshotName`.
//
Snapshots.prototype.activate = function (appName, snapshotName, callback) {
var username = jitsu.config.get('username'),
var username = this.options.username,
url = ['apps', username, appName, 'snapshots', snapshotName, 'activate'];

this.request('POST', url, callback, function (res, body) {
callback();
callback(null, body || res.statusCode);
});
};

1 comment on commit 9cea327

@3rd-Eden
Copy link
Member

Choose a reason for hiding this comment

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

The commit message doesn't really provide any useful context for the changes. What was the actual reason that you default the result to res.statusCode? It seems to me that it will break more than fix.. As most of the responses from the API would be an object and if you return a number instead, it will just run in to a cluster fuck.

Please sign in to comment.