Last active
December 13, 2020 11:56
-
-
Save gokmenbayram/cdc8d1d98952365c90b88bffa8ce0f9b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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