Skip to content

Instantly share code, notes, and snippets.

@BalakrishnanPT
Last active October 16, 2019 02:38
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 BalakrishnanPT/3e5db2d411be4a8e8b9244a6c55cd853 to your computer and use it in GitHub Desktop.
Save BalakrishnanPT/3e5db2d411be4a8e8b9244a6c55cd853 to your computer and use it in GitHub Desktop.
public class APIExample {
BoredActivitiesAPI sampleAPI;
public APIExample(BoredActivitiesAPI boredActivitiesAPI) {
this.sampleAPI = boredActivitiesAPI;
}
public Flowable<String> makeAPICall() {
return sampleAPI.getFlowableResponse()
.onErrorReturn(new Function<Throwable, BoredActivities>() {
@Override
public BoredActivities apply(Throwable throwable) throws Exception {
BoredActivities boredActivities = new BoredActivities();
boredActivities.setLink("");
return boredActivities;
}
})
.map(new Function<BoredActivities, String>() {
@Override
public String apply(BoredActivities boredActivities) throws Exception {
return boredActivities.getLink();
}
})
.subscribeOn(Schedulers.io()));
.observeOn(AndroidSchedulers.mainThread());
}
public void updateUI() {
makeAPICall().subscribe(new FlowableSubscriber<String>() {
@Override
public void onSubscribe(Subscription s) {
}
@Override
public void onNext(String s) {
// Result is received here for all the request we made here
}
@Override
public void onError(Throwable t) {
// Handle the error here
}
@Override
public void onComplete() {
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment