Skip to content

Commit

Permalink
docs: Smaller README refactoring (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziodemaria authored May 27, 2024
1 parent 45b9964 commit d4efefc
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,7 @@ val confidence = ConfidenceFactory.create(
region = ConfidenceRegion.EUROPE
)
```
Where `MY_SECRET` is an API key that can be generated in the [Confidence UI](https://confidence.spotify.com/console).

Make the initial fetching of flags using the `activateAndFetch` method. This is a suspending function that will fetch the flags from the server and activate them.
It needs to be run in a coroutine scope.

```kotlin
viewModelScope.launch {
confidence.fetchAndActivate()
}
```

<!-- TODO: add more information about activate, fetchAndActivate and fetch methods. -->
Where `MY_SECRET` is an API key that can be generated in the [Confidence UI](https://confidence.spotify.com/console)

### Setting the context
The context is a key-value map that will be used for sampling and for targeting input in assigning feature flag values by the Confidence backend. It is also a crucial way to create dimensions for metrics generated by event data.
Expand All @@ -59,7 +48,18 @@ confidence.putContext("key", ConfidenceValue.String("value")) // this will mutat
val otherConfidenceInstance = confidence.withContext("key", ConfidenceValue.String("value")) // this will return a new Confidence instance with the context changes applied but the context of the original instance is kept intact
```

### Resolving feature flags
### Fetching and resolving flags
Make the initial fetching of flags using the `activateAndFetch` method. This is a suspending function that will fetch the flags from the server and activate them.
It needs to be run in a coroutine scope.

```kotlin
viewModelScope.launch {
confidence.fetchAndActivate()
}
```

<!-- TODO: add more information about activate, fetchAndActivate and fetch methods. -->

**Once the flags are fetched and activated**, you can access their value using the `getValue` method or the `getFlag` method.
Both methods uses generics to return a type defined by the default value type.

Expand All @@ -70,7 +70,6 @@ In the case of an error, the default value will be returned and the `Evaluation`
The method `getValue` will simply return the assigned value or the default.

```kotlin

val message: String = confidence.getValue("flag-name.message", "default message")
val messageFlag: Evaluation<String> = confidence.getFlag("flag-name.message", "default message")

Expand Down

0 comments on commit d4efefc

Please sign in to comment.