diff options
author | Jonathan Brachthäuser <jonathan@b-studios.de> | 2015-09-03 23:41:17 +0200 |
---|---|---|
committer | Jonathan Brachthäuser <jonathan@b-studios.de> | 2015-09-04 11:38:55 +0200 |
commit | e2b7778e347b787707dfe4dcb46fa7e515dce643 (patch) | |
tree | 7dcf6f37407f65c211ddb24d2b593d2afb666128 /src | |
parent | 31ed45e7bf69505c0dedb6ddf19b69bb6c37ffaa (diff) | |
download | bbprb-e2b7778e347b787707dfe4dcb46fa7e515dce643.tar.gz |
Factor out url construction to v1 and v2
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/ApiClient.java | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/ApiClient.java b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/ApiClient.java index 7b15069..173ae1c 100644 --- a/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/ApiClient.java +++ b/src/main/java/bitbucketpullrequestbuilder/bitbucketpullrequestbuilder/bitbucket/ApiClient.java @@ -37,9 +37,8 @@ public class ApiClient { } public List<Pullrequest> getPullRequests() { - String response = get(V2_API_BASE_URL + this.owner + "/" + this.repositoryName + "/pullrequests/"); try { - return parse(response, Pullrequest.Response.class).getPullrequests(); + return parse(get(v2("/pullrequests/")), Pullrequest.Response.class).getPullrequests(); } catch(Exception e) { logger.log(Level.WARNING, "invalid pull request response.", e); } @@ -47,10 +46,8 @@ public class ApiClient { } public List<Pullrequest.Comment> getPullRequestComments(String commentOwnerName, String commentRepositoryName, String pullRequestId) { - String response = get( - V1_API_BASE_URL + commentOwnerName + "/" + commentRepositoryName + "/pullrequests/" + pullRequestId + "/comments"); try { - return parse(response, new TypeReference<List<Pullrequest.Comment>>() {}); + return parse(get(v1("/pullrequests/" + pullRequestId + "/comments")), new TypeReference<List<Pullrequest.Comment>>() {}); } catch(Exception e) { logger.log(Level.WARNING, "invalid pull request response.", e); } @@ -65,10 +62,10 @@ public class ApiClient { public Pullrequest.Comment postPullRequestComment(String pullRequestId, String comment) { - String path = V1_API_BASE_URL + this.owner + "/" + this.repositoryName + "/pullrequests/" + pullRequestId + "/comments"; try { - NameValuePair content = new NameValuePair("content", comment); - String response = post(path, new NameValuePair[]{ content }); + String response = post( + v1("/pullrequests/" + pullRequestId + "/comments"), + new NameValuePair[]{ new NameValuePair("content", comment) }); return parse(response, Pullrequest.Comment.class); } catch (UnsupportedEncodingException e) { e.printStackTrace(); @@ -80,15 +77,13 @@ public class ApiClient { } public void deletePullRequestApproval(String pullRequestId) { - String path = V2_API_BASE_URL + this.owner + "/" + this.repositoryName + "/pullrequests/" + pullRequestId + "/approve"; - delete(path); + delete(v2("/pullrequests/" + pullRequestId + "/approve")); } public Pullrequest.Participant postPullRequestApproval(String pullRequestId) { - String path = V2_API_BASE_URL + this.owner + "/" + this.repositoryName + "/pullrequests/" + pullRequestId + "/approve"; try { - String response = post(path, new NameValuePair[]{}); - return parse(response, Pullrequest.Participant.class); + return parse(post(v2("/pullrequests/" + pullRequestId + "/approve"), + new NameValuePair[]{}), Pullrequest.Participant.class); } catch (IOException e) { e.printStackTrace(); } @@ -115,6 +110,14 @@ public class ApiClient { return client; } + private String v1(String url) { + return V1_API_BASE_URL + this.owner + "/" + this.repositoryName + url; + } + + private String v2(String url) { + return V2_API_BASE_URL + this.owner + "/" + this.repositoryName + url; + } + private String get(String path) { return send(new GetMethod(path)); } |