https://github.com/GiuseppeGiacoppo/RemoteConfig
RemoteConfig is a Kotlin library that lets you manage all your remote configuration without requiring developers to manually download each configuration and integrate them into the Kotlin application.
https://github.com/GiuseppeGiacoppo/RemoteConfig
firebase-remote-config kotlin-dsl kotlin-library remote remote-config remoteconfig
Last synced: about 2 months ago
JSON representation
RemoteConfig is a Kotlin library that lets you manage all your remote configuration without requiring developers to manually download each configuration and integrate them into the Kotlin application.
- Host: GitHub
- URL: https://github.com/GiuseppeGiacoppo/RemoteConfig
- Owner: GiuseppeGiacoppo
- License: apache-2.0
- Created: 2018-01-09T14:54:11.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-10-19T18:01:03.000Z (over 3 years ago)
- Last Synced: 2024-08-02T19:38:21.345Z (10 months ago)
- Topics: firebase-remote-config, kotlin-dsl, kotlin-library, remote, remote-config, remoteconfig
- Language: Kotlin
- Homepage: https://giuseppegiacoppo.github.io/RemoteConfig/
- Size: 393 KB
- Stars: 17
- Watchers: 4
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-list - GiuseppeGiacoppo/RemoteConfig - RemoteConfig is a Kotlin library that lets you manage all your remote configuration without requiring developers to manually download each configuration and integrate them into the Kotlin application. (Kotlin)
README
# Introduction
[](https://jitpack.io/#GiuseppeGiacoppo/RemoteConfig)RemoteConfig is a Kotlin library that lets you manage all your remote configuration without requiring developers to manually download each configuration and integrate them into the Kotlin application.

You can have many configurations (messages, flags, server) on remote files, the library will do all the work for you.

## Download
Grab via Gradle:
```groovy
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.GiuseppeGiacoppo:RemoteConfig:LATEST_VERSION'
}
```
## Usage
Retrieve a specific instance of RemoteResource for every configuration class
```kotlin
fun welcome() {
val remoteAppConfig = remoteConfig()
val appConfig = remoteAppConfig.get()
println(appConfig.welcomeMessage)
}
```
You're done. `remoteAppConfig` will provide you the latest app configuration.
## Setup library
You need to setup each remote configuration with minimum effort. For each configuration, specify a remote repository and a local repository.
The library will know where to fetch the configuration and where to store it locally.
```kotlin
fun main(args: Array) {
initRemoteConfig {
remoteResource(
storage("./configs"),
network("https://www.your.server/latest/appconfig.json")
)remoteResource(
// init other configs
)
}
}
```
### Default configuration
Fetching is an async operation, this means it can take a while, and it can fail.
It is possible to set a default configuration that will be marked as *active* if no more recent config is available.
```kotlin
val remoteAppConfig = remoteConfig()
remoteAppConfig.setDefaultConfig(AppConfig("This is the default welcome message."))
```
### Fetch from the server
Fetch the configuration every time you need, invoking `fetch` method. Fresh configuration will be saved locally and you can activate it.
```kotlin
remoteAppConfig.fetch({
println("Fetch is successful")
remoteAppConfig.activateFetched()
}, {
println("Fetch is failed")
it.printStackTrace()
})
```
### Multiple configurations
The configuration will be named by the configuration class name.
You can have multiple configurations that share the same class by specifying a custom resource name
```kotlin
fun main(args: Array) {
initRemoteConfig {
remoteResource(
storage("./configs"),
network("https://www.your.server/latest/homemessages.json")
) {
resourceName = "home-messages"
}remoteResource(
storage("./configs"),
network("https://www.your.server/latest/detailmessages.json")
) {
resourceName = "detail-messages"
}
}
// you can then fetch, activate and use it
val homeMessages = remoteConfig("home-messages")
val detailMessages = remoteConfig("detail-messages")
}
```
### Configuration Format
RemoteConfig expects that each configuration is in json format. It supports also text format, and you can even create your own `ResourceMapper`.
```kotlin
fun main(args: Array) {
initRemoteConfig {
remoteResource(
storage("./configs"),
network("https://www.your.server/latest/custom.txt")
) {
format = TextResourceMapper
}
}
}
```
## Contributing
1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Added some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request :)## Credits and libraries
RemoteConfig is an open source library inspired by [Firebase Remote Config](https://firebase.google.com/docs/remote-config)
* [Gson](https://github.com/google/gson)
* [OkHttp](http://square.github.io/okhttp)