Skip to content

Instantly share code, notes, and snippets.

@gokmenbayram
Last active December 13, 2020 11:56
Show Gist options
  • Save gokmenbayram/cdc8d1d98952365c90b88bffa8ce0f9b to your computer and use it in GitHub Desktop.
Save gokmenbayram/cdc8d1d98952365c90b88bffa8ce0f9b to your computer and use it in GitHub Desktop.
private const val BASE_URL = "https://firestore.googleapis.com/v1/projects/firestoreforceupdate/databases/"
class FirebaseClient {
// Coroutines
private val job = Job()
private val coroutineContext = Dispatchers.IO + job
private val uiScope = CoroutineScope(coroutineContext)
fun getAppVersionFromApi(callback: (isSuccess: Boolean, response: Version?, message: String?) -> (Unit)) {
uiScope.launch {
ApiClient.api(BASE_URL)
.create(ApiService::class.java)
.getVersion()
.enqueue(object : Callback<Version> {
override fun onResponse(call: Call<Version>, response: Response<Version>) {
response.body()?.let { response ->
callback(true, response, null)
}
}
override fun onFailure(call: Call<Version>, t: Throwable) {
callback(false, null, t.localizedMessage)
}
})
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment