Skip to content

Instantly share code, notes, and snippets.

@amitshekhariitbhu
Last active February 1, 2017 11:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save amitshekhariitbhu/2a56a0aeb4472da1f596d489f67e5f7a to your computer and use it in GitHub Desktop.
Save amitshekhariitbhu/2a56a0aeb4472da1f596d489f67e5f7a to your computer and use it in GitHub Desktop.
RxAndroidNetworking.get("https://fierce-cove-29863.herokuapp.com/getAnUser/{userId}")
.addPathParameter("userId", "1")
.build()
.getObjectObservable(ApiUser.class) // This returns you an Observable
.subscribeOn(Schedulers.io()) // do the network call on another thread
.observeOn(AndroidSchedulers.mainThread()) // return the result in mainThread
.map(new Func1<ApiUser, User>() {
@Override
public User call(ApiUser apiUser) {
// here we get ApiUser from server
User user = convertApiUserToUser(apiUser);
// then by converting, we are returing user
return user;
}
})
.subscribe(new Observer<User>() {
@Override
public void onCompleted() {
// do anything onComplete
}
@Override
public void onError(Throwable e) {
// handle error
}
@Override
public void onNext(User user) {
// do anything with user
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment