Moved the Amiibo API implementation to its own package #2
101
Sources/Public/Clients/AmiiboMockClient.swift
Normal file
101
Sources/Public/Clients/AmiiboMockClient.swift
Normal file
@ -0,0 +1,101 @@
|
||||
//===----------------------------------------------------------------------===
|
||||
//
|
||||
// This source file is part of the AmiiboAPI open source project
|
||||
//
|
||||
// Copyright (c) 2024 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
|
||||
|
||||
public struct AmiiboMockClient {
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
private(set) public var amiibos: [Amiibo]?
|
||||
private(set) public var amiiboSeries: [AmiiboSeries]?
|
||||
private(set) public var amiiboTypes: [AmiiboType]?
|
||||
private(set) public var gameCharacters: [GameCharacter]?
|
||||
private(set) public var gameSeries: [GameSeries]?
|
||||
private(set) public var lastUpdated: Date?
|
||||
|
||||
// MARK: Initialisers
|
||||
|
||||
public init(
|
||||
amiibos: [Amiibo]? = nil,
|
||||
amiiboSeries: [AmiiboSeries]? = nil,
|
||||
amiiboTypes: [AmiiboType]? = nil,
|
||||
gameCharacters: [GameCharacter]? = nil,
|
||||
gameSeries: [GameSeries]? = nil,
|
||||
lastUpdated: Date? = nil
|
||||
) {
|
||||
self.amiibos = amiibos
|
||||
self.amiiboSeries = amiiboSeries
|
||||
self.amiiboTypes = amiiboTypes
|
||||
self.gameCharacters = gameCharacters
|
||||
self.gameSeries = gameSeries
|
||||
self.lastUpdated = lastUpdated
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: - APIClient
|
||||
|
||||
extension AmiiboMockClient: APIClient {
|
||||
|
||||
// MARK: Functions
|
||||
|
||||
public func getAmiibos(by filter: AmiiboFilter) async throws -> [Amiibo] {
|
||||
guard let amiibos else {
|
||||
throw AmiiboServiceError.notFound
|
||||
}
|
||||
|
||||
return amiibos
|
||||
}
|
||||
|
||||
public func getAmiiboSeries(by filter: AmiiboSeriesFilter) async throws -> [AmiiboSeries] {
|
||||
guard let amiiboSeries else {
|
||||
throw AmiiboServiceError.notFound
|
||||
}
|
||||
|
||||
return amiiboSeries
|
||||
}
|
||||
|
||||
public func getAmiiboTypes(by filter: AmiiboTypeFilter) async throws -> [AmiiboType] {
|
||||
guard let amiiboTypes else {
|
||||
throw AmiiboServiceError.notFound
|
||||
}
|
||||
|
||||
return amiiboTypes
|
||||
}
|
||||
|
||||
public func getGameCharacters(by filter: GameCharacterFilter) async throws -> [GameCharacter] {
|
||||
guard let gameCharacters else {
|
||||
throw AmiiboServiceError.notFound
|
||||
}
|
||||
|
||||
return gameCharacters
|
||||
}
|
||||
|
||||
public func getGameSeries(by filter: GameSeriesFilter) async throws -> [GameSeries] {
|
||||
guard let gameSeries else {
|
||||
throw AmiiboServiceError.notFound
|
||||
}
|
||||
|
||||
return gameSeries
|
||||
}
|
||||
|
||||
public func getLastUpdated() async throws -> Date {
|
||||
guard let lastUpdated else {
|
||||
throw AmiiboServiceError.notFound
|
||||
}
|
||||
|
||||
return lastUpdated
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user