diff --git a/samples/kotlin/src/main/kotlin/com/grid/sample/Config.kt b/samples/kotlin/src/main/kotlin/com/grid/sample/Config.kt index 3470e6ac..206f02b7 100644 --- a/samples/kotlin/src/main/kotlin/com/grid/sample/Config.kt +++ b/samples/kotlin/src/main/kotlin/com/grid/sample/Config.kt @@ -13,9 +13,16 @@ object Config { val apiClientSecret: String = getEnvVar("GRID_CLIENT_SECRET") val webhookPublicKey: String = getEnvVar("GRID_WEBHOOK_PUBKEY").replace("\\n", "\n") + // Optional override for the Grid API base URL (e.g. a dev/RC environment). + // When unset, the SDK uses its default (production) base URL. + val apiBaseUrl: String? = getEnvVarOrNull("GRID_API_BASE_URL") + private fun getEnvVar(key: String): String = + getEnvVarOrNull(key) + ?: throw IllegalStateException("$key environment variable not set") + + private fun getEnvVarOrNull(key: String): String? = System.getProperty(key) ?: dotenv[key] ?: System.getenv(key) - ?: throw IllegalStateException("$key environment variable not set") } diff --git a/samples/kotlin/src/main/kotlin/com/grid/sample/GridClientBuilder.kt b/samples/kotlin/src/main/kotlin/com/grid/sample/GridClientBuilder.kt index 96b1e2ee..6d86599d 100644 --- a/samples/kotlin/src/main/kotlin/com/grid/sample/GridClientBuilder.kt +++ b/samples/kotlin/src/main/kotlin/com/grid/sample/GridClientBuilder.kt @@ -8,6 +8,7 @@ object GridClientBuilder { LightsparkGridOkHttpClient.builder() .username(Config.apiTokenId) .password(Config.apiClientSecret) + .apply { Config.apiBaseUrl?.let { baseUrl(it) } } .build() } }