mirror of
https://github.com/LukeHagar/plexswift.git
synced 2025-12-09 20:57:45 +00:00
Regeneration
This commit is contained in:
121
Sources/Plexswift/internal/client/Response.swift
Normal file
121
Sources/Plexswift/internal/client/Response.swift
Normal file
@@ -0,0 +1,121 @@
|
||||
// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
|
||||
|
||||
import Foundation
|
||||
#if os(Linux)
|
||||
import FoundationNetworking
|
||||
#endif
|
||||
|
||||
/// Describes any header values returned as part of a response to a call made to the API.
|
||||
///
|
||||
/// As per the HTTP RFCs, header values can be queried in a case-insensitive manner.
|
||||
public struct ResponseHeaders {
|
||||
private let httpResponse: HTTPURLResponse
|
||||
|
||||
init(httpResponse: HTTPURLResponse) {
|
||||
self.httpResponse = httpResponse
|
||||
}
|
||||
|
||||
public func value(forHeaderNamed name: String) -> String? {
|
||||
return httpResponse.value(forHTTPHeaderField: name)
|
||||
}
|
||||
|
||||
public subscript(name: String) -> String? {
|
||||
return value(forHeaderNamed: name)
|
||||
}
|
||||
}
|
||||
|
||||
/// Describes the result of making a request to the API.
|
||||
///
|
||||
/// This type is returned by all functions which make calls to the API. It returns information about the response
|
||||
/// and is parameterised by `T` over the type of data which is returned by the API operation.
|
||||
public struct Response<T>: ResponseFields {
|
||||
|
||||
/// The HTTP status code returned by the server.
|
||||
///
|
||||
/// This property contains the HTTP status code returned by the server in response to the underlying network request
|
||||
/// made to fulfill the given API operation.
|
||||
public var statusCode: Int {
|
||||
return httpResponse.statusCode
|
||||
}
|
||||
|
||||
/// The media type returned by the server.
|
||||
///
|
||||
/// This property contains the media type returned by the server in response to the underlying network request
|
||||
/// made to fulfill the given API operation.
|
||||
public var contentType: String {
|
||||
return httpResponse.contentType
|
||||
}
|
||||
|
||||
/// The raw HTTP response object.
|
||||
///
|
||||
/// This property contains the [HTTPURLResponse](https://developer.apple.com/documentation/foundation/httpurlresponse) object
|
||||
/// returned from making the underlying network request to fulfill the given API operation.
|
||||
public let httpResponse: HTTPURLResponse
|
||||
|
||||
/// The response data.
|
||||
///
|
||||
/// This property contains any response data associated with the API operation.
|
||||
public let data: T
|
||||
|
||||
public init(httpResponse: HTTPURLResponse, data: T) {
|
||||
self.httpResponse = httpResponse
|
||||
self.data = data
|
||||
}
|
||||
}
|
||||
|
||||
/// Describes the result of making a request to the API which can contain resulting response header fields.
|
||||
///
|
||||
/// This type is returned by all functions which make calls to the API. It returns information about the response
|
||||
/// and is parameterised by `T` over the type of data which is returned by the API operation.
|
||||
public struct ResponseWithHeaders<T>: ResponseFields {
|
||||
|
||||
/// The HTTP status code returned by the server.
|
||||
///
|
||||
/// This property contains the HTTP status code returned by the server in response to the underlying network request
|
||||
/// made to fulfill the given API operation.
|
||||
public var statusCode: Int {
|
||||
return httpResponse.statusCode
|
||||
}
|
||||
|
||||
/// The media type returned by the server.
|
||||
///
|
||||
/// This property contains the media type returned by the server in response to the underlying network request
|
||||
/// made to fulfill the given API operation.
|
||||
public var contentType: String {
|
||||
return httpResponse.contentType
|
||||
}
|
||||
|
||||
/// The raw HTTP response object.
|
||||
///
|
||||
/// This property contains the [HTTPURLResponse](https://developer.apple.com/documentation/foundation/httpurlresponse) object
|
||||
/// returned from making the underlying network request to fulfill the given API operation.
|
||||
public let httpResponse: HTTPURLResponse
|
||||
|
||||
/// Any response headers returned by the underlying network request made to fulfill the given API operation.
|
||||
public let headers: ResponseHeaders?
|
||||
|
||||
/// The response data.
|
||||
///
|
||||
/// This property contains any response data associated with the API operation.
|
||||
public let data: T
|
||||
|
||||
public init(httpResponse: HTTPURLResponse, data: T) {
|
||||
self.httpResponse = httpResponse
|
||||
self.data = data
|
||||
self.headers = ResponseHeaders(httpResponse: httpResponse)
|
||||
}
|
||||
}
|
||||
|
||||
/// Describes the fields which are included in all responses to requests made to the API.
|
||||
///
|
||||
/// This protocol is adopted by ``Response`` and ``ResponseWithHeaders`` depending on the individual API operation.
|
||||
public protocol ResponseFields {
|
||||
associatedtype T;
|
||||
|
||||
var statusCode: Int { get }
|
||||
var contentType: String { get }
|
||||
var httpResponse: HTTPURLResponse { get }
|
||||
var data: T { get }
|
||||
|
||||
init(httpResponse: HTTPURLResponse, data: T)
|
||||
}
|
||||
60
Sources/Plexswift/internal/client/Servers.swift
Normal file
60
Sources/Plexswift/internal/client/Servers.swift
Normal file
@@ -0,0 +1,60 @@
|
||||
// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
|
||||
|
||||
import Foundation
|
||||
|
||||
struct Server {
|
||||
public let urlString: String
|
||||
}
|
||||
|
||||
protocol Servers {
|
||||
static var urlStrings: [String] { get }
|
||||
|
||||
static func `default`() throws -> Server
|
||||
static func server(at index: Int) throws -> Server
|
||||
static func server(at index: Int, substituting parameters: [String: String]?) throws -> Server
|
||||
}
|
||||
|
||||
protocol ServerConvertible {
|
||||
func server() throws -> Server
|
||||
}
|
||||
|
||||
enum ServerConversionError: Swift.Error {
|
||||
case `internal`
|
||||
case missingDefaultServer(serverType: String)
|
||||
case invalidServerIndex(serverType: String, index: Int)
|
||||
case missingServerParameterSubstitutionKey(_ key: String, serverString: String)
|
||||
}
|
||||
|
||||
extension Servers {
|
||||
static func `default`() throws -> Server {
|
||||
guard urlStrings.count > 0 else {
|
||||
throw ServerConversionError.missingDefaultServer(serverType: String(describing: self))
|
||||
}
|
||||
|
||||
return Server(urlString: urlStrings[0])
|
||||
}
|
||||
|
||||
static func server(at index: Int) throws -> Server {
|
||||
return try server(at: index, substituting: nil)
|
||||
}
|
||||
|
||||
static func server(at index: Int, substituting parameters: [String: String]?) throws -> Server {
|
||||
guard index >= 0 && index < urlStrings.count else {
|
||||
throw ServerConversionError.invalidServerIndex(serverType: String(describing: self), index: index)
|
||||
}
|
||||
if let parameters = parameters {
|
||||
do {
|
||||
return Server(urlString: try urlStrings[index].substituteComponents { key in parameters[key] })
|
||||
} catch let error as StringSubstitutionError {
|
||||
switch error {
|
||||
case .internal:
|
||||
throw ServerConversionError.internal
|
||||
case .missingParameter(named: let name, in: let string):
|
||||
throw ServerConversionError.missingServerParameterSubstitutionKey(name, serverString: string)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return Server(urlString: urlStrings[index])
|
||||
}
|
||||
}
|
||||
}
|
||||
154
Sources/Plexswift/internal/client/URLRequestBuilder.swift
Normal file
154
Sources/Plexswift/internal/client/URLRequestBuilder.swift
Normal file
@@ -0,0 +1,154 @@
|
||||
// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
|
||||
|
||||
|
||||
import Foundation
|
||||
#if os(Linux)
|
||||
import FoundationNetworking
|
||||
#endif
|
||||
|
||||
enum URLRequestBuilderError: Swift.Error {
|
||||
case internalError
|
||||
case invalidURL(String)
|
||||
case missingPathParameterSubstitutionKey(_ key: String, path: String)
|
||||
}
|
||||
|
||||
final class URLRequestBuilder: URLRequestConfiguration {
|
||||
private let baseURL: URL
|
||||
private let parameterDefaults: ParameterDefaults?
|
||||
private let defaultSecurityParameterProviding: SecurityParameterProviding?
|
||||
|
||||
var path: String = ""
|
||||
var method: URLRequestHTTPMethod = .get
|
||||
var contentType: String?
|
||||
|
||||
var securityParameterProviding: SecurityParameterProviding?
|
||||
|
||||
var pathParameterSerializable: PathParameterSerializable?
|
||||
var queryParameterSerializable: QueryParameterSerializable?
|
||||
var headerParameterSerializable: HeaderParameterSerializable?
|
||||
|
||||
var body: Data?
|
||||
|
||||
var telemetryHeader: TelemetryHeader = .userAgent
|
||||
|
||||
init(baseURL: URL, parameterDefaults: ParameterDefaults?, defaultSecurityParameterProviding: SecurityParameterProviding?) {
|
||||
self.baseURL = baseURL
|
||||
self.parameterDefaults = parameterDefaults
|
||||
self.defaultSecurityParameterProviding = defaultSecurityParameterProviding
|
||||
}
|
||||
|
||||
func build() throws -> URLRequest {
|
||||
guard var urlComponents = URLComponents(url: baseURL, resolvingAgainstBaseURL: true) else {
|
||||
throw URLRequestBuilderError.invalidURL(baseURL.absoluteString)
|
||||
}
|
||||
|
||||
try buildPathComponents(in: &urlComponents)
|
||||
|
||||
guard let url = urlComponents.url else {
|
||||
throw URLRequestBuilderError.invalidURL(baseURL.absoluteString)
|
||||
}
|
||||
|
||||
var urlRequest = URLRequest(url: url)
|
||||
if let headerParameterSerializable {
|
||||
for header in try headerParameterSerializable.serializedHeaderParameters() {
|
||||
urlRequest.setValue(header.serialized, forHTTPHeaderField: header.name)
|
||||
}
|
||||
}
|
||||
|
||||
urlRequest.httpMethod = method.rawValue
|
||||
urlRequest.httpBody = body
|
||||
|
||||
if let contentType {
|
||||
urlRequest.setValue(contentType, forHTTPHeaderField: "Content-Type")
|
||||
}
|
||||
|
||||
urlRequest.setValue("speakeasy-sdk/swift 0.1.2 2.302.1 0.0.3 plexswift", forHTTPHeaderField: telemetryHeader.headerName)
|
||||
|
||||
addSecurityParameters(to: &urlRequest)
|
||||
|
||||
return urlRequest
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func buildPathComponents(in urlComponents: inout URLComponents) throws {
|
||||
let (path, fragment) = parsePath(path)
|
||||
|
||||
if let pathParameterSerializable {
|
||||
urlComponents.path = (urlComponents.path as NSString).appendingPathComponent(
|
||||
try substitutePathParameters(in: path, with: pathParameterSerializable, parameterDefaults: parameterDefaults)
|
||||
)
|
||||
} else {
|
||||
urlComponents.path = (urlComponents.path as NSString).appendingPathComponent(path)
|
||||
}
|
||||
|
||||
if let queryParameterSerializable {
|
||||
urlComponents.percentEncodedQuery = queryString(
|
||||
from: try queryParameterSerializable.serializedQueryParameters(with: parameterDefaults, formatOverride: nil)
|
||||
)
|
||||
}
|
||||
|
||||
urlComponents.fragment = fragment
|
||||
}
|
||||
|
||||
private func parsePath(_ path: String) -> (path: String, fragment: String?) {
|
||||
let components = path.components(separatedBy: "#")
|
||||
guard let first = components.first else {
|
||||
return (path: "", fragment: nil)
|
||||
}
|
||||
return (path: first, fragment: components.count > 1 ? components[1] : nil)
|
||||
}
|
||||
|
||||
private func addSecurityParameters(to request: inout URLRequest) {
|
||||
guard let securityParameterProviding = securityParameterProviding ?? defaultSecurityParameterProviding else { return }
|
||||
|
||||
let parameters = securityParameterProviding.securityParameters()
|
||||
for parameter in parameters {
|
||||
switch parameter {
|
||||
case .httpBasic(username: let username, password: let password):
|
||||
if let username, let password, let encoded = "\(username):\(password)".data(using: .utf8)?.base64EncodedString() {
|
||||
request.addValue("Basic \(encoded)", forHTTPHeaderField: "Authorization")
|
||||
}
|
||||
case .httpBearer(value: let value):
|
||||
if let value {
|
||||
let headerValue = value.range(of: "Bearer ")?.lowerBound == value.startIndex ? value : "Bearer \(value)"
|
||||
request.addValue(headerValue, forHTTPHeaderField: "Authorization")
|
||||
}
|
||||
case .apiKey(name: let name, value: let value), .oauth2(name: let name, value: let value), .openIdConnect(name: let name, value: let value):
|
||||
if let value {
|
||||
request.addValue(value, forHTTPHeaderField: name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Substitute path parameters and rethrow `StringSubstitutionError`s as `URLRequestBuilderError`s.
|
||||
fileprivate func substitutePathParameters(
|
||||
in path: String,
|
||||
with pathParameterSerializable: PathParameterSerializable,
|
||||
parameterDefaults: ParameterDefaults?
|
||||
) throws -> String {
|
||||
do {
|
||||
let parameters = try pathParameterSerializable.serializedPathParameters(formatOverride: nil)
|
||||
return try path.substituteComponents { key in
|
||||
return try parameters[key] ?? parameterDefaults?.defaultSerializedPathParameter(for: key)
|
||||
}
|
||||
} catch let error as StringSubstitutionError {
|
||||
switch error {
|
||||
case .internal:
|
||||
throw URLRequestBuilderError.internalError
|
||||
case .missingParameter(named: let name, in: let string):
|
||||
throw URLRequestBuilderError.missingPathParameterSubstitutionKey(name, path: string)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate extension TelemetryHeader {
|
||||
var headerName: String {
|
||||
switch self {
|
||||
case .userAgent: return "User-Agent"
|
||||
case .speakeasyUserAgent: return "X-Speakeasy-User-Agent"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
|
||||
|
||||
import Foundation
|
||||
|
||||
enum URLRequestHTTPMethod: String {
|
||||
case get = "GET"
|
||||
case post = "POST"
|
||||
case put = "PUT"
|
||||
case patch = "PATCH"
|
||||
case delete = "DELETE"
|
||||
case head = "HEAD"
|
||||
case options = "OPTIONS"
|
||||
case trace = "TRACE"
|
||||
}
|
||||
|
||||
enum TelemetryHeader {
|
||||
case userAgent
|
||||
case speakeasyUserAgent
|
||||
}
|
||||
|
||||
protocol URLRequestConfiguration: AnyObject {
|
||||
var path: String { get set }
|
||||
var method: URLRequestHTTPMethod { get set }
|
||||
var contentType: String? { get set }
|
||||
|
||||
var securityParameterProviding: SecurityParameterProviding? { get set }
|
||||
|
||||
var pathParameterSerializable: PathParameterSerializable? { get set }
|
||||
var queryParameterSerializable: QueryParameterSerializable? { get set }
|
||||
var headerParameterSerializable: HeaderParameterSerializable? { get set }
|
||||
|
||||
var body: Data? { get set }
|
||||
|
||||
var telemetryHeader: TelemetryHeader { get set }
|
||||
}
|
||||
Reference in New Issue
Block a user