mirror of
https://github.com/LukeHagar/plexswift.git
synced 2025-12-06 04:20:52 +00:00
194 lines
7.0 KiB
Swift
194 lines
7.0 KiB
Swift
// Code generated by Speakeasy (https://speakeasyapi.dev). 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 .twoHundredApplicationJsonObject(try JSONDecoder().decode(Operations.GetButlerTasksResponseBody.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.GetButlerTasksButlerResponseBody.self, from: data))
|
|
} catch {
|
|
throw ResponseHandlerError.failedToDecodeJSON(error)
|
|
}
|
|
}
|
|
}
|
|
|
|
return .empty
|
|
}
|
|
|
|
private func handleStartAllTasksResponse(response: Client.APIResponse) throws -> Operations.StartAllTasksResponse {
|
|
let httpResponse = response.httpResponse
|
|
|
|
if [200, 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.StartAllTasksResponseBody.self, from: data))
|
|
} catch {
|
|
throw ResponseHandlerError.failedToDecodeJSON(error)
|
|
}
|
|
}
|
|
}
|
|
|
|
return .empty
|
|
}
|
|
|
|
private func handleStopAllTasksResponse(response: Client.APIResponse) throws -> Operations.StopAllTasksResponse {
|
|
let httpResponse = response.httpResponse
|
|
|
|
if [200, 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.StopAllTasksResponseBody.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, 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.StartTaskResponseBody.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, 400, 404].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.StopTaskResponseBody.self, from: data))
|
|
} catch {
|
|
throw ResponseHandlerError.failedToDecodeJSON(error)
|
|
}
|
|
}
|
|
}
|
|
|
|
return .empty
|
|
}
|
|
|