Skip to content

Commit

Permalink
[minor] Return the apiTokens to the full result.
Browse files Browse the repository at this point in the history
[minor] CodeStyle fixes
[doc] Readme indentation
  • Loading branch information
3rd-Eden committed Feb 14, 2013
1 parent 150b99f commit 5ff3a4e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
16 changes: 8 additions & 8 deletions node.js/README.md
Expand Up @@ -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
Expand Down
22 changes: 13 additions & 9 deletions node.js/lib/client/tokens.js
Expand Up @@ -8,8 +8,7 @@
*/

var util = require('util'),
Client = require('./client').Client,
defaultUser = require('./helpers').defaultUser;
Client = require('./client').Client;

//
// ### function Tokens (options)
Expand All @@ -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');
Expand Down

0 comments on commit 5ff3a4e

Please sign in to comment.