Skip to content

Commit

Permalink
single field can now be passed as string (i.e. '*' is now the same as…
Browse files Browse the repository at this point in the history
… ['*'])
  • Loading branch information
bhovhannes committed Feb 24, 2015
1 parent d91c2fa commit 68ea1d1
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/plugins/copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = function(Api) {
* @param {String} objCode One of object codes from {@link https://developers.attask.com/api-docs/api-explorer/|Workfront API Explorer}
* @param {String} objID ID of object to copy
* @param {Object} updates Which fields to set on copied object. See {@link https://developers.attask.com/api-docs/api-explorer/|Workfront API Explorer} for the list of available fields for the given objCode.
* @param {Object} [fields] Which fields to return. See {@link https://developers.attask.com/api-docs/api-explorer/|Workfront API Explorer} for the list of available fields for the given objCode.
* @param {String|String[]} [fields] Which fields to return. See {@link https://developers.attask.com/api-docs/api-explorer/|Workfront API Explorer} for the list of available fields for the given objCode.
* @return {Promise} A promise which will resolved with results if everything went ok and rejected otherwise
*/
Api.prototype.copy = function (objCode, objID, updates, fields) {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = function(Api) {
* @memberOf Workfront.Api
* @param {String} objCode One of object codes from {@link https://developers.attask.com/api-docs/api-explorer/|Workfront API Explorer}
* @param {Object} params Values of fields to be set for the new object. See {@link https://developers.attask.com/api-docs/api-explorer/|Workfront API Explorer} for the list of available fields for the given objCode.
* @param {String[]} [fields] Which fields of newly created object to return. See {@link https://developers.attask.com/api-docs/api-explorer/|Workfront API Explorer} for the list of available fields for the given objCode.
* @param {String|String[]} [fields] Which fields of newly created object to return. See {@link https://developers.attask.com/api-docs/api-explorer/|Workfront API Explorer} for the list of available fields for the given objCode.
* @returns {Promise} A promise which will resolved with the ID and any other specified fields of newly created object
*/
Api.prototype.create = function (objCode, params, fields) {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = function(Api) {
* @param {String} objCode One of object codes from {@link https://developers.attask.com/api-docs/api-explorer/|Workfront API Explorer}
* @param {String} objID ID of object to modify
* @param {Object} updates Which fields to set. See {@link https://developers.attask.com/api-docs/api-explorer/|Workfront API Explorer} for the list of available fields for the given objCode.
* @param {Object} [fields] Which fields to return. See {@link https://developers.attask.com/api-docs/api-explorer/|Workfront API Explorer} for the list of available fields for the given objCode.
* @param {String|String[]} [fields] Which fields to return. See {@link https://developers.attask.com/api-docs/api-explorer/|Workfront API Explorer} for the list of available fields for the given objCode.
* @return {Promise} A promise which will resolved with results if everything went ok and rejected otherwise
*/
Api.prototype.edit = function (objCode, objID, updates, fields) {
Expand Down
1 change: 1 addition & 0 deletions src/plugins/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module.exports = function(Api) {
endPoint += '/' + objID + '/' + action;
}
else {
actionArgs = actionArgs || {};
actionArgs['action'] = action;
}
return this.request(endPoint, actionArgs, null, Api.Methods.PUT);
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/namedQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = function(Api) {
* @param {String} objCode One of object codes from {@link https://developers.attask.com/api-docs/api-explorer/|Workfront API Explorer}
* @param {String} query A query to execute. A list of allowed named queries are available within the {@link https://developers.attask.com/api-docs/api-explorer/|Workfront API Explorer} under "actions" for each object.
* @param {Object} [queryArgs] Optional. Arguments for the action. See {@link https://developers.attask.com/api-docs/api-explorer/|Workfront API Explorer} for the list of valid arguments
* @param {Object} fields Which fields to return. See {@link https://developers.attask.com/api-docs/api-explorer/|Workfront API Explorer} for the list of available fields for the given objCode.
* @param {String|String[]} fields Which fields to return. See {@link https://developers.attask.com/api-docs/api-explorer/|Workfront API Explorer} for the list of available fields for the given objCode.
* @returns {Promise} A promise which will resolved with received data if everything went ok and rejected with error info otherwise
*/
Api.prototype.namedQuery = function (objCode, query, queryArgs, fields) {
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ module.exports = function(Api) {
params = params || {};
fields = fields || [];

if (typeof fields === 'string') {
fields = [fields];
}

var options = {};
util._extend(options, this.httpOptions);
options.method = method;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = function(Api) {
* @memberOf Workfront.Api
* @param {String} objCode One of object codes from {@link https://developers.attask.com/api-docs/api-explorer/|Workfront API Explorer}
* @param {Object} query An object with search criteria
* @param {Array} [fields] Which fields to return. See {@link https://developers.attask.com/api-docs/api-explorer/|Workfront API Explorer} for the list of available fields for the given objCode.
* @param {String|String[]} [fields] Which fields to return. See {@link https://developers.attask.com/api-docs/api-explorer/|Workfront API Explorer} for the list of available fields for the given objCode.
* @return {Promise} A promise which will resolved with search results if everything went ok and rejected otherwise
*/
Api.prototype.search = function (objCode, query, fields) {
Expand Down
6 changes: 6 additions & 0 deletions test/plugins/execute.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,10 @@ describe('Api.execute() method', function() {
expect(api.request).to.have.callCount(1);
expect(api.request).to.have.been.calledWith('foo', {objID: 111, action: 'doSomething'}, null, "PUT");
});

it('should call request() with proper params (without args) when objID is omitted', function() {
api.execute('foo', null, 'doSomething');
expect(api.request).to.have.callCount(1);
expect(api.request).to.have.been.calledWith('foo', {action: 'doSomething'}, null, "PUT");
});
});
24 changes: 24 additions & 0 deletions test/plugins/request.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,30 @@ describe('Api.request() method', function() {
});


it('should resolve returned promise with data if everything went ok when fields are specified as string', function(done) {
var url = 'http://foobar:8080',
path = '/test',
params = {
'foo': 1,
'bar': 'baz'
},
fields = '*',
method = 'GET';

nock(url)
.get('/attask/api' + path + '?foo=1&bar=baz&fields=*')
.reply(200, {
data: {
'got': 'ok'
}
});

var api = new Api({url: url});
var promise = api.request(path, params, fields, method);
expect(promise).to.eventually.deep.equal({'got': 'ok'}).and.notify(done);
});


it('should resolve returned promise with data if everything went ok when using POST', function(done) {
var url = 'http://foobar:8080',
path = '/test',
Expand Down

0 comments on commit 68ea1d1

Please sign in to comment.