Search in sources :

Example 21 with ApiHelpers

use of com.gh4a.utils.ApiHelpers in project gh4a by slapperwan.

the class EditDiffCommentActivity method editComment.

@Override
protected Single<GitHubCommentBase> editComment(String repoOwner, String repoName, long commentId, String body) {
    RepositoryCommentService service = ServiceFactory.get(RepositoryCommentService.class, false);
    CommentRequest request = CommentRequest.builder().body(body).build();
    return service.editCommitComment(repoOwner, repoName, commentId, request).map(ApiHelpers::throwOnFailure);
}
Also used : CommentRequest(com.meisolsson.githubsdk.model.request.CommentRequest) ApiHelpers(com.gh4a.utils.ApiHelpers) RepositoryCommentService(com.meisolsson.githubsdk.service.repositories.RepositoryCommentService)

Example 22 with ApiHelpers

use of com.gh4a.utils.ApiHelpers in project gh4a by slapperwan.

the class EditDiffCommentActivity method createComment.

@Override
protected Single<GitHubCommentBase> createComment(String repoOwner, String repoName, String body, long replyToCommentId) {
    Bundle extras = getIntent().getExtras();
    String commitId = extras.getString("commit_id");
    RepositoryCommentService service = ServiceFactory.get(RepositoryCommentService.class, false);
    CreateCommitComment request = CreateCommitComment.builder().body(body).path(extras.getString("path")).position(extras.getInt("position")).build();
    return service.createCommitComment(repoOwner, repoName, commitId, request).map(ApiHelpers::throwOnFailure);
}
Also used : Bundle(android.os.Bundle) ApiHelpers(com.gh4a.utils.ApiHelpers) RepositoryCommentService(com.meisolsson.githubsdk.service.repositories.RepositoryCommentService) CreateCommitComment(com.meisolsson.githubsdk.model.request.repository.CreateCommitComment)

Example 23 with ApiHelpers

use of com.gh4a.utils.ApiHelpers in project gh4a by slapperwan.

the class EditPullRequestCommentActivity method createComment.

@Override
protected Single<GitHubCommentBase> createComment(String repoOwner, String repoName, String body, long replyToCommentId) {
    int prNumber = getIntent().getIntExtra("pr", 0);
    PullRequestReviewCommentService service = ServiceFactory.get(PullRequestReviewCommentService.class, false);
    CreateReviewComment request = CreateReviewComment.builder().body(body).inReplyTo(replyToCommentId).build();
    return service.createReviewComment(repoOwner, repoName, prNumber, request).map(ApiHelpers::throwOnFailure);
}
Also used : ApiHelpers(com.gh4a.utils.ApiHelpers) CreateReviewComment(com.meisolsson.githubsdk.model.request.pull_request.CreateReviewComment) PullRequestReviewCommentService(com.meisolsson.githubsdk.service.pull_request.PullRequestReviewCommentService)

Example 24 with ApiHelpers

use of com.gh4a.utils.ApiHelpers in project gh4a by slapperwan.

the class FileViewerActivity method loadFile.

private void loadFile(boolean force) {
    RepositoryContentService service = ServiceFactory.get(RepositoryContentService.class, force);
    service.getContents(mRepoOwner, mRepoName, mPath, mRef).map(ApiHelpers::throwOnFailure).map(Optional::of).onErrorResumeNext(error -> {
        if (error instanceof ApiRequestException) {
            ClientErrorResponse response = ((ApiRequestException) error).getResponse();
            List<ClientErrorResponse.FieldError> errors = response != null ? response.errors() : null;
            if (errors != null) {
                for (ClientErrorResponse.FieldError fe : errors) {
                    if (fe.reason() == ClientErrorResponse.FieldError.Reason.TooLarge) {
                        openUnsuitableFileAndFinish();
                        return Single.just(Optional.absent());
                    }
                }
            }
        }
        return Single.error(error);
    }).compose(makeLoaderSingle(ID_LOADER_FILE, force)).subscribe(result -> {
        if (result.isPresent()) {
            mContent = result.get();
            onDataReady();
            setContentEmpty(false);
        } else {
            setContentEmpty(true);
            setContentShown(true);
        }
    }, this::handleLoadFailure);
}
Also used : ApiRequestException(com.gh4a.ApiRequestException) ClientErrorResponse(com.meisolsson.githubsdk.model.ClientErrorResponse) RepositoryContentService(com.meisolsson.githubsdk.service.repositories.RepositoryContentService) ApiHelpers(com.gh4a.utils.ApiHelpers)

Example 25 with ApiHelpers

use of com.gh4a.utils.ApiHelpers in project gh4a by slapperwan.

the class CommitActivity method loadCommit.

private void loadCommit(boolean force) {
    RepositoryCommitService service = ServiceFactory.get(RepositoryCommitService.class, force);
    service.getCommit(mRepoOwner, mRepoName, mObjectSha).map(ApiHelpers::throwOnFailure).compose(makeLoaderSingle(ID_LOADER_COMMIT, force)).subscribe(result -> {
        mCommit = result;
        showContentIfReady();
    }, this::handleLoadFailure);
}
Also used : ApiHelpers(com.gh4a.utils.ApiHelpers) RepositoryCommitService(com.meisolsson.githubsdk.service.repositories.RepositoryCommitService)

Aggregations

ApiHelpers (com.gh4a.utils.ApiHelpers)68 Response (retrofit2.Response)13 RxUtils (com.gh4a.utils.RxUtils)12 ServiceFactory (com.gh4a.ServiceFactory)11 Intent (android.content.Intent)10 Bundle (android.os.Bundle)10 Optional (com.gh4a.utils.Optional)10 PullRequestReviewCommentService (com.meisolsson.githubsdk.service.pull_request.PullRequestReviewCommentService)10 Single (io.reactivex.Single)9 Context (android.content.Context)7 LayoutInflater (android.view.LayoutInflater)7 CommentRequest (com.meisolsson.githubsdk.model.request.CommentRequest)7 List (java.util.List)7 View (android.view.View)6 R (com.gh4a.R)6 IntentUtils (com.gh4a.utils.IntentUtils)6 User (com.meisolsson.githubsdk.model.User)6 ReactionRequest (com.meisolsson.githubsdk.model.request.ReactionRequest)6 CreateReviewComment (com.meisolsson.githubsdk.model.request.pull_request.CreateReviewComment)6 ReactionService (com.meisolsson.githubsdk.service.reactions.ReactionService)6