/* * 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 { StreamingPolicies } from "../operationsInterfaces"; import * as coreClient from "@azure/core-client"; import * as Mappers from "../models/mappers"; import * as Parameters from "../models/parameters"; import { AzureMediaServices } from "../azureMediaServices"; import { StreamingPolicy, StreamingPoliciesListNextOptionalParams, StreamingPoliciesListOptionalParams, StreamingPoliciesListResponse, StreamingPoliciesGetOptionalParams, StreamingPoliciesGetResponse, StreamingPoliciesCreateOptionalParams, StreamingPoliciesCreateResponse, StreamingPoliciesDeleteOptionalParams, StreamingPoliciesListNextResponse } from "../models"; /// /** Class containing StreamingPolicies operations. */ export class StreamingPoliciesImpl implements StreamingPolicies { private readonly client: AzureMediaServices; /** * Initialize a new instance of the class StreamingPolicies class. * @param client Reference to the service client */ constructor(client: AzureMediaServices) { this.client = client; } /** * Lists the Streaming Policies in the account * @param resourceGroupName The name of the resource group within the Azure subscription. * @param accountName The Media Services account name. * @param options The options parameters. */ public list( resourceGroupName: string, accountName: string, options?: StreamingPoliciesListOptionalParams ): PagedAsyncIterableIterator { const iter = this.listPagingAll(resourceGroupName, accountName, 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, accountName, options, settings ); } }; } private async *listPagingPage( resourceGroupName: string, accountName: string, options?: StreamingPoliciesListOptionalParams, settings?: PageSettings ): AsyncIterableIterator { let result: StreamingPoliciesListResponse; let continuationToken = settings?.continuationToken; if (!continuationToken) { result = await this._list(resourceGroupName, accountName, options); let page = result.value || []; continuationToken = result.odataNextLink; setContinuationToken(page, continuationToken); yield page; } while (continuationToken) { result = await this._listNext( resourceGroupName, accountName, continuationToken, options ); continuationToken = result.odataNextLink; let page = result.value || []; setContinuationToken(page, continuationToken); yield page; } } private async *listPagingAll( resourceGroupName: string, accountName: string, options?: StreamingPoliciesListOptionalParams ): AsyncIterableIterator { for await (const page of this.listPagingPage( resourceGroupName, accountName, options )) { yield* page; } } /** * Lists the Streaming Policies in the account * @param resourceGroupName The name of the resource group within the Azure subscription. * @param accountName The Media Services account name. * @param options The options parameters. */ private _list( resourceGroupName: string, accountName: string, options?: StreamingPoliciesListOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, accountName, options }, listOperationSpec ); } /** * Get the details of a Streaming Policy in the Media Services account * @param resourceGroupName The name of the resource group within the Azure subscription. * @param accountName The Media Services account name. * @param streamingPolicyName The Streaming Policy name. * @param options The options parameters. */ get( resourceGroupName: string, accountName: string, streamingPolicyName: string, options?: StreamingPoliciesGetOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, accountName, streamingPolicyName, options }, getOperationSpec ); } /** * Create a Streaming Policy in the Media Services account * @param resourceGroupName The name of the resource group within the Azure subscription. * @param accountName The Media Services account name. * @param streamingPolicyName The Streaming Policy name. * @param parameters The request parameters * @param options The options parameters. */ create( resourceGroupName: string, accountName: string, streamingPolicyName: string, parameters: StreamingPolicy, options?: StreamingPoliciesCreateOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, accountName, streamingPolicyName, parameters, options }, createOperationSpec ); } /** * Deletes a Streaming Policy in the Media Services account * @param resourceGroupName The name of the resource group within the Azure subscription. * @param accountName The Media Services account name. * @param streamingPolicyName The Streaming Policy name. * @param options The options parameters. */ delete( resourceGroupName: string, accountName: string, streamingPolicyName: string, options?: StreamingPoliciesDeleteOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, accountName, streamingPolicyName, options }, deleteOperationSpec ); } /** * ListNext * @param resourceGroupName The name of the resource group within the Azure subscription. * @param accountName The Media Services account name. * @param nextLink The nextLink from the previous successful call to the List method. * @param options The options parameters. */ private _listNext( resourceGroupName: string, accountName: string, nextLink: string, options?: StreamingPoliciesListNextOptionalParams ): Promise { return this.client.sendOperationRequest( { resourceGroupName, accountName, nextLink, options }, listNextOperationSpec ); } } // Operation Specifications const serializer = coreClient.createSerializer(Mappers, /* isXml */ false); const listOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Media/mediaServices/{accountName}/streamingPolicies", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.StreamingPolicyCollection }, default: { bodyMapper: Mappers.ErrorResponse } }, queryParameters: [ Parameters.apiVersion, Parameters.filter, Parameters.top, Parameters.orderby ], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.accountName ], headerParameters: [Parameters.accept], serializer }; const getOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Media/mediaServices/{accountName}/streamingPolicies/{streamingPolicyName}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.StreamingPolicy }, default: { bodyMapper: Mappers.ErrorResponse } }, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.accountName, Parameters.streamingPolicyName ], headerParameters: [Parameters.accept], serializer }; const createOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Media/mediaServices/{accountName}/streamingPolicies/{streamingPolicyName}", httpMethod: "PUT", responses: { 201: { bodyMapper: Mappers.StreamingPolicy }, default: { bodyMapper: Mappers.ErrorResponse } }, requestBody: Parameters.parameters14, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.accountName, Parameters.streamingPolicyName ], headerParameters: [Parameters.accept, Parameters.contentType], mediaType: "json", serializer }; const deleteOperationSpec: coreClient.OperationSpec = { path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Media/mediaServices/{accountName}/streamingPolicies/{streamingPolicyName}", httpMethod: "DELETE", responses: { 200: {}, 204: {}, default: { bodyMapper: Mappers.ErrorResponse } }, queryParameters: [Parameters.apiVersion], urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.accountName, Parameters.streamingPolicyName ], headerParameters: [Parameters.accept], serializer }; const listNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.StreamingPolicyCollection }, default: { bodyMapper: Mappers.ErrorResponse } }, urlParameters: [ Parameters.$host, Parameters.subscriptionId, Parameters.resourceGroupName, Parameters.accountName, Parameters.nextLink ], headerParameters: [Parameters.accept], serializer };