-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update
fetchSystemStatusReport
remote and action to use `SystemStat…
…usReport` type for SSR.
- Loading branch information
Showing
7 changed files
with
48 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
Networking/Networking/Mapper/SystemStatusReportMapper.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import Foundation | ||
|
||
/// Mapper: System Status Report | ||
/// | ||
struct SystemStatusReportMapper: Mapper { | ||
|
||
/// Site Identifier associated to the system status that will be parsed. | ||
/// We're injecting this field via `JSONDecoder.userInfo` because the remote endpoints don't return the SiteID in the system plugin endpoint. | ||
/// | ||
let siteID: Int64 | ||
|
||
/// (Attempts) to convert a dictionary into SystemStatusReport | ||
/// | ||
func map(response: Data) throws -> SystemStatusReport { | ||
let decoder = JSONDecoder() | ||
decoder.userInfo = [ | ||
.siteID: siteID | ||
] | ||
|
||
if hasDataEnvelope(in: response) { | ||
return try decoder.decode(SystemStatusReportEnvelope.self, from: response).systemStatusReport | ||
} else { | ||
return try decoder.decode(SystemStatusReport.self, from: response) | ||
} | ||
} | ||
} | ||
|
||
/// System Status Report endpoint returns the requested account in the `data` key. This entity | ||
/// allows us to parse it with JSONDecoder. | ||
/// | ||
struct SystemStatusReportEnvelope: Decodable { | ||
let systemStatusReport: SystemStatusReport | ||
|
||
private enum CodingKeys: String, CodingKey { | ||
case systemStatusReport = "data" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters