Skip to content

Commit 937b8ab

Browse files
committed
rebuilt to include latest changes
1 parent 8851707 commit 937b8ab

2 files changed

Lines changed: 122 additions & 27 deletions

File tree

dist/workfront.js

Lines changed: 119 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6851,6 +6851,9 @@ function Api(config) {
68516851
headers: {}
68526852
};
68536853

6854+
// These params will be sent with each request
6855+
this.httpParams = {};
6856+
68546857
if (isHttps) {
68556858
this.httpOptions.secureProtocol = config.secureProtocol || 'TLSv1_method';
68566859
this.httpOptions.agent = false;
@@ -6892,9 +6895,10 @@ require('./plugins/upload')(Api);
68926895
require('./plugins/execute')(Api);
68936896
require('./plugins/namedQuery')(Api);
68946897
require('./plugins/metadata')(Api);
6898+
require('./plugins/apiKey')(Api);
68956899

68966900
module.exports = Api;
6897-
},{"./plugins/copy":40,"./plugins/count":41,"./plugins/create":42,"./plugins/edit":43,"./plugins/execute":44,"./plugins/get":45,"./plugins/login":46,"./plugins/logout":47,"./plugins/metadata":48,"./plugins/namedQuery":49,"./plugins/remove":50,"./plugins/report":51,"./plugins/request":52,"./plugins/search":53,"./plugins/upload":54,"http":8,"https":12,"url":33}],37:[function(require,module,exports){
6901+
},{"./plugins/apiKey":40,"./plugins/copy":41,"./plugins/count":42,"./plugins/create":43,"./plugins/edit":44,"./plugins/execute":45,"./plugins/get":46,"./plugins/login":47,"./plugins/logout":48,"./plugins/metadata":49,"./plugins/namedQuery":50,"./plugins/remove":51,"./plugins/report":52,"./plugins/request":53,"./plugins/search":54,"./plugins/upload":55,"http":8,"https":12,"url":33}],37:[function(require,module,exports){
68986902
/**
68996903
* Copyright 2015 Workfront
69006904
*
@@ -7000,6 +7004,13 @@ var ApiConstants = {
70007004
*/
70017005
ROLLUP: "$$ROLLUP",
70027006

7007+
/**
7008+
* Prefix for constants.
7009+
* @readonly
7010+
* @type {String}
7011+
*/
7012+
INTERNAL_PREFIX: '$$',
7013+
70037014
/**
70047015
* Values which can be used as wildcards
70057016
* @readonly
@@ -7530,6 +7541,73 @@ module.exports = {
75307541
* limitations under the License.
75317542
*/
75327543

7544+
/**
7545+
* @author Hovhannes Babayan <bhovhannes at gmail dot com>
7546+
*/
7547+
module.exports = function(Api) {
7548+
7549+
/**
7550+
* Used to obtain an API key
7551+
* @memberOf Workfront.Api
7552+
* @param {String} username A username in Workfront
7553+
* @param {String} password Password to use
7554+
* @return {Promise} A promise which will resolved with API key if everything went ok and rejected otherwise
7555+
*/
7556+
Api.prototype.getApiKey = function (username, password) {
7557+
var that = this;
7558+
return new Promise(function (resolve, reject) {
7559+
if (typeof that.httpParams.apiKey !== 'undefined') {
7560+
resolve(that.httpParams.apiKey);
7561+
}
7562+
else {
7563+
that.execute('USER', null, 'getApiKey', {
7564+
username: username,
7565+
password: password
7566+
}).then(function (data) {
7567+
that.httpParams.apiKey = data.result;
7568+
resolve(that.httpParams.apiKey);
7569+
}, reject);
7570+
}
7571+
});
7572+
};
7573+
7574+
/**
7575+
* Invalidates the current API key.
7576+
* Call this to be able to retrieve a new one using getApiKey().
7577+
* @memberOf Workfront.Api
7578+
* @return {Promise} A promise which will resolved if everything went ok and rejected otherwise
7579+
*/
7580+
Api.prototype.clearApiKey = function () {
7581+
var that = this;
7582+
return new Promise(function (resolve, reject) {
7583+
that.execute('USER', null, 'clearApiKey').then(function (result) {
7584+
if (result) {
7585+
delete that.httpParams.apiKey;
7586+
resolve();
7587+
} else {
7588+
reject();
7589+
}
7590+
});
7591+
});
7592+
}
7593+
};
7594+
},{}],41:[function(require,module,exports){
7595+
/**
7596+
* Copyright 2015 Workfront
7597+
*
7598+
* Licensed under the Apache License, Version 2.0 (the "License");
7599+
* you may not use this file except in compliance with the License.
7600+
* You may obtain a copy of the License at
7601+
*
7602+
* http://www.apache.org/licenses/LICENSE-2.0
7603+
*
7604+
* Unless required by applicable law or agreed to in writing, software
7605+
* distributed under the License is distributed on an "AS IS" BASIS,
7606+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7607+
* See the License for the specific language governing permissions and
7608+
* limitations under the License.
7609+
*/
7610+
75337611
/**
75347612
* @author Hovhannes Babayan <bhovhannes at gmail dot com>
75357613
*/
@@ -7541,7 +7619,7 @@ module.exports = function(Api) {
75417619
* @param {String} objCode One of object codes from {@link https://developers.attask.com/api-docs/api-explorer/|Workfront API Explorer}
75427620
* @param {String} objID ID of object to copy
75437621
* @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.
7544-
* @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.
7622+
* @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.
75457623
* @return {Promise} A promise which will resolved with results if everything went ok and rejected otherwise
75467624
*/
75477625
Api.prototype.copy = function (objCode, objID, updates, fields) {
@@ -7554,7 +7632,7 @@ module.exports = function(Api) {
75547632
return this.request(objCode, params, fields, Api.Methods.POST);
75557633
};
75567634
};
7557-
},{}],41:[function(require,module,exports){
7635+
},{}],42:[function(require,module,exports){
75587636
/**
75597637
* Copyright 2015 Workfront
75607638
*
@@ -7592,7 +7670,7 @@ module.exports = function(Api) {
75927670
});
75937671
};
75947672
};
7595-
},{}],42:[function(require,module,exports){
7673+
},{}],43:[function(require,module,exports){
75967674
/**
75977675
* Copyright 2015 Workfront
75987676
*
@@ -7619,14 +7697,14 @@ module.exports = function(Api) {
76197697
* @memberOf Workfront.Api
76207698
* @param {String} objCode One of object codes from {@link https://developers.attask.com/api-docs/api-explorer/|Workfront API Explorer}
76217699
* @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.
7622-
* @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.
7700+
* @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.
76237701
* @returns {Promise} A promise which will resolved with the ID and any other specified fields of newly created object
76247702
*/
76257703
Api.prototype.create = function (objCode, params, fields) {
76267704
return this.request(objCode, params, fields, Api.Methods.POST);
76277705
};
76287706
};
7629-
},{}],43:[function(require,module,exports){
7707+
},{}],44:[function(require,module,exports){
76307708
/**
76317709
* Copyright 2015 Workfront
76327710
*
@@ -7653,7 +7731,7 @@ module.exports = function(Api) {
76537731
* @param {String} objCode One of object codes from {@link https://developers.attask.com/api-docs/api-explorer/|Workfront API Explorer}
76547732
* @param {String} objID ID of object to modify
76557733
* @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.
7656-
* @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.
7734+
* @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.
76577735
* @return {Promise} A promise which will resolved with results if everything went ok and rejected otherwise
76587736
*/
76597737
Api.prototype.edit = function (objCode, objID, updates, fields) {
@@ -7663,7 +7741,7 @@ module.exports = function(Api) {
76637741
return this.request(objCode + '/' + objID, params, fields, Api.Methods.PUT);
76647742
};
76657743
};
7666-
},{}],44:[function(require,module,exports){
7744+
},{}],45:[function(require,module,exports){
76677745
/**
76687746
* Copyright 2015 Workfront
76697747
*
@@ -7700,12 +7778,13 @@ module.exports = function(Api) {
77007778
endPoint += '/' + objID + '/' + action;
77017779
}
77027780
else {
7781+
actionArgs = actionArgs || {};
77037782
actionArgs['action'] = action;
77047783
}
77057784
return this.request(endPoint, actionArgs, null, Api.Methods.PUT);
77067785
};
77077786
};
7708-
},{}],45:[function(require,module,exports){
7787+
},{}],46:[function(require,module,exports){
77097788
/**
77107789
* Copyright 2015 Workfront
77117790
*
@@ -7726,27 +7805,38 @@ module.exports = function(Api) {
77267805
* @author Hovhannes Babayan <bhovhannes at gmail dot com>
77277806
* @author Sassoun Derderian <citizen.sas at gmail dot com>
77287807
*/
7808+
7809+
var ApiConstants = require('./../ApiConstants');
7810+
77297811
module.exports = function(Api) {
77307812
/**
77317813
* Used for retrieve an object or multiple objects.
77327814
* @memberOf Workfront.Api
77337815
* @param {String} objCode One of object codes from {@link https://developers.attask.com/api-docs/api-explorer/|Workfront API Explorer}
77347816
* @param {String|Array} objIDs Either one or multiple object ids
7735-
* @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.
7817+
* @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.
77367818
* @return {Promise} A promise which will resolved with results if everything went ok and rejected otherwise
77377819
*/
77387820
Api.prototype.get = function (objCode, objIDs, fields) {
77397821
if (typeof objIDs === 'string') {
77407822
objIDs = [objIDs];
77417823
}
7824+
var endPoint = objCode,
7825+
params = null;
77427826
if (objIDs.length === 1) {
7743-
return this.request(objCode + '/' + objIDs[0], null, fields, Api.Methods.GET);
7827+
if (objIDs[0].indexOf(ApiConstants.INTERNAL_PREFIX) === 0) {
7828+
params = {id: objIDs[0]};
7829+
}
7830+
else {
7831+
endPoint += '/' + objIDs[0];
7832+
}
77447833
} else {
7745-
return this.request(objCode, {id: objIDs}, fields, Api.Methods.GET);
7834+
params = {id: objIDs};
77467835
}
7836+
return this.request(endPoint, params, fields, Api.Methods.GET);
77477837
};
77487838
};
7749-
},{}],46:[function(require,module,exports){
7839+
},{"./../ApiConstants":37}],47:[function(require,module,exports){
77507840
/**
77517841
* Copyright 2015 Workfront
77527842
*
@@ -7787,7 +7877,7 @@ module.exports = function(Api) {
77877877
});
77887878
};
77897879
};
7790-
},{}],47:[function(require,module,exports){
7880+
},{}],48:[function(require,module,exports){
77917881
/**
77927882
* Copyright 2015 Workfront
77937883
*
@@ -7828,7 +7918,7 @@ module.exports = function(Api) {
78287918
});
78297919
};
78307920
};
7831-
},{}],48:[function(require,module,exports){
7921+
},{}],49:[function(require,module,exports){
78327922
/**
78337923
* Copyright 2015 Workfront
78347924
*
@@ -7863,7 +7953,7 @@ module.exports = function(Api) {
78637953
return this.request(path, null, null, Api.Methods.GET);
78647954
};
78657955
};
7866-
},{}],49:[function(require,module,exports){
7956+
},{}],50:[function(require,module,exports){
78677957
/**
78687958
* Copyright 2015 Workfront
78697959
*
@@ -7891,14 +7981,14 @@ module.exports = function(Api) {
78917981
* @param {String} objCode One of object codes from {@link https://developers.attask.com/api-docs/api-explorer/|Workfront API Explorer}
78927982
* @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.
78937983
* @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
7894-
* @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.
7984+
* @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.
78957985
* @returns {Promise} A promise which will resolved with received data if everything went ok and rejected with error info otherwise
78967986
*/
78977987
Api.prototype.namedQuery = function (objCode, query, queryArgs, fields) {
78987988
return this.request(objCode + '/' + query, queryArgs, fields, Api.Methods.GET);
78997989
};
79007990
};
7901-
},{}],50:[function(require,module,exports){
7991+
},{}],51:[function(require,module,exports){
79027992
/**
79037993
* Copyright 2015 Workfront
79047994
*
@@ -7942,7 +8032,7 @@ module.exports = function(Api) {
79428032
});
79438033
};
79448034
};
7945-
},{}],51:[function(require,module,exports){
8035+
},{}],52:[function(require,module,exports){
79468036
/**
79478037
* Copyright 2015 Workfront
79488038
*
@@ -7974,7 +8064,7 @@ module.exports = function(Api) {
79748064
return this.request(objCode + '/report', query, null, Api.Methods.GET);
79758065
};
79768066
};
7977-
},{}],52:[function(require,module,exports){
8067+
},{}],53:[function(require,module,exports){
79788068
/**
79798069
* Copyright 2015 Workfront
79808070
*
@@ -8005,8 +8095,13 @@ module.exports = function(Api) {
80058095
};
80068096

80078097
Api.prototype.request = function(path, params, fields, method) {
8008-
params = params || {};
80098098
fields = fields || [];
8099+
if (typeof fields === 'string') {
8100+
fields = [fields];
8101+
}
8102+
8103+
params = params || {};
8104+
util._extend(params, this.httpParams);
80108105

80118106
var options = {};
80128107
util._extend(options, this.httpOptions);
@@ -8070,7 +8165,7 @@ module.exports = function(Api) {
80708165
};
80718166

80728167

8073-
},{"querystring":19,"util":35}],53:[function(require,module,exports){
8168+
},{"querystring":19,"util":35}],54:[function(require,module,exports){
80748169
/**
80758170
* Copyright 2015 Workfront
80768171
*
@@ -8097,14 +8192,14 @@ module.exports = function(Api) {
80978192
* @memberOf Workfront.Api
80988193
* @param {String} objCode One of object codes from {@link https://developers.attask.com/api-docs/api-explorer/|Workfront API Explorer}
80998194
* @param {Object} query An object with search criteria
8100-
* @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.
8195+
* @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.
81018196
* @return {Promise} A promise which will resolved with search results if everything went ok and rejected otherwise
81028197
*/
81038198
Api.prototype.search = function (objCode, query, fields) {
81048199
return this.request(objCode + '/search', query, fields, Api.Methods.GET);
81058200
};
81068201
};
8107-
},{}],54:[function(require,module,exports){
8202+
},{}],55:[function(require,module,exports){
81088203
/**
81098204
* Copyright 2015 Workfront
81108205
*

0 commit comments

Comments
 (0)