Documented the AmiiboService service in the library target.
This commit is contained in:
@@ -17,7 +17,8 @@ import OpenAPIRuntime
|
|||||||
struct ISOTimestampTranscoder {
|
struct ISOTimestampTranscoder {
|
||||||
|
|
||||||
// MARK: Properties
|
// MARK: Properties
|
||||||
|
|
||||||
|
/// A formatter to use to decode and encode ISO timestamps dates.
|
||||||
private let dateFormatter: DateFormatter = .isoTimestamp
|
private let dateFormatter: DateFormatter = .isoTimestamp
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,51 +12,81 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
|
/// A type that implements the service that uses a client to make calls.
|
||||||
public struct AmiiboService {
|
public struct AmiiboService {
|
||||||
|
|
||||||
// MARK: Properties
|
// MARK: Properties
|
||||||
|
|
||||||
|
/// A client to interact with the endpoints.
|
||||||
private let client: any APIClient
|
private let client: any APIClient
|
||||||
|
|
||||||
// MARK: Initialisers
|
// MARK: Initializers
|
||||||
|
|
||||||
public init(_ client: any APIClient) {
|
/// Initializes this service with a specific client type.
|
||||||
self.client = client
|
/// - Parameter client: A representation of a client to use to interact with the endpoints.
|
||||||
|
public init(_ client: AmiiboClient) {
|
||||||
|
self.client = switch client {
|
||||||
|
case let .mock(mockClient): mockClient
|
||||||
|
case let .live(liveClient): liveClient
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Functions
|
// MARK: Functions
|
||||||
|
|
||||||
|
/// 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(
|
public func getAmiibos(
|
||||||
_ filter: AmiiboFilter = .init()
|
_ filter: AmiiboFilter = .init()
|
||||||
) async throws -> [Amiibo] {
|
) async throws(AmiiboServiceError) -> [Amiibo] {
|
||||||
try await client.getAmiibos(by: filter)
|
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(
|
public func getAmiiboSeries(
|
||||||
_ filter: AmiiboSeriesFilter = .init()
|
_ filter: AmiiboSeriesFilter = .init()
|
||||||
) async throws -> [AmiiboSeries] {
|
) async throws(AmiiboServiceError) -> [AmiiboSeries] {
|
||||||
try await client.getAmiiboSeries(by: filter)
|
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(
|
public func getAmiiboTypes(
|
||||||
_ filter: AmiiboTypeFilter = .init()
|
_ filter: AmiiboTypeFilter = .init()
|
||||||
) async throws -> [AmiiboType] {
|
) async throws(AmiiboServiceError) -> [AmiiboType] {
|
||||||
try await client.getAmiiboTypes(by: filter)
|
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(
|
public func getGameCharacters(
|
||||||
_ filter: GameCharacterFilter = .init()
|
_ filter: GameCharacterFilter = .init()
|
||||||
) async throws -> [GameCharacter] {
|
) async throws(AmiiboServiceError) -> [GameCharacter] {
|
||||||
try await client.getGameCharacters(by: filter)
|
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(
|
public func getGameSeries(
|
||||||
_ filter: GameSeriesFilter = .init()
|
_ filter: GameSeriesFilter = .init()
|
||||||
) async throws -> [GameSeries] {
|
) async throws(AmiiboServiceError) -> [GameSeries] {
|
||||||
try await client.getGameSeries(by: filter)
|
try await client.getGameSeries(by: filter)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func getLastUpdated() async throws -> Date {
|
/// 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()
|
try await client.getLastUpdated()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,10 +23,8 @@ struct AmiiboServiceLiveTests {
|
|||||||
|
|
||||||
// MARK: Initialisers
|
// MARK: Initialisers
|
||||||
|
|
||||||
init() throws {
|
init() {
|
||||||
let client = try AmiiboLiveClient()
|
self.service = .init(.live())
|
||||||
|
|
||||||
self.service = .init(client)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Functions tests
|
// MARK: Functions tests
|
||||||
|
|||||||
Reference in New Issue
Block a user