Initializing the SDK
Initializing the SDK
Overview
This section covers the process of initializing the SDK in your application. Initialization is the first step in using the SDK's features and is critical for setting up the necessary configurations.
Method Signature
The initialize method is defined as follows:
fun initialize(config: BWellConfig): OperationOutcomeconfig: The configuration settings for the SDK.OperationOutcome: The result of the initialization operation, indicating success or failure.
Please note that configuration parameters passed during the initialization (initialize) of the SDK are only respected in non-Production environments. This allows for more flexible development and testing configurations without affecting live production setups.
In Production environments, configurations are made server-side and dynamically pulled at runtime, ensuring that the most current settings are always in use.
Sample Code
Below is a sample implementation of the initialize method:
private fun initializeBWellSDK(clientKey: String, oAuthCredentials: String) {
lifecycleScope.launch {
Log.i(TAG, "Initializing SDK")
val keystore: KeyStoreConfig = KeyStoreConfig.Builder()
.path(requireContext().filesDir.absolutePath)
.build()
val config: BWellConfig = BWellConfig.Builder()
.clientKey(clientKey)
.logLevel(LogLevel.DEBUG)
.timeout(20000)
.retryPolicy(
RetryPolicy.Builder()
.maxRetries(5)
.retryInterval(500)
.build()
)
.keystore(keystore)
.build()
BWellSdk.initialize(config = config)Detailed Explanation
- Keystore Setup:
KeyStoreConfig.Builder(): Constructs a new Keystore configuration. This is critical for securely storing and retrieving sensitive data such as client keys..path(...): Specifies the file path where the keystore is located.
- BWellConfig Object:
clientKey: A unique key that identifies your client application. Replace"your_client_key"with the actual key provided to you.logLevel: This sets the logging level for SDK operations.LogLevel.DEBUGis used here for detailed logging, useful during development.timeout: Specifies the timeout duration (in milliseconds) for SDK operations. Here, it is set to 20,000 ms (20 seconds).retryPolicy: Defines the retry policy for failed operations. This configuration sets a maximum of 5 retries with a 500 ms interval between retries.keystore: Integrates the previously set up keystore configuration into the SDK.
- Initialization Call:
- The
initializemethod of theBWellSdkclass is called within a coroutine scope (lifecycleScope.launch). This is necessary as the initialization process might involve IO operations that should not block the main thread. - The result (
OperationOutcome) can be used to determine if the initialization was successful or if there were errors.
- The
- Security Note:
- Ensure that the client key and authentication tokens are securely managed and not hardcoded in production environments.
- Use the keystore to store sensitive information securely.
Best Practices
- Asynchronous Initialization: Perform the initialization asynchronously to prevent blocking the main thread, especially if the initialization process involves network requests or heavy computations.
- Logging: Adjust the logging level appropriately for development and production environments. Use
LogLevel.ERROR,LogLevel.WARNorLogLevel.INFOfor production to reduce verbosity. - Timeouts and Retry Policies: Customize these settings based on your application's needs and network conditions.
Updated about 2 months ago
Once the SDK is successfully initialized, you can proceed to user authentication.
