microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
lib/app-center-node-client/src/account/operations/apiTokens.js
619lines · modecode
| 1 | /* |
| 2 | * Code generated by Microsoft (R) AutoRest Code Generator. |
| 3 | * Changes may cause incorrect behavior and will be lost if the code is |
| 4 | * regenerated. |
| 5 | */ |
| 6 | |
| 7 | 'use strict'; |
| 8 | |
| 9 | const msRest = require('ms-rest'); |
| 10 | const WebResource = msRest.WebResource; |
| 11 | |
| 12 | /** |
| 13 | * Returns api tokens for the authenticated user |
| 14 | * |
| 15 | * @param {object} [options] Optional Parameters. |
| 16 | * |
| 17 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 18 | * request |
| 19 | * |
| 20 | * @param {function} callback - The callback. |
| 21 | * |
| 22 | * @returns {function} callback(err, result, request, response) |
| 23 | * |
| 24 | * {Error} err - The Error object if an error occurred, null otherwise. |
| 25 | * |
| 26 | * {array} [result] - The deserialized result object if an error did not occur. |
| 27 | * |
| 28 | * {object} [request] - The HTTP Request object if an error did not occur. |
| 29 | * |
| 30 | * {stream} [response] - The HTTP Response stream if an error did not occur. |
| 31 | */ |
| 32 | function _list(options, callback) { |
| 33 | /* jshint validthis: true */ |
| 34 | let client = this.client; |
| 35 | if(!callback && typeof options === 'function') { |
| 36 | callback = options; |
| 37 | options = null; |
| 38 | } |
| 39 | if (!callback) { |
| 40 | throw new Error('callback cannot be null.'); |
| 41 | } |
| 42 | |
| 43 | // Construct URL |
| 44 | let baseUrl = this.client.baseUri; |
| 45 | let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'v0.1/api_tokens'; |
| 46 | |
| 47 | // Create HTTP transport objects |
| 48 | let httpRequest = new WebResource(); |
| 49 | httpRequest.method = 'GET'; |
| 50 | httpRequest.url = requestUrl; |
| 51 | httpRequest.headers = {}; |
| 52 | // Set Headers |
| 53 | httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; |
| 54 | if(options) { |
| 55 | for(let headerName in options['customHeaders']) { |
| 56 | if (options['customHeaders'].hasOwnProperty(headerName)) { |
| 57 | httpRequest.headers[headerName] = options['customHeaders'][headerName]; |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | httpRequest.body = null; |
| 62 | // Send Request |
| 63 | return client.pipeline(httpRequest, (err, response, responseBody) => { |
| 64 | if (err) { |
| 65 | return callback(err); |
| 66 | } |
| 67 | let statusCode = response.statusCode; |
| 68 | if (statusCode !== 200) { |
| 69 | let error = new Error(responseBody); |
| 70 | error.statusCode = response.statusCode; |
| 71 | error.request = msRest.stripRequest(httpRequest); |
| 72 | error.response = msRest.stripResponse(response); |
| 73 | if (responseBody === '') responseBody = null; |
| 74 | let parsedErrorResponse; |
| 75 | try { |
| 76 | parsedErrorResponse = JSON.parse(responseBody); |
| 77 | if (parsedErrorResponse) { |
| 78 | let internalError = null; |
| 79 | if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; |
| 80 | error.code = internalError ? internalError.code : parsedErrorResponse.code; |
| 81 | error.message = internalError ? internalError.message : parsedErrorResponse.message; |
| 82 | } |
| 83 | } catch (defaultError) { |
| 84 | error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + |
| 85 | `- "${responseBody}" for the default response.`; |
| 86 | return callback(error); |
| 87 | } |
| 88 | return callback(error); |
| 89 | } |
| 90 | // Create Result |
| 91 | let result = null; |
| 92 | if (responseBody === '') responseBody = null; |
| 93 | // Deserialize Response |
| 94 | if (statusCode === 200) { |
| 95 | let parsedResponse = null; |
| 96 | try { |
| 97 | parsedResponse = JSON.parse(responseBody); |
| 98 | result = JSON.parse(responseBody); |
| 99 | if (parsedResponse !== null && parsedResponse !== undefined) { |
| 100 | let resultMapper = { |
| 101 | required: false, |
| 102 | serializedName: 'parsedResponse', |
| 103 | type: { |
| 104 | name: 'Sequence', |
| 105 | element: { |
| 106 | required: false, |
| 107 | serializedName: 'ApiTokensGetResponseElementType', |
| 108 | type: { |
| 109 | name: 'Composite', |
| 110 | className: 'ApiTokensGetResponse' |
| 111 | } |
| 112 | } |
| 113 | } |
| 114 | }; |
| 115 | result = client.deserialize(resultMapper, parsedResponse, 'result'); |
| 116 | } |
| 117 | } catch (error) { |
| 118 | let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`); |
| 119 | deserializationError.request = msRest.stripRequest(httpRequest); |
| 120 | deserializationError.response = msRest.stripResponse(response); |
| 121 | return callback(deserializationError); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | return callback(null, result, httpRequest, response); |
| 126 | }); |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Creates a new API token |
| 131 | * |
| 132 | * @param {object} [options] Optional Parameters. |
| 133 | * |
| 134 | * @param {object} [options.description] Description of the token |
| 135 | * |
| 136 | * @param {string} [options.description.description] The description of the |
| 137 | * token |
| 138 | * |
| 139 | * @param {array} [options.description.scope] The scope for this token. |
| 140 | * |
| 141 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 142 | * request |
| 143 | * |
| 144 | * @param {function} callback - The callback. |
| 145 | * |
| 146 | * @returns {function} callback(err, result, request, response) |
| 147 | * |
| 148 | * {Error} err - The Error object if an error occurred, null otherwise. |
| 149 | * |
| 150 | * {object} [result] - The deserialized result object if an error did not occur. |
| 151 | * See {@link ApiTokensCreateResponse} for more |
| 152 | * information. |
| 153 | * |
| 154 | * {object} [request] - The HTTP Request object if an error did not occur. |
| 155 | * |
| 156 | * {stream} [response] - The HTTP Response stream if an error did not occur. |
| 157 | */ |
| 158 | function _newMethod(options, callback) { |
| 159 | /* jshint validthis: true */ |
| 160 | let client = this.client; |
| 161 | if(!callback && typeof options === 'function') { |
| 162 | callback = options; |
| 163 | options = null; |
| 164 | } |
| 165 | if (!callback) { |
| 166 | throw new Error('callback cannot be null.'); |
| 167 | } |
| 168 | let description = (options && options.description !== undefined) ? options.description : undefined; |
| 169 | |
| 170 | // Construct URL |
| 171 | let baseUrl = this.client.baseUri; |
| 172 | let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'v0.1/api_tokens'; |
| 173 | |
| 174 | // Create HTTP transport objects |
| 175 | let httpRequest = new WebResource(); |
| 176 | httpRequest.method = 'POST'; |
| 177 | httpRequest.url = requestUrl; |
| 178 | httpRequest.headers = {}; |
| 179 | // Set Headers |
| 180 | httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; |
| 181 | if(options) { |
| 182 | for(let headerName in options['customHeaders']) { |
| 183 | if (options['customHeaders'].hasOwnProperty(headerName)) { |
| 184 | httpRequest.headers[headerName] = options['customHeaders'][headerName]; |
| 185 | } |
| 186 | } |
| 187 | } |
| 188 | // Serialize Request |
| 189 | let requestContent = null; |
| 190 | let requestModel = null; |
| 191 | try { |
| 192 | if (description !== null && description !== undefined) { |
| 193 | let requestModelMapper = new client.models['ApiTokensCreateRequest']().mapper(); |
| 194 | requestModel = client.serialize(requestModelMapper, description, 'description'); |
| 195 | requestContent = JSON.stringify(requestModel); |
| 196 | } |
| 197 | } catch (error) { |
| 198 | let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` + |
| 199 | `payload - ${JSON.stringify(description, null, 2)}.`); |
| 200 | return callback(serializationError); |
| 201 | } |
| 202 | httpRequest.body = requestContent; |
| 203 | // Send Request |
| 204 | return client.pipeline(httpRequest, (err, response, responseBody) => { |
| 205 | if (err) { |
| 206 | return callback(err); |
| 207 | } |
| 208 | let statusCode = response.statusCode; |
| 209 | if (statusCode !== 201) { |
| 210 | let error = new Error(responseBody); |
| 211 | error.statusCode = response.statusCode; |
| 212 | error.request = msRest.stripRequest(httpRequest); |
| 213 | error.response = msRest.stripResponse(response); |
| 214 | if (responseBody === '') responseBody = null; |
| 215 | let parsedErrorResponse; |
| 216 | try { |
| 217 | parsedErrorResponse = JSON.parse(responseBody); |
| 218 | if (parsedErrorResponse) { |
| 219 | let internalError = null; |
| 220 | if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; |
| 221 | error.code = internalError ? internalError.code : parsedErrorResponse.code; |
| 222 | error.message = internalError ? internalError.message : parsedErrorResponse.message; |
| 223 | } |
| 224 | } catch (defaultError) { |
| 225 | error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + |
| 226 | `- "${responseBody}" for the default response.`; |
| 227 | return callback(error); |
| 228 | } |
| 229 | return callback(error); |
| 230 | } |
| 231 | // Create Result |
| 232 | let result = null; |
| 233 | if (responseBody === '') responseBody = null; |
| 234 | // Deserialize Response |
| 235 | if (statusCode === 201) { |
| 236 | let parsedResponse = null; |
| 237 | try { |
| 238 | parsedResponse = JSON.parse(responseBody); |
| 239 | result = JSON.parse(responseBody); |
| 240 | if (parsedResponse !== null && parsedResponse !== undefined) { |
| 241 | let resultMapper = new client.models['ApiTokensCreateResponse']().mapper(); |
| 242 | result = client.deserialize(resultMapper, parsedResponse, 'result'); |
| 243 | } |
| 244 | } catch (error) { |
| 245 | let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`); |
| 246 | deserializationError.request = msRest.stripRequest(httpRequest); |
| 247 | deserializationError.response = msRest.stripResponse(response); |
| 248 | return callback(deserializationError); |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | return callback(null, result, httpRequest, response); |
| 253 | }); |
| 254 | } |
| 255 | |
| 256 | /** |
| 257 | * Delete the api_token object with the specific id |
| 258 | * |
| 259 | * @param {string} apiTokenId The unique ID (UUID) of the api token |
| 260 | * |
| 261 | * @param {object} [options] Optional Parameters. |
| 262 | * |
| 263 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 264 | * request |
| 265 | * |
| 266 | * @param {function} callback - The callback. |
| 267 | * |
| 268 | * @returns {function} callback(err, result, request, response) |
| 269 | * |
| 270 | * {Error} err - The Error object if an error occurred, null otherwise. |
| 271 | * |
| 272 | * {null} [result] - The deserialized result object if an error did not occur. |
| 273 | * |
| 274 | * {object} [request] - The HTTP Request object if an error did not occur. |
| 275 | * |
| 276 | * {stream} [response] - The HTTP Response stream if an error did not occur. |
| 277 | */ |
| 278 | function _deleteMethod(apiTokenId, options, callback) { |
| 279 | /* jshint validthis: true */ |
| 280 | let client = this.client; |
| 281 | if(!callback && typeof options === 'function') { |
| 282 | callback = options; |
| 283 | options = null; |
| 284 | } |
| 285 | if (!callback) { |
| 286 | throw new Error('callback cannot be null.'); |
| 287 | } |
| 288 | // Validate |
| 289 | try { |
| 290 | if (apiTokenId === null || apiTokenId === undefined || typeof apiTokenId.valueOf() !== 'string') { |
| 291 | throw new Error('apiTokenId cannot be null or undefined and it must be of type string.'); |
| 292 | } |
| 293 | } catch (error) { |
| 294 | return callback(error); |
| 295 | } |
| 296 | |
| 297 | // Construct URL |
| 298 | let baseUrl = this.client.baseUri; |
| 299 | let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'v0.1/api_tokens/{api_token_id}'; |
| 300 | requestUrl = requestUrl.replace('{api_token_id}', encodeURIComponent(apiTokenId)); |
| 301 | |
| 302 | // Create HTTP transport objects |
| 303 | let httpRequest = new WebResource(); |
| 304 | httpRequest.method = 'DELETE'; |
| 305 | httpRequest.url = requestUrl; |
| 306 | httpRequest.headers = {}; |
| 307 | // Set Headers |
| 308 | httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; |
| 309 | if(options) { |
| 310 | for(let headerName in options['customHeaders']) { |
| 311 | if (options['customHeaders'].hasOwnProperty(headerName)) { |
| 312 | httpRequest.headers[headerName] = options['customHeaders'][headerName]; |
| 313 | } |
| 314 | } |
| 315 | } |
| 316 | httpRequest.body = null; |
| 317 | // Send Request |
| 318 | return client.pipeline(httpRequest, (err, response, responseBody) => { |
| 319 | if (err) { |
| 320 | return callback(err); |
| 321 | } |
| 322 | let statusCode = response.statusCode; |
| 323 | if (statusCode < 200 || statusCode >= 300) { |
| 324 | let error = new Error(responseBody); |
| 325 | error.statusCode = response.statusCode; |
| 326 | error.request = msRest.stripRequest(httpRequest); |
| 327 | error.response = msRest.stripResponse(response); |
| 328 | if (responseBody === '') responseBody = null; |
| 329 | let parsedErrorResponse; |
| 330 | try { |
| 331 | parsedErrorResponse = JSON.parse(responseBody); |
| 332 | if (parsedErrorResponse) { |
| 333 | let internalError = null; |
| 334 | if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; |
| 335 | error.code = internalError ? internalError.code : parsedErrorResponse.code; |
| 336 | error.message = internalError ? internalError.message : parsedErrorResponse.message; |
| 337 | } |
| 338 | } catch (defaultError) { |
| 339 | error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + |
| 340 | `- "${responseBody}" for the default response.`; |
| 341 | return callback(error); |
| 342 | } |
| 343 | return callback(error); |
| 344 | } |
| 345 | // Create Result |
| 346 | let result = null; |
| 347 | if (responseBody === '') responseBody = null; |
| 348 | |
| 349 | return callback(null, result, httpRequest, response); |
| 350 | }); |
| 351 | } |
| 352 | |
| 353 | /** Class representing a ApiTokens. */ |
| 354 | class ApiTokens { |
| 355 | /** |
| 356 | * Create a ApiTokens. |
| 357 | * @param {AccountClient} client Reference to the service client. |
| 358 | */ |
| 359 | constructor(client) { |
| 360 | this.client = client; |
| 361 | this._list = _list; |
| 362 | this._newMethod = _newMethod; |
| 363 | this._deleteMethod = _deleteMethod; |
| 364 | } |
| 365 | |
| 366 | /** |
| 367 | * Returns api tokens for the authenticated user |
| 368 | * |
| 369 | * @param {object} [options] Optional Parameters. |
| 370 | * |
| 371 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 372 | * request |
| 373 | * |
| 374 | * @returns {Promise} A promise is returned |
| 375 | * |
| 376 | * @resolve {HttpOperationResponse<Array>} - The deserialized result object. |
| 377 | * |
| 378 | * @reject {Error} - The error object. |
| 379 | */ |
| 380 | listWithHttpOperationResponse(options) { |
| 381 | let client = this.client; |
| 382 | let self = this; |
| 383 | return new Promise((resolve, reject) => { |
| 384 | self._list(options, (err, result, request, response) => { |
| 385 | let httpOperationResponse = new msRest.HttpOperationResponse(request, response); |
| 386 | httpOperationResponse.body = result; |
| 387 | if (err) { reject(err); } |
| 388 | else { resolve(httpOperationResponse); } |
| 389 | return; |
| 390 | }); |
| 391 | }); |
| 392 | } |
| 393 | |
| 394 | /** |
| 395 | * Returns api tokens for the authenticated user |
| 396 | * |
| 397 | * @param {object} [options] Optional Parameters. |
| 398 | * |
| 399 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 400 | * request |
| 401 | * |
| 402 | * @param {function} [optionalCallback] - The optional callback. |
| 403 | * |
| 404 | * @returns {function|Promise} If a callback was passed as the last parameter |
| 405 | * then it returns the callback else returns a Promise. |
| 406 | * |
| 407 | * {Promise} A promise is returned |
| 408 | * |
| 409 | * @resolve {Array} - The deserialized result object. |
| 410 | * |
| 411 | * @reject {Error} - The error object. |
| 412 | * |
| 413 | * {function} optionalCallback(err, result, request, response) |
| 414 | * |
| 415 | * {Error} err - The Error object if an error occurred, null otherwise. |
| 416 | * |
| 417 | * {array} [result] - The deserialized result object if an error did not occur. |
| 418 | * |
| 419 | * {object} [request] - The HTTP Request object if an error did not occur. |
| 420 | * |
| 421 | * {stream} [response] - The HTTP Response stream if an error did not occur. |
| 422 | */ |
| 423 | list(options, optionalCallback) { |
| 424 | let client = this.client; |
| 425 | let self = this; |
| 426 | if (!optionalCallback && typeof options === 'function') { |
| 427 | optionalCallback = options; |
| 428 | options = null; |
| 429 | } |
| 430 | if (!optionalCallback) { |
| 431 | return new Promise((resolve, reject) => { |
| 432 | self._list(options, (err, result, request, response) => { |
| 433 | if (err) { reject(err); } |
| 434 | else { resolve(result); } |
| 435 | return; |
| 436 | }); |
| 437 | }); |
| 438 | } else { |
| 439 | return self._list(options, optionalCallback); |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | /** |
| 444 | * Creates a new API token |
| 445 | * |
| 446 | * @param {object} [options] Optional Parameters. |
| 447 | * |
| 448 | * @param {object} [options.description] Description of the token |
| 449 | * |
| 450 | * @param {string} [options.description.description] The description of the |
| 451 | * token |
| 452 | * |
| 453 | * @param {array} [options.description.scope] The scope for this token. |
| 454 | * |
| 455 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 456 | * request |
| 457 | * |
| 458 | * @returns {Promise} A promise is returned |
| 459 | * |
| 460 | * @resolve {HttpOperationResponse<ApiTokensCreateResponse>} - The deserialized result object. |
| 461 | * |
| 462 | * @reject {Error} - The error object. |
| 463 | */ |
| 464 | newMethodWithHttpOperationResponse(options) { |
| 465 | let client = this.client; |
| 466 | let self = this; |
| 467 | return new Promise((resolve, reject) => { |
| 468 | self._newMethod(options, (err, result, request, response) => { |
| 469 | let httpOperationResponse = new msRest.HttpOperationResponse(request, response); |
| 470 | httpOperationResponse.body = result; |
| 471 | if (err) { reject(err); } |
| 472 | else { resolve(httpOperationResponse); } |
| 473 | return; |
| 474 | }); |
| 475 | }); |
| 476 | } |
| 477 | |
| 478 | /** |
| 479 | * Creates a new API token |
| 480 | * |
| 481 | * @param {object} [options] Optional Parameters. |
| 482 | * |
| 483 | * @param {object} [options.description] Description of the token |
| 484 | * |
| 485 | * @param {string} [options.description.description] The description of the |
| 486 | * token |
| 487 | * |
| 488 | * @param {array} [options.description.scope] The scope for this token. |
| 489 | * |
| 490 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 491 | * request |
| 492 | * |
| 493 | * @param {function} [optionalCallback] - The optional callback. |
| 494 | * |
| 495 | * @returns {function|Promise} If a callback was passed as the last parameter |
| 496 | * then it returns the callback else returns a Promise. |
| 497 | * |
| 498 | * {Promise} A promise is returned |
| 499 | * |
| 500 | * @resolve {ApiTokensCreateResponse} - The deserialized result object. |
| 501 | * |
| 502 | * @reject {Error} - The error object. |
| 503 | * |
| 504 | * {function} optionalCallback(err, result, request, response) |
| 505 | * |
| 506 | * {Error} err - The Error object if an error occurred, null otherwise. |
| 507 | * |
| 508 | * {object} [result] - The deserialized result object if an error did not occur. |
| 509 | * See {@link ApiTokensCreateResponse} for more |
| 510 | * information. |
| 511 | * |
| 512 | * {object} [request] - The HTTP Request object if an error did not occur. |
| 513 | * |
| 514 | * {stream} [response] - The HTTP Response stream if an error did not occur. |
| 515 | */ |
| 516 | newMethod(options, optionalCallback) { |
| 517 | let client = this.client; |
| 518 | let self = this; |
| 519 | if (!optionalCallback && typeof options === 'function') { |
| 520 | optionalCallback = options; |
| 521 | options = null; |
| 522 | } |
| 523 | if (!optionalCallback) { |
| 524 | return new Promise((resolve, reject) => { |
| 525 | self._newMethod(options, (err, result, request, response) => { |
| 526 | if (err) { reject(err); } |
| 527 | else { resolve(result); } |
| 528 | return; |
| 529 | }); |
| 530 | }); |
| 531 | } else { |
| 532 | return self._newMethod(options, optionalCallback); |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | /** |
| 537 | * Delete the api_token object with the specific id |
| 538 | * |
| 539 | * @param {string} apiTokenId The unique ID (UUID) of the api token |
| 540 | * |
| 541 | * @param {object} [options] Optional Parameters. |
| 542 | * |
| 543 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 544 | * request |
| 545 | * |
| 546 | * @returns {Promise} A promise is returned |
| 547 | * |
| 548 | * @resolve {HttpOperationResponse<null>} - The deserialized result object. |
| 549 | * |
| 550 | * @reject {Error} - The error object. |
| 551 | */ |
| 552 | deleteMethodWithHttpOperationResponse(apiTokenId, options) { |
| 553 | let client = this.client; |
| 554 | let self = this; |
| 555 | return new Promise((resolve, reject) => { |
| 556 | self._deleteMethod(apiTokenId, options, (err, result, request, response) => { |
| 557 | let httpOperationResponse = new msRest.HttpOperationResponse(request, response); |
| 558 | httpOperationResponse.body = result; |
| 559 | if (err) { reject(err); } |
| 560 | else { resolve(httpOperationResponse); } |
| 561 | return; |
| 562 | }); |
| 563 | }); |
| 564 | } |
| 565 | |
| 566 | /** |
| 567 | * Delete the api_token object with the specific id |
| 568 | * |
| 569 | * @param {string} apiTokenId The unique ID (UUID) of the api token |
| 570 | * |
| 571 | * @param {object} [options] Optional Parameters. |
| 572 | * |
| 573 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 574 | * request |
| 575 | * |
| 576 | * @param {function} [optionalCallback] - The optional callback. |
| 577 | * |
| 578 | * @returns {function|Promise} If a callback was passed as the last parameter |
| 579 | * then it returns the callback else returns a Promise. |
| 580 | * |
| 581 | * {Promise} A promise is returned |
| 582 | * |
| 583 | * @resolve {null} - The deserialized result object. |
| 584 | * |
| 585 | * @reject {Error} - The error object. |
| 586 | * |
| 587 | * {function} optionalCallback(err, result, request, response) |
| 588 | * |
| 589 | * {Error} err - The Error object if an error occurred, null otherwise. |
| 590 | * |
| 591 | * {null} [result] - The deserialized result object if an error did not occur. |
| 592 | * |
| 593 | * {object} [request] - The HTTP Request object if an error did not occur. |
| 594 | * |
| 595 | * {stream} [response] - The HTTP Response stream if an error did not occur. |
| 596 | */ |
| 597 | deleteMethod(apiTokenId, options, optionalCallback) { |
| 598 | let client = this.client; |
| 599 | let self = this; |
| 600 | if (!optionalCallback && typeof options === 'function') { |
| 601 | optionalCallback = options; |
| 602 | options = null; |
| 603 | } |
| 604 | if (!optionalCallback) { |
| 605 | return new Promise((resolve, reject) => { |
| 606 | self._deleteMethod(apiTokenId, options, (err, result, request, response) => { |
| 607 | if (err) { reject(err); } |
| 608 | else { resolve(result); } |
| 609 | return; |
| 610 | }); |
| 611 | }); |
| 612 | } else { |
| 613 | return self._deleteMethod(apiTokenId, options, optionalCallback); |
| 614 | } |
| 615 | } |
| 616 | |
| 617 | } |
| 618 | |
| 619 | module.exports = ApiTokens; |