Skip to main content

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:

  • clientUUID
  • secret
  • environment
  • packageName (Optional, if not provided, the SDK will retrieve it from Context.)
val environment = if (BuildConfig.DEBUG) RookEnvironment.SANDBOX else RookEnvironment.PRODUCTION
val configuration = RookConfiguration(clientUUID, secret, environment)

// Enable logging only on debug builds
if (BuildConfig.DEBUG) {
rookConfigurationManager.enableLocalLogs()
}

rookConfigurationManager.setConfiguration(configuration)
rookConfigurationManager.initRook().fold(
{
// Success
},
{
// Handle error
}
)
Critical Requirement

You must register your applicationId (package name) and its corresponding secret in the ROOK Portal before attempting to initialize the SDK. Failure to register these credentials will cause the initialization to fail with an HCNotAuthorizedException.

The ROOK Portal supports independent configurations for Sandbox and Production environments. Each environment requires its own unique pair of Package Name and secret

If you come from a previous version you MUST re-initialize the SDK with the new authentication flow.

Recommendations

You should only initialize the SDK once per app launch. We recommend using the RookConfigurationManager as a singleton with a ServiceLocator or with dependency injection.

<!--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, environment)

if (BuildConfig.DEBUG) {
enableLocalLogs() // MUST be called first if you want to enable native logs
}

setConfiguration(rookConfiguration)
}
}
}