-
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.
Merge branch 'ios-814-store-the-raw-json-payload-from-the-getrelays-a…
…pi-call'
- Loading branch information
Showing
13 changed files
with
138 additions
and
64 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,43 @@ | ||
// | ||
// StoredRelays.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 let relays: REST.ServerRelaysResponse | ||
|
||
/// `CachedRelays` representation | ||
public var cachedRelays: CachedRelays { | ||
CachedRelays(etag: etag, relays: relays, updatedAt: updatedAt) | ||
} | ||
|
||
public init(etag: String? = nil, rawData: Data, updatedAt: Date) throws { | ||
self.etag = etag | ||
self.rawData = rawData | ||
self.updatedAt = updatedAt | ||
relays = try REST.Coding.makeJSONDecoder().decode(REST.ServerRelaysResponse.self, from: rawData) | ||
} | ||
|
||
public init(cachedRelays: CachedRelays) throws { | ||
etag = cachedRelays.etag | ||
rawData = try REST.Coding.makeJSONEncoder().encode(cachedRelays.relays) | ||
updatedAt = cachedRelays.updatedAt | ||
relays = cachedRelays.relays | ||
} | ||
} |
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.