Permalink
Browse files

[api] App and Log commands now support fully qualified application id…

…s. Added more examples.
  • Loading branch information...
1 parent 1ef85ff commit 6d75d0a7825a593e312f5deb503efdc2e81da01d @Marak Marak committed Nov 18, 2011
@@ -8,7 +8,7 @@ var client = nj.createClient({
});
-client.apps.view('hellonode', function(err, result){
+client.apps.view('marak/hellonode', function(err, result){
if (err) {
console.log(err);
return;
@@ -0,0 +1,16 @@
+var nj = require('../lib/client');
+
+var client = nj.createClient({
+ username: 'marak',
+ password: 'foo',
+ remoteUri: 'http://api.nodejitsu.com'
+ });
+
+client.logs.byApp('marak/hellonode', 100, function(err, result){
+ if (err) {
+ console.log(err);
+ return;
+ }
+ console.log(JSON.stringify(result, null, 2, true));
+});
+
@@ -0,0 +1,16 @@
+var nj = require('../lib/client');
+
+var client = nj.createClient({
+ username: 'marak',
+ password: 'foo',
+ remoteUri: 'http://api.nodejitsu.com'
+ });
+
+client.logs.byUser('marak', 100, function(err, result){
+ if (err) {
+ console.log(err);
+ return;
+ }
+ console.log(JSON.stringify(result, null, 2, true));
+});
+
@@ -7,7 +7,7 @@ var client = nj.createClient({
remoteUri: 'http://api.nodejitsu.com'
});
-client.apps.list(function(err, result){
+client.apps.list('marak', function(err, result){
if (err) {
console.log(err);
return;
@@ -0,0 +1,16 @@
+var nj = require('../lib/client');
+
+var client = nj.createClient({
+ username: 'marak',
+ password: 'foobar',
+ remoteUri: 'http://api.nodejitsu.com'
+ });
+
+client.apps.restart('marak/hellonode', function(err, result){
+ if (err) {
+ console.log(err);
+ return;
+ }
+ console.log(JSON.stringify(result, null, 2, true));
+});
+
@@ -1,13 +1,12 @@
-var nj = require('../lib/client'),
- fs = require('fs');
+var nj = require('../lib/client');
var client = nj.createClient({
username: 'marak',
password: 'foobar',
remoteUri: 'http://api.nodejitsu.com'
});
-client.apps.start('hellonode', function(err, result){
+client.apps.start('marak/hellonode', function(err, result){
if (err) {
console.log(err);
return;
@@ -1,13 +1,12 @@
-var nj = require('../lib/client'),
- fs = require('fs');
+var nj = require('../lib/client');
var client = nj.createClient({
username: 'marak',
password: 'foobar',
remoteUri: 'http://api.nodejitsu.com'
});
-client.apps.stop('hellonode', function(err, result){
+client.apps.stop('marak/hellonode', function(err, result){
if (err) {
console.log(err);
return;
View
@@ -27,8 +27,7 @@ util.inherits(Apps, Client);
// #### @callback {function} Continuation to pass control to when complete
// Lists all applications for the authenticated user
//
-Apps.prototype.list = function (callback) {
- var username = this.options.get('username');
+Apps.prototype.list = function (username, callback) {
this.request('GET', ['apps', username], callback, function (res, result) {
callback(null, result.apps || res.statusCode);
})
@@ -54,8 +53,7 @@ Apps.prototype.create = function (app, callback) {
// Views the application specified by `name`.
//
Apps.prototype.view = function (name, callback) {
- var username = this.options.get('username');
- this.request('GET', ['apps', username, name], callback, function (res, result) {
+ this.request('GET', ['apps', name], callback, function (res, result) {
callback(null, result.app || res.statusCode);
})
};
@@ -68,8 +66,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.get('username');
- this.request('PUT', ['apps', username, name], attrs, callback, function (res, result) {
+ this.request('PUT', ['apps', name], attrs, callback, function (res, result) {
callback(null, result || res.statusCode);
});
};
@@ -81,8 +78,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.get('username');
- this.request('DELETE', ['apps', username, name], callback, function (res, result) {
+ this.request('DELETE', ['apps', name], callback, function (res, result) {
callback(null, result || res.statusCode);
})
};
@@ -94,8 +90,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.get('username');
- this.request('POST', ['apps', username, name, 'start'], callback, function (res, result) {
+ this.request('POST', ['apps', name, 'start'], callback, function (res, result) {
callback(null, result || res.statusCode);
});
};
@@ -107,8 +102,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.get('username');
- this.request('POST', ['apps', username, name, 'restart'], callback, function (res, result) {
+ this.request('POST', ['apps', name, 'restart'], callback, function (res, result) {
callback(null, result || res.statusCode);
});
};
@@ -120,8 +114,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.get('username');
- this.request('POST', ['apps', username, name, 'stop'], callback, function (res, result) {
+ this.request('POST', ['apps', name, 'stop'], callback, function (res, result) {
callback(null, result || res.statusCode);
});
};
@@ -29,14 +29,14 @@ util.inherits(Logs, Client);
// #### @callback {function} Continuation to pass control to when complete.
// It retrieves the specified amount of logs for the application
//
-Logs.prototype.byApp = function (appId, amount, callback) {
+Logs.prototype.byApp = function (name, amount, callback) {
var options = {
from: 'NOW-1DAY',
until: 'NOW',
rows: amount
};
- this.request('POST', ['logs', this.options.get('username') , appId], options, callback, function (res, result) {
+ this.request('POST', ['logs', name], options, callback, function (res, result) {
callback(null, result);
});
};
@@ -47,14 +47,14 @@ Logs.prototype.byApp = function (appId, amount, callback) {
// #### @callback {function} Continuation to pass control to when complete.
// It retrieves the specified amount of logs for all the applications for the user
//
-Logs.prototype.byUser = function (amount, callback) {
+Logs.prototype.byUser = function (username, amount, callback) {
var options = {
from: 'NOW-1DAY',
until: 'NOW',
rows: amount
};
- this.request('POST', ['logs', this.options.get('username')], options, callback, function (res, result) {
+ this.request('POST', ['logs', username], options, callback, function (res, result) {
callback(null, result);
});
};

0 comments on commit 6d75d0a

Please sign in to comment.