PushMessage.swift 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // LoopFollow
  2. // PushMessage.swift
  3. import Foundation
  4. struct EncryptedPushMessage: Encodable {
  5. let aps: APSPayload
  6. let encryptedData: String
  7. init(encryptedData: String, commandType: TRCCommandType) {
  8. self.encryptedData = encryptedData
  9. aps = APSPayload(alert: "Remote Command: \(commandType.displayName)")
  10. }
  11. struct APSPayload: Encodable {
  12. let contentAvailable: Int = 1
  13. let interruptionLevel: String = "time-sensitive"
  14. let alert: String
  15. enum CodingKeys: String, CodingKey {
  16. case contentAvailable = "content-available"
  17. case interruptionLevel = "interruption-level"
  18. case alert
  19. }
  20. }
  21. enum CodingKeys: String, CodingKey {
  22. case aps
  23. case encryptedData = "encrypted_data"
  24. }
  25. }
  26. struct CommandPayload: Encodable {
  27. var user: String
  28. var commandType: TRCCommandType
  29. var timestamp: TimeInterval
  30. var bolusAmount: Decimal?
  31. var target: Int?
  32. var duration: Int?
  33. var carbs: Int?
  34. var protein: Int?
  35. var fat: Int?
  36. var overrideName: String?
  37. var scheduledTime: TimeInterval?
  38. var returnNotification: ReturnNotificationInfo?
  39. struct ReturnNotificationInfo: Encodable {
  40. let productionEnvironment: Bool
  41. let deviceToken: String
  42. let bundleId: String
  43. let teamId: String
  44. let keyId: String
  45. let apnsKey: String
  46. enum CodingKeys: String, CodingKey {
  47. case productionEnvironment = "production_environment"
  48. case deviceToken = "device_token"
  49. case bundleId = "bundle_id"
  50. case teamId = "team_id"
  51. case keyId = "key_id"
  52. case apnsKey = "apns_key"
  53. }
  54. }
  55. enum CodingKeys: String, CodingKey {
  56. case user
  57. case commandType = "command_type"
  58. case timestamp
  59. case bolusAmount = "bolus_amount"
  60. case target
  61. case duration
  62. case carbs
  63. case protein
  64. case fat
  65. case overrideName
  66. case scheduledTime = "scheduled_time"
  67. case returnNotification = "return_notification"
  68. }
  69. }