diff --git a/.speakeasy/gen.lock b/.speakeasy/gen.lock index 9c0a40c..8befdfc 100755 --- a/.speakeasy/gen.lock +++ b/.speakeasy/gen.lock @@ -1,18 +1,19 @@ lockVersion: 2.0.0 id: 5d77204e-e413-4fd0-a14a-bad3aee2247a management: - docChecksum: e34dac84738ebf2d447ea2b9055a6eeb + docChecksum: a91eaf9ec1e6a3a6f4bf0571f5b18bae docVersion: 0.0.3 - speakeasyVersion: 1.213.0 - generationVersion: 2.283.1 - releaseVersion: 0.0.2 - configChecksum: 9eb228df4cab70cbab8695a6a5458559 + speakeasyVersion: 1.228.1 + generationVersion: 2.292.0 + releaseVersion: 0.1.0 + configChecksum: b2cfa34ed4663bdec9d08c57f8e59960 repoURL: https://github.com/LukeHagar/plexswift.git features: swift: core: 3.2.2 globalSecurity: 2.81.5 globalServerURLs: 2.82.1 + globals: 2.81.3 methodServerURLs: 3.0.1 nameOverrides: 2.81.1 generatedFiles: @@ -32,6 +33,7 @@ generatedFiles: - Sources/Plexswift/internal/api/_SessionsAPI.swift - Sources/Plexswift/internal/api/_UpdaterAPI.swift - Sources/Plexswift/configuration/GlobalServer.swift + - Sources/Plexswift/configuration/GlobalParameters.swift - Sources/Plexswift/Client.swift - Package.swift - Sources/plexswift/AnyValue.swift diff --git a/.speakeasy/gen.yaml b/.speakeasy/gen.yaml index 638d717..85dc82d 100644 --- a/.speakeasy/gen.yaml +++ b/.speakeasy/gen.yaml @@ -12,7 +12,7 @@ generation: auth: oAuth2ClientCredentialsEnabled: true swift: - version: 0.0.2 + version: 0.1.0 author: LukeHagar description: Swift Client SDK Generated by Speakeasy imports: diff --git a/README.md b/README.md index e14da5e..7be4411 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ You can add `plexswift` to your project directly in Xcode `(File > Add Packages. ```bash dependencies: [ - .package(url: "https://github.com/LukeHagar/plexswift.git", .upToNextMajor(from: "0.0.2")) + .package(url: "https://github.com/LukeHagar/plexswift.git", .upToNextMajor(from: "0.1.0")) ] ``` @@ -106,6 +106,55 @@ case .empty: ``` + +## Global Parameters + +A parameter is configured globally. This parameter must be set on the SDK client instance itself during initialization. When configured as an option during SDK initialization, This global value will be used as the default on the operations that use it. When such operations are called, there is a place in each to override the global value, if needed. + +For example, you can set `X-Plex-Client-Identifier` to `""` at SDK initialization and then you do not have to pass the same value on calls to operations like `getPin`. But if you want to do so you may, which will locally override the global setting. See the example code below for a demonstration. + + +### Available Globals + +The following global parameter is available. The required parameter must be set when you initialize the SDK client. + +| Name | Type | Required | Description | +| ---- | ---- |:--------:| ----------- | +| xPlexClientIdentifier | String | ✔️ | The unique identifier for the client application +This is used to track the client application and its usage +(UUID, serial number, or other number unique per device) + | + + +### Example + +```swift +import Foundation +import Plexswift + +let client = Client() + +let response = try await client.plex.getPin( + request: Operations.GetPinRequest( + strong: false, + ) +) + +switch response.data { +case .twoHundredApplicationJsonObject(let twoHundredApplicationJsonObject): + // Handle response + break +case .fourHundredApplicationJsonObject(let fourHundredApplicationJsonObject): + // Handle response + break +case .empty: + // Handle empty response + break +} + +``` + + # Development diff --git a/RELEASES.md b/RELEASES.md index 7184762..dd4a489 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -6,4 +6,12 @@ Based on: - OpenAPI Doc - Speakeasy CLI 1.213.0 (2.283.1) https://github.com/speakeasy-api/speakeasy ### Generated -- [swift v0.0.2] . \ No newline at end of file +- [swift v0.0.2] . + +## 2024-03-29 16:36:48 +### Changes +Based on: +- OpenAPI Doc +- Speakeasy CLI 1.228.1 (2.292.0) https://github.com/speakeasy-api/speakeasy +### Generated +- [swift v0.1.0] . \ No newline at end of file diff --git a/Sources/Plexswift/Client.swift b/Sources/Plexswift/Client.swift index 02ada6d..a7e13e1 100644 --- a/Sources/Plexswift/Client.swift +++ b/Sources/Plexswift/Client.swift @@ -50,7 +50,7 @@ import FoundationNetworking /// /// ### Initializers /// -/// - ``init(security:)`` +/// - ``init(globalParameters:security:)`` /// /// ### API calls /// @@ -88,12 +88,14 @@ public final class Client { // Underscore-prefix properties so these do not potentially conflict with any operation namespaces. private lazy var _session = URLSession(configuration: .default) + private var _globalParameters: GlobalParameters? private var _security: Shared.Security private var _selectedServer: GlobalServers? /// Creates an API client object with the specified parameters. - public init(security: Shared.Security) { + public init(globalParameters: GlobalParameters? = nil, security: Shared.Security) { + self._globalParameters = globalParameters self._security = security } @@ -163,7 +165,7 @@ public final class Client { do { let builder = URLRequestBuilder( baseURL: try baseURL(serverOverride: server), - parameterDefaults: nil, + parameterDefaults: _globalParameters, defaultSecurityParameterProviding: _security ) try configureRequest(builder) diff --git a/Sources/Plexswift/Plexswift.docc/Plexswift.md b/Sources/Plexswift/Plexswift.docc/Plexswift.md index a849ddc..fe657a5 100644 --- a/Sources/Plexswift/Plexswift.docc/Plexswift.md +++ b/Sources/Plexswift/Plexswift.docc/Plexswift.md @@ -40,6 +40,7 @@ case .empty: ### Connecting to the API - ``Client`` +- ``GlobalParameters`` - ``Shared/Security`` - ``Response`` - ``ResponseWithHeaders`` diff --git a/Sources/Plexswift/configuration/GlobalParameters.swift b/Sources/Plexswift/configuration/GlobalParameters.swift new file mode 100644 index 0000000..24955d5 --- /dev/null +++ b/Sources/Plexswift/configuration/GlobalParameters.swift @@ -0,0 +1,37 @@ +// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT. + +import Foundation + +/// Describes common parameters which can be used when making API requests. +/// +/// > Note: These parameters may be overridden by individual API operations +public struct GlobalParameters { + public let xPlexClientIdentifier: String? + + /// Creates an object with the given parameters + /// + /// - Parameter xPlexClientIdentifier: The unique identifier for the client application + /// This is used to track the client application and its usage + /// (UUID, serial number, or other number unique per device) + /// + /// + public init( + xPlexClientIdentifier: String? = nil + ) { + self.xPlexClientIdentifier = xPlexClientIdentifier + } +} + +extension GlobalParameters: ParameterDefaults { + public func defaultSerializedPathParameter(for key: String) throws -> String? { + switch key { + default: return nil + } + } + + public func defaultQueryParameter(for key: String) -> AnyValue? { + switch key { + default: return nil + } + } +} diff --git a/Sources/Plexswift/internal/models/GetPinRequest+Serialization.swift b/Sources/Plexswift/internal/models/GetPinRequest+Serialization.swift index c8917ba..c9ef89d 100644 --- a/Sources/Plexswift/internal/models/GetPinRequest+Serialization.swift +++ b/Sources/Plexswift/internal/models/GetPinRequest+Serialization.swift @@ -31,7 +31,7 @@ extension Operations.GetPinRequest: QueryParameterSerializable { extension Operations.GetPinRequest: HeaderParameterSerializable { func serializedHeaderParameters() throws -> [SerializedParameter] { return [ - SerializedParameter(name: "X-Plex-Client-Identifier", serialized: try xPlexClientIdentifier.serialize(with: .header(explode: false))) + SerializedParameter(name: "X-Plex-Client-Identifier", serialized: try xPlexClientIdentifier?.serialize(with: .header(explode: false))) ] } } diff --git a/Sources/Plexswift/internal/models/GetTokenRequest+Serialization.swift b/Sources/Plexswift/internal/models/GetTokenRequest+Serialization.swift index 11eb05d..943d5c9 100644 --- a/Sources/Plexswift/internal/models/GetTokenRequest+Serialization.swift +++ b/Sources/Plexswift/internal/models/GetTokenRequest+Serialization.swift @@ -27,7 +27,7 @@ extension Operations.GetTokenRequest: PathParameterSerializable { extension Operations.GetTokenRequest: HeaderParameterSerializable { func serializedHeaderParameters() throws -> [SerializedParameter] { return [ - SerializedParameter(name: "X-Plex-Client-Identifier", serialized: try xPlexClientIdentifier.serialize(with: .header(explode: false))) + SerializedParameter(name: "X-Plex-Client-Identifier", serialized: try xPlexClientIdentifier?.serialize(with: .header(explode: false))) ] } } diff --git a/Sources/Plexswift/models/operations/GetPinRequest.swift b/Sources/Plexswift/models/operations/GetPinRequest.swift index 42fcef8..a96e8e5 100644 --- a/Sources/Plexswift/models/operations/GetPinRequest.swift +++ b/Sources/Plexswift/models/operations/GetPinRequest.swift @@ -5,31 +5,31 @@ import Foundation extension Operations { /// A model object public struct GetPinRequest: APIValue { - /// The unique identifier for the client application - /// This is used to track the client application and its usage - /// (UUID, serial number, or other number unique per device) - /// - public let xPlexClientIdentifier: String /// Determines the kind of code returned by the API call /// Strong codes are used for Pin authentication flows /// Non-Strong codes are used for `Plex.tv/link` /// public let strong: Bool? - - /// Creates an object with the specified parameters - /// - /// - Parameter xPlexClientIdentifier: The unique identifier for the client application + /// The unique identifier for the client application /// This is used to track the client application and its usage /// (UUID, serial number, or other number unique per device) /// + public let xPlexClientIdentifier: String? + + /// Creates an object with the specified parameters + /// /// - Parameter strong: Determines the kind of code returned by the API call /// Strong codes are used for Pin authentication flows /// Non-Strong codes are used for `Plex.tv/link` /// + /// - Parameter xPlexClientIdentifier: The unique identifier for the client application + /// This is used to track the client application and its usage + /// (UUID, serial number, or other number unique per device) + /// /// - public init(xPlexClientIdentifier: String, strong: Bool? = nil) { - self.xPlexClientIdentifier = xPlexClientIdentifier + public init(strong: Bool? = nil, xPlexClientIdentifier: String? = nil) { self.strong = strong + self.xPlexClientIdentifier = xPlexClientIdentifier } } } diff --git a/Sources/Plexswift/models/operations/GetTokenRequest.swift b/Sources/Plexswift/models/operations/GetTokenRequest.swift index c61280e..90d951c 100644 --- a/Sources/Plexswift/models/operations/GetTokenRequest.swift +++ b/Sources/Plexswift/models/operations/GetTokenRequest.swift @@ -11,7 +11,7 @@ extension Operations { /// This is used to track the client application and its usage /// (UUID, serial number, or other number unique per device) /// - public let xPlexClientIdentifier: String + public let xPlexClientIdentifier: String? /// Creates an object with the specified parameters /// @@ -21,7 +21,7 @@ extension Operations { /// (UUID, serial number, or other number unique per device) /// /// - public init(pinID: String, xPlexClientIdentifier: String) { + public init(pinID: String, xPlexClientIdentifier: String? = nil) { self.pinID = pinID self.xPlexClientIdentifier = xPlexClientIdentifier } diff --git a/Sources/plexswift/internal/client/URLRequestBuilder.swift b/Sources/plexswift/internal/client/URLRequestBuilder.swift index fa3377a..9909993 100644 --- a/Sources/plexswift/internal/client/URLRequestBuilder.swift +++ b/Sources/plexswift/internal/client/URLRequestBuilder.swift @@ -62,7 +62,7 @@ final class URLRequestBuilder: URLRequestConfiguration { urlRequest.setValue(contentType, forHTTPHeaderField: "Content-Type") } - urlRequest.setValue("speakeasy-sdk/swift 0.0.2 2.283.1 0.0.3 plexswift", forHTTPHeaderField: telemetryHeader.headerName) + urlRequest.setValue("speakeasy-sdk/swift 0.1.0 2.292.0 0.0.3 plexswift", forHTTPHeaderField: telemetryHeader.headerName) addSecurityParameters(to: &urlRequest)