/* * 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 { NotificationChannels } from "../operationsInterfaces"; import * as coreClient from "@azure/core-client"; import * as Mappers from "../models/mappers"; import * as Parameters from "../models/parameters"; import { DevTestLabsClient } from "../devTestLabsClient"; import { NotificationChannel, NotificationChannelsListNextOptionalParams, NotificationChannelsListOptionalParams, NotificationChannelsListResponse, NotificationChannelsGetOptionalParams, NotificationChannelsGetResponse, NotificationChannelsCreateOrUpdateOptionalParams, NotificationChannelsCreateOrUpdateResponse, NotificationChannelsDeleteOptionalParams, NotificationChannelFragment, NotificationChannelsUpdateOptionalParams, NotificationChannelsUpdateResponse, NotifyParameters, NotificationChannelsNotifyOptionalParams, NotificationChannelsListNextResponse } from "../models"; /// /** Class containing NotificationChannels operations. */ export class NotificationChannelsImpl implements NotificationChannels { private readonly client: DevTestLabsClient; /** * Initialize a new instance of the class NotificationChannels class. * @param client Reference to the service client */ constructor(client: DevTestLabsClient) { this.client = client; } /** * List notification channels in a given lab. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param options The options parameters. */ public list( resourceGroupName: string, labName: string, options?: NotificationChannelsListOptionalParams ): PagedAsyncIterableIterator { const iter = this.listPagingAll(resourceGroupName, labName, 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( resourceGroupName, labName, options, settings ); } }; } private async *listPagingPage( resourceGroupName: string, labName: string, options?: NotificationChannelsListOptionalParams, settings?: PageSettings ): AsyncIterableIterator { let result: NotificationChannelsListResponse; let continuationToken = settings?.continuationToken; if (!continuationToken) { result = await this._list(resourceGroupName, labName, options); let page = result.value || []; continuationToken = result.nextLink; setContinuationToken(page, continuationToken); yield page; } while (continuationToken) { result = await this._listNext( resourceGroupName, labName, continuationToken, options ); continuationToken = result.nextLink; let page = result.value || []; setContinuationToken(page, continuationToken); yield page; } } private async *listPagingAll( resourceGroupName: string, labName: string, options?: NotificationChannelsListOptionalParams ): AsyncIterableIterator { for await (const page of this.listPagingPage( resourceGroupName, labName, options )) { yield* page; } } /** * List notification channels in a given lab. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param options The options parameters. */ private _list( resourceGroupName: string, labName: string, options?: NotificationChannelsListOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, labName, options }, listOperationSpec ); } /** * Get notification channel. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param name The name of the notification channel. * @param options The options parameters. */ get( resourceGroupName: string, labName: string, name: string, options?: NotificationChannelsGetOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, labName, name, options }, getOperationSpec ); } /** * Create or replace an existing notification channel. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param name The name of the notification channel. * @param notificationChannel A notification. * @param options The options parameters. */ createOrUpdate( resourceGroupName: string, labName: string, name: string, notificationChannel: NotificationChannel, options?: NotificationChannelsCreateOrUpdateOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, labName, name, notificationChannel, options }, createOrUpdateOperationSpec ); } /** * Delete notification channel. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param name The name of the notification channel. * @param options The options parameters. */ delete( resourceGroupName: string, labName: string, name: string, options?: NotificationChannelsDeleteOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, labName, name, options }, deleteOperationSpec ); } /** * Allows modifying tags of notification channels. All other properties will be ignored. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param name The name of the notification channel. * @param notificationChannel A notification. * @param options The options parameters. */ update( resourceGroupName: string, labName: string, name: string, notificationChannel: NotificationChannelFragment, options?: NotificationChannelsUpdateOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, labName, name, notificationChannel, options }, updateOperationSpec ); } /** * Send notification to provided channel. * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param name The name of the notification channel. * @param notifyParameters Properties for generating a Notification. * @param options The options parameters. */ notify( resourceGroupName: string, labName: string, name: string, notifyParameters: NotifyParameters, options?: NotificationChannelsNotifyOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, labName, name, notifyParameters, options }, notifyOperationSpec ); } /** * ListNext * @param resourceGroupName The name of the resource group. * @param labName The name of the lab. * @param nextLink The nextLink from the previous successful call to the List method. * @param options The options parameters. */ private _listNext( resourceGroupName: string, labName: string, nextLink: string, options?: NotificationChannelsListNextOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, labName, nextLink, options }, listNextOperationSpec ); } } // Operation Specifications const serializer = coreClient.createSerializer(Mappers, /* isXml */ false); const listOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/notificationchannels", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.NotificationChannelList }, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [ Parameters.apiVersion, Parameters.expand, Parameters.filter, Parameters.top, Parameters.orderby ], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.labName ], headerParameters: [Parameters.accept], serializer }; const getOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/notificationchannels/{name}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.NotificationChannel }, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [Parameters.apiVersion, Parameters.expand], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.name, Parameters.labName ], headerParameters: [Parameters.accept], serializer }; const createOrUpdateOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/notificationchannels/{name}", httpMethod: "PUT", responses: { 200: { bodyMapper: Mappers.NotificationChannel }, 201: { bodyMapper: Mappers.NotificationChannel }, default: { bodyMapper: Mappers.CloudError } }, requestBody: Parameters.notificationChannel, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.name, Parameters.labName ], headerParameters: [Parameters.accept, Parameters.contentType], mediaType: "json", serializer }; const deleteOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/notificationchannels/{name}", httpMethod: "DELETE", responses: { 200: {}, 204: {}, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.name, Parameters.labName ], headerParameters: [Parameters.accept], serializer }; const updateOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/notificationchannels/{name}", httpMethod: "PATCH", responses: { 200: { bodyMapper: Mappers.NotificationChannel }, default: { bodyMapper: Mappers.CloudError } }, requestBody: Parameters.notificationChannel1, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.name, Parameters.labName ], headerParameters: [Parameters.accept, Parameters.contentType], mediaType: "json", serializer }; const notifyOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DevTestLab/labs/{labName}/notificationchannels/{name}/notify", httpMethod: "POST", responses: { 200: {}, default: { bodyMapper: Mappers.CloudError } }, requestBody: Parameters.notifyParameters, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.name, Parameters.labName ], headerParameters: [Parameters.accept, Parameters.contentType], mediaType: "json", serializer }; const listNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.NotificationChannelList }, default: { bodyMapper: Mappers.CloudError } }, queryParameters: [ Parameters.apiVersion, Parameters.expand, Parameters.filter, Parameters.top, Parameters.orderby ], urlParameters: [ Parameters.$host, Parameters.nextLink, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.labName ], headerParameters: [Parameters.accept], serializer };