diff --git a/DevCycle/Models/DevCycleOptions.swift b/DevCycle/Models/DevCycleOptions.swift index 6b1ef7c..0d1f80a 100644 --- a/DevCycle/Models/DevCycleOptions.swift +++ b/DevCycle/Models/DevCycleOptions.swift @@ -16,6 +16,7 @@ public class DevCycleOptions { var disableAutomaticEventLogging: Bool = false var disableCustomEventLogging: Bool = false var apiProxyURL: String? + var eventsApiProxyURL: String? public class OptionsBuilder { var options: DevCycleOptions @@ -90,6 +91,12 @@ public class DevCycleOptions { return self } + // Allows the SDK to use a proxy to send to for the events API + public func eventsApiProxyURL(_ proxyURL: String) -> OptionsBuilder { + self.options.eventsApiProxyURL = proxyURL + return self + } + public func build() -> DevCycleOptions { let result = self.options self.options = DevCycleOptions() diff --git a/DevCycle/Networking/DevCycleService.swift b/DevCycle/Networking/DevCycleService.swift index 04d57c7..03c90be 100644 --- a/DevCycle/Networking/DevCycleService.swift +++ b/DevCycle/Networking/DevCycleService.swift @@ -245,7 +245,7 @@ class DevCycleService: DevCycleServiceProtocol { switch(type) { case "event": - if let proxyUrl = self.options?.apiProxyURL { + if let proxyUrl = self.options?.eventsApiProxyURL { url = proxyUrl } else { url = NetworkingConstants.eventsUrl + NetworkingConstants.hostUrl diff --git a/DevCycleTests/Models/DevCycleOptionsTest.swift b/DevCycleTests/Models/DevCycleOptionsTest.swift index 19cd5d5..eefe5f5 100644 --- a/DevCycleTests/Models/DevCycleOptionsTest.swift +++ b/DevCycleTests/Models/DevCycleOptionsTest.swift @@ -24,6 +24,7 @@ class DevCycleOptionsTest: XCTestCase { .disableCustomEventLogging(true) .disableAutomaticEventLogging(true) .apiProxyURL("localhost:4000") + .eventsApiProxyURL("localhost:4001") .build() XCTAssertNotNil(options) XCTAssert(options.eventFlushIntervalMS == 1000) @@ -35,6 +36,7 @@ class DevCycleOptionsTest: XCTestCase { XCTAssert(options.disableCustomEventLogging) XCTAssert(options.disableAutomaticEventLogging) XCTAssert(options.apiProxyURL == "localhost:4000") + XCTAssert(options.eventsApiProxyURL == "localhost:4001") } func testBuilderReturnsOptionsAndSomeAreNil() { diff --git a/DevCycleTests/Networking/DevCycleServiceTests.swift b/DevCycleTests/Networking/DevCycleServiceTests.swift index e8ab575..12abeaa 100644 --- a/DevCycleTests/Networking/DevCycleServiceTests.swift +++ b/DevCycleTests/Networking/DevCycleServiceTests.swift @@ -17,10 +17,14 @@ class DevCycleServiceTests: XCTestCase { func testProxyConfigURL() throws { let options = DevCycleOptions.builder().apiProxyURL("localhost:4000").build() - let url = getService(options).createConfigRequest(user: getTestUser(), enableEdgeDB: false).url?.absoluteString + let service = getService(options) + let url = service.createConfigRequest(user: getTestUser(), enableEdgeDB: false).url?.absoluteString + let eventsUrl = service.createEventsRequest().url?.absoluteString + XCTAssert(url!.contains("localhost:4000/v1/mobileSDKConfig")) XCTAssert(url!.contains("sdkKey=my_sdk_key")) XCTAssert(url!.contains("user_id=my_user")) + XCTAssertFalse(eventsUrl!.contains("localhost:4000")) } func testCreateConfigURLRequestWithEdgeDB() throws { @@ -38,9 +42,13 @@ class DevCycleServiceTests: XCTestCase { } func testProxyEventUrl() throws { - let options = DevCycleOptions.builder().apiProxyURL("localhost:4000").build() - let url = getService(options).createEventsRequest().url?.absoluteString + let options = DevCycleOptions.builder().eventsApiProxyURL("localhost:4000").build() + let service = getService(options) + let url = service.createEventsRequest().url?.absoluteString + let apiUrl = service.createConfigRequest(user: getTestUser(), enableEdgeDB: false).url?.absoluteString + XCTAssert(url!.contains("localhost:4000/v1/events")) + XCTAssertFalse(apiUrl!.contains("localhost:4000")) XCTAssertFalse(url!.contains("user_id=my_user")) }