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

202 lines
8.6 KiB
Swift

// Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
import Foundation
class _AuthenticationAPI: AuthenticationAPI {
private let client: Client
init(client: Client) {
self.client = client
}
public func getTransientToken(request: Operations.GetTransientTokenRequest) async throws -> Response<Operations.GetTransientTokenResponse> {
return try await client.makeRequest(
configureRequest: { configuration in
try configureGetTransientTokenRequest(with: configuration, request: request)
},
handleResponse: handleGetTransientTokenResponse
)
}
public func getSourceConnectionInformation(request: Operations.GetSourceConnectionInformationRequest) async throws -> Response<Operations.GetSourceConnectionInformationResponse> {
return try await client.makeRequest(
configureRequest: { configuration in
try configureGetSourceConnectionInformationRequest(with: configuration, request: request)
},
handleResponse: handleGetSourceConnectionInformationResponse
)
}
public func getTokenDetails(server: AuthenticationServers.GetTokenDetails?) async throws -> Response<Operations.GetTokenDetailsResponse> {
return try await client.makeRequest(
with: try server?.server() ?? AuthenticationServers.GetTokenDetails.default(),
configureRequest: { configuration in
try configureGetTokenDetailsRequest(with: configuration)
},
handleResponse: handleGetTokenDetailsResponse
)
}
public func postUsersSignInData(request: Operations.PostUsersSignInDataRequest, server: AuthenticationServers.PostUsersSignInData?) async throws -> Response<Operations.PostUsersSignInDataResponse> {
return try await client.makeRequest(
with: try server?.server() ?? AuthenticationServers.PostUsersSignInData.default(),
configureRequest: { configuration in
try configurePostUsersSignInDataRequest(with: configuration, request: request)
},
handleResponse: handlePostUsersSignInDataResponse
)
}
}
// MARK: - Request Configuration
private func configureGetTransientTokenRequest(with configuration: URLRequestConfiguration, request: Operations.GetTransientTokenRequest) throws {
configuration.path = "/security/token"
configuration.method = .get
configuration.queryParameterSerializable = request
configuration.telemetryHeader = .userAgent
}
private func configureGetSourceConnectionInformationRequest(with configuration: URLRequestConfiguration, request: Operations.GetSourceConnectionInformationRequest) throws {
configuration.path = "/security/resources"
configuration.method = .get
configuration.queryParameterSerializable = request
configuration.telemetryHeader = .userAgent
}
private func configureGetTokenDetailsRequest(with configuration: URLRequestConfiguration) throws {
configuration.path = "/user"
configuration.method = .get
configuration.telemetryHeader = .userAgent
}
private func configurePostUsersSignInDataRequest(with configuration: URLRequestConfiguration, request: Operations.PostUsersSignInDataRequest) throws {
configuration.path = "/users/signin"
configuration.method = .post
configuration.headerParameterSerializable = request
configuration.contentType = "application/x-www-form-urlencoded"
configuration.body = try serializeFormData(with: request.requestBody)
configuration.telemetryHeader = .userAgent
}
// MARK: - Response Handlers
private func handleGetTransientTokenResponse(response: Client.APIResponse) throws -> Operations.GetTransientTokenResponse {
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.GetTransientTokenBadRequest.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.GetTransientTokenUnauthorized.self, from: data))
} catch {
throw ResponseHandlerError.failedToDecodeJSON(error)
}
}
}
return .empty
}
private func handleGetSourceConnectionInformationResponse(response: Client.APIResponse) throws -> Operations.GetSourceConnectionInformationResponse {
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.GetSourceConnectionInformationBadRequest.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.GetSourceConnectionInformationUnauthorized.self, from: data))
} catch {
throw ResponseHandlerError.failedToDecodeJSON(error)
}
}
}
return .empty
}
private func handleGetTokenDetailsResponse(response: Client.APIResponse) throws -> Operations.GetTokenDetailsResponse {
let httpResponse = response.httpResponse
if httpResponse.statusCode == 200 {
if httpResponse.contentType.matchContentType(pattern: "application/json"), let data = response.data {
do {
return .userPlexAccount(try JSONDecoder().decode(Operations.GetTokenDetailsUserPlexAccount.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 .badRequest(try JSONDecoder().decode(Operations.GetTokenDetailsBadRequest.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.GetTokenDetailsUnauthorized.self, from: data))
} catch {
throw ResponseHandlerError.failedToDecodeJSON(error)
}
}
}
return .empty
}
private func handlePostUsersSignInDataResponse(response: Client.APIResponse) throws -> Operations.PostUsersSignInDataResponse {
let httpResponse = response.httpResponse
if httpResponse.statusCode == 201 {
if httpResponse.contentType.matchContentType(pattern: "application/json"), let data = response.data {
do {
return .userPlexAccount(try JSONDecoder().decode(Operations.PostUsersSignInDataUserPlexAccount.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 .badRequest(try JSONDecoder().decode(Operations.PostUsersSignInDataBadRequest.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.PostUsersSignInDataUnauthorized.self, from: data))
} catch {
throw ResponseHandlerError.failedToDecodeJSON(error)
}
}
}
return .empty
}