mirror of
https://github.com/LukeHagar/plexswift.git
synced 2025-12-06 12:47:44 +00:00
87 lines
3.1 KiB
Swift
87 lines
3.1 KiB
Swift
// Code generated by Speakeasy (https://speakeasyapi.dev). 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 [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.GetTimelineResponseBody.self, from: data))
|
|
} catch {
|
|
throw ResponseHandlerError.failedToDecodeJSON(error)
|
|
}
|
|
}
|
|
}
|
|
|
|
return .empty
|
|
}
|
|
|
|
private func handleStartUniversalTranscodeResponse(response: Client.APIResponse) throws -> Operations.StartUniversalTranscodeResponse {
|
|
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.StartUniversalTranscodeResponseBody.self, from: data))
|
|
} catch {
|
|
throw ResponseHandlerError.failedToDecodeJSON(error)
|
|
}
|
|
}
|
|
}
|
|
|
|
return .empty
|
|
}
|
|
|