From 9bb086a31d5ce90a415b725b7654716411a46a30 Mon Sep 17 00:00:00 2001 From: York Wei Date: Mon, 29 Jan 2024 13:58:35 -0500 Subject: [PATCH 1/3] add hostname to init --- sdk/src/main/java/io/radar/sdk/Radar.kt | 12 +++++++++--- sdk/src/main/java/io/radar/sdk/RadarSettings.kt | 4 ++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/sdk/src/main/java/io/radar/sdk/Radar.kt b/sdk/src/main/java/io/radar/sdk/Radar.kt index 462a035c7..c68295193 100644 --- a/sdk/src/main/java/io/radar/sdk/Radar.kt +++ b/sdk/src/main/java/io/radar/sdk/Radar.kt @@ -443,10 +443,11 @@ object Radar { * * @param[context] The context. * @param[publishableKey] Your publishable API key. + * @param[hostname] Your Radar API hostname. */ @JvmStatic - fun initialize(context: Context?, publishableKey: String? = null) { - initialize(context, publishableKey, null) + fun initialize(context: Context?, publishableKey: String? = null, hostname: String? = null) { + initialize(context, publishableKey, null, hostname = hostname) } /** @@ -459,9 +460,10 @@ object Radar { * @param[receiver] An optional receiver for the client-side delivery of events. * @param[provider] The location services provider. * @param[fraud] A boolean indicating whether to enable additional fraud detection signals for location verification. + * @param[hostname] Your Radar API hostname. */ @JvmStatic - fun initialize(context: Context?, publishableKey: String? = null, receiver: RadarReceiver? = null, provider: RadarLocationServicesProvider = RadarLocationServicesProvider.GOOGLE, fraud: Boolean = false) { + fun initialize(context: Context?, publishableKey: String? = null, receiver: RadarReceiver? = null, provider: RadarLocationServicesProvider = RadarLocationServicesProvider.GOOGLE, fraud: Boolean = false, hostname: String? = null) { if (context == null) { return } @@ -489,6 +491,10 @@ object Radar { RadarSettings.setPublishableKey(this.context, publishableKey) } + if (hostname != null) { + RadarSettings.setHost(this.context, hostname); + } + if (!this::apiClient.isInitialized) { this.apiClient = RadarApiClient(this.context, logger) } diff --git a/sdk/src/main/java/io/radar/sdk/RadarSettings.kt b/sdk/src/main/java/io/radar/sdk/RadarSettings.kt index 6737b1efa..8ce5569f2 100644 --- a/sdk/src/main/java/io/radar/sdk/RadarSettings.kt +++ b/sdk/src/main/java/io/radar/sdk/RadarSettings.kt @@ -324,6 +324,10 @@ internal object RadarSettings { getSharedPreferences(context).edit { putInt(KEY_LOG_LEVEL, logLevelInt) } } + internal fun setHost(context: Context, host: String) { + getSharedPreferences(context).edit { putString(KEY_HOST, host) } + } + internal fun getHost(context: Context): String { return getSharedPreferences(context).getString(KEY_HOST, null) ?: "https://api.radar.io" } From 4421307b68d0a9e9db73b7b9dcafdaabea8364b0 Mon Sep 17 00:00:00 2001 From: York Wei Date: Mon, 29 Jan 2024 13:59:06 -0500 Subject: [PATCH 2/3] bump --- sdk/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/build.gradle b/sdk/build.gradle index 9c9583e5d..a098d085b 100644 --- a/sdk/build.gradle +++ b/sdk/build.gradle @@ -10,7 +10,7 @@ apply plugin: "org.jetbrains.dokka" apply plugin: 'io.radar.mvnpublish' ext { - radarVersion = '3.9.1' + radarVersion = '3.9.2' } String buildNumber = ".${System.currentTimeMillis()}" From acb09fa4dbee1e713f2488dd595a6db42df2ee9b Mon Sep 17 00:00:00 2001 From: York Wei Date: Tue, 6 Feb 2024 15:53:00 -0500 Subject: [PATCH 3/3] use enums --- sdk/src/main/java/io/radar/sdk/Radar.kt | 26 +++++++++++++------ .../main/java/io/radar/sdk/RadarSettings.kt | 16 +++++++++--- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/sdk/src/main/java/io/radar/sdk/Radar.kt b/sdk/src/main/java/io/radar/sdk/Radar.kt index 7f7bb7cb5..6067c5d9f 100644 --- a/sdk/src/main/java/io/radar/sdk/Radar.kt +++ b/sdk/src/main/java/io/radar/sdk/Radar.kt @@ -421,6 +421,18 @@ object Radar { HUAWEI } + /** + * The Radar API host regions. + */ + enum class RadarHostRegion { + /** https://api.na.radar.com */ + NORTH_AMERICA, + /** https://api.eu.radar.com */ + EUROPE, + /** https://api.radar.io */ + GLOBAL + } + internal var initialized = false internal var isFlushingReplays = false private lateinit var context: Context @@ -443,11 +455,11 @@ object Radar { * * @param[context] The context. * @param[publishableKey] Your publishable API key. - * @param[hostname] Your Radar API hostname. + * @param[region] Your Radar API host region. */ @JvmStatic - fun initialize(context: Context?, publishableKey: String? = null, hostname: String? = null) { - initialize(context, publishableKey, null, hostname = hostname) + fun initialize(context: Context?, publishableKey: String? = null, region: RadarHostRegion = RadarHostRegion.GLOBAL) { + initialize(context, publishableKey, null, region = region) } /** @@ -460,10 +472,10 @@ object Radar { * @param[receiver] An optional receiver for the client-side delivery of events. * @param[provider] The location services provider. * @param[fraud] A boolean indicating whether to enable additional fraud detection signals for location verification. - * @param[hostname] Your Radar API hostname. + * @param[region] Your Radar API host region. */ @JvmStatic - fun initialize(context: Context?, publishableKey: String? = null, receiver: RadarReceiver? = null, provider: RadarLocationServicesProvider = RadarLocationServicesProvider.GOOGLE, fraud: Boolean = false, hostname: String? = null) { + fun initialize(context: Context?, publishableKey: String? = null, receiver: RadarReceiver? = null, provider: RadarLocationServicesProvider = RadarLocationServicesProvider.GOOGLE, fraud: Boolean = false, region: RadarHostRegion = RadarHostRegion.GLOBAL) { if (context == null) { return } @@ -491,9 +503,7 @@ object Radar { RadarSettings.setPublishableKey(this.context, publishableKey) } - if (hostname != null) { - RadarSettings.setHost(this.context, hostname); - } + RadarSettings.setHostRegion(this.context, region); if (!this::apiClient.isInitialized) { this.apiClient = RadarApiClient(this.context, logger) diff --git a/sdk/src/main/java/io/radar/sdk/RadarSettings.kt b/sdk/src/main/java/io/radar/sdk/RadarSettings.kt index 8ce5569f2..f5fa7bdb2 100644 --- a/sdk/src/main/java/io/radar/sdk/RadarSettings.kt +++ b/sdk/src/main/java/io/radar/sdk/RadarSettings.kt @@ -44,6 +44,11 @@ internal object RadarSettings { private const val KEY_OLD_OFFLINE_MODE = "offline_mode" private const val KEY_USER_DEBUG = "user_debug" + private const val RADAR_HOST_GLOBAL = "https://api.radar.io" + private const val RADAR_HOST_NORTH_AMERICA = "https://api.na.radar.com" + private const val RADAR_HOST_EUROPE = "https://api.eu.radar.com" + + private fun getSharedPreferences(context: Context): SharedPreferences { return context.getSharedPreferences("RadarSDK", Context.MODE_PRIVATE) } @@ -324,12 +329,17 @@ internal object RadarSettings { getSharedPreferences(context).edit { putInt(KEY_LOG_LEVEL, logLevelInt) } } - internal fun setHost(context: Context, host: String) { - getSharedPreferences(context).edit { putString(KEY_HOST, host) } + internal fun setHostRegion(context: Context, region: Radar.RadarHostRegion) { + val hostString = when(region) { + Radar.RadarHostRegion.NORTH_AMERICA -> RADAR_HOST_NORTH_AMERICA + Radar.RadarHostRegion.EUROPE -> RADAR_HOST_EUROPE + Radar.RadarHostRegion.GLOBAL -> RADAR_HOST_GLOBAL + } + getSharedPreferences(context).edit { putString(KEY_HOST, hostString) } } internal fun getHost(context: Context): String { - return getSharedPreferences(context).getString(KEY_HOST, null) ?: "https://api.radar.io" + return getSharedPreferences(context).getString(KEY_HOST, null) ?: RADAR_HOST_GLOBAL } internal fun setPermissionsDenied(context: Context, denied: Boolean) {