Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: added eventsApiProxyURL option for proxying to a different url than the sdk config #194

Merged
merged 2 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions DevCycle/Models/DevCycleOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion DevCycle/Networking/DevCycleService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions DevCycleTests/Models/DevCycleOptionsTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class DevCycleOptionsTest: XCTestCase {
.disableCustomEventLogging(true)
.disableAutomaticEventLogging(true)
.apiProxyURL("localhost:4000")
.eventsApiProxyURL("localhost:4001")
.build()
XCTAssertNotNil(options)
XCTAssert(options.eventFlushIntervalMS == 1000)
Expand All @@ -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() {
Expand Down
14 changes: 11 additions & 3 deletions DevCycleTests/Networking/DevCycleServiceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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"))
}

Expand Down
Loading