Skip to content

Commit 1a8700f

Browse files
JsonKeyRepresentable is no more!!!
1 parent d3461b6 commit 1a8700f

24 files changed

+422
-490
lines changed

swift-sdk/Constants.swift

Lines changed: 88 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ enum Endpoint {
1212
static let links = linksHostName + "/"
1313
}
1414

15-
public enum Const {
16-
public static let apiPath = "/api/"
15+
enum Const {
16+
static let apiPath = "/api/"
1717

1818
static let deepLinkRegex = "/a/[a-zA-Z0-9]+"
1919
static let href = "href"
@@ -74,99 +74,95 @@ public enum Const {
7474
}
7575
}
7676

77-
public protocol JsonKeyRepresentable {
78-
var jsonKey: String { get }
79-
}
80-
81-
public enum JsonKey: String, JsonKeyRepresentable {
82-
case email
83-
case userId
84-
case currentEmail
85-
case currentUserId
86-
case newEmail
87-
case emailListIds
88-
case unsubscribedChannelIds
89-
case unsubscribedMessageTypeIds
90-
case subscribedMessageTypeIds
91-
case preferUserId
92-
93-
case mergeNestedObjects
94-
95-
case inboxMetadata
96-
case inboxTitle = "title"
97-
case inboxSubtitle = "subtitle"
98-
case inboxIcon = "icon"
99-
100-
case inboxExpiresAt = "expiresAt"
101-
case inboxCreatedAt = "createdAt"
102-
103-
case inAppMessageContext = "messageContext"
104-
105-
case campaignId
106-
case templateId
107-
case messageId
108-
case inboxSessionId
109-
110-
case saveToInbox
111-
case silentInbox
112-
case inAppLocation = "location"
113-
case clickedUrl
114-
case read
115-
case priorityLevel
116-
117-
case inboxSessionStart
118-
case inboxSessionEnd
119-
case startTotalMessageCount
120-
case startUnreadMessageCount
121-
case endTotalMessageCount
122-
case endUnreadMessageCount
123-
case impressions
124-
case closeAction
125-
case deleteAction
126-
127-
case url
128-
129-
case device
130-
case token
131-
case dataFields
132-
case deviceInfo
133-
case identifierForVendor
134-
case deviceId
135-
case localizedModel
136-
case model
137-
case userInterfaceIdiom
138-
case systemName
139-
case systemVersion
140-
case platform
141-
case appPackageName
142-
case appVersion
143-
case appBuild
144-
case applicationName
145-
case eventName
146-
case actionIdentifier
147-
case userText
148-
case appAlreadyRunning
149-
150-
case html
151-
152-
case iterableSdkVersion
153-
154-
case notificationsEnabled
155-
156-
case contentType = "Content-Type"
157-
158-
public enum ActionButton {
77+
enum JsonKey {
78+
static let email = "email"
79+
static let userId = "userId"
80+
static let currentEmail = "currentEmail"
81+
static let currentUserId = "currentUserId"
82+
static let newEmail = "newEmail"
83+
static let emailListIds = "emailListIds"
84+
static let unsubscribedChannelIds = "unsubscribedChannelIds"
85+
static let unsubscribedMessageTypeIds = "unsubscribedMessageTypeIds"
86+
static let subscribedMessageTypeIds = "subscribedMessageTypeIds"
87+
static let preferUserId = "preferUserId"
88+
89+
static let mergeNestedObjects = "mergeNestedObjects"
90+
91+
static let inboxMetadata = "inboxMetadata"
92+
static let inboxTitle = "title"
93+
static let inboxSubtitle = "subtitle"
94+
static let inboxIcon = "icon"
95+
96+
static let inboxExpiresAt = "expiresAt"
97+
static let inboxCreatedAt = "createdAt"
98+
99+
static let inAppMessageContext = "messageContext"
100+
101+
static let campaignId = "campaignId"
102+
static let templateId = "templateId"
103+
static let messageId = "messageId"
104+
static let inboxSessionId = "inboxSessionId"
105+
106+
static let saveToInbox = "saveToInbox"
107+
static let silentInbox = "silentInbox"
108+
static let inAppLocation = "location"
109+
static let clickedUrl = "clickedUrl"
110+
static let read = "read"
111+
static let priorityLevel = "priorityLevel"
112+
113+
static let inboxSessionStart = "inboxSessionStart"
114+
static let inboxSessionEnd = "inboxSessionEnd"
115+
static let startTotalMessageCount = "startTotalMessageCount"
116+
static let startUnreadMessageCount = "startUnreadMessageCount"
117+
static let endTotalMessageCount = "endTotalMessageCount"
118+
static let endUnreadMessageCount = "endUnreadMessageCount"
119+
static let impressions = "impressions"
120+
static let closeAction = "closeAction"
121+
static let deleteAction = "deleteAction"
122+
123+
static let url = "url"
124+
125+
static let device = "device"
126+
static let token = "token"
127+
static let dataFields = "dataFields"
128+
static let deviceInfo = "deviceInfo"
129+
static let identifierForVendor = "identifierForVendor"
130+
static let deviceId = "deviceId"
131+
static let localizedModel = "localizedModel"
132+
static let model = "model"
133+
static let userInterfaceIdiom = "userInterfaceIdiom"
134+
static let systemName = "systemName"
135+
static let systemVersion = "systemVersion"
136+
static let platform = "platform"
137+
static let appPackageName = "appPackageName"
138+
static let appVersion = "appVersion"
139+
static let appBuild = "appBuild"
140+
static let applicationName = "applicationName"
141+
static let eventName = "eventName"
142+
static let actionIdentifier = "actionIdentifier"
143+
static let userText = "userText"
144+
static let appAlreadyRunning = "appAlreadyRunning"
145+
146+
static let html = "html"
147+
148+
static let iterableSdkVersion = "iterableSdkVersion"
149+
150+
static let notificationsEnabled = "notificationsEnabled"
151+
152+
static let contentType = "Content-Type"
153+
154+
enum ActionButton {
159155
static let identifier = "identifier"
160156
static let action = "action"
161157
}
162158

163-
public enum Commerce {
159+
enum Commerce {
164160
static let items = "items"
165161
static let total = "total"
166162
static let user = "user"
167163
}
168164

169-
public enum Device {
165+
enum Device {
170166
static let localizedModel = "localizedModel"
171167
static let vendorId = "identifierForVendor"
172168
static let model = "model"
@@ -175,7 +171,7 @@ public enum JsonKey: String, JsonKeyRepresentable {
175171
static let userInterfaceIdiom = "userInterfaceIdiom"
176172
}
177173

178-
public enum Header {
174+
enum Header {
179175
static let apiKey = "Api-Key"
180176
static let sdkVersion = "SDK-Version"
181177
static let sdkPlatform = "SDK-Platform"
@@ -184,11 +180,11 @@ public enum JsonKey: String, JsonKeyRepresentable {
184180
static let requestProcessor = "SDK-Request-Processor"
185181
}
186182

187-
public enum Body {
183+
enum Body {
188184
static let createdAt = "createdAt"
189185
}
190186

191-
public enum InApp {
187+
enum InApp {
192188
static let trigger = "trigger"
193189
static let type = "type"
194190
static let contentType = "contentType"
@@ -202,23 +198,19 @@ public enum JsonKey: String, JsonKeyRepresentable {
202198
static let content = "content"
203199
}
204200

205-
public enum Payload {
201+
enum Payload {
206202
static let metadata = "itbl"
207203
static let actionButtons = "actionButtons"
208204
static let defaultAction = "defaultAction"
209205
}
210206

211-
public enum Response {
207+
enum Response {
212208
static let iterableCode = "code"
213209
}
214210

215-
public enum JWT {
211+
enum JWT {
216212
static let exp = "exp"
217213
}
218-
219-
public var jsonKey: String {
220-
rawValue
221-
}
222214
}
223215

224216
public protocol JsonValueRepresentable {

swift-sdk/Internal/ClassExtensions.swift

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -24,52 +24,24 @@ extension Array where Element: Comparable {
2424
}
2525

2626
extension Dictionary where Key == AnyHashable, Value == Any {
27-
func getValue(for key: JsonKey) -> Any? {
28-
self[key.jsonKey]
29-
}
30-
31-
func getValue(for key: JsonKeyRepresentable) -> Any? {
32-
self[key.jsonKey]
33-
}
34-
35-
func getStringValue(for key: JsonKey, withDefault default: String? = nil) -> String? {
36-
getValue(for: key) as? String ?? `default`
37-
}
38-
39-
func getStringValue(for key: JsonKeyRepresentable, withDefault default: String? = nil) -> String? {
40-
getValue(for: key) as? String ?? `default`
41-
}
42-
43-
func getIntValue(for key: JsonKey) -> Int? {
44-
getValue(for: key) as? Int
45-
}
46-
47-
func getIntValue(for key: JsonKeyRepresentable) -> Int? {
48-
getValue(for: key) as? Int
27+
func getStringValue(for key: AnyHashable, withDefault default: String? = nil) -> String? {
28+
self[key] as? String ?? `default`
4929
}
5030

51-
func getDoubleValue(for key: JsonKey) -> Double? {
52-
getValue(for: key) as? Double
31+
func getIntValue(for key: AnyHashable) -> Int? {
32+
self[key] as? Int
5333
}
5434

55-
func getDoubleValue(for key: JsonKeyRepresentable) -> Double? {
56-
getValue(for: key) as? Double
35+
func getDoubleValue(for key: AnyHashable) -> Double? {
36+
self[key] as? Double
5737
}
5838

59-
func getBoolValue(for key: JsonKey) -> Bool? {
60-
getValue(for: key).flatMap ( Self.parseBool(_:) )
39+
func getBoolValue(for key: AnyHashable) -> Bool? {
40+
self[key].flatMap ( Self.parseBool(_:) )
6141
}
6242

63-
func getBoolValue(for key: JsonKeyRepresentable) -> Bool? {
64-
getValue(for: key).flatMap ( Self.parseBool(_:) )
65-
}
66-
67-
mutating func setValue(for key: JsonKey, value: JsonValueRepresentable?) {
68-
self[key.jsonKey] = value?.jsonValue
69-
}
70-
71-
mutating func setValue(for key: JsonKeyRepresentable, value: JsonValueRepresentable?) {
72-
self[key.jsonKey] = value?.jsonValue
43+
mutating func setValue(for key: AnyHashable, value: JsonValueRepresentable?) {
44+
self[key] = value?.jsonValue
7345
}
7446

7547
private static func parseBool(_ any: Any?) -> Bool? {

swift-sdk/Internal/DataFieldsHelper.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ struct DataFieldsHelper {
2121
dataFields[deviceAttribute.key] = deviceAttribute.value
2222
}
2323

24-
dataFields[JsonKey.deviceId.jsonKey] = deviceId
24+
dataFields[JsonKey.deviceId] = deviceId
2525

2626
if let sdkVersion = sdkVersion {
27-
dataFields[JsonKey.iterableSdkVersion.jsonKey] = sdkVersion
27+
dataFields[JsonKey.iterableSdkVersion] = sdkVersion
2828
}
2929

30-
dataFields[JsonKey.notificationsEnabled.jsonKey] = notificationsEnabled
30+
dataFields[JsonKey.notificationsEnabled] = notificationsEnabled
3131

3232
dataFields.addAll(other: createBundleFields(bundle: bundle))
3333

@@ -40,13 +40,13 @@ struct DataFieldsHelper {
4040
var fields = [String: Any]()
4141

4242
if let appPackageName = bundle.appPackageName {
43-
fields[JsonKey.appPackageName.jsonKey] = appPackageName
43+
fields[JsonKey.appPackageName] = appPackageName
4444
}
4545
if let appVersion = bundle.appVersion {
46-
fields[JsonKey.appVersion.jsonKey] = appVersion
46+
fields[JsonKey.appVersion] = appVersion
4747
}
4848
if let appBuild = bundle.appBuild {
49-
fields[JsonKey.appBuild.jsonKey] = appBuild
49+
fields[JsonKey.appBuild] = appBuild
5050
}
5151

5252
return fields

0 commit comments

Comments
 (0)