-
Notifications
You must be signed in to change notification settings - Fork 1
/
NotificareApplication.swift
156 lines (134 loc) · 5.72 KB
/
NotificareApplication.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//
// Copyright (c) 2020 Notificare. All rights reserved.
//
import NotificareUtilitiesKit
public struct NotificareApplication: Codable, Equatable {
public let id: String
public let name: String
public let category: String
public let appStoreId: String?
public let services: [String: Bool]
public let inboxConfig: InboxConfig?
public let regionConfig: RegionConfig?
public let userDataFields: [UserDataField]
public let actionCategories: [ActionCategory]
public init(id: String, name: String, category: String, appStoreId: String?, services: [String: Bool], inboxConfig: NotificareApplication.InboxConfig?, regionConfig: NotificareApplication.RegionConfig?, userDataFields: [NotificareApplication.UserDataField], actionCategories: [NotificareApplication.ActionCategory]) {
self.id = id
self.name = name
self.category = category
self.appStoreId = appStoreId
self.services = services
self.inboxConfig = inboxConfig
self.regionConfig = regionConfig
self.userDataFields = userDataFields
self.actionCategories = actionCategories
}
public enum ServiceKey: String {
case oauth2
case richPush
case locationServices
case apns
case gcm
case websockets
case passbook
case inAppPurchase
case inbox
case storage
}
public struct InboxConfig: Codable, Equatable {
public let useInbox: Bool
public let useUserInbox: Bool
public let autoBadge: Bool
public init(useInbox: Bool, useUserInbox: Bool, autoBadge: Bool) {
self.useInbox = useInbox
self.useUserInbox = useUserInbox
self.autoBadge = autoBadge
}
}
public struct RegionConfig: Codable, Equatable {
public let proximityUUID: String?
public init(proximityUUID: String?) {
self.proximityUUID = proximityUUID
}
}
public struct UserDataField: Codable, Equatable {
public let type: String
public let key: String
public let label: String
public init(type: String, key: String, label: String) {
self.type = type
self.key = key
self.label = label
}
}
public struct ActionCategory: Codable, Equatable {
public let name: String
public let description: String?
public let type: String
public let actions: [NotificareNotification.Action]
public init(name: String, description: String?, type: String, actions: [NotificareNotification.Action]) {
self.name = name
self.description = description
self.type = type
self.actions = actions
}
}
}
// Identifiable: NotificareApplication
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
extension NotificareApplication: Identifiable {}
// JSON: NotificareApplication
extension NotificareApplication {
public func toJson() throws -> [String: Any] {
let data = try JSONEncoder.notificare.encode(self)
return try JSONSerialization.jsonObject(with: data, options: []) as! [String: Any]
}
public static func fromJson(json: [String: Any]) throws -> NotificareApplication {
let data = try JSONSerialization.data(withJSONObject: json, options: [])
return try JSONDecoder.notificare.decode(NotificareApplication.self, from: data)
}
}
// JSON: NotificareApplication.InboxConfig
extension NotificareApplication.InboxConfig {
public func toJson() throws -> [String: Any] {
let data = try JSONEncoder.notificare.encode(self)
return try JSONSerialization.jsonObject(with: data, options: []) as! [String: Any]
}
public static func fromJson(json: [String: Any]) throws -> NotificareApplication.InboxConfig {
let data = try JSONSerialization.data(withJSONObject: json, options: [])
return try JSONDecoder.notificare.decode(NotificareApplication.InboxConfig.self, from: data)
}
}
// JSON: NotificareApplication.RegionConfig
extension NotificareApplication.RegionConfig {
public func toJson() throws -> [String: Any] {
let data = try JSONEncoder.notificare.encode(self)
return try JSONSerialization.jsonObject(with: data, options: []) as! [String: Any]
}
public static func fromJson(json: [String: Any]) throws -> NotificareApplication.RegionConfig {
let data = try JSONSerialization.data(withJSONObject: json, options: [])
return try JSONDecoder.notificare.decode(NotificareApplication.RegionConfig.self, from: data)
}
}
// JSON: NotificareApplication.UserDataField
extension NotificareApplication.UserDataField {
public func toJson() throws -> [String: Any] {
let data = try JSONEncoder.notificare.encode(self)
return try JSONSerialization.jsonObject(with: data, options: []) as! [String: Any]
}
public static func fromJson(json: [String: Any]) throws -> NotificareApplication.UserDataField {
let data = try JSONSerialization.data(withJSONObject: json, options: [])
return try JSONDecoder.notificare.decode(NotificareApplication.UserDataField.self, from: data)
}
}
// JSON: NotificareApplication.ActionCategory
extension NotificareApplication.ActionCategory {
public func toJson() throws -> [String: Any] {
let data = try JSONEncoder.notificare.encode(self)
return try JSONSerialization.jsonObject(with: data, options: []) as! [String: Any]
}
public static func fromJson(json: [String: Any]) throws -> NotificareApplication.ActionCategory {
let data = try JSONSerialization.data(withJSONObject: json, options: [])
return try JSONDecoder.notificare.decode(NotificareApplication.ActionCategory.self, from: data)
}
}