Skip to content

Commit

Permalink
[minor] Upgraded the tokens API to the new internals
Browse files Browse the repository at this point in the history
  • Loading branch information
3rd-Eden committed Feb 11, 2013
1 parent 52847fc commit e443169
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions node.js/lib/client/tokens.js
@@ -1,14 +1,16 @@
'use strict';

/*
* tokens.js: Client for the Nodejitsu Tokens API.
*
* (C) 2013, Nodejitsu Inc.
*
*/

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

//
// ### function Tokens (options)
// #### @options {Object} Options for this instance
Expand All @@ -32,9 +34,8 @@ Tokens.prototype.list = function (username, callback) {
callback = username;
username = this.options.get('username');
}
this.request('GET', ['users', username, 'tokens'], callback, function (res, result) {
callback(null, result);
});

this.request({ uri: ['users', username, 'tokens'] }, callback);
};

//
Expand All @@ -49,20 +50,17 @@ Tokens.prototype.create = function (username, tokenID, callback) {
tokenID = null;
username = this.options.get('username');
}

if(arguments.length === 2) {
callback = tokenID;
tokenID = username;
username = this.options.get('username');
}

if(tokenID !== null){
this.request('PUT', ['users', username, 'tokens', tokenID], callback, function (res, result) {
callback(null, result);
});
this.request({ method: 'PUT', uri: ['users', username, 'tokens', tokenID] }, callback);
} else {
this.request('POST', ['users', username, 'tokens'], callback, function (res, result) {
callback(null, result);
});
this.request({ method: 'POST', uri: ['users', username, 'tokens'] }, callback);
}
};

Expand All @@ -79,9 +77,6 @@ Tokens.prototype.destroy = function (username, tokenID, callback) {
tokenID = username;
username = this.options.get('username');
}
this.request('DELETE', ['users', username, 'tokens', tokenID], callback, function (res, result) {
callback(null, result);
});
};


this.request({ method: 'DELETE', uri: ['users', username, 'tokens', tokenID] }, callback);
};

0 comments on commit e443169

Please sign in to comment.