Created
July 26, 2018 16:23
-
-
Save enginebai/9728457445d1422e03a64e4c876889c9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
fun zipApi1AndApi2(): Observable<Pair<Media, okhttp3.Response>> { | |
return Api.api1().flatMap { response -> | |
if (response.isSuccessful) { | |
var uploadUrl = response.headers().get(ApiUtils.Header.LOCATION) | |
uploadUrl?.let {url -> | |
Observable.zip( | |
Observable.just(response.body()), | |
Api.api2(url) | |
) { t1, t2 -> Pair(t1, t2) } | |
} ?: 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