Extra: Data sources
Show a connections page for other data sources inside the app.
Introduction
This feature included in rook-sdk allows developers to retrieve a list of available API data sources to build a custom connections page. Also, a pre-built connections page can be shown for immediate implementation.
Android Studio
Go to the main Android Studio section to see the IDE configuration.
Getting started
Android configuration
Go to the main Android configuration section to see the basic configuration.
Logging
Go to the main Logging section to configure logs.
Usage
Initialize
Go to the main Initialize and Update userID sections to initialize.
RookDataSources
Create an instance of RookDataSources
:
- context - Application context
val rookDataSources = RookDataSources(context)
Recommendations
We recommend to use the RookDataSources
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 rookDataSources: RookDataSources by lazy {
RookDataSources(context)
}
}
Get available data sources
To get the available data sources for the current user call getAvailableDataSources
:
- redirectUrl (Optional) - After the user successfully connects to a data source, the user will be redirected to this URL.
coroutineScope.launch {
rookDataSources.getAvailableDataSources().fold(
{ dataSources ->
// Data Sources obtained successfully
},
{ throwable ->
// Error obtaining Data Sources
},
)
}
Unlink from a data source
To unlink (revoke authorization) from a data source call revokeDataSource
:
- dataSourceType - The type of the data source to revoke.
coroutineScope.launch {
rookDataSources.revokeDataSource(dataSourceType).fold(
{
// Success
},
{ throwable ->
// Hanlde error
}
)
}
Pre-built connections page
If you don't want to create your own connections page, you can use our pre-built screen by
calling presentDataSourceView
:
- redirectUrl (Optional) - After the user successfully connects to a data source, the user will be redirected to this URL.
rookDataSources.presentDataSourceView().fold(
{ dataSources ->
// Data Sources activity launched successfully
},
{ throwable ->
// Error launching activity
},
)