use of com.gh4a.utils.ApiHelpers in project gh4a by slapperwan.
the class NotificationListFragment method unsubscribe.
@Override
public void unsubscribe(NotificationHolder notificationHolder) {
NotificationThread notification = notificationHolder.notification;
NotificationService service = ServiceFactory.get(NotificationService.class, false);
SubscriptionRequest request = SubscriptionRequest.builder().subscribed(false).build();
service.setNotificationThreadSubscription(notification.id(), request).map(ApiHelpers::throwOnFailure).compose(RxUtils::doInBackground).subscribe(result -> handleMarkAsRead(null, notification));
}
use of com.gh4a.utils.ApiHelpers in project gh4a by slapperwan.
the class PullRequestFragment method deletePullRequestBranch.
private void deletePullRequestBranch() {
GitService service = ServiceFactory.get(GitService.class, false);
PullRequestMarker head = mPullRequest.head();
String owner = head.repo().owner().login();
String repo = head.repo().name();
service.deleteGitReference(owner, repo, "heads/" + head.ref()).map(ApiHelpers::mapToBooleanOrThrowOnFailure).compose(RxUtils.wrapForBackgroundTask(getBaseActivity(), R.string.deleting_msg, R.string.delete_branch_error)).subscribe(result -> {
mHeadReference = null;
onHeadReferenceUpdated();
}, error -> handleActionFailure("Deleting PR branch failed", error));
}
use of com.gh4a.utils.ApiHelpers in project gh4a by slapperwan.
the class PullRequestFragment method restorePullRequestBranch.
private void restorePullRequestBranch() {
PullRequestMarker head = mPullRequest.head();
if (head.repo() == null) {
return;
}
String owner = head.repo().owner().login();
String repo = head.repo().name();
GitService service = ServiceFactory.get(GitService.class, false);
CreateGitReference request = CreateGitReference.builder().ref("refs/heads/" + head.ref()).sha(head.sha()).build();
service.createGitReference(owner, repo, request).map(ApiHelpers::throwOnFailure).compose(RxUtils.wrapForBackgroundTask(getBaseActivity(), R.string.saving_msg, R.string.restore_branch_error)).subscribe(result -> {
mHeadReference = result;
onHeadReferenceUpdated();
}, error -> handleActionFailure("Restoring PR branch failed", error));
}
use of com.gh4a.utils.ApiHelpers 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);
}
use of com.gh4a.utils.ApiHelpers 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));
});
}
Aggregations