Skip to content

Instantly share code, notes, and snippets.

@romansl
Last active December 17, 2017 17:34
Show Gist options
  • Save romansl/b3dd199532cfa4481b60953440912e92 to your computer and use it in GitHub Desktop.
Save romansl/b3dd199532cfa4481b60953440912e92 to your computer and use it in GitHub Desktop.
Coroutine version.
class Rest {
suspend fun sendInstalledApps() {}
suspend fun updateCustomer() {}
suspend fun checkClientVersion() {}
suspend fun createOrUpdateDevice() {}
suspend fun refreshCustomerToken() {}
suspend fun getProfile() {}
}
suspend fun register(): Profile {
rest.checkClientVersion()
rest.sendInstalledApps(App.installedPackages)
val device = rest.createOrUpdateDevice()
val tokenData = if (device.data?.device?.isCustomer == true) {
rest.updateCustomer(prefStorage.googleAuth)
rest.refreshCustomerToken()
} else {
val td = rest.refreshCustomerToken()
rest.updateCustomer()
td
}
tokenData.data?.let {
prefStorage.accessToken.set(it.accessToken)
}
val profileData = rest.getProfile()
return profileData.data
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment