Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
prem-p-simform committed Jun 10, 2024
1 parent ef5fdd4 commit 7c6e2e3
Showing 1 changed file with 42 additions and 28 deletions.
70 changes: 42 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,39 +75,53 @@ Bagel.start(bagelConfig)
## Install Android client
#### Dependency
* Add the below dependency in your preferred build system
* `com.simformsolutions:bagel:1.0`
```groovy
implementation 'com.simform:bagel:1.0.0'
```
### Usage
In order to start Bagel we need to start the client and add a interceptor to intercept [OkHttp](https://square.github.io/okhttp/) API calls.
* You can start client in anyway you like from below
* Start client when `Application` class starts

```kotlin
class App : Application() {
override fun onCreate() {
super.onCreate()
Bagel.start(this)
}
}
```
* Start client using [AppStartup](https://developer.android.com/topic/libraries/app-startup)

```kotlin
class BagelInitializer : Initializer<Unit> {
override fun create(context: Context) {
Bagel.start(context)
}

override fun dependencies(): MutableList<Class<out Initializer<*>>> =
mutableListOf()
}
```

* Intercept API calls in [OkHttp](https://square.github.io/okhttp/)
* You can start client in any one of the way you like from below
1. Start client when `Application` class starts
```kotlin
class App : Application() {
override fun onCreate() {
super.onCreate()
if (BuildConfig.DEBUG) { // Only expose in debug
Bagel.start(context)
}
}
}
```
2. Start client using [AppStartup](https://developer.android.com/topic/libraries/app-startup)
```kotlin
class BagelInitializer : Initializer<Unit> {
override fun create(context: Context) {
if (BuildConfig.DEBUG) { // Only expose in debug
Bagel.start(context)
}
}
override fun dependencies(): MutableList<Class<out Initializer<*>>> =
mutableListOf()
}
```
* Add [OkHttp](https://square.github.io/okhttp/) interceptor (**This is required to route API call details**)
* While building your `OkHttp` client create interceptor instance as below
* `BagelInterceptor.getInstance()`

```kotlin
OkHttpClient.Builder()
.apply {
if (BuildConfig.DEBUG) { // Only expose in debug
val bagelInterceptor = BagelInterceptor.getInstance()
addInterceptor(bagelInterceptor)
}
}
. // Add all other interceptor and configurations
.build()
```
### Configuring Bagel
By default, Bagel gets your project name and device information. Desktop client uses these informations to separate projects and devices. You can configure `projectName` and `netServiceType` if you wish:
Expand Down

0 comments on commit 7c6e2e3

Please sign in to comment.