Skip to content

Instantly share code, notes, and snippets.

@enginebai

enginebai/ChainApi3.kt

Last active Jul 27, 2018
Embed
What would you like to do?
fun cacheApi1AndZipApi2(): Observable<Pair<Media, okhttp3.Response>> {
val api1: Observable<Response<Media>> = Api.api1().cache()
return api1.flatMap { response ->
if (response.isSuccessful) {
var uploadUrl = response.headers().get(ApiUtils.Header.LOCATION)
uploadUrl?.let { url ->
Api.api2(url).zipWith(api1) { r2, r1 -> Pair(r1.body(), r2) }
} ?: run {
throw Exceptions.propagate(NullPointerException("Media upload URL is empty"))
}
} else
Observable.error(ApiRequestException(response))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.