Skip to content

Commit 55d5159

Browse files
authored
Merge pull request #638 from Iterable/eudc-updates
[MOB-6320] prepare EUDC updates for release
2 parents 3f3b3cd + 7d6d0a4 commit 55d5159

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

swift-sdk/Constants.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,11 @@ enum JsonValue {
267267
}
268268
}
269269

270+
public enum IterableDataRegion {
271+
public static let US = "https://api.iterable.com/api/"
272+
public static let EU = "https://api.eu.iterable.com/api/"
273+
}
274+
270275
public protocol JsonValueRepresentable {
271276
var jsonValue: Any { get }
272277
}

swift-sdk/Internal/InternalIterableAPI.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
8282
self.dependencyContainer.createAuthManager(config: self.config)
8383
}()
8484

85+
var apiEndPointForTest: String {
86+
get {
87+
apiEndPoint
88+
}
89+
}
90+
8591
// MARK: - SDK Functions
8692

8793
@discardableResult func handleUniversalLink(_ url: URL) -> Bool {
@@ -583,6 +589,11 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
583589
}
584590
}
585591

592+
private static func setApiEndpoint(apiEndPointOverride: String?, config: IterableConfig) -> String {
593+
let apiEndPoint = config.dataRegion
594+
return apiEndPointOverride ?? apiEndPoint
595+
}
596+
586597
init(apiKey: String,
587598
launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil,
588599
config: IterableConfig = IterableConfig(),
@@ -593,7 +604,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
593604
self.apiKey = apiKey
594605
self.launchOptions = launchOptions
595606
self.config = config
596-
apiEndPoint = apiEndPointOverride ?? Endpoint.api
607+
apiEndPoint = InternalIterableAPI.setApiEndpoint(apiEndPointOverride: apiEndPointOverride, config: config)
597608
self.dependencyContainer = dependencyContainer
598609
dateProvider = dependencyContainer.dateProvider
599610
networkSession = dependencyContainer.networkSession

swift-sdk/IterableConfig.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,7 @@ public class IterableConfig: NSObject {
124124

125125
/// Set whether the SDK should store in-apps only in memory, or in file storage
126126
public var useInMemoryStorageForInApps = false
127+
128+
/// Sets data region which determines data center and endpoints used by the SDK
129+
public var dataRegion: String = IterableDataRegion.US
127130
}

tests/unit-tests/IterableAPITests.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class IterableAPITests: XCTestCase {
1111
private static let apiKey = "zeeApiKey"
1212
private static let email = "[email protected]"
1313
private static let userId = "testUserId"
14+
private static let apiEndPointUS = "https://api.iterable.com/api/"
15+
private static let apiEndPointEU = "https://api.eu.iterable.com/api/"
1416

1517
override func setUp() {
1618
super.setUp()
@@ -34,6 +36,32 @@ class IterableAPITests: XCTestCase {
3436
XCTAssertEqual(internalAPI.apiKey, IterableAPITests.apiKey)
3537
}
3638

39+
func testInitializeWithDefaultDataRegion() {
40+
let prodIntegrationName = "the-best-app-ever"
41+
42+
let config = IterableConfig()
43+
config.pushIntegrationName = prodIntegrationName
44+
config.inAppDisplayInterval = 1.0
45+
config.dataRegion = IterableDataRegion.US
46+
47+
let internalAPI = InternalIterableAPI.initializeForTesting(apiKey: IterableAPITests.apiKey, config: config)
48+
49+
XCTAssertEqual(internalAPI.apiEndPointForTest, IterableAPITests.apiEndPointUS)
50+
}
51+
52+
func testInitializeWithEUDataRegion() {
53+
let prodIntegrationName = "the-best-app-ever"
54+
55+
let config = IterableConfig()
56+
config.pushIntegrationName = prodIntegrationName
57+
config.inAppDisplayInterval = 1.0
58+
config.dataRegion = IterableDataRegion.EU
59+
60+
let internalAPI = InternalIterableAPI.initializeForTesting(apiKey: IterableAPITests.apiKey, config: config)
61+
62+
XCTAssertEqual(internalAPI.apiEndPointForTest, IterableAPITests.apiEndPointEU)
63+
}
64+
3765
func testInitializeCheckEndpoint() {
3866
let expectation1 = XCTestExpectation(description: "api endpoint called")
3967

0 commit comments

Comments
 (0)