UNPKG

appcenter-cli

Version:

Command line tool for Visual Studio App Center

557 lines (539 loc) 21.9 kB
/* * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for * license information. * * Code generated by Microsoft (R) AutoRest Code Generator. * Changes may cause incorrect behavior and will be lost if the code is * regenerated. */ 'use strict'; const msRest = require('ms-rest'); const WebResource = msRest.WebResource; /** * Aggregated Billing Information for a given Organization. * * @param {string} orgName The name of the Organization * * @param {object} [options] Optional Parameters. * * @param {string} [options.service] Type of service that should be included in * the Billing Information. Possible values include: 'Test', 'Build' * * @param {string} [options.period] Type of period that should be included in * the Billing Information. Possible values include: 'Previous', 'Current', * 'Next' * * @param {boolean} [options.showOriginalPlans] Controls whether the API should * show the original plan when Azure Subscription is not enabled * * @param {object} [options.customHeaders] Headers that will be added to the * request * * @param {function} callback - The callback. * * @returns {function} callback(err, result, request, response) * * {Error} err - The Error object if an error occurred, null otherwise. * * {object} [result] - The deserialized result object if an error did not occur. * See {@link AggregatedBillingInformation} for more * information. * * {object} [request] - The HTTP Request object if an error did not occur. * * {stream} [response] - The HTTP Response stream if an error did not occur. */ function _getForOrg(orgName, options, callback) { /* jshint validthis: true */ let client = this.client; if(!callback && typeof options === 'function') { callback = options; options = null; } if (!callback) { throw new Error('callback cannot be null.'); } let service = (options && options.service !== undefined) ? options.service : undefined; let period = (options && options.period !== undefined) ? options.period : undefined; let showOriginalPlans = (options && options.showOriginalPlans !== undefined) ? options.showOriginalPlans : undefined; // Validate try { if (orgName === null || orgName === undefined || typeof orgName.valueOf() !== 'string') { throw new Error('orgName cannot be null or undefined and it must be of type string.'); } if (service !== null && service !== undefined && typeof service.valueOf() !== 'string') { throw new Error('service must be of type string.'); } if (period !== null && period !== undefined && typeof period.valueOf() !== 'string') { throw new Error('period must be of type string.'); } if (showOriginalPlans !== null && showOriginalPlans !== undefined && typeof showOriginalPlans !== 'boolean') { throw new Error('showOriginalPlans must be of type boolean.'); } } catch (error) { return callback(error); } // Construct URL let baseUrl = this.client.baseUri; let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'v0.1/orgs/{orgName}/billing/aggregated'; requestUrl = requestUrl.replace('{orgName}', encodeURIComponent(orgName)); let queryParameters = []; if (service !== null && service !== undefined) { queryParameters.push('service=' + encodeURIComponent(service)); } if (period !== null && period !== undefined) { queryParameters.push('period=' + encodeURIComponent(period)); } if (showOriginalPlans !== null && showOriginalPlans !== undefined) { queryParameters.push('showOriginalPlans=' + encodeURIComponent(showOriginalPlans.toString())); } if (queryParameters.length > 0) { requestUrl += '?' + queryParameters.join('&'); } // Create HTTP transport objects let httpRequest = new WebResource(); httpRequest.method = 'GET'; httpRequest.url = requestUrl; httpRequest.headers = {}; // Set Headers httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; if(options) { for(let headerName in options['customHeaders']) { if (options['customHeaders'].hasOwnProperty(headerName)) { httpRequest.headers[headerName] = options['customHeaders'][headerName]; } } } httpRequest.body = null; // Send Request return client.pipeline(httpRequest, (err, response, responseBody) => { if (err) { return callback(err); } let statusCode = response.statusCode; if (statusCode !== 200) { let error = new Error(responseBody); error.statusCode = response.statusCode; error.request = msRest.stripRequest(httpRequest); error.response = msRest.stripResponse(response); if (responseBody === '') responseBody = null; let parsedErrorResponse; try { parsedErrorResponse = JSON.parse(responseBody); if (parsedErrorResponse) { let internalError = null; if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; error.code = internalError ? internalError.code : parsedErrorResponse.code; error.message = internalError ? internalError.message : parsedErrorResponse.message; } if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) { let resultMapper = new client.models['BillingError']().mapper(); error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body'); } } catch (defaultError) { error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + `- "${responseBody}" for the default response.`; return callback(error); } return callback(error); } // Create Result let result = null; if (responseBody === '') responseBody = null; // Deserialize Response if (statusCode === 200) { let parsedResponse = null; try { parsedResponse = JSON.parse(responseBody); result = JSON.parse(responseBody); if (parsedResponse !== null && parsedResponse !== undefined) { let resultMapper = new client.models['AggregatedBillingInformation']().mapper(); result = client.deserialize(resultMapper, parsedResponse, 'result'); } } catch (error) { let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`); deserializationError.request = msRest.stripRequest(httpRequest); deserializationError.response = msRest.stripResponse(response); return callback(deserializationError); } } return callback(null, result, httpRequest, response); }); } /** * Aggregated Billing Information for owner of a given app. * * @param {string} ownerName The name of the owner * * @param {string} appName The name of the application * * @param {object} [options] Optional Parameters. * * @param {string} [options.service] Type of service that should be included in * the Billing Information. Possible values include: 'Test', 'Build' * * @param {string} [options.period] Type of period that should be included in * the Billing Information. Possible values include: 'Previous', 'Current', * 'Next' * * @param {boolean} [options.showOriginalPlans] Controls whether the API should * show the original plan when Azure Subscription is not enabled * * @param {object} [options.customHeaders] Headers that will be added to the * request * * @param {function} callback - The callback. * * @returns {function} callback(err, result, request, response) * * {Error} err - The Error object if an error occurred, null otherwise. * * {object} [result] - The deserialized result object if an error did not occur. * See {@link AggregatedBillingInformation} for more * information. * * {object} [request] - The HTTP Request object if an error did not occur. * * {stream} [response] - The HTTP Response stream if an error did not occur. */ function _getByApp(ownerName, appName, options, callback) { /* jshint validthis: true */ let client = this.client; if(!callback && typeof options === 'function') { callback = options; options = null; } if (!callback) { throw new Error('callback cannot be null.'); } let service = (options && options.service !== undefined) ? options.service : undefined; let period = (options && options.period !== undefined) ? options.period : undefined; let showOriginalPlans = (options && options.showOriginalPlans !== undefined) ? options.showOriginalPlans : undefined; // Validate try { if (service !== null && service !== undefined && typeof service.valueOf() !== 'string') { throw new Error('service must be of type string.'); } if (period !== null && period !== undefined && typeof period.valueOf() !== 'string') { throw new Error('period must be of type string.'); } if (showOriginalPlans !== null && showOriginalPlans !== undefined && typeof showOriginalPlans !== 'boolean') { throw new Error('showOriginalPlans must be of type boolean.'); } if (ownerName === null || ownerName === undefined || typeof ownerName.valueOf() !== 'string') { throw new Error('ownerName cannot be null or undefined and it must be of type string.'); } if (appName === null || appName === undefined || typeof appName.valueOf() !== 'string') { throw new Error('appName cannot be null or undefined and it must be of type string.'); } } catch (error) { return callback(error); } // Construct URL let baseUrl = this.client.baseUri; let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'v0.1/apps/{owner_name}/{app_name}/billing/aggregated'; requestUrl = requestUrl.replace('{owner_name}', encodeURIComponent(ownerName)); requestUrl = requestUrl.replace('{app_name}', encodeURIComponent(appName)); let queryParameters = []; if (service !== null && service !== undefined) { queryParameters.push('service=' + encodeURIComponent(service)); } if (period !== null && period !== undefined) { queryParameters.push('period=' + encodeURIComponent(period)); } if (showOriginalPlans !== null && showOriginalPlans !== undefined) { queryParameters.push('showOriginalPlans=' + encodeURIComponent(showOriginalPlans.toString())); } if (queryParameters.length > 0) { requestUrl += '?' + queryParameters.join('&'); } // Create HTTP transport objects let httpRequest = new WebResource(); httpRequest.method = 'GET'; httpRequest.url = requestUrl; httpRequest.headers = {}; // Set Headers httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8'; if(options) { for(let headerName in options['customHeaders']) { if (options['customHeaders'].hasOwnProperty(headerName)) { httpRequest.headers[headerName] = options['customHeaders'][headerName]; } } } httpRequest.body = null; // Send Request return client.pipeline(httpRequest, (err, response, responseBody) => { if (err) { return callback(err); } let statusCode = response.statusCode; if (statusCode !== 200) { let error = new Error(responseBody); error.statusCode = response.statusCode; error.request = msRest.stripRequest(httpRequest); error.response = msRest.stripResponse(response); if (responseBody === '') responseBody = null; let parsedErrorResponse; try { parsedErrorResponse = JSON.parse(responseBody); if (parsedErrorResponse) { let internalError = null; if (parsedErrorResponse.error) internalError = parsedErrorResponse.error; error.code = internalError ? internalError.code : parsedErrorResponse.code; error.message = internalError ? internalError.message : parsedErrorResponse.message; } if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) { let resultMapper = new client.models['BillingError']().mapper(); error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body'); } } catch (defaultError) { error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` + `- "${responseBody}" for the default response.`; return callback(error); } return callback(error); } // Create Result let result = null; if (responseBody === '') responseBody = null; // Deserialize Response if (statusCode === 200) { let parsedResponse = null; try { parsedResponse = JSON.parse(responseBody); result = JSON.parse(responseBody); if (parsedResponse !== null && parsedResponse !== undefined) { let resultMapper = new client.models['AggregatedBillingInformation']().mapper(); result = client.deserialize(resultMapper, parsedResponse, 'result'); } } catch (error) { let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`); deserializationError.request = msRest.stripRequest(httpRequest); deserializationError.response = msRest.stripResponse(response); return callback(deserializationError); } } return callback(null, result, httpRequest, response); }); } /** Class representing a BillingAggregatedInformation. */ class BillingAggregatedInformation { /** * Create a BillingAggregatedInformation. * @param {AppCenterClient} client Reference to the service client. */ constructor(client) { this.client = client; this._getForOrg = _getForOrg; this._getByApp = _getByApp; } /** * Aggregated Billing Information for a given Organization. * * @param {string} orgName The name of the Organization * * @param {object} [options] Optional Parameters. * * @param {string} [options.service] Type of service that should be included in * the Billing Information. Possible values include: 'Test', 'Build' * * @param {string} [options.period] Type of period that should be included in * the Billing Information. Possible values include: 'Previous', 'Current', * 'Next' * * @param {boolean} [options.showOriginalPlans] Controls whether the API should * show the original plan when Azure Subscription is not enabled * * @param {object} [options.customHeaders] Headers that will be added to the * request * * @returns {Promise} A promise is returned * * @resolve {HttpOperationResponse<AggregatedBillingInformation>} - The deserialized result object. * * @reject {Error} - The error object. */ getForOrgWithHttpOperationResponse(orgName, options) { let client = this.client; let self = this; return new Promise((resolve, reject) => { self._getForOrg(orgName, options, (err, result, request, response) => { let httpOperationResponse = new msRest.HttpOperationResponse(request, response); httpOperationResponse.body = result; if (err) { reject(err); } else { resolve(httpOperationResponse); } return; }); }); } /** * Aggregated Billing Information for a given Organization. * * @param {string} orgName The name of the Organization * * @param {object} [options] Optional Parameters. * * @param {string} [options.service] Type of service that should be included in * the Billing Information. Possible values include: 'Test', 'Build' * * @param {string} [options.period] Type of period that should be included in * the Billing Information. Possible values include: 'Previous', 'Current', * 'Next' * * @param {boolean} [options.showOriginalPlans] Controls whether the API should * show the original plan when Azure Subscription is not enabled * * @param {object} [options.customHeaders] Headers that will be added to the * request * * @param {function} [optionalCallback] - The optional callback. * * @returns {function|Promise} If a callback was passed as the last parameter * then it returns the callback else returns a Promise. * * {Promise} A promise is returned * * @resolve {AggregatedBillingInformation} - The deserialized result object. * * @reject {Error} - The error object. * * {function} optionalCallback(err, result, request, response) * * {Error} err - The Error object if an error occurred, null otherwise. * * {object} [result] - The deserialized result object if an error did not occur. * See {@link AggregatedBillingInformation} for more * information. * * {object} [request] - The HTTP Request object if an error did not occur. * * {stream} [response] - The HTTP Response stream if an error did not occur. */ getForOrg(orgName, options, optionalCallback) { let client = this.client; let self = this; if (!optionalCallback && typeof options === 'function') { optionalCallback = options; options = null; } if (!optionalCallback) { return new Promise((resolve, reject) => { self._getForOrg(orgName, options, (err, result, request, response) => { if (err) { reject(err); } else { resolve(result); } return; }); }); } else { return self._getForOrg(orgName, options, optionalCallback); } } /** * Aggregated Billing Information for owner of a given app. * * @param {string} ownerName The name of the owner * * @param {string} appName The name of the application * * @param {object} [options] Optional Parameters. * * @param {string} [options.service] Type of service that should be included in * the Billing Information. Possible values include: 'Test', 'Build' * * @param {string} [options.period] Type of period that should be included in * the Billing Information. Possible values include: 'Previous', 'Current', * 'Next' * * @param {boolean} [options.showOriginalPlans] Controls whether the API should * show the original plan when Azure Subscription is not enabled * * @param {object} [options.customHeaders] Headers that will be added to the * request * * @returns {Promise} A promise is returned * * @resolve {HttpOperationResponse<AggregatedBillingInformation>} - The deserialized result object. * * @reject {Error} - The error object. */ getByAppWithHttpOperationResponse(ownerName, appName, options) { let client = this.client; let self = this; return new Promise((resolve, reject) => { self._getByApp(ownerName, appName, options, (err, result, request, response) => { let httpOperationResponse = new msRest.HttpOperationResponse(request, response); httpOperationResponse.body = result; if (err) { reject(err); } else { resolve(httpOperationResponse); } return; }); }); } /** * Aggregated Billing Information for owner of a given app. * * @param {string} ownerName The name of the owner * * @param {string} appName The name of the application * * @param {object} [options] Optional Parameters. * * @param {string} [options.service] Type of service that should be included in * the Billing Information. Possible values include: 'Test', 'Build' * * @param {string} [options.period] Type of period that should be included in * the Billing Information. Possible values include: 'Previous', 'Current', * 'Next' * * @param {boolean} [options.showOriginalPlans] Controls whether the API should * show the original plan when Azure Subscription is not enabled * * @param {object} [options.customHeaders] Headers that will be added to the * request * * @param {function} [optionalCallback] - The optional callback. * * @returns {function|Promise} If a callback was passed as the last parameter * then it returns the callback else returns a Promise. * * {Promise} A promise is returned * * @resolve {AggregatedBillingInformation} - The deserialized result object. * * @reject {Error} - The error object. * * {function} optionalCallback(err, result, request, response) * * {Error} err - The Error object if an error occurred, null otherwise. * * {object} [result] - The deserialized result object if an error did not occur. * See {@link AggregatedBillingInformation} for more * information. * * {object} [request] - The HTTP Request object if an error did not occur. * * {stream} [response] - The HTTP Response stream if an error did not occur. */ getByApp(ownerName, appName, options, optionalCallback) { let client = this.client; let self = this; if (!optionalCallback && typeof options === 'function') { optionalCallback = options; options = null; } if (!optionalCallback) { return new Promise((resolve, reject) => { self._getByApp(ownerName, appName, options, (err, result, request, response) => { if (err) { reject(err); } else { resolve(result); } return; }); }); } else { return self._getByApp(ownerName, appName, options, optionalCallback); } } } module.exports = BillingAggregatedInformation;