34627840db
This PR contains the work done to: * update the header files of all the existing source files in the project with the Apache License; * update the main article of the `DocC` documentation catalog; * update the `README` file; * regenerate the Github Pages documentation from the `DocC` documentation catalog. Reviewed-on: #18 Co-authored-by: Javier Cicchelli <javier@rock-n-code.com> Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
152 lines
6.5 KiB
Swift
152 lines
6.5 KiB
Swift
// ===----------------------------------------------------------------------===
|
|
//
|
|
// This source file is part of the Amiibo Service open source project
|
|
//
|
|
// Copyright (c) 2025 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
|
|
|
|
/// A type that implements the service that uses a client to make calls.
|
|
public struct AmiiboService {
|
|
|
|
// MARK: Properties
|
|
|
|
/// A client to interact with the endpoints.
|
|
private let client: any AmiiboClient
|
|
|
|
// MARK: Initializers
|
|
|
|
/// Initializes this service with a specific client type.
|
|
/// - Parameter client: A client to use to interact with the endpoints.
|
|
public init(client: some AmiiboClient = AmiiboLiveClient()) {
|
|
self.client = client
|
|
}
|
|
|
|
// MARK: Functions
|
|
|
|
#if swift(>=6.0)
|
|
/// Gets a list of amiibo items based on a given filter.
|
|
/// - Parameter filter: A filter to remove unwanted items from the result.
|
|
/// - Returns: A list of filtered amiibo items.
|
|
/// - Throws: An ``AmiiboServiceError`` error in case some issue is encountered while generating the result.
|
|
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 to remove unwanted items from the result.
|
|
/// - Returns: A list of filtered amiibo series.
|
|
/// - Throws: An ``AmiiboServiceError`` error in case some issue is encountered while generating the result.
|
|
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 to remove unwanted items from the result.
|
|
/// - Returns: A list of filtered amiibo types.
|
|
/// - Throws: An ``AmiiboServiceError`` error in case some issue is encountered while generating the result.
|
|
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 to remove unwanted items from the result.
|
|
/// - Returns: A list of filtered game characters.
|
|
/// - Throws: An ``AmiiboServiceError`` error in case some issue is encountered while generating the result.
|
|
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 to remove unwanted items from the result.
|
|
/// - Returns: A list of filtered game series.
|
|
/// - Throws: An ``AmiiboServiceError`` error in case some issue is encountered while generating the result.
|
|
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.
|
|
/// - Throws: An ``AmiiboServiceError`` error in case some issue is encountered while generating the result.
|
|
public func getLastUpdated() async throws(AmiiboServiceError) -> Date {
|
|
try await client.getLastUpdated()
|
|
}
|
|
#else
|
|
/// Gets a list of amiibo items based on a given filter.
|
|
/// - Parameter filter: A filter to remove unwanted items from the result.
|
|
/// - Returns: A list of filtered amiibo items.
|
|
/// - Throws: An ``AmiiboServiceError`` error in case some issue is encountered while generating the result.
|
|
public func getAmiibos(
|
|
_ filter: AmiiboFilter = .init()
|
|
) async throws -> [Amiibo] {
|
|
try await client.getAmiibos(by: filter)
|
|
}
|
|
|
|
/// Gets a list of amiibo series based on a given filter.
|
|
/// - Parameter filter: A filter to remove unwanted items from the result.
|
|
/// - Returns: A list of filtered amiibo series.
|
|
/// - Throws: An ``AmiiboServiceError`` error in case some issue is encountered while generating the result.
|
|
public func getAmiiboSeries(
|
|
_ filter: AmiiboSeriesFilter = .init()
|
|
) async throws -> [AmiiboSeries] {
|
|
try await client.getAmiiboSeries(by: filter)
|
|
}
|
|
|
|
/// Gets a list of amiibo types based on a given filter.
|
|
/// - Parameter filter: A filter to remove unwanted items from the result.
|
|
/// - Returns: A list of filtered amiibo types.
|
|
/// - Throws: An ``AmiiboServiceError`` error in case some issue is encountered while generating the result.
|
|
public func getAmiiboTypes(
|
|
_ filter: AmiiboTypeFilter = .init()
|
|
) async throws -> [AmiiboType] {
|
|
try await client.getAmiiboTypes(by: filter)
|
|
}
|
|
|
|
/// Gets a list of game characters based on a given filter.
|
|
/// - Parameter filter: A filter to remove unwanted items from the result.
|
|
/// - Returns: A list of filtered game characters.
|
|
/// - Throws: An ``AmiiboServiceError`` error in case some issue is encountered while generating the result.
|
|
public func getGameCharacters(
|
|
_ filter: GameCharacterFilter = .init()
|
|
) async throws -> [GameCharacter] {
|
|
try await client.getGameCharacters(by: filter)
|
|
}
|
|
|
|
/// Gets a list of game series based on a given filter.
|
|
/// - Parameter filter: A filter to remove unwanted items from the result.
|
|
/// - Returns: A list of filtered game series.
|
|
/// - Throws: An ``AmiiboServiceError`` error in case some issue is encountered while generating the result.
|
|
public func getGameSeries(
|
|
_ filter: GameSeriesFilter = .init()
|
|
) async throws -> [GameSeries] {
|
|
try await client.getGameSeries(by: filter)
|
|
}
|
|
|
|
/// Gets the date when the data was last updated.
|
|
/// - Returns: A last updated date.
|
|
/// - Throws: An ``AmiiboServiceError`` error in case some issue is encountered while generating the result.
|
|
public func getLastUpdated() async throws -> Date {
|
|
try await client.getLastUpdated()
|
|
}
|
|
#endif
|
|
|
|
}
|