Skip to content

Commit a2505d8

Browse files
authored
Merge pull request #624 from Iterable/evan/MOB-5935-redirect-endpoints
[MOB-5935] redirect endpoints
2 parents 0042229 + c66af11 commit a2505d8

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

swift-sdk/Internal/InternalIterableAPI.swift

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

81+
var apiEndPointForTest: String {
82+
get {
83+
apiEndPoint
84+
}
85+
}
86+
8187
// MARK: - SDK Functions
8288

8389
@discardableResult func handleUniversalLink(_ url: URL) -> Bool {
@@ -555,6 +561,11 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
555561
}
556562
}
557563

564+
private static func setApiEndpoint(apiEndPointOverride: String?, config: IterableConfig) -> String {
565+
let apiEndPoint = config.dataRegion
566+
return apiEndPointOverride ?? apiEndPoint
567+
}
568+
558569
init(apiKey: String,
559570
launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil,
560571
config: IterableConfig = IterableConfig(),
@@ -565,7 +576,7 @@ final class InternalIterableAPI: NSObject, PushTrackerProtocol, AuthProvider {
565576
self.apiKey = apiKey
566577
self.launchOptions = launchOptions
567578
self.config = config
568-
apiEndPoint = apiEndPointOverride ?? Endpoint.api
579+
apiEndPoint = InternalIterableAPI.setApiEndpoint(apiEndPointOverride: apiEndPointOverride, config: config)
569580
self.dependencyContainer = dependencyContainer
570581
dateProvider = dependencyContainer.dateProvider
571582
networkSession = dependencyContainer.networkSession

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"
15+
private static let apiEndPointEU = "https://api.eu.iterable.com"
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)