Improvements on the AmiiboService service type initialization (#12)
This PR addresses the issue #10 as described in the *Possible Solution* section in that issue. Reviewed-on: #12 Co-authored-by: Javier Cicchelli <javier@rock-n-code.com> Co-committed-by: Javier Cicchelli <javier@rock-n-code.com>
This commit was merged in pull request #12.
This commit is contained in:
@@ -36,10 +36,10 @@ public struct AmiiboLiveClient {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - APIClient
|
// MARK: - AmiiboClient
|
||||||
// TODO: Remove the documentation from the functions inside the following extension as the `--enable-inherited-docs` flag when generating DocC documentation is not working as intended (?).
|
// TODO: Remove the documentation from the functions inside the following extension as the `--enable-inherited-docs` flag when generating DocC documentation is not working as intended (?).
|
||||||
|
|
||||||
extension AmiiboLiveClient: APIClient {
|
extension AmiiboLiveClient: AmiiboClient {
|
||||||
|
|
||||||
// MARK: Functions
|
// MARK: Functions
|
||||||
|
|
||||||
|
|||||||
@@ -1,263 +0,0 @@
|
|||||||
//===----------------------------------------------------------------------===
|
|
||||||
//
|
|
||||||
// This source file is part of the AmiiboService open source project
|
|
||||||
//
|
|
||||||
// Copyright (c) 2024-2025 Röck+Cöde VoF. and the AmiiboAPI project authors
|
|
||||||
// Licensed under the EUPL 1.2 or later.
|
|
||||||
//
|
|
||||||
// See LICENSE for license information
|
|
||||||
// See CONTRIBUTORS for the list of AmiiboAPI project authors
|
|
||||||
//
|
|
||||||
//===----------------------------------------------------------------------===
|
|
||||||
|
|
||||||
import Foundation
|
|
||||||
|
|
||||||
/// A type that implements a mock client, for testing purposes.
|
|
||||||
public struct AmiiboMockClient {
|
|
||||||
|
|
||||||
// MARK: Properties
|
|
||||||
|
|
||||||
/// A list of amiibo items to return, if any.
|
|
||||||
private let amiibos: [Amiibo]?
|
|
||||||
|
|
||||||
/// A list of amiibo series to return, if any.
|
|
||||||
private let amiiboSeries: [AmiiboSeries]?
|
|
||||||
|
|
||||||
/// A list of amiibo types to return, if any.
|
|
||||||
private let amiiboTypes: [AmiiboType]?
|
|
||||||
|
|
||||||
/// An error to throw, if any.
|
|
||||||
private let error: AmiiboServiceError?
|
|
||||||
|
|
||||||
/// A list of game characters to return, if any.
|
|
||||||
private let gameCharacters: [GameCharacter]?
|
|
||||||
|
|
||||||
/// A list of game series to return, if any.
|
|
||||||
private let gameSeries: [GameSeries]?
|
|
||||||
|
|
||||||
/// A last updated date to return, if any.
|
|
||||||
private let lastUpdated: Date?
|
|
||||||
|
|
||||||
// MARK: Initializers
|
|
||||||
|
|
||||||
/// Initializes this client.
|
|
||||||
/// - Parameters:
|
|
||||||
/// - amiibos: A list of amiibo items to return, if any.
|
|
||||||
/// - amiiboSeries: A list of amiibo series to return, if any.
|
|
||||||
/// - amiiboTypes: A list of amiibo types to return, if any.
|
|
||||||
/// - gameCharacters: A list of game characters to return, if any.
|
|
||||||
/// - gameSeries: A list of game series to return, if any.
|
|
||||||
/// - lastUpdated: A last updated date to return, if any.
|
|
||||||
/// - error: An error to throw, if any.
|
|
||||||
public init(
|
|
||||||
amiibos: [Amiibo]? = nil,
|
|
||||||
amiiboSeries: [AmiiboSeries]? = nil,
|
|
||||||
amiiboTypes: [AmiiboType]? = nil,
|
|
||||||
gameCharacters: [GameCharacter]? = nil,
|
|
||||||
gameSeries: [GameSeries]? = nil,
|
|
||||||
lastUpdated: Date? = nil,
|
|
||||||
error: AmiiboServiceError? = nil
|
|
||||||
) {
|
|
||||||
self.amiibos = amiibos
|
|
||||||
self.amiiboSeries = amiiboSeries
|
|
||||||
self.amiiboTypes = amiiboTypes
|
|
||||||
self.error = error
|
|
||||||
self.gameCharacters = gameCharacters
|
|
||||||
self.gameSeries = gameSeries
|
|
||||||
self.lastUpdated = lastUpdated
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - APIClient
|
|
||||||
// TODO: Remove the documentation from the functions inside the following extension as the `--enable-inherited-docs` flag when generating DocC documentation is not working as intended (?).
|
|
||||||
|
|
||||||
extension AmiiboMockClient: APIClient {
|
|
||||||
|
|
||||||
// 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(by filter: AmiiboFilter) async throws(AmiiboServiceError) -> [Amiibo] {
|
|
||||||
try throwErrorIfExists()
|
|
||||||
|
|
||||||
guard let amiibos else {
|
|
||||||
throw AmiiboServiceError.notFound
|
|
||||||
}
|
|
||||||
|
|
||||||
return amiibos
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 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(by filter: AmiiboSeriesFilter) async throws(AmiiboServiceError) -> [AmiiboSeries] {
|
|
||||||
try throwErrorIfExists()
|
|
||||||
|
|
||||||
guard let amiiboSeries else {
|
|
||||||
throw AmiiboServiceError.notFound
|
|
||||||
}
|
|
||||||
|
|
||||||
return amiiboSeries
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 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(by filter: AmiiboTypeFilter) async throws(AmiiboServiceError) -> [AmiiboType] {
|
|
||||||
try throwErrorIfExists()
|
|
||||||
|
|
||||||
guard let amiiboTypes else {
|
|
||||||
throw AmiiboServiceError.notFound
|
|
||||||
}
|
|
||||||
|
|
||||||
return amiiboTypes
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 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(by filter: GameCharacterFilter) async throws(AmiiboServiceError) -> [GameCharacter] {
|
|
||||||
try throwErrorIfExists()
|
|
||||||
|
|
||||||
guard let gameCharacters else {
|
|
||||||
throw AmiiboServiceError.notFound
|
|
||||||
}
|
|
||||||
|
|
||||||
return gameCharacters
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 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(by filter: GameSeriesFilter) async throws(AmiiboServiceError) -> [GameSeries] {
|
|
||||||
try throwErrorIfExists()
|
|
||||||
|
|
||||||
guard let gameSeries else {
|
|
||||||
throw AmiiboServiceError.notFound
|
|
||||||
}
|
|
||||||
|
|
||||||
return gameSeries
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 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 throwErrorIfExists()
|
|
||||||
|
|
||||||
guard let lastUpdated else {
|
|
||||||
throw AmiiboServiceError.notFound
|
|
||||||
}
|
|
||||||
|
|
||||||
return lastUpdated
|
|
||||||
}
|
|
||||||
#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(by filter: AmiiboFilter) async throws -> [Amiibo] {
|
|
||||||
try throwErrorIfExists()
|
|
||||||
|
|
||||||
guard let amiibos else {
|
|
||||||
throw AmiiboServiceError.notFound
|
|
||||||
}
|
|
||||||
|
|
||||||
return amiibos
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 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(by filter: AmiiboSeriesFilter) async throws -> [AmiiboSeries] {
|
|
||||||
try throwErrorIfExists()
|
|
||||||
|
|
||||||
guard let amiiboSeries else {
|
|
||||||
throw AmiiboServiceError.notFound
|
|
||||||
}
|
|
||||||
|
|
||||||
return amiiboSeries
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 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(by filter: AmiiboTypeFilter) async throws -> [AmiiboType] {
|
|
||||||
try throwErrorIfExists()
|
|
||||||
|
|
||||||
guard let amiiboTypes else {
|
|
||||||
throw AmiiboServiceError.notFound
|
|
||||||
}
|
|
||||||
|
|
||||||
return amiiboTypes
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 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(by filter: GameCharacterFilter) async throws -> [GameCharacter] {
|
|
||||||
try throwErrorIfExists()
|
|
||||||
|
|
||||||
guard let gameCharacters else {
|
|
||||||
throw AmiiboServiceError.notFound
|
|
||||||
}
|
|
||||||
|
|
||||||
return gameCharacters
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 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(by filter: GameSeriesFilter) async throws -> [GameSeries] {
|
|
||||||
try throwErrorIfExists()
|
|
||||||
|
|
||||||
guard let gameSeries else {
|
|
||||||
throw AmiiboServiceError.notFound
|
|
||||||
}
|
|
||||||
|
|
||||||
return gameSeries
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 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 throwErrorIfExists()
|
|
||||||
|
|
||||||
guard let lastUpdated else {
|
|
||||||
throw AmiiboServiceError.notFound
|
|
||||||
}
|
|
||||||
|
|
||||||
return lastUpdated
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Helpers
|
|
||||||
|
|
||||||
private extension AmiiboMockClient {
|
|
||||||
|
|
||||||
// MARK: Functions
|
|
||||||
|
|
||||||
/// Throws an error if it has been provided,
|
|
||||||
/// - Throws: An ``AmiiboServiceError`` error in case an error has been provided.
|
|
||||||
func throwErrorIfExists() throws(AmiiboServiceError) {
|
|
||||||
if let error {
|
|
||||||
throw error
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
+1
-1
@@ -13,7 +13,7 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
/// A protocol that defines API clients containing all available endpoints to interact with.
|
/// A protocol that defines API clients containing all available endpoints to interact with.
|
||||||
protocol APIClient {
|
public protocol AmiiboClient {
|
||||||
|
|
||||||
// MARK: Functions
|
// MARK: Functions
|
||||||
|
|
||||||
@@ -18,17 +18,14 @@ public struct AmiiboService {
|
|||||||
// MARK: Properties
|
// MARK: Properties
|
||||||
|
|
||||||
/// A client to interact with the endpoints.
|
/// A client to interact with the endpoints.
|
||||||
private let client: any APIClient
|
private let client: any AmiiboClient
|
||||||
|
|
||||||
// MARK: Initializers
|
// MARK: Initializers
|
||||||
|
|
||||||
/// Initializes this service with a specific client type.
|
/// Initializes this service with a specific client type.
|
||||||
/// - Parameter client: A representation of a client to use to interact with the endpoints.
|
/// - Parameter client: A client to use to interact with the endpoints.
|
||||||
public init(_ client: AmiiboClient) {
|
public init(client: some AmiiboClient = AmiiboLiveClient()) {
|
||||||
self.client = switch client {
|
self.client = client
|
||||||
case let .mock(mockClient): mockClient
|
|
||||||
case let .live(liveClient): liveClient
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Functions
|
// MARK: Functions
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,217 @@
|
|||||||
|
//===----------------------------------------------------------------------===
|
||||||
|
//
|
||||||
|
// This source file is part of the AmiiboService open source project
|
||||||
|
//
|
||||||
|
// Copyright (c) 2024-2025 Röck+Cöde VoF. and the AmiiboAPI project authors
|
||||||
|
// Licensed under the EUPL 1.2 or later.
|
||||||
|
//
|
||||||
|
// See LICENSE for license information
|
||||||
|
// See CONTRIBUTORS for the list of AmiiboAPI project authors
|
||||||
|
//
|
||||||
|
//===----------------------------------------------------------------------===
|
||||||
|
|
||||||
|
import AmiiboService
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
/// A type that implements a mock client, for testing purposes.
|
||||||
|
struct AmiiboMockClient {
|
||||||
|
|
||||||
|
// MARK: Properties
|
||||||
|
|
||||||
|
/// A list of amiibo items to return, if any.
|
||||||
|
private let amiibos: [Amiibo]?
|
||||||
|
|
||||||
|
/// A list of amiibo series to return, if any.
|
||||||
|
private let amiiboSeries: [AmiiboSeries]?
|
||||||
|
|
||||||
|
/// A list of amiibo types to return, if any.
|
||||||
|
private let amiiboTypes: [AmiiboType]?
|
||||||
|
|
||||||
|
/// An error to throw, if any.
|
||||||
|
private let error: AmiiboServiceError?
|
||||||
|
|
||||||
|
/// A list of game characters to return, if any.
|
||||||
|
private let gameCharacters: [GameCharacter]?
|
||||||
|
|
||||||
|
/// A list of game series to return, if any.
|
||||||
|
private let gameSeries: [GameSeries]?
|
||||||
|
|
||||||
|
/// A last updated date to return, if any.
|
||||||
|
private let lastUpdated: Date?
|
||||||
|
|
||||||
|
// MARK: Initializers
|
||||||
|
|
||||||
|
/// Initializes this client.
|
||||||
|
/// - Parameters:
|
||||||
|
/// - amiibos: A list of amiibo items to return, if any.
|
||||||
|
/// - amiiboSeries: A list of amiibo series to return, if any.
|
||||||
|
/// - amiiboTypes: A list of amiibo types to return, if any.
|
||||||
|
/// - gameCharacters: A list of game characters to return, if any.
|
||||||
|
/// - gameSeries: A list of game series to return, if any.
|
||||||
|
/// - lastUpdated: A last updated date to return, if any.
|
||||||
|
/// - error: An error to throw, if any.
|
||||||
|
init(
|
||||||
|
amiibos: [Amiibo]? = nil,
|
||||||
|
amiiboSeries: [AmiiboSeries]? = nil,
|
||||||
|
amiiboTypes: [AmiiboType]? = nil,
|
||||||
|
gameCharacters: [GameCharacter]? = nil,
|
||||||
|
gameSeries: [GameSeries]? = nil,
|
||||||
|
lastUpdated: Date? = nil,
|
||||||
|
error: AmiiboServiceError? = nil
|
||||||
|
) {
|
||||||
|
self.amiibos = amiibos
|
||||||
|
self.amiiboSeries = amiiboSeries
|
||||||
|
self.amiiboTypes = amiiboTypes
|
||||||
|
self.error = error
|
||||||
|
self.gameCharacters = gameCharacters
|
||||||
|
self.gameSeries = gameSeries
|
||||||
|
self.lastUpdated = lastUpdated
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - AmiiboClient
|
||||||
|
|
||||||
|
extension AmiiboMockClient: AmiiboClient {
|
||||||
|
|
||||||
|
// MARK: Functions
|
||||||
|
|
||||||
|
#if swift(>=6.0)
|
||||||
|
func getAmiibos(by filter: AmiiboFilter) async throws(AmiiboServiceError) -> [Amiibo] {
|
||||||
|
try throwErrorIfExists()
|
||||||
|
|
||||||
|
guard let amiibos else {
|
||||||
|
throw AmiiboServiceError.notFound
|
||||||
|
}
|
||||||
|
|
||||||
|
return amiibos
|
||||||
|
}
|
||||||
|
|
||||||
|
func getAmiiboSeries(by filter: AmiiboSeriesFilter) async throws(AmiiboServiceError) -> [AmiiboSeries] {
|
||||||
|
try throwErrorIfExists()
|
||||||
|
|
||||||
|
guard let amiiboSeries else {
|
||||||
|
throw AmiiboServiceError.notFound
|
||||||
|
}
|
||||||
|
|
||||||
|
return amiiboSeries
|
||||||
|
}
|
||||||
|
|
||||||
|
func getAmiiboTypes(by filter: AmiiboTypeFilter) async throws(AmiiboServiceError) -> [AmiiboType] {
|
||||||
|
try throwErrorIfExists()
|
||||||
|
|
||||||
|
guard let amiiboTypes else {
|
||||||
|
throw AmiiboServiceError.notFound
|
||||||
|
}
|
||||||
|
|
||||||
|
return amiiboTypes
|
||||||
|
}
|
||||||
|
|
||||||
|
func getGameCharacters(by filter: GameCharacterFilter) async throws(AmiiboServiceError) -> [GameCharacter] {
|
||||||
|
try throwErrorIfExists()
|
||||||
|
|
||||||
|
guard let gameCharacters else {
|
||||||
|
throw AmiiboServiceError.notFound
|
||||||
|
}
|
||||||
|
|
||||||
|
return gameCharacters
|
||||||
|
}
|
||||||
|
|
||||||
|
func getGameSeries(by filter: GameSeriesFilter) async throws(AmiiboServiceError) -> [GameSeries] {
|
||||||
|
try throwErrorIfExists()
|
||||||
|
|
||||||
|
guard let gameSeries else {
|
||||||
|
throw AmiiboServiceError.notFound
|
||||||
|
}
|
||||||
|
|
||||||
|
return gameSeries
|
||||||
|
}
|
||||||
|
|
||||||
|
func getLastUpdated() async throws(AmiiboServiceError) -> Date {
|
||||||
|
try throwErrorIfExists()
|
||||||
|
|
||||||
|
guard let lastUpdated else {
|
||||||
|
throw AmiiboServiceError.notFound
|
||||||
|
}
|
||||||
|
|
||||||
|
return lastUpdated
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
func getAmiibos(by filter: AmiiboFilter) async throws -> [Amiibo] {
|
||||||
|
try throwErrorIfExists()
|
||||||
|
|
||||||
|
guard let amiibos else {
|
||||||
|
throw AmiiboServiceError.notFound
|
||||||
|
}
|
||||||
|
|
||||||
|
return amiibos
|
||||||
|
}
|
||||||
|
|
||||||
|
func getAmiiboSeries(by filter: AmiiboSeriesFilter) async throws -> [AmiiboSeries] {
|
||||||
|
try throwErrorIfExists()
|
||||||
|
|
||||||
|
guard let amiiboSeries else {
|
||||||
|
throw AmiiboServiceError.notFound
|
||||||
|
}
|
||||||
|
|
||||||
|
return amiiboSeries
|
||||||
|
}
|
||||||
|
|
||||||
|
func getAmiiboTypes(by filter: AmiiboTypeFilter) async throws -> [AmiiboType] {
|
||||||
|
try throwErrorIfExists()
|
||||||
|
|
||||||
|
guard let amiiboTypes else {
|
||||||
|
throw AmiiboServiceError.notFound
|
||||||
|
}
|
||||||
|
|
||||||
|
return amiiboTypes
|
||||||
|
}
|
||||||
|
|
||||||
|
func getGameCharacters(by filter: GameCharacterFilter) async throws -> [GameCharacter] {
|
||||||
|
try throwErrorIfExists()
|
||||||
|
|
||||||
|
guard let gameCharacters else {
|
||||||
|
throw AmiiboServiceError.notFound
|
||||||
|
}
|
||||||
|
|
||||||
|
return gameCharacters
|
||||||
|
}
|
||||||
|
|
||||||
|
func getGameSeries(by filter: GameSeriesFilter) async throws -> [GameSeries] {
|
||||||
|
try throwErrorIfExists()
|
||||||
|
|
||||||
|
guard let gameSeries else {
|
||||||
|
throw AmiiboServiceError.notFound
|
||||||
|
}
|
||||||
|
|
||||||
|
return gameSeries
|
||||||
|
}
|
||||||
|
|
||||||
|
func getLastUpdated() async throws -> Date {
|
||||||
|
try throwErrorIfExists()
|
||||||
|
|
||||||
|
guard let lastUpdated else {
|
||||||
|
throw AmiiboServiceError.notFound
|
||||||
|
}
|
||||||
|
|
||||||
|
return lastUpdated
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Helpers
|
||||||
|
|
||||||
|
private extension AmiiboMockClient {
|
||||||
|
|
||||||
|
// MARK: Functions
|
||||||
|
|
||||||
|
/// Throws an error if it has been provided,
|
||||||
|
/// - Throws: An ``AmiiboServiceError`` error in case an error has been provided.
|
||||||
|
func throwErrorIfExists() throws(AmiiboServiceError) {
|
||||||
|
if let error {
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+9
-8
@@ -10,12 +10,13 @@
|
|||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===
|
//===----------------------------------------------------------------------===
|
||||||
|
|
||||||
/// A representation of the types of client that a ``AmiiboService`` service can utilize.
|
import Testing
|
||||||
///
|
|
||||||
/// > important: This enumeration has been defined as a way to avoid exposing the `APIClient` protocol outside the boundaries of this library.
|
extension Tag {
|
||||||
public enum AmiiboClient {
|
|
||||||
/// A live Amiibo client to interact with the online service.
|
// MARK: Properties
|
||||||
case live(AmiiboLiveClient = .init())
|
|
||||||
///A mock Amiibo client, for testing purposes.
|
/// Tag that indicates tests against a live backend service.
|
||||||
case mock(AmiiboMockClient)
|
@Tag static var live: Self
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user