mirror of
https://github.com/LukeHagar/plexswift.git
synced 2025-12-09 12:47:44 +00:00
Regeneration
This commit is contained in:
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])
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user