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

FENCE-1758: Add hostname to init #335

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
22 changes: 19 additions & 3 deletions sdk/src/main/java/io/radar/sdk/Radar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -443,10 +455,11 @@ object Radar {
*
* @param[context] The context.
* @param[publishableKey] Your publishable API key.
* @param[region] Your Radar API host region.
*/
@JvmStatic
fun initialize(context: Context?, publishableKey: String? = null) {
initialize(context, publishableKey, null)
fun initialize(context: Context?, publishableKey: String? = null, region: RadarHostRegion = RadarHostRegion.GLOBAL) {
initialize(context, publishableKey, null, region = region)
}

/**
Expand All @@ -459,9 +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[region] Your Radar API host region.
*/
@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, region: RadarHostRegion = RadarHostRegion.GLOBAL) {
if (context == null) {
return
}
Expand Down Expand Up @@ -489,6 +503,8 @@ object Radar {
RadarSettings.setPublishableKey(this.context, publishableKey)
}

RadarSettings.setHostRegion(this.context, region);

if (!this::apiClient.isInitialized) {
this.apiClient = RadarApiClient(this.context, logger)
}
Expand Down
16 changes: 15 additions & 1 deletion sdk/src/main/java/io/radar/sdk/RadarSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -324,8 +329,17 @@ internal object RadarSettings {
getSharedPreferences(context).edit { putInt(KEY_LOG_LEVEL, logLevelInt) }
}

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) {
Expand Down