com.deque.networking.usageservice.UsageService.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of axe-devtools-android-core Show documentation
Show all versions of axe-devtools-android-core Show documentation
The Axe Devtools Android Core Library
The newest version!
package com.deque.networking.usageservice
import com.deque.axe.android.constants.AxeBuildEnv
import com.deque.axe.android.constants.Config
import com.deque.networking.interfaces.DashboardService
import com.deque.networking.utils.DistinctId
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.launch
class UsageService(val config: UsageServiceConfig) {
private var usageServiceClient: UsageServiceClient
private val scope = MainScope()
private var baseUrl: String = SERVICE_PROD_URL
private var buildFlavor: String = "auth"
init {
baseUrl = when (config.buildEnv) {
AxeBuildEnv.QA -> SERVICE_QA_URL
AxeBuildEnv.PROD -> SERVICE_PROD_URL
else -> SERVICE_DEV_URL
}
buildFlavor = config.buildFlavor
usageServiceClient = UsageServiceClient(baseUrl)
}
internal constructor(config: UsageServiceConfig, client: UsageServiceClient) : this(config) {
usageServiceClient = client
}
fun sendEvent(
event: UsageServiceEvent
): Job? {
return if (skipDuringTestInProduction() || ignoreNoAuthRequestsOrNoOrgId()) {
null
} else {
scope.launch(Dispatchers.IO) {
usageServiceClient.sendEvent(event)
}
}
}
private fun ignoreNoAuthRequestsOrNoOrgId(): Boolean {
return buildFlavor == "noauth" || orgId == null
}
private fun skipDuringTestInProduction(): Boolean {
return Config.UNDER_TEST && config.buildEnv == AxeBuildEnv.PROD
}
companion object {
internal val distinctId: String
get() = DistinctId(DashboardService.userId, DashboardService.email).toString()
var orgId: String? = null
internal const val ANDROID = "android"
internal const val AXE_DEVTOOLS_MOBILE = "axe-devtools-mobile"
internal const val EVENT_V2 = "v2"
internal const val SERVICE_DEV_URL = "https://usage.dequelabs.com"
internal const val SERVICE_QA_URL = "https://usage-qa.dequelabs.com"
internal const val SERVICE_PROD_URL = "https://usage.deque.com"
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy