Skip to content

Commit

Permalink
fix #73: getApiKey method not working
Browse files Browse the repository at this point in the history
  • Loading branch information
Sassoun Derderian committed May 31, 2017
1 parent c9e2db0 commit 5539236
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion examples/node/get-user-details-using-api-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var util = require('util');

var instance = new Workfront.Api({
url: 'http://localhost:8080',
version: '4.0'
version: '5.0'
});


Expand Down
14 changes: 8 additions & 6 deletions src/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class Api {
}

_httpOptions: IHttpOptions
_httpParams: THttpParams
_httpParams: THttpParams = {}

constructor(config) {
this._httpOptions = {
Expand Down Expand Up @@ -88,7 +88,9 @@ export class Api {
resolve(this._httpParams.apiKey)
}
else {
this.execute('USER', null, 'getApiKey', {
this.request('USER', {
method: Api.Methods.PUT,
action: 'getApiKey',
username: username,
password: password
}).then((data) => {
Expand Down Expand Up @@ -143,7 +145,7 @@ export class Api {
*/
clearApiKey() {
return new Promise((resolve, reject) => {
this.execute('USER', null, 'clearApiKey').then(function(result) {
this.execute('USER', null, 'clearApiKey').then((result) => {
if (result) {
delete this._httpParams.apiKey
resolve()
Expand Down Expand Up @@ -188,13 +190,13 @@ export class Api {
* @param {Object} [actionArgs] Optional. Arguments for the action. See {@link https://developers.attask.com/api-docs/api-explorer/|Workfront API Explorer} for the list of valid arguments
* @returns {Promise} A promise which will resolved if everything went ok and rejected otherwise
*/
execute(objCode: string, objID: string|null, action: string, actionArgs?: object) {
execute(objCode: string, objID: string | null, action: string, actionArgs?: object) {
let endPoint = objCode
if (objID) {
endPoint += '/' + objID + '/' + action
}
else {
endPoint += '?method='+ Api.Methods.PUT +'&action=' + action
endPoint += '?method=' + Api.Methods.PUT + '&action=' + action
}
const JSONstringifiedArgs = JSON.stringify(actionArgs)
let params = null
Expand All @@ -214,7 +216,7 @@ export class Api {
* @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
*/
get(objCode: string, objIDs: string|string[], fields?: TFields) {
get(objCode: string, objIDs: string | string[], fields?: TFields) {
if (typeof objIDs === 'string') {
objIDs = [objIDs]
}
Expand Down

0 comments on commit 5539236

Please sign in to comment.