Last active
October 16, 2019 02:38
-
-
Save BalakrishnanPT/3e5db2d411be4a8e8b9244a6c55cd853 to your computer and use it in GitHub Desktop.
This file contains 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
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