microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
lib/app-center-node-client/src/account/operations/distributionGroupInvitations.js
191lines · 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 | * Accepts all pending invitations to distribution groups for the specified |
| 14 | * user |
| 15 | * |
| 16 | * @param {object} [options] Optional Parameters. |
| 17 | * |
| 18 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 19 | * request |
| 20 | * |
| 21 | * @param {function} callback - The callback. |
| 22 | * |
| 23 | * @returns {function} callback(err, result, request, response) |
| 24 | * |
| 25 | * {Error} err - The Error object if an error occurred, null otherwise. |
| 26 | * |
| 27 | * {null} [result] - The deserialized result object if an error did not occur. |
| 28 | * |
| 29 | * {object} [request] - The HTTP Request object if an error did not occur. |
| 30 | * |
| 31 | * {stream} [response] - The HTTP Response stream if an error did not occur. |
| 32 | */ |
| 33 | function _acceptAll(options, callback) { |
| 34 | /* jshint validthis: true */ |
| 35 | let client = this.client; |
| 36 | if(!callback && typeof options === 'function') { |
| 37 | callback = options; |
| 38 | options = null; |
| 39 | } |
| 40 | if (!callback) { |
| 41 | throw new Error('callback cannot be null.'); |
| 42 | } |
| 43 | |
| 44 | // Construct URL |
| 45 | let baseUrl = this.client.baseUri; |
| 46 | let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'v0.1/user/invitations/distribution_groups/accept'; |
| 47 | |
| 48 | // Create HTTP transport objects |
| 49 | let httpRequest = new WebResource(); |
| 50 | httpRequest.method = 'POST'; |
| 51 | httpRequest.url = requestUrl; |
| 52 | httpRequest.headers = {}; |
| 53 | // Set Headers |
| 54 | httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; |
| 55 | if(options) { |
| 56 | for(let headerName in options['customHeaders']) { |
| 57 | if (options['customHeaders'].hasOwnProperty(headerName)) { |
| 58 | httpRequest.headers[headerName] = options['customHeaders'][headerName]; |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | httpRequest.body = null; |
| 63 | // Send Request |
| 64 | return client.pipeline(httpRequest, (err, response, responseBody) => { |
| 65 | if (err) { |
| 66 | return callback(err); |
| 67 | } |
| 68 | let statusCode = response.statusCode; |
| 69 | if (statusCode < 200 || statusCode >= 300) { |
| 70 | let error = new Error(responseBody); |
| 71 | error.statusCode = response.statusCode; |
| 72 | error.request = msRest.stripRequest(httpRequest); |
| 73 | error.response = msRest.stripResponse(response); |
| 74 | if (responseBody === '') responseBody = null; |
| 75 | let parsedErrorResponse; |
| 76 | try { |
| 77 | parsedErrorResponse = JSON.parse(responseBody); |
| 78 | if (parsedErrorResponse) { |
| 79 | let internalError = null; |
| 80 | if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; |
| 81 | error.code = internalError ? internalError.code : parsedErrorResponse.code; |
| 82 | error.message = internalError ? internalError.message : parsedErrorResponse.message; |
| 83 | } |
| 84 | } catch (defaultError) { |
| 85 | error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + |
| 86 | `- "${responseBody}" for the default response.`; |
| 87 | return callback(error); |
| 88 | } |
| 89 | return callback(error); |
| 90 | } |
| 91 | // Create Result |
| 92 | let result = null; |
| 93 | if (responseBody === '') responseBody = null; |
| 94 | |
| 95 | return callback(null, result, httpRequest, response); |
| 96 | }); |
| 97 | } |
| 98 | |
| 99 | /** Class representing a DistributionGroupInvitations. */ |
| 100 | class DistributionGroupInvitations { |
| 101 | /** |
| 102 | * Create a DistributionGroupInvitations. |
| 103 | * @param {AccountClient} client Reference to the service client. |
| 104 | */ |
| 105 | constructor(client) { |
| 106 | this.client = client; |
| 107 | this._acceptAll = _acceptAll; |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Accepts all pending invitations to distribution groups for the specified |
| 112 | * user |
| 113 | * |
| 114 | * @param {object} [options] Optional Parameters. |
| 115 | * |
| 116 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 117 | * request |
| 118 | * |
| 119 | * @returns {Promise} A promise is returned |
| 120 | * |
| 121 | * @resolve {HttpOperationResponse<null>} - The deserialized result object. |
| 122 | * |
| 123 | * @reject {Error} - The error object. |
| 124 | */ |
| 125 | acceptAllWithHttpOperationResponse(options) { |
| 126 | let client = this.client; |
| 127 | let self = this; |
| 128 | return new Promise((resolve, reject) => { |
| 129 | self._acceptAll(options, (err, result, request, response) => { |
| 130 | let httpOperationResponse = new msRest.HttpOperationResponse(request, response); |
| 131 | httpOperationResponse.body = result; |
| 132 | if (err) { reject(err); } |
| 133 | else { resolve(httpOperationResponse); } |
| 134 | return; |
| 135 | }); |
| 136 | }); |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Accepts all pending invitations to distribution groups for the specified |
| 141 | * user |
| 142 | * |
| 143 | * @param {object} [options] Optional Parameters. |
| 144 | * |
| 145 | * @param {object} [options.customHeaders] Headers that will be added to the |
| 146 | * request |
| 147 | * |
| 148 | * @param {function} [optionalCallback] - The optional callback. |
| 149 | * |
| 150 | * @returns {function|Promise} If a callback was passed as the last parameter |
| 151 | * then it returns the callback else returns a Promise. |
| 152 | * |
| 153 | * {Promise} A promise is returned |
| 154 | * |
| 155 | * @resolve {null} - The deserialized result object. |
| 156 | * |
| 157 | * @reject {Error} - The error object. |
| 158 | * |
| 159 | * {function} optionalCallback(err, result, request, response) |
| 160 | * |
| 161 | * {Error} err - The Error object if an error occurred, null otherwise. |
| 162 | * |
| 163 | * {null} [result] - The deserialized result object if an error did not occur. |
| 164 | * |
| 165 | * {object} [request] - The HTTP Request object if an error did not occur. |
| 166 | * |
| 167 | * {stream} [response] - The HTTP Response stream if an error did not occur. |
| 168 | */ |
| 169 | acceptAll(options, optionalCallback) { |
| 170 | let client = this.client; |
| 171 | let self = this; |
| 172 | if (!optionalCallback && typeof options === 'function') { |
| 173 | optionalCallback = options; |
| 174 | options = null; |
| 175 | } |
| 176 | if (!optionalCallback) { |
| 177 | return new Promise((resolve, reject) => { |
| 178 | self._acceptAll(options, (err, result, request, response) => { |
| 179 | if (err) { reject(err); } |
| 180 | else { resolve(result); } |
| 181 | return; |
| 182 | }); |
| 183 | }); |
| 184 | } else { |
| 185 | return self._acceptAll(options, optionalCallback); |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | } |
| 190 | |
| 191 | module.exports = DistributionGroupInvitations; |
| 192 | |