-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Store the raw JSON payload from the getRelays API call
- Loading branch information
Jon Petersson
committed
Sep 9, 2024
1 parent
50c9d86
commit 059fad1
Showing
13 changed files
with
123 additions
and
59 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// CachedRelayData.swift | ||
// MullvadVPNUITests | ||
// | ||
// Created by Jon Petersson on 2024-09-09. | ||
// Copyright © 2024 Mullvad VPN AB. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
/// A struct that represents the relay cache on disk | ||
public struct StoredRelays: Codable, Equatable { | ||
/// E-tag returned by server | ||
public let etag: String? | ||
|
||
/// The raw relay JSON data stored within the cache entry | ||
public let rawData: Data | ||
|
||
/// The date when this cache was last updated | ||
public let updatedAt: Date | ||
|
||
/// Relays parsed from the JSON data | ||
public var relays: REST.ServerRelaysResponse { | ||
get throws { | ||
try REST.Coding.makeJSONDecoder().decode(REST.ServerRelaysResponse.self, from: rawData) | ||
} | ||
} | ||
|
||
/// `CachedRelays` representation | ||
public var toCachedRelays: CachedRelays { | ||
get throws { | ||
try CachedRelays(etag: etag, relays: relays, updatedAt: updatedAt) | ||
} | ||
} | ||
|
||
public init(etag: String? = nil, rawData: Data, updatedAt: Date) { | ||
self.etag = etag | ||
self.rawData = rawData | ||
self.updatedAt = updatedAt | ||
} | ||
} |
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
Oops, something went wrong.