mirror of
https://github.com/LukeHagar/plexswift.git
synced 2025-12-06 12:47:44 +00:00
Cleaning and regenerating
This commit is contained in:
@@ -1,96 +0,0 @@
|
||||
// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
|
||||
|
||||
|
||||
import Foundation
|
||||
|
||||
class _PlexAPI: PlexAPI {
|
||||
private let client: Client
|
||||
|
||||
init(client: Client) {
|
||||
self.client = client
|
||||
}
|
||||
|
||||
public func getPin(request: Operations.GetPinRequest, server: PlexServers.GetPin?) async throws -> Response<Operations.GetPinResponse> {
|
||||
return try await client.makeRequest(
|
||||
with: try server?.server() ?? PlexServers.GetPin.default(),
|
||||
configureRequest: { configuration in
|
||||
try configureGetPinRequest(with: configuration, request: request)
|
||||
},
|
||||
handleResponse: handleGetPinResponse
|
||||
)
|
||||
}
|
||||
|
||||
public func getToken(request: Operations.GetTokenRequest, server: PlexServers.GetToken?) async throws -> Response<Operations.GetTokenResponse> {
|
||||
return try await client.makeRequest(
|
||||
with: try server?.server() ?? PlexServers.GetToken.default(),
|
||||
configureRequest: { configuration in
|
||||
try configureGetTokenRequest(with: configuration, request: request)
|
||||
},
|
||||
handleResponse: handleGetTokenResponse
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Request Configuration
|
||||
|
||||
private func configureGetPinRequest(with configuration: URLRequestConfiguration, request: Operations.GetPinRequest) throws {
|
||||
configuration.path = "/pins"
|
||||
configuration.method = .post
|
||||
configuration.queryParameterSerializable = request
|
||||
configuration.headerParameterSerializable = request
|
||||
configuration.telemetryHeader = .userAgent
|
||||
}
|
||||
|
||||
private func configureGetTokenRequest(with configuration: URLRequestConfiguration, request: Operations.GetTokenRequest) throws {
|
||||
configuration.path = "/pins/{pinID}"
|
||||
configuration.method = .get
|
||||
configuration.pathParameterSerializable = request
|
||||
configuration.headerParameterSerializable = request
|
||||
configuration.telemetryHeader = .userAgent
|
||||
}
|
||||
|
||||
// MARK: - Response Handlers
|
||||
|
||||
private func handleGetPinResponse(response: Client.APIResponse) throws -> Operations.GetPinResponse {
|
||||
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.GetPinResponseBody.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 .fourHundredApplicationJsonObject(try JSONDecoder().decode(Operations.GetPinPlexResponseBody.self, from: data))
|
||||
} catch {
|
||||
throw ResponseHandlerError.failedToDecodeJSON(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return .empty
|
||||
}
|
||||
|
||||
private func handleGetTokenResponse(response: Client.APIResponse) throws -> Operations.GetTokenResponse {
|
||||
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 .object(try JSONDecoder().decode(Operations.GetTokenResponseBody.self, from: data))
|
||||
} catch {
|
||||
throw ResponseHandlerError.failedToDecodeJSON(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return .empty
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user