Permalink
Browse files

[minor] Return the `apiTokens` to the full result.

[minor] CodeStyle fixes
[doc] Readme indentation
  • Loading branch information...
1 parent 150b99f commit 5ff3a4eed5876cdf28570daa8d9fa766bfb26682 @3rd-Eden 3rd-Eden committed Feb 14, 2013
Showing with 21 additions and 17 deletions.
  1. +8 −8 node.js/README.md
  2. +13 −9 node.js/lib/client/tokens.js
View
16 node.js/README.md
@@ -96,14 +96,14 @@ The following API resources are exposes in the module:
- [snapshots.destroy][snapshots.destroy]
- [snapshots.activate][snapshots.activate]
- [users][users] Manage your Nodejitsu account.
-- [users.auth][users.auth]
-- [users.create][users.create]
-- [users.available][users.available]
-- [users.view][users.view]
-- [users.confirm][users.confirm]
-- [users.forgot][users.forgot]
-- [users.update][users.update]
-- [users.destroy][users.destroy]
+ - [users.auth][users.auth]
+ - [users.create][users.create]
+ - [users.available][users.available]
+ - [users.view][users.view]
+ - [users.confirm][users.confirm]
+ - [users.forgot][users.forgot]
+ - [users.update][users.update]
+ - [users.destroy][users.destroy]
[apps]: #clientapps
[apps.available]: #clientappsavailable
View
22 node.js/lib/client/tokens.js
@@ -8,8 +8,7 @@
*/
var util = require('util'),
- Client = require('./client').Client,
- defaultUser = require('./helpers').defaultUser;
+ Client = require('./client').Client;
//
// ### function Tokens (options)
@@ -35,44 +34,49 @@ Tokens.prototype.list = function (username, callback) {
username = this.options.get('username');
}
- this.request({ uri: ['users', username, 'tokens'] }, callback);
+ this.request({ uri: ['users', username, 'tokens'] }, function (err, result) {
+ if (err) return callback(err);
+
+ callback(err, result.apiTokens);
+ });
};
//
// ### function create (username, tokenID, callback)
-// #### @token String Properties for the new token.
+// #### @tokenID String Properties for the new token.
// #### @callback {function} Continuation to pass control to when complete
// Creates a new token with the properties specified by `tokenID` if provided.
//
Tokens.prototype.create = function (username, tokenID, callback) {
- if(arguments.length === 1) {
+ var length = arguments.length;
+
+ if (length === 1) {
callback = username;
tokenID = null;
username = this.options.get('username');
}
- if(arguments.length === 2) {
+ if (length === 2) {
callback = tokenID;
tokenID = username;
username = this.options.get('username');
}
- if(tokenID !== null){
+ if (tokenID !== null) {
this.request({ method: 'PUT', uri: ['users', username, 'tokens', tokenID] }, callback);
} else {
this.request({ method: 'POST', uri: ['users', username, 'tokens'] }, callback);
}
};
-
//
// ### function destroy (token, callback)
// #### @token {Object} Properties for the new token.
// #### @callback {function} Continuation to pass control to when complete
// Destroys a token with the id specified by `token`.
//
Tokens.prototype.destroy = function (username, tokenID, callback) {
- if(arguments.length === 2) {
+ if (arguments.length === 2) {
callback = tokenID;
tokenID = username;
username = this.options.get('username');

0 comments on commit 5ff3a4e

Please sign in to comment.