Skip to content

Commit

Permalink
add apiProxyUrl, eventsApiProxyUrl to DevcycleOptions and update test…
Browse files Browse the repository at this point in the history
…s to use them rather than overriding the apiUrl param
  • Loading branch information
elliotCamblor committed Mar 27, 2024
1 parent 5be0355 commit 0cc7d8d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,18 @@ class DevCycleClient private constructor(

fun withOptions(options: DevCycleOptions): DevCycleClientBuilder {
this.options = options
options.apiProxyUrl?.let {
if (it.isNotEmpty()) {
// Override the apiUrl with the apiProxyUrl from options
apiUrl = it
}
}
options.eventsApiProxyUrl?.let {
if (it.isNotEmpty()) {
// Override the eventsUrl with the eventsApiProxyUrl from options
eventsUrl = it
}
}
return this
}

Expand All @@ -598,13 +610,6 @@ class DevCycleClient private constructor(
return this
}

@TestOnly
@JvmSynthetic internal fun withApiUrl(apiUrl: String): DevCycleClientBuilder {
this.apiUrl = apiUrl
this.eventsUrl = apiUrl
return this
}

fun build(): DevCycleClient {
requireNotNull(context) { "Context must be set" }
require(!(sdkKey == null || sdkKey == "")) { "SDK key must be set" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ class DevCycleOptions(
val disableConfigCache: Boolean,
val disableRealtimeUpdates: Boolean,
val disableAutomaticEventLogging : Boolean,
val disableCustomEventLogging : Boolean
val disableCustomEventLogging : Boolean,
val apiProxyUrl: String?,
val eventsApiProxyUrl: String?
) {
class DevCycleOptionsBuilder internal constructor() {
private var flushEventsIntervalMs = 0L
Expand All @@ -19,6 +21,8 @@ class DevCycleOptions(
private var disableRealtimeUpdates = false
private var disableAutomaticEventLogging = false
private var disableCustomEventLogging = false
private var apiProxyUrl: String? = null
private var eventsApiProxyUrl: String? = null

fun flushEventsIntervalMs(flushEventsIntervalMs: Long): DevCycleOptionsBuilder {
this.flushEventsIntervalMs = flushEventsIntervalMs
Expand Down Expand Up @@ -59,6 +63,16 @@ class DevCycleOptions(
this.disableRealtimeUpdates = disableRealtimeUpdates
return this
}

fun apiProxyUrl(apiProxyUrl: String): DevCycleOptionsBuilder {
this.apiProxyUrl = apiProxyUrl
return this
}

fun eventsApiProxyUrl(eventsApiProxyUrl: String): DevCycleOptionsBuilder {
this.eventsApiProxyUrl = eventsApiProxyUrl
return this
}
fun build(): DevCycleOptions {
return DevCycleOptions(
flushEventsIntervalMs,
Expand All @@ -68,7 +82,9 @@ class DevCycleOptions(
disableConfigCache,
disableRealtimeUpdates,
disableAutomaticEventLogging,
disableCustomEventLogging
disableCustomEventLogging,
apiProxyUrl,
eventsApiProxyUrl
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ class DevCycleClientTests {
} else {
// expect only the first and last user id to be sent as a result of the identify calls
try {
println("printing the path")
println(it.path)
Assertions.assertEquals(true, it.path?.contains("expected_userid"))
} catch (e: org.opentest4j.AssertionFailedError) {
println(it.path)
Expand Down Expand Up @@ -724,6 +726,8 @@ class DevCycleClientTests {
val options = DevCycleOptions.builder()
.flushEventsIntervalMs(flushInMs)
.disableAutomaticEventLogging(true)
.apiProxyUrl(mockWebServer.url("/").toString())
.eventsApiProxyUrl(mockWebServer.url("/").toString())
.build()

val client = createClient("pretend-its-a-real-sdk-key", mockWebServer.url("/").toString(), flushInMs, false ,null, LogLevel.DEBUG, options)
Expand Down Expand Up @@ -792,6 +796,8 @@ class DevCycleClientTests {
val options = DevCycleOptions.builder()
.flushEventsIntervalMs(flushInMs)
.disableCustomEventLogging(true)
.apiProxyUrl(mockWebServer.url("/").toString())
.eventsApiProxyUrl(mockWebServer.url("/").toString())
.build()

val client = createClient("pretend-its-a-real-sdk-key", mockWebServer.url("/").toString(), flushInMs, false ,null, logLevel = LogLevel.INFO, options)
Expand Down Expand Up @@ -1483,11 +1489,12 @@ class DevCycleClientTests {
.withSDKKey(sdkKey)
.withLogger(logger)
.withLogLevel(logLevel)
.withApiUrl(mockUrl)
.withOptions(
options ?: DevCycleOptions.builder()
.flushEventsIntervalMs(flushInMs)
.enableEdgeDB(enableEdgeDB)
.apiProxyUrl(mockUrl)
.eventsApiProxyUrl(mockUrl)
.build()
)

Expand Down

0 comments on commit 0cc7d8d

Please sign in to comment.