Skip to content

Commit 211cb81

Browse files
Cleanup JsonValueRepresentable
1 parent ce82603 commit 211cb81

13 files changed

+35
-43
lines changed

swift-sdk/Constants.swift

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -213,41 +213,33 @@ enum JsonKey {
213213
}
214214
}
215215

216-
public protocol JsonValueRepresentable {
217-
var jsonValue: Any { get }
218-
}
216+
enum JsonValue {
217+
static let applicationJson = "application/json"
218+
static let apnsSandbox = "APNS_SANDBOX"
219+
static let apnsProduction = "APNS"
220+
static let iOS = "iOS"
221+
static let bearer = "Bearer"
219222

220-
public enum JsonValue: String, JsonValueRepresentable {
221-
case applicationJson = "application/json"
222-
case apnsSandbox = "APNS_SANDBOX"
223-
case apnsProduction = "APNS"
224-
case iOS
225-
case bearer = "Bearer"
226-
227-
public enum ActionIdentifier {
223+
enum ActionIdentifier {
228224
static let pushOpenDefault = "default"
229225
}
230226

231-
public enum DeviceIdiom {
227+
enum DeviceIdiom {
232228
static let pad = "Pad"
233229
static let phone = "Phone"
234230
static let carPlay = "CarPlay"
235231
static let tv = "TV"
236232
static let unspecified = "Unspecified"
237233
}
238234

239-
public enum Code {
235+
enum Code {
240236
static let badApiKey = "BadApiKey"
241237
static let invalidJwtPayload = "InvalidJwtPayload"
242238
}
243-
244-
public var jsonStringValue: String {
245-
rawValue
246-
}
247-
248-
public var jsonValue: Any {
249-
rawValue
250-
}
239+
}
240+
241+
public protocol JsonValueRepresentable {
242+
var jsonValue: Any { get }
251243
}
252244

253245
@objc public enum InAppLocation: Int, JsonValueRepresentable {

swift-sdk/Internal/InternalIterableAPI.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
3737

3838
var deviceMetadata: DeviceMetadata {
3939
DeviceMetadata(deviceId: deviceId,
40-
platform: JsonValue.iOS.jsonStringValue,
40+
platform: JsonValue.iOS,
4141
appPackageName: Bundle.main.appPackageName ?? "")
4242
}
4343

swift-sdk/Internal/IterableAPICallRequest.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ struct IterableAPICallRequest {
5454
}
5555

5656
private func createIterableHeaders(currentDate: Date, processorType: ProcessorType) -> [String: String] {
57-
var headers = [JsonKey.contentType: JsonValue.applicationJson.jsonStringValue,
58-
JsonKey.Header.sdkPlatform: JsonValue.iOS.jsonStringValue,
57+
var headers = [JsonKey.contentType: JsonValue.applicationJson,
58+
JsonKey.Header.sdkPlatform: JsonValue.iOS,
5959
JsonKey.Header.sdkVersion: IterableAPI.sdkVersion,
6060
JsonKey.Header.apiKey: apiKey,
6161
JsonKey.Header.sentAt: Self.format(sentAt: currentDate),

swift-sdk/Internal/RequestCreator.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ struct RequestCreator {
203203
}
204204

205205
var args: [AnyHashable: Any] = [JsonKey.InApp.count: count.description,
206-
JsonKey.platform: JsonValue.iOS.jsonStringValue,
206+
JsonKey.platform: JsonValue.iOS,
207207
JsonKey.systemVersion: UIDevice.current.systemVersion,
208208
JsonKey.InApp.sdkVersion: IterableAPI.sdkVersion]
209209

@@ -400,7 +400,7 @@ struct RequestCreator {
400400
}
401401

402402
func createGetRemoteConfigurationRequest() -> Result<IterableRequest, IterableError> {
403-
var args: [AnyHashable: Any] = [JsonKey.platform: JsonValue.iOS.jsonStringValue,
403+
var args: [AnyHashable: Any] = [JsonKey.platform: JsonValue.iOS,
404404
JsonKey.systemVersion: UIDevice.current.systemVersion,
405405
JsonKey.InApp.sdkVersion: IterableAPI.sdkVersion]
406406

@@ -427,11 +427,11 @@ struct RequestCreator {
427427
private static func pushServicePlatformToString(_ pushServicePlatform: PushServicePlatform, apnsType: APNSType) -> String {
428428
switch pushServicePlatform {
429429
case .production:
430-
return JsonValue.apnsProduction.jsonStringValue
430+
return JsonValue.apnsProduction
431431
case .sandbox:
432-
return JsonValue.apnsSandbox.jsonStringValue
432+
return JsonValue.apnsSandbox
433433
case .auto:
434-
return apnsType == .sandbox ? JsonValue.apnsSandbox.jsonStringValue : JsonValue.apnsProduction.jsonStringValue
434+
return apnsType == .sandbox ? JsonValue.apnsSandbox : JsonValue.apnsProduction
435435
}
436436
}
437437

tests/endpoint-tests/IterableAPISupport.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ struct IterableAPISupport {
5454
}
5555

5656
private static func createIterableHeaders() -> [String: String] {
57-
[JsonKey.contentType.jsonKey: JsonValue.applicationJson.jsonStringValue,
58-
JsonKey.Header.sdkPlatform: JsonValue.iOS.jsonStringValue,
57+
[JsonKey.contentType.jsonKey: JsonValue.applicationJson,
58+
JsonKey.Header.sdkPlatform: JsonValue.iOS,
5959
JsonKey.Header.sdkVersion: IterableAPI.sdkVersion,
6060
JsonKey.Header.apiKey: apiKey]
6161
}

tests/offline-events-tests/RequestHandlerTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ class RequestHandlerTests: XCTestCase {
935935
}
936936

937937
private static let deviceMetadata = DeviceMetadata(deviceId: IterableUtil.generateUUID(),
938-
platform: JsonValue.iOS.jsonStringValue,
938+
platform: JsonValue.iOS,
939939
appPackageName: Bundle.main.appPackageName ?? "")
940940

941941
private let dateProvider = MockDateProvider()

tests/offline-events-tests/TaskProcessorTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ class TaskProcessorTests: XCTestCase {
251251
}
252252

253253
private let deviceMetadata = DeviceMetadata(deviceId: IterableUtil.generateUUID(),
254-
platform: JsonValue.iOS.jsonStringValue,
254+
platform: JsonValue.iOS,
255255
appPackageName: Bundle.main.appPackageName ?? "")
256256

257257
private lazy var persistenceProvider: IterablePersistenceContextProvider = {

tests/offline-events-tests/TaskRunnerTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ class TaskRunnerTests: XCTestCase {
330330
}
331331

332332
private let deviceMetadata = DeviceMetadata(deviceId: IterableUtil.generateUUID(),
333-
platform: JsonValue.iOS.jsonStringValue,
333+
platform: JsonValue.iOS,
334334
appPackageName: Bundle.main.appPackageName ?? "")
335335

336336
private lazy var persistenceContextProvider: IterablePersistenceContextProvider = {

tests/offline-events-tests/TaskSchedulerTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class TaskSchedulerTests: XCTestCase {
5555
}
5656

5757
private let deviceMetadata = DeviceMetadata(deviceId: IterableUtil.generateUUID(),
58-
platform: JsonValue.iOS.jsonStringValue,
58+
platform: JsonValue.iOS,
5959
appPackageName: Bundle.main.appPackageName ?? "")
6060

6161
private lazy var persistenceContextProvider: IterablePersistenceContextProvider = {

tests/swift-sdk-swift-tests/IterableAPIResponseTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,14 @@ class IterableAPIResponseTests: XCTestCase {
187187
}
188188

189189
private func verifyIterableHeaders(_ urlRequest: URLRequest) {
190-
XCTAssertEqual(urlRequest.value(forHTTPHeaderField: JsonKey.Header.sdkPlatform), JsonValue.iOS.jsonStringValue)
190+
XCTAssertEqual(urlRequest.value(forHTTPHeaderField: JsonKey.Header.sdkPlatform), JsonValue.iOS)
191191
XCTAssertEqual(urlRequest.value(forHTTPHeaderField: JsonKey.Header.sdkVersion), IterableAPI.sdkVersion)
192192
XCTAssertEqual(urlRequest.value(forHTTPHeaderField: JsonKey.Header.apiKey), apiKey)
193-
XCTAssertEqual(urlRequest.value(forHTTPHeaderField: JsonKey.contentType), JsonValue.applicationJson.jsonStringValue)
193+
XCTAssertEqual(urlRequest.value(forHTTPHeaderField: JsonKey.contentType), JsonValue.applicationJson)
194194
}
195195

196196
private func verifyAuthTokenInHeader(_ urlRequest: URLRequest, _ authToken: String) {
197-
XCTAssertEqual(urlRequest.value(forHTTPHeaderField: JsonKey.Header.authorization), "\(JsonValue.bearer.rawValue) \(authToken)")
197+
XCTAssertEqual(urlRequest.value(forHTTPHeaderField: JsonKey.Header.authorization), "\(JsonValue.bearer) \(authToken)")
198198
}
199199

200200
private func createApiClient(networkSession: NetworkSessionProtocol = MockNetworkSession()) -> ApiClient {

0 commit comments

Comments
 (0)