Improved the generic interface for the "map(_: )" helper function for the AmiiboLiveClient client in the library target.
This commit is contained in:
@@ -226,7 +226,7 @@ private extension AmiiboLiveClient {
|
|||||||
case let .ok(ok):
|
case let .ok(ok):
|
||||||
switch ok.body {
|
switch ok.body {
|
||||||
case let .json(output):
|
case let .json(output):
|
||||||
return map(output, as: AmiiboSeries.self)
|
return map(output)
|
||||||
}
|
}
|
||||||
case .badRequest:
|
case .badRequest:
|
||||||
throw AmiiboServiceError.badRequest
|
throw AmiiboServiceError.badRequest
|
||||||
@@ -261,7 +261,7 @@ private extension AmiiboLiveClient {
|
|||||||
case let .ok(ok):
|
case let .ok(ok):
|
||||||
switch ok.body {
|
switch ok.body {
|
||||||
case let .json(output):
|
case let .json(output):
|
||||||
return map(output, as: AmiiboType.self)
|
return map(output)
|
||||||
}
|
}
|
||||||
case .badRequest:
|
case .badRequest:
|
||||||
throw AmiiboServiceError.badRequest
|
throw AmiiboServiceError.badRequest
|
||||||
@@ -296,7 +296,7 @@ private extension AmiiboLiveClient {
|
|||||||
case let .ok(ok):
|
case let .ok(ok):
|
||||||
switch ok.body {
|
switch ok.body {
|
||||||
case let .json(output):
|
case let .json(output):
|
||||||
return map(output, as: GameCharacter.self)
|
return map(output)
|
||||||
}
|
}
|
||||||
case .badRequest:
|
case .badRequest:
|
||||||
throw AmiiboServiceError.badRequest
|
throw AmiiboServiceError.badRequest
|
||||||
@@ -331,7 +331,7 @@ private extension AmiiboLiveClient {
|
|||||||
case let .ok(ok):
|
case let .ok(ok):
|
||||||
switch ok.body {
|
switch ok.body {
|
||||||
case let .json(output):
|
case let .json(output):
|
||||||
return map(output, as: GameSeries.self)
|
return map(output)
|
||||||
}
|
}
|
||||||
case .badRequest:
|
case .badRequest:
|
||||||
throw AmiiboServiceError.badRequest
|
throw AmiiboServiceError.badRequest
|
||||||
@@ -406,29 +406,26 @@ private extension AmiiboLiveClient {
|
|||||||
) -> [Amiibo] {
|
) -> [Amiibo] {
|
||||||
switch wrapper.amiibo {
|
switch wrapper.amiibo {
|
||||||
case let .Amiibo(object):
|
case let .Amiibo(object):
|
||||||
return [.init(object)]
|
return [Amiibo(object)]
|
||||||
case let .AmiiboList(list):
|
case let .AmiiboList(list):
|
||||||
return list
|
return list
|
||||||
.map { .init($0) }
|
.map { Amiibo($0) }
|
||||||
.sorted { $0.identifier < $1.identifier }
|
.sorted { $0.identifier < $1.identifier }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieves a list of items that conforms to the `KeyNameModel` protocol from a wrapper container.
|
/// Retrieves a list of items that conforms to the `KeyNameModel` protocol from a wrapper container.
|
||||||
/// - Parameters:
|
/// - Parameter wrapper: A wrapper container that either has an object or a list of items.
|
||||||
/// - wrapper: A wrapper container that either has an object or a list of items.
|
|
||||||
/// - as: a model type that conforms to the `KeyNameModel` protocol.
|
|
||||||
/// - Returns: A list of items that conforms to the `KeyNameModel` protocol, sorted by keys.
|
/// - Returns: A list of items that conforms to the `KeyNameModel` protocol, sorted by keys.
|
||||||
func map<Model: KeyNameModel>(
|
func map<Model: KeyNameModel>(
|
||||||
_ wrapper: Components.Schemas.TupleWrapper,
|
_ wrapper: Components.Schemas.TupleWrapper
|
||||||
as: Model.Type
|
|
||||||
) -> [Model] {
|
) -> [Model] {
|
||||||
switch wrapper.amiibo {
|
switch wrapper.amiibo {
|
||||||
case let .Tuple(payload):
|
case let .Tuple(payload):
|
||||||
return [.init(payload)]
|
return [Model(payload)]
|
||||||
case let .TupleList(list):
|
case let .TupleList(list):
|
||||||
return list
|
return list
|
||||||
.map { .init($0) }
|
.map { Model($0) }
|
||||||
.sorted { $0.key < $1.key }
|
.sorted { $0.key < $1.key }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user