PushMessage.swift 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // LoopFollow
  2. // PushMessage.swift
  3. // Created by Jonas Björkert.
  4. import Foundation
  5. struct PushMessage: Encodable {
  6. let aps: [String: Int] = ["content-available": 1]
  7. var user: String
  8. var commandType: TRCCommandType
  9. var bolusAmount: Decimal?
  10. var target: Int?
  11. var duration: Int?
  12. var carbs: Int?
  13. var protein: Int?
  14. var fat: Int?
  15. var sharedSecret: String
  16. var timestamp: TimeInterval
  17. var overrideName: String?
  18. var scheduledTime: TimeInterval?
  19. var returnNotification: ReturnNotificationInfo?
  20. struct ReturnNotificationInfo: Encodable {
  21. let productionEnvironment: Bool
  22. let deviceToken: String
  23. let bundleId: String
  24. let teamId: String
  25. let keyId: String
  26. let apnsKey: String
  27. enum CodingKeys: String, CodingKey {
  28. case productionEnvironment = "production_environment"
  29. case deviceToken = "device_token"
  30. case bundleId = "bundle_id"
  31. case teamId = "team_id"
  32. case keyId = "key_id"
  33. case apnsKey = "apns_key"
  34. }
  35. }
  36. enum CodingKeys: String, CodingKey {
  37. case aps
  38. case user
  39. case commandType = "command_type"
  40. case bolusAmount = "bolus_amount"
  41. case target
  42. case duration
  43. case carbs
  44. case protein
  45. case fat
  46. case sharedSecret = "shared_secret"
  47. case timestamp
  48. case overrideName
  49. case scheduledTime = "scheduled_time"
  50. case returnNotification = "return_notification"
  51. }
  52. func encode(to encoder: Encoder) throws {
  53. var container = encoder.container(keyedBy: CodingKeys.self)
  54. try container.encode(aps, forKey: .aps)
  55. try container.encode(user, forKey: .user)
  56. try container.encode(commandType.rawValue, forKey: .commandType)
  57. try container.encodeIfPresent(bolusAmount, forKey: .bolusAmount)
  58. try container.encodeIfPresent(target, forKey: .target)
  59. try container.encodeIfPresent(duration, forKey: .duration)
  60. try container.encodeIfPresent(carbs, forKey: .carbs)
  61. try container.encodeIfPresent(protein, forKey: .protein)
  62. try container.encodeIfPresent(fat, forKey: .fat)
  63. try container.encode(sharedSecret, forKey: .sharedSecret)
  64. try container.encode(timestamp, forKey: .timestamp)
  65. try container.encodeIfPresent(overrideName, forKey: .overrideName)
  66. try container.encodeIfPresent(scheduledTime, forKey: .scheduledTime)
  67. try container.encodeIfPresent(returnNotification, forKey: .returnNotification)
  68. }
  69. }