How to pass an object from flatMap
to subscribe
in a chain? And in the code snippet below how would the blog
object can be accessed down the chain?
Single<HttpResponse<JsonNode>> singleHttpClient = httClient.post();
singleHttpClient .toObservable().flatMap(httpResponse -> {
if(httpResponse.getStatus() == 200) {
JsonNode responseNode = httpResponse.getBody();
List<JSONObject> blogObjects = iterateFrom(responseNode.getObject().getJSONArray("blogs"))
}
return Observable.fromIterable(blogObjects).toList().toObservable();
}).flatMap(jsonObjects -> Observable.fromIterable(jsonObjects))
.flatMap(jsonObject -> {
return Observable.just(new Blog(jsonObject.getString("id"), jsonObject.getString("guid")));
}).flatMap(blog -> {
Single<HttpResponse<JsonNode>> singleHttpClient2 = httpClient2.post();
singleHttpClient2.getParams().put("guid", blog.getImageGuid());
return singleHttpClient2.postAsBinary().toObservable();
}).subscribe(javaScriptObjectHttpResponse -> {
JavaScriptObject jsoBody = javaScriptObjectHttpResponse.getBody();
doSomethingWith(blog, jsBody); // How to access `blog` from here?
});