CI / Build and test (push) Canceled after 0s
Documentation / Build documentation (push) Canceled after 0s
Documentation / Deploy to GitHub Pages (push) Canceled after 0s
This PR contains the work done to fix a cancellation-mapping bug in `AmiiboLiveClient`, bring the client under offline test coverage, add the conformances SwiftUI and persistence need, and moves CI and documentation publishing to GitHub Actions. All public API changes are additive.
### Fix
- `AmiiboLiveClient` reported an early task cancellation as `.unknown("CancellationError()")`. The OpenAPI runtime wraps every error in `ClientError`, so the `CancellationError` check never matched; it now also checks the wrapped error and throws `.cancelled`.
### Tests
- `ThrowingTransport` and `StubTransport` test doubles let the live client run offline. New tests cover error mapping, HTTP status → error mapping, `oneOf` object-vs-list decoding, `"amiibo": null`, sorting, filter → query encoding, `Platform`/`Release` mapping, and the date transcoder.
- Models gained `package` memberwise initializers so tests can build real fixtures without `@testable`. These are not public API.
- The test target now depends on `OpenAPIRuntime` and `HTTPTypes` (both already in the dependency graph).
### API
- Models are `Codable` and `Identifiable` (`Amiibo.id` is its `identifier`; the key/name models use `key`).
- Filters are `Hashable`.
### Documentation
- Doc comments trimmed library-wide; one repeated `- Throws:` sentence appeared 24 times. `Library.md` and the README tightened to match.
### CI and docs publishing
- `ci.yml`: build and offline tests on PRs and pushes to `main`.
- `live-tests.yml`: weekly and on-demand run against the live API.
- `docs.yml`: builds DocC on PRs, deploys to GitHub Pages on `main`. Pinned to Xcode 26 because swift-docc-plugin 1.5.0 fails to launch its tools under Xcode 27.
- The generated `docs/` folder (327 files) is removed from the repository and ignored.
Reviewed-on: #31
Co-authored-by: Javier Cicchelli <javier@rock-n-code.com>
95 lines
3.5 KiB
Swift
95 lines
3.5 KiB
Swift
// ===----------------------------------------------------------------------===
|
|
//
|
|
// This source file is part of the Amiibo Service open source project
|
|
//
|
|
// Copyright (c) 2026 Röck+Cöde VoF. and the Amiibo Service project authors
|
|
// Licensed under Apache license v2.0
|
|
//
|
|
// See LICENSE for license information
|
|
// See CONTRIBUTORS for the list of Amiibo Service project authors
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
// ===----------------------------------------------------------------------===
|
|
|
|
import Foundation
|
|
|
|
/// The entry point for fetching data from the Amiibo API.
|
|
///
|
|
/// It forwards every call to the ``AmiiboClient`` given at initialization, which defaults to ``AmiiboLiveClient``. Instances are `Sendable`.
|
|
public struct AmiiboService: Sendable {
|
|
|
|
// MARK: Properties
|
|
|
|
/// A client to interact with the endpoints.
|
|
private let client: any AmiiboClient
|
|
|
|
// MARK: Initializers
|
|
|
|
/// Initializes this service with a client.
|
|
/// - Parameter client: The client that performs the calls. Defaults to ``AmiiboLiveClient``.
|
|
public init(client: some AmiiboClient = AmiiboLiveClient()) {
|
|
self.client = client
|
|
}
|
|
|
|
// MARK: Functions
|
|
|
|
/// Gets a list of amiibo items based on a given filter.
|
|
/// - Parameter filter: A filter for the result.
|
|
/// - Returns: A list of filtered amiibo items.
|
|
/// - Throws: An ``AmiiboServiceError`` if the call fails.
|
|
public func getAmiibos(
|
|
_ filter: AmiiboFilter = .init()
|
|
) async throws(AmiiboServiceError) -> [Amiibo] {
|
|
try await client.getAmiibos(by: filter)
|
|
}
|
|
|
|
/// Gets a list of amiibo series based on a given filter.
|
|
/// - Parameter filter: A filter for the result.
|
|
/// - Returns: A list of filtered amiibo series.
|
|
/// - Throws: An ``AmiiboServiceError`` if the call fails.
|
|
public func getAmiiboSeries(
|
|
_ filter: AmiiboSeriesFilter = .init()
|
|
) async throws(AmiiboServiceError) -> [AmiiboSeries] {
|
|
try await client.getAmiiboSeries(by: filter)
|
|
}
|
|
|
|
/// Gets a list of amiibo types based on a given filter.
|
|
/// - Parameter filter: A filter for the result.
|
|
/// - Returns: A list of filtered amiibo types.
|
|
/// - Throws: An ``AmiiboServiceError`` if the call fails.
|
|
public func getAmiiboTypes(
|
|
_ filter: AmiiboTypeFilter = .init()
|
|
) async throws(AmiiboServiceError) -> [AmiiboType] {
|
|
try await client.getAmiiboTypes(by: filter)
|
|
}
|
|
|
|
/// Gets a list of game characters based on a given filter.
|
|
/// - Parameter filter: A filter for the result.
|
|
/// - Returns: A list of filtered game characters.
|
|
/// - Throws: An ``AmiiboServiceError`` if the call fails.
|
|
public func getGameCharacters(
|
|
_ filter: GameCharacterFilter = .init()
|
|
) async throws(AmiiboServiceError) -> [GameCharacter] {
|
|
try await client.getGameCharacters(by: filter)
|
|
}
|
|
|
|
/// Gets a list of game series based on a given filter.
|
|
/// - Parameter filter: A filter for the result.
|
|
/// - Returns: A list of filtered game series.
|
|
/// - Throws: An ``AmiiboServiceError`` if the call fails.
|
|
public func getGameSeries(
|
|
_ filter: GameSeriesFilter = .init()
|
|
) async throws(AmiiboServiceError) -> [GameSeries] {
|
|
try await client.getGameSeries(by: filter)
|
|
}
|
|
|
|
/// Gets the date when the data was last updated.
|
|
/// - Returns: A last updated date, decoded as UTC.
|
|
/// - Throws: An ``AmiiboServiceError`` if the call fails.
|
|
public func getLastUpdated() async throws(AmiiboServiceError) -> Date {
|
|
try await client.getLastUpdated()
|
|
}
|
|
|
|
}
|