Moved the Amiibo API implementation to its own package #2

Merged
javier merged 12 commits from migration/api-work into main 2024-09-14 22:26:39 +00:00
3 changed files with 30 additions and 15 deletions
Showing only changes of commit 420ed8f7a3 - Show all commits

View File

@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===
import Foundation
import OpenAPIRuntime
import OpenAPIURLSession
public struct AmiiboLiveClient {
@ -38,19 +39,31 @@ extension AmiiboLiveClient: APIClient {
// MARK: Functions
public func getAmiibos(by filter: AmiiboFilter) async throws -> [Amiibo] {
let response = try await client.getAmiibos(
.init(query: .init(
amiiboSeries: filter.series,
character: filter.gameCharacter,
gameseries: filter.gameSeries,
id: filter.identifier,
name: filter.name,
showgames: filter.showGames,
showusage: filter.showUsage,
_type: filter.type
))
)
let response = try await {
do {
return try await client.getAmiibos(
.init(query: .init(
amiiboSeries: filter.series,
character: filter.gameCharacter,
gameseries: filter.gameSeries,
id: filter.identifier,
name: filter.name,
showgames: filter.showGames,
showusage: filter.showUsage,
_type: filter.type
))
)
} catch let error as ClientError {
guard let _ = error.underlyingError as? DecodingError else {
throw AmiiboServiceError.unknown
}
throw AmiiboServiceError.decoding
} catch {
throw AmiiboServiceError.unknown
}
}()
switch response {
case let .ok(ok):
switch ok.body {

View File

@ -12,9 +12,11 @@
public enum AmiiboServiceError: Error {
case badRequest
case decoding
case notAvailable
case notFound
case undocumented(_ statusCode: Int)
case unknown
}
// MARK: - Equatable

View File

@ -67,7 +67,7 @@ struct AmiiboServiceLiveTests {
// WHEN
// THEN
await #expect(throws: AmiiboServiceError.undocumented(404)) {
await #expect(throws: AmiiboServiceError.decoding) {
try await service.getAmiibos(.init(identifier: identifier))
}
}
@ -79,7 +79,7 @@ struct AmiiboServiceLiveTests {
// WHEN
// THEN
await #expect(throws: AmiiboServiceError.undocumented(404)) {
await #expect(throws: AmiiboServiceError.decoding) {
try await service.getAmiibos(.init(identifier: identifier))
}
}