Last active
November 7, 2017 21:54
-
-
Save alin-turcu/337686c53299e5ed89b59e1dd3b8d6d0 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
import static rx.Observable.error; | |
import static rx.Observable.fromCallable; | |
import static rx.Observable.just; | |
import static rx.schedulers.Schedulers.io; | |
import com.groupon.grox.Action; | |
import com.groupon.grox.commands.rxjava1.Command; | |
import rx.Observable; | |
public class LoginCommand implements Command { | |
private LoginApiClient loginApiClient; | |
private String username; | |
private String password; | |
public LoginCommand(CharSequence username, CharSequence password, LoginApiClient loginApiClient){ | |
this.username = username; | |
this.password = password; | |
this.loginApiClient = loginApiClient; | |
} | |
@Override | |
public Observable<? extends Action> actions() { | |
return just(LogInProgressAction).concatWith(performLoginRequest()); | |
} | |
public Observable<? extends Action> performLoginRequest(){ | |
return loginApiClient.performLogin(username, password) | |
.subscribeOn(io()) | |
.map(LoginSuccessfulAction::new) | |
.cast(Action.class) | |
.onErrorReturn(LoginFailedAction::new) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment