mirror of
https://github.com/LukeHagar/plexswift.git
synced 2025-12-06 20:57:46 +00:00
232 lines
8.8 KiB
Swift
232 lines
8.8 KiB
Swift
// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
|
|
|
|
|
|
import Foundation
|
|
|
|
class _ButlerAPI: ButlerAPI {
|
|
private let client: Client
|
|
|
|
init(client: Client) {
|
|
self.client = client
|
|
}
|
|
|
|
public func getButlerTasks() async throws -> Response<Operations.GetButlerTasksResponse> {
|
|
return try await client.makeRequest(
|
|
configureRequest: { configuration in
|
|
try configureGetButlerTasksRequest(with: configuration)
|
|
},
|
|
handleResponse: handleGetButlerTasksResponse
|
|
)
|
|
}
|
|
|
|
public func startAllTasks() async throws -> Response<Operations.StartAllTasksResponse> {
|
|
return try await client.makeRequest(
|
|
configureRequest: { configuration in
|
|
try configureStartAllTasksRequest(with: configuration)
|
|
},
|
|
handleResponse: handleStartAllTasksResponse
|
|
)
|
|
}
|
|
|
|
public func stopAllTasks() async throws -> Response<Operations.StopAllTasksResponse> {
|
|
return try await client.makeRequest(
|
|
configureRequest: { configuration in
|
|
try configureStopAllTasksRequest(with: configuration)
|
|
},
|
|
handleResponse: handleStopAllTasksResponse
|
|
)
|
|
}
|
|
|
|
public func startTask(request: Operations.StartTaskRequest) async throws -> Response<Operations.StartTaskResponse> {
|
|
return try await client.makeRequest(
|
|
configureRequest: { configuration in
|
|
try configureStartTaskRequest(with: configuration, request: request)
|
|
},
|
|
handleResponse: handleStartTaskResponse
|
|
)
|
|
}
|
|
|
|
public func stopTask(request: Operations.StopTaskRequest) async throws -> Response<Operations.StopTaskResponse> {
|
|
return try await client.makeRequest(
|
|
configureRequest: { configuration in
|
|
try configureStopTaskRequest(with: configuration, request: request)
|
|
},
|
|
handleResponse: handleStopTaskResponse
|
|
)
|
|
}
|
|
|
|
}
|
|
|
|
// MARK: - Request Configuration
|
|
|
|
private func configureGetButlerTasksRequest(with configuration: URLRequestConfiguration) throws {
|
|
configuration.path = "/butler"
|
|
configuration.method = .get
|
|
configuration.telemetryHeader = .userAgent
|
|
}
|
|
|
|
private func configureStartAllTasksRequest(with configuration: URLRequestConfiguration) throws {
|
|
configuration.path = "/butler"
|
|
configuration.method = .post
|
|
configuration.telemetryHeader = .userAgent
|
|
}
|
|
|
|
private func configureStopAllTasksRequest(with configuration: URLRequestConfiguration) throws {
|
|
configuration.path = "/butler"
|
|
configuration.method = .delete
|
|
configuration.telemetryHeader = .userAgent
|
|
}
|
|
|
|
private func configureStartTaskRequest(with configuration: URLRequestConfiguration, request: Operations.StartTaskRequest) throws {
|
|
configuration.path = "/butler/{taskName}"
|
|
configuration.method = .post
|
|
configuration.pathParameterSerializable = request
|
|
configuration.telemetryHeader = .userAgent
|
|
}
|
|
|
|
private func configureStopTaskRequest(with configuration: URLRequestConfiguration, request: Operations.StopTaskRequest) throws {
|
|
configuration.path = "/butler/{taskName}"
|
|
configuration.method = .delete
|
|
configuration.pathParameterSerializable = request
|
|
configuration.telemetryHeader = .userAgent
|
|
}
|
|
|
|
// MARK: - Response Handlers
|
|
|
|
private func handleGetButlerTasksResponse(response: Client.APIResponse) throws -> Operations.GetButlerTasksResponse {
|
|
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.GetButlerTasksResponseBody.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.GetButlerTasksBadRequest.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.GetButlerTasksUnauthorized.self, from: data))
|
|
} catch {
|
|
throw ResponseHandlerError.failedToDecodeJSON(error)
|
|
}
|
|
}
|
|
}
|
|
|
|
return .empty
|
|
}
|
|
|
|
private func handleStartAllTasksResponse(response: Client.APIResponse) throws -> Operations.StartAllTasksResponse {
|
|
let httpResponse = response.httpResponse
|
|
|
|
if httpResponse.statusCode == 200 {
|
|
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.StartAllTasksBadRequest.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.StartAllTasksUnauthorized.self, from: data))
|
|
} catch {
|
|
throw ResponseHandlerError.failedToDecodeJSON(error)
|
|
}
|
|
}
|
|
}
|
|
|
|
return .empty
|
|
}
|
|
|
|
private func handleStopAllTasksResponse(response: Client.APIResponse) throws -> Operations.StopAllTasksResponse {
|
|
let httpResponse = response.httpResponse
|
|
|
|
if httpResponse.statusCode == 200 {
|
|
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.StopAllTasksBadRequest.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.StopAllTasksUnauthorized.self, from: data))
|
|
} catch {
|
|
throw ResponseHandlerError.failedToDecodeJSON(error)
|
|
}
|
|
}
|
|
}
|
|
|
|
return .empty
|
|
}
|
|
|
|
private func handleStartTaskResponse(response: Client.APIResponse) throws -> Operations.StartTaskResponse {
|
|
let httpResponse = response.httpResponse
|
|
|
|
if [200, 202].contains(httpResponse.statusCode) {
|
|
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.StartTaskBadRequest.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.StartTaskUnauthorized.self, from: data))
|
|
} catch {
|
|
throw ResponseHandlerError.failedToDecodeJSON(error)
|
|
}
|
|
}
|
|
}
|
|
|
|
return .empty
|
|
}
|
|
|
|
private func handleStopTaskResponse(response: Client.APIResponse) throws -> Operations.StopTaskResponse {
|
|
let httpResponse = response.httpResponse
|
|
|
|
if [200, 404].contains(httpResponse.statusCode) {
|
|
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.StopTaskBadRequest.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.StopTaskUnauthorized.self, from: data))
|
|
} catch {
|
|
throw ResponseHandlerError.failedToDecodeJSON(error)
|
|
}
|
|
}
|
|
}
|
|
|
|
return .empty
|
|
}
|
|
|