From 03426ab3acf09723b56c65712ec1d60fcee33817 Mon Sep 17 00:00:00 2001 From: Christoph Hagen Date: Sun, 5 Jun 2022 18:25:39 +0200 Subject: [PATCH] Add public initializers --- .../PushAPI/AuthenticatedPushMessage.swift | 10 +++++++ Sources/PushAPI/DeviceAuthentication.swift | 10 +++++++ Sources/PushAPI/DeviceDecision.swift | 11 ++++++++ Sources/PushAPI/DeviceRegistration.swift | 12 +++++++++ Sources/PushAPI/DeviceUpdate.swift | 11 ++++++++ Sources/PushAPI/PushMessage.swift | 27 +++++++++++++++++++ 6 files changed, 81 insertions(+) diff --git a/Sources/PushAPI/AuthenticatedPushMessage.swift b/Sources/PushAPI/AuthenticatedPushMessage.swift index 7d22e01..826c3e3 100644 --- a/Sources/PushAPI/AuthenticatedPushMessage.swift +++ b/Sources/PushAPI/AuthenticatedPushMessage.swift @@ -14,4 +14,14 @@ public struct AuthenticatedPushMessage: Codable { /// The message to send public let message: PushMessage + /** + Create an authenticated push message + - Parameter sender: The authentication of the sender + - Parameter message: The message metadata and content + */ + public init(sender: DeviceAuthentication, message: PushMessage) { + self.sender = sender + self.message = message + } + } diff --git a/Sources/PushAPI/DeviceAuthentication.swift b/Sources/PushAPI/DeviceAuthentication.swift index 3f0355c..838bea7 100644 --- a/Sources/PushAPI/DeviceAuthentication.swift +++ b/Sources/PushAPI/DeviceAuthentication.swift @@ -19,4 +19,14 @@ public struct DeviceAuthentication: Codable { */ public let authentication: AuthenticationToken + /** + Create a device authentication object. + + - Parameter pushToken: The APNs device token + - Parameter authentication: The authentication token generated by the server + */ + public init(pushToken: PushToken, authentication: AuthenticationToken) { + self.pushToken = pushToken + self.authentication = authentication + } } diff --git a/Sources/PushAPI/DeviceDecision.swift b/Sources/PushAPI/DeviceDecision.swift index 491a3f2..67b6937 100644 --- a/Sources/PushAPI/DeviceDecision.swift +++ b/Sources/PushAPI/DeviceDecision.swift @@ -12,4 +12,15 @@ public struct DeviceDecision: Codable { /// The hash of the master key to authenticate the request. public let masterKeyHash: Data + + /** + Create a decision object to approve or reject a device registration. + + - Parameter pushToken: The APNs device token + - Parameter masterKeyHash: The SHA256 hash of the administrator master key. + */ + public init(pushToken: PushToken, masterKeyHash: Data) { + self.pushToken = pushToken + self.masterKeyHash = masterKeyHash + } } diff --git a/Sources/PushAPI/DeviceRegistration.swift b/Sources/PushAPI/DeviceRegistration.swift index b8c15ad..5302746 100644 --- a/Sources/PushAPI/DeviceRegistration.swift +++ b/Sources/PushAPI/DeviceRegistration.swift @@ -17,4 +17,16 @@ public struct DeviceRegistration: Codable { The name is displayed when registered users request a list of all devices in an application. */ public let name: String + + /** + Create a new device registration object. + - Parameter pushToken: The push token to register + - Parameter application: The application the device uses + - Parameter name: A descriptive name of the device. + */ + public init(pushToken: PushToken, application: ApplicationId, name: String) { + self.pushToken = pushToken + self.application = application + self.name = name + } } diff --git a/Sources/PushAPI/DeviceUpdate.swift b/Sources/PushAPI/DeviceUpdate.swift index b7b9b24..9bc8c35 100644 --- a/Sources/PushAPI/DeviceUpdate.swift +++ b/Sources/PushAPI/DeviceUpdate.swift @@ -10,4 +10,15 @@ public struct PushTokenUpdate: Codable { /// The new push token to register public let newToken: PushToken + + /** + Create a device authentication object. + + - Parameter device: The authentication of the device requesting the change. + - Parameter PushToken: The new APNs token to use from now on + */ + public init(device: DeviceAuthentication, newToken: PushToken) { + self.device = device + self.newToken = newToken + } } diff --git a/Sources/PushAPI/PushMessage.swift b/Sources/PushAPI/PushMessage.swift index 23f5d40..fd62df0 100644 --- a/Sources/PushAPI/PushMessage.swift +++ b/Sources/PushAPI/PushMessage.swift @@ -55,6 +55,33 @@ public struct PushMessage: Codable { In general, the topic is your app’s bundle ID/app ID. It can have a suffix based on the type of push notification. If you’re using a certificate that supports PushKit VoIP or watchOS complication notifications, you must include this header with bundle ID of you app and if applicable, the proper suffix. If you’re using token-based authentication with APNs, you must include this header with the correct bundle ID and suffix combination. To learn more about app ID, see [Register an App ID](https://help.apple.com/developer-account/#/dev1b35d6f83). */ public let topic: String? + + /** + Create a new push message. + + - Parameter recipients: A list of push tokens for all recipients of the message + - Parameter payload: The message content and metadata + - Parameter pushType: The content type of the message + - Parameter topic: The topic id + - Parameter expiration: An optional expiration date for the message + - Parameter lowPriority: Specify `true` to deliver message with lower priority + - Parameter collapseIdentifier: An optional identifier to group push notifications + */ + public init(recipients: [PushToken], + payload: APNSwiftPayload, + pushType: APNSwiftConnection.PushType, + topic: String, + expiration: Date? = nil, + lowPriority: Bool = false, + collapseIdentifier: String? = nil) { + self.recipients = recipients + self.payload = payload + self.pushType = pushType + self.topic = topic + self.expiration = expiration + self.lowPriority = lowPriority + self.collapseIdentifier = collapseIdentifier + } } extension APNSwiftConnection.PushType: Codable {