mirror of
https://github.com/LukeHagar/plexswift.git
synced 2025-12-06 12:47:44 +00:00
120 lines
4.3 KiB
Swift
120 lines
4.3 KiB
Swift
// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
|
|
|
|
|
|
import Foundation
|
|
|
|
class _UpdaterAPI: UpdaterAPI {
|
|
private let client: Client
|
|
|
|
init(client: Client) {
|
|
self.client = client
|
|
}
|
|
|
|
public func getUpdateStatus() async throws -> Response<Operations.GetUpdateStatusResponse> {
|
|
return try await client.makeRequest(
|
|
configureRequest: { configuration in
|
|
try configureGetUpdateStatusRequest(with: configuration)
|
|
},
|
|
handleResponse: handleGetUpdateStatusResponse
|
|
)
|
|
}
|
|
|
|
public func checkForUpdates(request: Operations.CheckForUpdatesRequest) async throws -> Response<Operations.CheckForUpdatesResponse> {
|
|
return try await client.makeRequest(
|
|
configureRequest: { configuration in
|
|
try configureCheckForUpdatesRequest(with: configuration, request: request)
|
|
},
|
|
handleResponse: handleCheckForUpdatesResponse
|
|
)
|
|
}
|
|
|
|
public func applyUpdates(request: Operations.ApplyUpdatesRequest) async throws -> Response<Operations.ApplyUpdatesResponse> {
|
|
return try await client.makeRequest(
|
|
configureRequest: { configuration in
|
|
try configureApplyUpdatesRequest(with: configuration, request: request)
|
|
},
|
|
handleResponse: handleApplyUpdatesResponse
|
|
)
|
|
}
|
|
|
|
}
|
|
|
|
// MARK: - Request Configuration
|
|
|
|
private func configureGetUpdateStatusRequest(with configuration: URLRequestConfiguration) throws {
|
|
configuration.path = "/updater/status"
|
|
configuration.method = .get
|
|
configuration.telemetryHeader = .userAgent
|
|
}
|
|
|
|
private func configureCheckForUpdatesRequest(with configuration: URLRequestConfiguration, request: Operations.CheckForUpdatesRequest) throws {
|
|
configuration.path = "/updater/check"
|
|
configuration.method = .put
|
|
configuration.queryParameterSerializable = request
|
|
configuration.telemetryHeader = .userAgent
|
|
}
|
|
|
|
private func configureApplyUpdatesRequest(with configuration: URLRequestConfiguration, request: Operations.ApplyUpdatesRequest) throws {
|
|
configuration.path = "/updater/apply"
|
|
configuration.method = .put
|
|
configuration.queryParameterSerializable = request
|
|
configuration.telemetryHeader = .userAgent
|
|
}
|
|
|
|
// MARK: - Response Handlers
|
|
|
|
private func handleGetUpdateStatusResponse(response: Client.APIResponse) throws -> Operations.GetUpdateStatusResponse {
|
|
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.GetUpdateStatusResponseBody.self, from: data))
|
|
} catch {
|
|
throw ResponseHandlerError.failedToDecodeJSON(error)
|
|
}
|
|
}
|
|
}
|
|
|
|
return .empty
|
|
}
|
|
|
|
private func handleCheckForUpdatesResponse(response: Client.APIResponse) throws -> Operations.CheckForUpdatesResponse {
|
|
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.CheckForUpdatesResponseBody.self, from: data))
|
|
} catch {
|
|
throw ResponseHandlerError.failedToDecodeJSON(error)
|
|
}
|
|
}
|
|
}
|
|
|
|
return .empty
|
|
}
|
|
|
|
private func handleApplyUpdatesResponse(response: Client.APIResponse) throws -> Operations.ApplyUpdatesResponse {
|
|
let httpResponse = response.httpResponse
|
|
|
|
if [200, 400, 500].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.ApplyUpdatesResponseBody.self, from: data))
|
|
} catch {
|
|
throw ResponseHandlerError.failedToDecodeJSON(error)
|
|
}
|
|
}
|
|
}
|
|
|
|
return .empty
|
|
}
|
|
|