Files
plexswift/Sources/Plexswift/internal/api/_LogAPI.swift

148 lines
5.4 KiB
Swift

// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
import Foundation
class _LogAPI: LogAPI {
private let client: Client
init(client: Client) {
self.client = client
}
public func logLine(request: Operations.LogLineRequest) async throws -> Response<Operations.LogLineResponse> {
return try await client.makeRequest(
configureRequest: { configuration in
try configureLogLineRequest(with: configuration, request: request)
},
handleResponse: handleLogLineResponse
)
}
public func logMultiLine(request: String) async throws -> Response<Operations.LogMultiLineResponse> {
return try await client.makeRequest(
configureRequest: { configuration in
try configureLogMultiLineRequest(with: configuration, request: request)
},
handleResponse: handleLogMultiLineResponse
)
}
public func enablePaperTrail() async throws -> Response<Operations.EnablePaperTrailResponse> {
return try await client.makeRequest(
configureRequest: { configuration in
try configureEnablePaperTrailRequest(with: configuration)
},
handleResponse: handleEnablePaperTrailResponse
)
}
}
// MARK: - Request Configuration
private func configureLogLineRequest(with configuration: URLRequestConfiguration, request: Operations.LogLineRequest) throws {
configuration.path = "/log"
configuration.method = .get
configuration.queryParameterSerializable = request
configuration.telemetryHeader = .userAgent
}
private func configureLogMultiLineRequest(with configuration: URLRequestConfiguration, request: String) throws {
configuration.path = "/log"
configuration.method = .post
configuration.contentType = "text/plain"
configuration.body = request.data(using: .utf8)
if configuration.body == nil {
throw SerializationError.missingRequiredRequestBody
}
configuration.telemetryHeader = .userAgent
}
private func configureEnablePaperTrailRequest(with configuration: URLRequestConfiguration) throws {
configuration.path = "/log/networked"
configuration.method = .get
configuration.telemetryHeader = .userAgent
}
// MARK: - Response Handlers
private func handleLogLineResponse(response: Client.APIResponse) throws -> Operations.LogLineResponse {
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.LogLineBadRequest.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.LogLineUnauthorized.self, from: data))
} catch {
throw ResponseHandlerError.failedToDecodeJSON(error)
}
}
}
return .empty
}
private func handleLogMultiLineResponse(response: Client.APIResponse) throws -> Operations.LogMultiLineResponse {
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.LogMultiLineBadRequest.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.LogMultiLineUnauthorized.self, from: data))
} catch {
throw ResponseHandlerError.failedToDecodeJSON(error)
}
}
}
return .empty
}
private func handleEnablePaperTrailResponse(response: Client.APIResponse) throws -> Operations.EnablePaperTrailResponse {
let httpResponse = response.httpResponse
if [200, 403].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.EnablePaperTrailBadRequest.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.EnablePaperTrailUnauthorized.self, from: data))
} catch {
throw ResponseHandlerError.failedToDecodeJSON(error)
}
}
}
return .empty
}