Search in sources :

Example 1 with UserService

use of com.meisolsson.githubsdk.service.users.UserService in project gh4a by slapperwan.

the class Github4AndroidActivity method handleIntent.

private boolean handleIntent(Intent intent) {
    Uri data = intent.getData();
    if (data != null && data.getScheme().equals(CALLBACK_URI.getScheme()) && data.getHost().equals(CALLBACK_URI.getHost())) {
        OAuthService service = ServiceGenerator.createAuthService();
        RequestToken request = RequestToken.builder().clientId(BuildConfig.CLIENT_ID).clientSecret(BuildConfig.CLIENT_SECRET).code(data.getQueryParameter(PARAM_CODE)).build();
        service.getToken(request).map(ApiHelpers::throwOnFailure).flatMap(token -> {
            UserService userService = ServiceFactory.get(UserService.class, true, null, token.accessToken(), null);
            Single<User> userSingle = userService.getUser().map(ApiHelpers::throwOnFailure);
            return Single.zip(Single.just(token), userSingle, (t, user) -> Pair.create(t.accessToken(), user));
        }).compose(RxUtils::doInBackground).subscribe(pair -> onLoginFinished(pair.first, pair.second), this::handleLoadFailure);
        return true;
    }
    return false;
}
Also used : OAuthService(com.meisolsson.githubsdk.service.OAuthService) User(com.meisolsson.githubsdk.model.User) UserService(com.meisolsson.githubsdk.service.users.UserService) RequestToken(com.meisolsson.githubsdk.model.request.RequestToken) ApiHelpers(com.gh4a.utils.ApiHelpers) Uri(android.net.Uri)

Example 2 with UserService

use of com.meisolsson.githubsdk.service.users.UserService in project gh4a by slapperwan.

the class UserActivity method loadUser.

private void loadUser(boolean force) {
    UserService service = ServiceFactory.get(UserService.class, force);
    service.getUser(mUserLogin).map(ApiHelpers::throwOnFailure).compose(makeLoaderSingle(ID_LOADER_USER, force)).subscribe(result -> {
        mUser = result;
        invalidateTabs();
        setContentShown(true);
        invalidateOptionsMenu();
    }, this::handleLoadFailure);
}
Also used : UserService(com.meisolsson.githubsdk.service.users.UserService) ApiHelpers(com.gh4a.utils.ApiHelpers)

Example 3 with UserService

use of com.meisolsson.githubsdk.service.users.UserService in project gh4a by slapperwan.

the class UserPasswordLoginDialogFragment method makeLoginSingle.

private Single<Pair<String, User>> makeLoginSingle(LoginService.AuthorizationRequest request) {
    return getService().createAuthorization(request).map(ApiHelpers::throwOnFailure).compose(RxUtils::doInBackground).flatMap(response -> {
        UserService userService = ServiceFactory.get(UserService.class, true, null, response.token(), null);
        Single<User> userSingle = userService.getUser().map(ApiHelpers::throwOnFailure).compose(RxUtils::doInBackground);
        return Single.zip(Single.just(response), userSingle, (r, user) -> Pair.create(r.token(), user));
    });
}
Also used : User(com.meisolsson.githubsdk.model.User) RxUtils(com.gh4a.utils.RxUtils) UserService(com.meisolsson.githubsdk.service.users.UserService) ApiHelpers(com.gh4a.utils.ApiHelpers)

Example 4 with UserService

use of com.meisolsson.githubsdk.service.users.UserService in project gh4a by slapperwan.

the class HomeActivity method loadUserInfo.

private void loadUserInfo(boolean force) {
    UserService service = ServiceFactory.get(UserService.class, force);
    service.getUser(mUserLogin).map(ApiHelpers::throwOnFailure).compose(makeLoaderSingle(ID_LOADER_USER, force)).subscribe(result -> {
        Gh4Application.get().setCurrentAccountInfo(result);
        mUserInfo = result;
        updateUserInfo();
    }, this::handleLoadFailure);
}
Also used : UserService(com.meisolsson.githubsdk.service.users.UserService) ApiHelpers(com.gh4a.utils.ApiHelpers)

Aggregations

ApiHelpers (com.gh4a.utils.ApiHelpers)4 UserService (com.meisolsson.githubsdk.service.users.UserService)4 User (com.meisolsson.githubsdk.model.User)2 Uri (android.net.Uri)1 RxUtils (com.gh4a.utils.RxUtils)1 RequestToken (com.meisolsson.githubsdk.model.request.RequestToken)1 OAuthService (com.meisolsson.githubsdk.service.OAuthService)1