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

103 lines
3.9 KiB
Swift

// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
import Foundation
class _VideoAPI: VideoAPI {
private let client: Client
init(client: Client) {
self.client = client
}
public func getTimeline(request: Operations.GetTimelineRequest) async throws -> Response<Operations.GetTimelineResponse> {
return try await client.makeRequest(
configureRequest: { configuration in
try configureGetTimelineRequest(with: configuration, request: request)
},
handleResponse: handleGetTimelineResponse
)
}
public func startUniversalTranscode(request: Operations.StartUniversalTranscodeRequest) async throws -> Response<Operations.StartUniversalTranscodeResponse> {
return try await client.makeRequest(
configureRequest: { configuration in
try configureStartUniversalTranscodeRequest(with: configuration, request: request)
},
handleResponse: handleStartUniversalTranscodeResponse
)
}
}
// MARK: - Request Configuration
private func configureGetTimelineRequest(with configuration: URLRequestConfiguration, request: Operations.GetTimelineRequest) throws {
configuration.path = "/:/timeline"
configuration.method = .get
configuration.queryParameterSerializable = request
configuration.telemetryHeader = .userAgent
}
private func configureStartUniversalTranscodeRequest(with configuration: URLRequestConfiguration, request: Operations.StartUniversalTranscodeRequest) throws {
configuration.path = "/video/:/transcode/universal/start.mpd"
configuration.method = .get
configuration.queryParameterSerializable = request
configuration.telemetryHeader = .userAgent
}
// MARK: - Response Handlers
private func handleGetTimelineResponse(response: Client.APIResponse) throws -> Operations.GetTimelineResponse {
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.GetTimelineBadRequest.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.GetTimelineUnauthorized.self, from: data))
} catch {
throw ResponseHandlerError.failedToDecodeJSON(error)
}
}
}
return .empty
}
private func handleStartUniversalTranscodeResponse(response: Client.APIResponse) throws -> Operations.StartUniversalTranscodeResponse {
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.StartUniversalTranscodeBadRequest.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.StartUniversalTranscodeUnauthorized.self, from: data))
} catch {
throw ResponseHandlerError.failedToDecodeJSON(error)
}
}
}
return .empty
}