Push-Definitions/Sources/PushAPI/Push.swift

128 lines
4.5 KiB
Swift
Raw Normal View History

2022-06-05 11:47:58 +02:00
import Foundation
/**
All routes available on the server.
The raw values of the cases represent the path to the route.
*/
2022-06-05 12:10:38 +02:00
public enum Route: String {
2022-06-05 11:47:58 +02:00
/**
Register a device for push notifications.
If the selected application requires approval, then the administrator must approve the device before it can receive push notifications.
* HTTP Method: `POST`
* HTTP Body: `DeviceRegistration` JSON object.
* Response: The binary authentication token generated for the device. Status `417`, if the application does not exist.
*/
case registerNewDevice = "register"
/**
Update the push token for a registered device.
* HTTP Method: `POST`
* HTTP Body: A `PushTokenUpdate` JSON object.
* Response: A status of `200` is returned on success. `401` if the authorization fails.
*/
case updatePushToken = "update"
/**
Get a list of unapproved devices for review.
* HTTP Method: `POST`
2022-06-07 17:14:20 +02:00
* HTTP Body: An `AdminRequest` JSON object with the SHA256 hash of the admin key and the application id
2022-06-05 11:47:58 +02:00
* Response: An array of `DeviceRegistration` elements encoded in JSON. `401` if the master key is incorrect.
*/
case listUnapprovedDevices = "check"
/**
Get a list of approved devices for the same application as the requestor.
* HTTP Method: `POST`
* HTTP Body: A `DeviceConfirmation` JSON object
* Response: An array of `DeviceRegistration` with all devices registered for the same application. Status `401` if the authentication is incorrect. Status `417`, if the application does not allow device listing.
*/
case listDevicesInApplication = "devices"
/**
Approve a device for an application.
* HTTP Method: `POST`
* HTTP Body: A `DeviceDecision` object with the push token of the approved device and the SHA256 hash of the master key.
* Response: Status `200` on success, `401` for an invalid master key.
- Note: If no device with the push token exists, then this call does nothing and returns `200`
*/
case approveDevice = "approve"
/**
Reject a device.
* HTTP Method: `POST`
* HTTP Body: A `DeviceDecision` object with the push token of the rejected device and the SHA256 hash of the master key.
* Response: Status `200` on success, `401` for an invalid master key.
- Note: If no device with the push token exists, then this call does nothing and returns `200`
*/
case rejectDevice = "reject"
/**
Check if a registered device is approved for usage.
* HTTP Method: `POST`
* HTTP Body: A `DeviceAuthentication` object
* Response: Status `200` if the device is confirmed, and `401` if the device is not confirmed.
*/
case isDeviceApproved = "approved"
/**
Send a push notification to a list of devices.
* HTTP Method: `POST`
* HTTP Body: An `AuthenticatedPushMessage` object
* Response: `200` on success, `401` if authentication is invalid.
*/
case sendPushNotification = "push"
/// The HTTP method required for the route.
2022-06-05 12:13:47 +02:00
public var httpMethod: String {
2022-06-05 11:47:58 +02:00
// Currently all routes expect `POST` requests.
return "POST"
}
/**
Create the url for the route on a server.
- Parameter server: The url of the server.
- Returns: The url to the route.
*/
2022-06-05 12:13:47 +02:00
public func url(for server: URL) -> URL {
2022-06-05 11:47:58 +02:00
server.appendingPathComponent(rawValue)
}
}
/**
An apple push token (usually 32 byte).
Push tokens are created when a device registers with the Apple Push Notification Service (APNS). The tokens act as identifiers to transmit push notifications to devices. The server uses the unique push tokens to identify devices and assign them to applications.
*/
2022-06-05 12:10:38 +02:00
public typealias PushToken = Data
2022-06-05 11:47:58 +02:00
/**
An authentication token of a device.
These tokens are created by the server during device registration, and used for all subsequent requests in combination with the push token.
*/
2022-06-05 12:10:38 +02:00
public typealias AuthenticationToken = Data
2022-06-05 11:47:58 +02:00
/**
The name of an application.
The push server can simultaneously handle multiple applications, which are identified by a unique string. Applications can require confirmation of new device registrations by the administrator. The server configuration also specifies if applications allow the retrieval of device lists for all registered devices, to directly send push notifications to the participants.
*/
2022-06-05 12:10:38 +02:00
public typealias ApplicationId = String
2022-06-05 11:47:58 +02:00
/**
The SHA256 hash of the master key with a salt.
*/
2022-06-05 12:10:38 +02:00
public typealias MasterKeyHash = Data