Skip to content

Instantly share code, notes, and snippets.

@enginebai
Created April 10, 2019 23:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enginebai/7b8e4a26dab750a1cec825070dce0dee to your computer and use it in GitHub Desktop.
Save enginebai/7b8e4a26dab750a1cec825070dce0dee to your computer and use it in GitHub Desktop.
fun zipApi1AndApi2(): Observable<Pair<Media, okhttp3.Response>> {
return Api.api1().flatMap { response1 ->
if (response1.isSuccessful) {
var uploadUrl = response1.headers().get(ApiUtils.Header.LOCATION)
uploadUrl?.let { url ->
Api.api2(url).map { response2 -> Pair(response1, response2) }
} ?: run {
throw Exceptions.propagate(NullPointerException("Media upload URL is empty"))
}
} else
Observable.error(ApiRequestException(response1))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment