Tusker/Packages/PushNotifications/Sources/PushNotifications/PushProxyRegistration.swift

40 lines
937 B
Swift

//
// PushProxyRegistration.swift
// PushNotifications
//
// Created by Shadowfacts on 4/7/24.
//
import Foundation
public struct PushProxyRegistration: Decodable {
let id: String
let endpoint: URL
let deviceToken: String
var defaultsDict: [String: String] {
[
"id": id,
"endpoint": endpoint.absoluteString,
"deviceToken": deviceToken,
]
}
init?(defaultsDict: [String: String]) {
guard let id = defaultsDict["id"],
let endpoint = defaultsDict["endpoint"].flatMap(URL.init(string:)),
let deviceToken = defaultsDict["deviceToken"] else {
return nil
}
self.id = id
self.endpoint = endpoint
self.deviceToken = deviceToken
}
private enum CodingKeys: String, CodingKey {
case id
case endpoint
case deviceToken = "device_token"
}
}