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

119 lines
4.0 KiB
Swift

// Code generated by Speakeasy (https://speakeasyapi.dev). 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() async throws -> Response<Operations.LogMultiLineResponse> {
return try await client.makeRequest(
configureRequest: { configuration in
try configureLogMultiLineRequest(with: configuration)
},
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) throws {
configuration.path = "/log"
configuration.method = .post
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 [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.LogLineResponseBody.self, from: data))
} catch {
throw ResponseHandlerError.failedToDecodeJSON(error)
}
}
}
return .empty
}
private func handleLogMultiLineResponse(response: Client.APIResponse) throws -> Operations.LogMultiLineResponse {
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.LogMultiLineResponseBody.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, 400, 403].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.EnablePaperTrailResponseBody.self, from: data))
} catch {
throw ResponseHandlerError.failedToDecodeJSON(error)
}
}
}
return .empty
}