Files
plexswift/Sources/Plexswift/internal/api/_SessionsAPI.swift

203 lines
8.2 KiB
Swift

// 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<Operations.GetSessionsResponse> {
return try await client.makeRequest(
configureRequest: { configuration in
try configureGetSessionsRequest(with: configuration)
},
handleResponse: handleGetSessionsResponse
)
}
public func getSessionHistory(request: Operations.GetSessionHistoryRequest) async throws -> Response<Operations.GetSessionHistoryResponse> {
return try await client.makeRequest(
configureRequest: { configuration in
try configureGetSessionHistoryRequest(with: configuration, request: request)
},
handleResponse: handleGetSessionHistoryResponse
)
}
public func getTranscodeSessions() async throws -> Response<Operations.GetTranscodeSessionsResponse> {
return try await client.makeRequest(
configureRequest: { configuration in
try configureGetTranscodeSessionsRequest(with: configuration)
},
handleResponse: handleGetTranscodeSessionsResponse
)
}
public func stopTranscodeSession(request: Operations.StopTranscodeSessionRequest) async throws -> Response<Operations.StopTranscodeSessionResponse> {
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
}