/*
* 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 { StudentLabs } 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 {
StudentLabDetails,
StudentLabsListAllNextOptionalParams,
StudentLabsListAllOptionalParams,
StudentLabsListAllResponse,
StudentLabsGetOptionalParams,
StudentLabsGetResponse,
StudentLabsListAllNextResponse
} from "../models";
///
/** Class containing StudentLabs operations. */
export class StudentLabsImpl implements StudentLabs {
private readonly client: EducationManagementClient;
/**
* Initialize a new instance of the class StudentLabs class.
* @param client Reference to the service client
*/
constructor(client: EducationManagementClient) {
this.client = client;
}
/**
* Get a list of all labs associated with the caller of the API.
* @param options The options parameters.
*/
public listAll(
options?: StudentLabsListAllOptionalParams
): 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?: StudentLabsListAllOptionalParams,
settings?: PageSettings
): AsyncIterableIterator {
let result: StudentLabsListAllResponse;
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?: StudentLabsListAllOptionalParams
): AsyncIterableIterator {
for await (const page of this.listAllPagingPage(options)) {
yield* page;
}
}
/**
* Get a list of all labs associated with the caller of the API.
* @param options The options parameters.
*/
private _listAll(
options?: StudentLabsListAllOptionalParams
): Promise {
return this.client.sendOperationRequest({ options }, listAllOperationSpec);
}
/**
* Get the details for a specified lab associated with the student lab.
* @param studentLabName Student lab name.
* @param options The options parameters.
*/
get(
studentLabName: string,
options?: StudentLabsGetOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ studentLabName, 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?: StudentLabsListAllNextOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ nextLink, options },
listAllNextOperationSpec
);
}
}
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);
const listAllOperationSpec: coreClient.OperationSpec = {
path: "/providers/Microsoft.Education/studentLabs",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.StudentLabListResult
},
default: {
bodyMapper: Mappers.ErrorResponseBody
}
},
queryParameters: [Parameters.apiVersion],
urlParameters: [Parameters.$host],
headerParameters: [Parameters.accept],
serializer
};
const getOperationSpec: coreClient.OperationSpec = {
path: "/providers/Microsoft.Education/studentLabs/{studentLabName}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.StudentLabDetails
},
default: {
bodyMapper: Mappers.ErrorResponseBody
}
},
queryParameters: [Parameters.apiVersion],
urlParameters: [Parameters.$host, Parameters.studentLabName],
headerParameters: [Parameters.accept],
serializer
};
const listAllNextOperationSpec: coreClient.OperationSpec = {
path: "{nextLink}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.StudentLabListResult
},
default: {
bodyMapper: Mappers.ErrorResponseBody
}
},
urlParameters: [Parameters.$host, Parameters.nextLink],
headerParameters: [Parameters.accept],
serializer
};