mirror of
https://github.com/LukeHagar/plexswift.git
synced 2025-12-06 12:47:44 +00:00
176 lines
6.8 KiB
Swift
176 lines
6.8 KiB
Swift
// Code generated by Speakeasy (https://speakeasyapi.dev). 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() async throws -> Response<Operations.GetSessionHistoryResponse> {
|
|
return try await client.makeRequest(
|
|
configureRequest: { configuration in
|
|
try configureGetSessionHistoryRequest(with: configuration)
|
|
},
|
|
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) throws {
|
|
configuration.path = "/status/sessions/history/all"
|
|
configuration.method = .get
|
|
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 .twoHundredApplicationJsonObject(try JSONDecoder().decode(Operations.GetSessionsResponseBody.self, from: data))
|
|
} catch {
|
|
throw ResponseHandlerError.failedToDecodeJSON(error)
|
|
}
|
|
}
|
|
} else if httpResponse.statusCode == 400 {
|
|
return .empty
|
|
} else if httpResponse.statusCode == 401 {
|
|
if httpResponse.contentType.matchContentType(pattern: "application/json"), let data = response.data {
|
|
do {
|
|
return .fourHundredAndOneApplicationJsonObject(try JSONDecoder().decode(Operations.GetSessionsSessionsResponseBody.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 .twoHundredApplicationJsonObject(try JSONDecoder().decode(Operations.GetSessionHistoryResponseBody.self, from: data))
|
|
} catch {
|
|
throw ResponseHandlerError.failedToDecodeJSON(error)
|
|
}
|
|
}
|
|
} else if httpResponse.statusCode == 400 {
|
|
return .empty
|
|
} else if httpResponse.statusCode == 401 {
|
|
if httpResponse.contentType.matchContentType(pattern: "application/json"), let data = response.data {
|
|
do {
|
|
return .fourHundredAndOneApplicationJsonObject(try JSONDecoder().decode(Operations.GetSessionHistorySessionsResponseBody.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 .twoHundredApplicationJsonObject(try JSONDecoder().decode(Operations.GetTranscodeSessionsResponseBody.self, from: data))
|
|
} catch {
|
|
throw ResponseHandlerError.failedToDecodeJSON(error)
|
|
}
|
|
}
|
|
} else if httpResponse.statusCode == 400 {
|
|
return .empty
|
|
} else if httpResponse.statusCode == 401 {
|
|
if httpResponse.contentType.matchContentType(pattern: "application/json"), let data = response.data {
|
|
do {
|
|
return .fourHundredAndOneApplicationJsonObject(try JSONDecoder().decode(Operations.GetTranscodeSessionsSessionsResponseBody.self, from: data))
|
|
} catch {
|
|
throw ResponseHandlerError.failedToDecodeJSON(error)
|
|
}
|
|
}
|
|
}
|
|
|
|
return .empty
|
|
}
|
|
|
|
private func handleStopTranscodeSessionResponse(response: Client.APIResponse) throws -> Operations.StopTranscodeSessionResponse {
|
|
let httpResponse = response.httpResponse
|
|
|
|
if [204, 400].contains(httpResponse.statusCode) {
|
|
return .empty
|
|
} else if httpResponse.statusCode == 401 {
|
|
if httpResponse.contentType.matchContentType(pattern: "application/json"), let data = response.data {
|
|
do {
|
|
return .object(try JSONDecoder().decode(Operations.StopTranscodeSessionResponseBody.self, from: data))
|
|
} catch {
|
|
throw ResponseHandlerError.failedToDecodeJSON(error)
|
|
}
|
|
}
|
|
}
|
|
|
|
return .empty
|
|
}
|
|
|