/* * Copyright (c) Microsoft Corporation. * Licensed under the MIT License. * * Code generated by Microsoft (R) AutoRest Code Generator. * Changes may cause incorrect behavior and will be lost if the code is regenerated. */ import { PagedAsyncIterableIterator, PageSettings } from "@azure/core-paging"; import { setContinuationToken } from "../pagingHelper"; import { Grants } from "../operationsInterfaces"; import * as coreClient from "@azure/core-client"; import * as Mappers from "../models/mappers"; import * as Parameters from "../models/parameters"; import { EducationManagementClient } from "../educationManagementClient"; import { GrantDetails, GrantsListAllNextOptionalParams, GrantsListAllOptionalParams, GrantsListAllResponse, GrantsListNextOptionalParams, GrantsListOptionalParams, GrantsListResponse, GrantsGetOptionalParams, GrantsGetResponse, GrantsListAllNextResponse, GrantsListNextResponse } from "../models"; /// /** Class containing Grants operations. */ export class GrantsImpl implements Grants { private readonly client: EducationManagementClient; /** * Initialize a new instance of the class Grants class. * @param client Reference to the service client */ constructor(client: EducationManagementClient) { this.client = client; } /** * Get a list of grants that Microsoft has provided. * @param options The options parameters. */ public listAll( options?: GrantsListAllOptionalParams ): PagedAsyncIterableIterator { const iter = this.listAllPagingAll(options); return { next() { return iter.next(); }, [Symbol.asyncIterator]() { return this; }, byPage: (settings?: PageSettings) => { if (settings?.maxPageSize) { throw new Error("maxPageSize is not supported by this operation."); } return this.listAllPagingPage(options, settings); } }; } private async *listAllPagingPage( options?: GrantsListAllOptionalParams, settings?: PageSettings ): AsyncIterableIterator { let result: GrantsListAllResponse; let continuationToken = settings?.continuationToken; if (!continuationToken) { result = await this._listAll(options); let page = result.value || []; continuationToken = result.nextLink; setContinuationToken(page, continuationToken); yield page; } while (continuationToken) { result = await this._listAllNext(continuationToken, options); continuationToken = result.nextLink; let page = result.value || []; setContinuationToken(page, continuationToken); yield page; } } private async *listAllPagingAll( options?: GrantsListAllOptionalParams ): AsyncIterableIterator { for await (const page of this.listAllPagingPage(options)) { yield* page; } } /** * Get details for a specific grant linked to the provided billing account and billing profile. * @param billingAccountName Billing account name. * @param billingProfileName Billing profile name. * @param options The options parameters. */ public list( billingAccountName: string, billingProfileName: string, options?: GrantsListOptionalParams ): PagedAsyncIterableIterator { const iter = this.listPagingAll( billingAccountName, billingProfileName, options ); return { next() { return iter.next(); }, [Symbol.asyncIterator]() { return this; }, byPage: (settings?: PageSettings) => { if (settings?.maxPageSize) { throw new Error("maxPageSize is not supported by this operation."); } return this.listPagingPage( billingAccountName, billingProfileName, options, settings ); } }; } private async *listPagingPage( billingAccountName: string, billingProfileName: string, options?: GrantsListOptionalParams, settings?: PageSettings ): AsyncIterableIterator { let result: GrantsListResponse; let continuationToken = settings?.continuationToken; if (!continuationToken) { result = await this._list( billingAccountName, billingProfileName, options ); let page = result.value || []; continuationToken = result.nextLink; setContinuationToken(page, continuationToken); yield page; } while (continuationToken) { result = await this._listNext( billingAccountName, billingProfileName, continuationToken, options ); continuationToken = result.nextLink; let page = result.value || []; setContinuationToken(page, continuationToken); yield page; } } private async *listPagingAll( billingAccountName: string, billingProfileName: string, options?: GrantsListOptionalParams ): AsyncIterableIterator { for await (const page of this.listPagingPage( billingAccountName, billingProfileName, options )) { yield* page; } } /** * Get a list of grants that Microsoft has provided. * @param options The options parameters. */ private _listAll( options?: GrantsListAllOptionalParams ): Promise { return this.client.sendOperationRequest({ options }, listAllOperationSpec); } /** * Get details for a specific grant linked to the provided billing account and billing profile. * @param billingAccountName Billing account name. * @param billingProfileName Billing profile name. * @param options The options parameters. */ private _list( billingAccountName: string, billingProfileName: string, options?: GrantsListOptionalParams ): Promise { return this.client.sendOperationRequest( { billingAccountName, billingProfileName, options }, listOperationSpec ); } /** * Get details for a specific grant linked to the provided billing account and billing profile. * @param billingAccountName Billing account name. * @param billingProfileName Billing profile name. * @param options The options parameters. */ get( billingAccountName: string, billingProfileName: string, options?: GrantsGetOptionalParams ): Promise { return this.client.sendOperationRequest( { billingAccountName, billingProfileName, options }, getOperationSpec ); } /** * ListAllNext * @param nextLink The nextLink from the previous successful call to the ListAll method. * @param options The options parameters. */ private _listAllNext( nextLink: string, options?: GrantsListAllNextOptionalParams ): Promise { return this.client.sendOperationRequest( { nextLink, options }, listAllNextOperationSpec ); } /** * ListNext * @param billingAccountName Billing account name. * @param billingProfileName Billing profile name. * @param nextLink The nextLink from the previous successful call to the List method. * @param options The options parameters. */ private _listNext( billingAccountName: string, billingProfileName: string, nextLink: string, options?: GrantsListNextOptionalParams ): Promise { return this.client.sendOperationRequest( { billingAccountName, billingProfileName, nextLink, options }, listNextOperationSpec ); } } // Operation Specifications const serializer = coreClient.createSerializer(Mappers, /* isXml */ false); const listAllOperationSpec: coreClient.OperationSpec = { path: "/providers/Microsoft.Education/grants", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.GrantListResponse }, default: { bodyMapper: Mappers.ErrorResponseBody } }, queryParameters: [Parameters.apiVersion, Parameters.includeAllocatedBudget], urlParameters: [Parameters.$host], headerParameters: [Parameters.accept], serializer }; const listOperationSpec: coreClient.OperationSpec = { path: "/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/billingProfiles/{billingProfileName}/providers/Microsoft.Education/grants", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.GrantListResponse }, default: { bodyMapper: Mappers.ErrorResponseBody } }, queryParameters: [Parameters.apiVersion, Parameters.includeAllocatedBudget], urlParameters: [ Parameters.$host, Parameters.billingAccountName, Parameters.billingProfileName ], headerParameters: [Parameters.accept], serializer }; const getOperationSpec: coreClient.OperationSpec = { path: "/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/billingProfiles/{billingProfileName}/providers/Microsoft.Education/grants/default", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.GrantDetails }, default: { bodyMapper: Mappers.ErrorResponseBody } }, queryParameters: [Parameters.apiVersion, Parameters.includeAllocatedBudget], urlParameters: [ Parameters.$host, Parameters.billingAccountName, Parameters.billingProfileName ], headerParameters: [Parameters.accept], serializer }; const listAllNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.GrantListResponse }, default: { bodyMapper: Mappers.ErrorResponseBody } }, urlParameters: [Parameters.$host, Parameters.nextLink], headerParameters: [Parameters.accept], serializer }; const listNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.GrantListResponse }, default: { bodyMapper: Mappers.ErrorResponseBody } }, urlParameters: [ Parameters.$host, Parameters.billingAccountName, Parameters.billingProfileName, Parameters.nextLink ], headerParameters: [Parameters.accept], serializer };