Usage: SDK initialization
Set your credentials and get authorization of usage.
Initialize
Create an instance of RookConfigurationManager
providing a context:
val rookConfigurationManager = RookConfigurationManager(context)
Set a configuration and initialize. The RookConfiguration
requires the following parameters:
val environment = if (BuildConfig.DEBUG) RookEnvironment.SANDBOX else RookEnvironment.PRODUCTION
val rookConfiguration = RookConfiguration(
CLIENT_UUID,
SECRET_KEY,
environment,
)
if (BuildConfig.DEBUG) {
rookConfigurationManager.enableLocalLogs() // MUST be called first if you want to enable native logs
}
rookConfigurationManager.setConfiguration(rookConfiguration)
val result = rookConfigurationManager.initRook()
result.fold(
{
// SDK initialized successfully
},
{
// Error initializing SDK
val error = when (it) {
is MissingConfigurationException -> "MissingConfigurationException: ${it.message}"
is TimeoutException -> "TimeoutException: ${it.message}"
else -> "${it.message}"
}
}
)
Recommendations
When you initialize the SDK with initRook
, an HTTP request is made, so you should only initialize the SDK once. We recommend using the RookConfigurationManager
as a singleton with a ServiceLocator or with dependency
<!--AndroidManifest.xml-->
<application
android:name=".RookApplication">
</application>
class RookApplication : Application() {
lateinit var serviceLocator: ServiceLocator
override fun onCreate() {
super.onCreate()
serviceLocator = ServiceLocator(applicationContext)
}
}
class ServiceLocator(context: Context) {
val rookConfigurationManager: RookConfigurationManager by lazy {
RookConfigurationManager(context).apply {
val environment = if (BuildConfig.DEBUG) RookEnvironment.SANDBOX else RookEnvironment.PRODUCTION
val rookConfiguration = RookConfiguration(CLIENT_UUID, SECRET_KEY, environment)
if (BuildConfig.DEBUG) {
enableLocalLogs() // MUST be called first if you want to enable native logs
}
setConfiguration(rookConfiguration)
}
}
}