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
57 lines
1.0 KiB
Swift
57 lines
1.0 KiB
Swift
public struct KeyNameFilter {
|
|
|
|
// MARK: Properties
|
|
|
|
private let key: String?
|
|
private let name: String?
|
|
|
|
// MARK: Initialisers
|
|
|
|
public init(
|
|
key: String? = nil,
|
|
name: String? = nil
|
|
) {
|
|
self.key = key
|
|
self.name = name
|
|
}
|
|
|
|
}
|
|
|
|
// MARK: - Filter
|
|
|
|
extension KeyNameFilter: Filter {
|
|
|
|
// MARK: Functions
|
|
|
|
func makeParameters() -> [String : String?] {
|
|
var parameters: [String : String?] = [:]
|
|
|
|
if let key {
|
|
parameters[.Key.key] = key
|
|
}
|
|
|
|
if let name {
|
|
parameters[.Key.name] = name
|
|
}
|
|
|
|
return parameters
|
|
}
|
|
|
|
}
|
|
|
|
// MARK: - Type aliases
|
|
|
|
public typealias AmiiboSeriesFilter = KeyNameFilter
|
|
public typealias AmiiboTypeFilter = KeyNameFilter
|
|
public typealias CharacterFilter = KeyNameFilter
|
|
public typealias GameSeriesFilter = KeyNameFilter
|
|
|
|
// MARK: - String+Key
|
|
|
|
private extension String {
|
|
enum Key {
|
|
static let key = "key"
|
|
static let name = "name"
|
|
}
|
|
}
|