Last active
February 1, 2017 11:45
-
-
Save amitshekhariitbhu/2a56a0aeb4472da1f596d489f67e5f7a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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