This PR contains the work done to implement the actual public service interface to the Amiibo API. To provide further details about this work: - [x] defined a `Filter` protocol; - [x] implemented the `AmiiboFilter` and the `KeyNameFilter` filters; - [x] implemented the `Result` model; - [x] defined the `Service` protocol; - [x] implemented the `AmiiboService` concrete service; - [x] fixed the `path` of the `GetAmiiboEndpoint` endpoint; - [x] made the `usage` property of the `Game` model optional; - [x] replaced the `showGames` and the `showUsage` flags of the `AmiiboFilter` filter with an enumeration. Co-authored-by: Javier Cicchelli <javier@rock-n-code.com> Reviewed-on: #4
28 lines
589 B
Swift
28 lines
589 B
Swift
struct Result<Model: Decodable> {
|
|
let items: [Model]
|
|
}
|
|
|
|
// MARK: - Decodable
|
|
|
|
extension Result: Decodable {
|
|
|
|
// MARK: Enumerations
|
|
|
|
enum CodingKeys: String, CodingKey {
|
|
case items = "amiibo"
|
|
}
|
|
|
|
// MARK: Initialisers
|
|
|
|
init(from decoder: Decoder) throws {
|
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
|
|
|
do {
|
|
self.items = try container.decode([Model].self, forKey: .items)
|
|
} catch {
|
|
self.items = [try container.decode(Model.self, forKey: .items)]
|
|
}
|
|
}
|
|
|
|
}
|