Skip to content

Instantly share code, notes, and snippets.

@vvsevolodovich
Created April 17, 2018 15:24
Show Gist options
  • Save vvsevolodovich/69457b324f5df68dd0e007c453a97a69 to your computer and use it in GitHub Desktop.
Save vvsevolodovich/69457b324f5df68dd0e007c453a97a69 to your computer and use it in GitHub Desktop.
Single.fromCallable
override fun login(auth: Authorization): Single<GithubUser> = Single.fromCallable {
val response = get("https://api.github.com/user", auth = auth)
if (response.statusCode != 200) {
throw RuntimeException("Incorrect login or password")
}
val jsonObject = response.jsonObject
with(jsonObject) {
return@with GithubUser(getString("login"), getInt("id"),
getString("repos_url"), getString("name"))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment