// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT. import Foundation class _SessionsAPI: SessionsAPI { private let client: Client init(client: Client) { self.client = client } public func getSessions() async throws -> Response { return try await client.makeRequest( configureRequest: { configuration in try configureGetSessionsRequest(with: configuration) }, handleResponse: handleGetSessionsResponse ) } public func getSessionHistory(request: Operations.GetSessionHistoryRequest) async throws -> Response { return try await client.makeRequest( configureRequest: { configuration in try configureGetSessionHistoryRequest(with: configuration, request: request) }, handleResponse: handleGetSessionHistoryResponse ) } public func getTranscodeSessions() async throws -> Response { return try await client.makeRequest( configureRequest: { configuration in try configureGetTranscodeSessionsRequest(with: configuration) }, handleResponse: handleGetTranscodeSessionsResponse ) } public func stopTranscodeSession(request: Operations.StopTranscodeSessionRequest) async throws -> Response { return try await client.makeRequest( configureRequest: { configuration in try configureStopTranscodeSessionRequest(with: configuration, request: request) }, handleResponse: handleStopTranscodeSessionResponse ) } } // MARK: - Request Configuration private func configureGetSessionsRequest(with configuration: URLRequestConfiguration) throws { configuration.path = "/status/sessions" configuration.method = .get configuration.telemetryHeader = .userAgent } private func configureGetSessionHistoryRequest(with configuration: URLRequestConfiguration, request: Operations.GetSessionHistoryRequest) throws { configuration.path = "/status/sessions/history/all" configuration.method = .get configuration.queryParameterSerializable = request configuration.telemetryHeader = .userAgent } private func configureGetTranscodeSessionsRequest(with configuration: URLRequestConfiguration) throws { configuration.path = "/transcode/sessions" configuration.method = .get configuration.telemetryHeader = .userAgent } private func configureStopTranscodeSessionRequest(with configuration: URLRequestConfiguration, request: Operations.StopTranscodeSessionRequest) throws { configuration.path = "/transcode/sessions/{sessionKey}" configuration.method = .delete configuration.pathParameterSerializable = request configuration.telemetryHeader = .userAgent } // MARK: - Response Handlers private func handleGetSessionsResponse(response: Client.APIResponse) throws -> Operations.GetSessionsResponse { let httpResponse = response.httpResponse if httpResponse.statusCode == 200 { if httpResponse.contentType.matchContentType(pattern: "application/json"), let data = response.data { do { return .object(try JSONDecoder().decode(Operations.GetSessionsResponseBody.self, from: data)) } catch { throw ResponseHandlerError.failedToDecodeJSON(error) } } } else if httpResponse.statusCode == 400 { if httpResponse.contentType.matchContentType(pattern: "application/json"), let data = response.data { do { return .badRequest(try JSONDecoder().decode(Operations.GetSessionsBadRequest.self, from: data)) } catch { throw ResponseHandlerError.failedToDecodeJSON(error) } } } else if httpResponse.statusCode == 401 { if httpResponse.contentType.matchContentType(pattern: "application/json"), let data = response.data { do { return .unauthorized(try JSONDecoder().decode(Operations.GetSessionsUnauthorized.self, from: data)) } catch { throw ResponseHandlerError.failedToDecodeJSON(error) } } } return .empty } private func handleGetSessionHistoryResponse(response: Client.APIResponse) throws -> Operations.GetSessionHistoryResponse { let httpResponse = response.httpResponse if httpResponse.statusCode == 200 { if httpResponse.contentType.matchContentType(pattern: "application/json"), let data = response.data { do { return .object(try JSONDecoder().decode(Operations.GetSessionHistoryResponseBody.self, from: data)) } catch { throw ResponseHandlerError.failedToDecodeJSON(error) } } } else if httpResponse.statusCode == 400 { if httpResponse.contentType.matchContentType(pattern: "application/json"), let data = response.data { do { return .badRequest(try JSONDecoder().decode(Operations.GetSessionHistoryBadRequest.self, from: data)) } catch { throw ResponseHandlerError.failedToDecodeJSON(error) } } } else if httpResponse.statusCode == 401 { if httpResponse.contentType.matchContentType(pattern: "application/json"), let data = response.data { do { return .unauthorized(try JSONDecoder().decode(Operations.GetSessionHistoryUnauthorized.self, from: data)) } catch { throw ResponseHandlerError.failedToDecodeJSON(error) } } } return .empty } private func handleGetTranscodeSessionsResponse(response: Client.APIResponse) throws -> Operations.GetTranscodeSessionsResponse { let httpResponse = response.httpResponse if httpResponse.statusCode == 200 { if httpResponse.contentType.matchContentType(pattern: "application/json"), let data = response.data { do { return .object(try JSONDecoder().decode(Operations.GetTranscodeSessionsResponseBody.self, from: data)) } catch { throw ResponseHandlerError.failedToDecodeJSON(error) } } } else if httpResponse.statusCode == 400 { if httpResponse.contentType.matchContentType(pattern: "application/json"), let data = response.data { do { return .badRequest(try JSONDecoder().decode(Operations.GetTranscodeSessionsBadRequest.self, from: data)) } catch { throw ResponseHandlerError.failedToDecodeJSON(error) } } } else if httpResponse.statusCode == 401 { if httpResponse.contentType.matchContentType(pattern: "application/json"), let data = response.data { do { return .unauthorized(try JSONDecoder().decode(Operations.GetTranscodeSessionsUnauthorized.self, from: data)) } catch { throw ResponseHandlerError.failedToDecodeJSON(error) } } } return .empty } private func handleStopTranscodeSessionResponse(response: Client.APIResponse) throws -> Operations.StopTranscodeSessionResponse { let httpResponse = response.httpResponse if httpResponse.statusCode == 204 { return .empty } else if httpResponse.statusCode == 400 { if httpResponse.contentType.matchContentType(pattern: "application/json"), let data = response.data { do { return .badRequest(try JSONDecoder().decode(Operations.StopTranscodeSessionBadRequest.self, from: data)) } catch { throw ResponseHandlerError.failedToDecodeJSON(error) } } } else if httpResponse.statusCode == 401 { if httpResponse.contentType.matchContentType(pattern: "application/json"), let data = response.data { do { return .unauthorized(try JSONDecoder().decode(Operations.StopTranscodeSessionUnauthorized.self, from: data)) } catch { throw ResponseHandlerError.failedToDecodeJSON(error) } } } return .empty }