Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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