diff --git a/src/main/java/com/inteligr8/github/ApiGateway.java b/src/main/java/com/inteligr8/github/ApiGateway.java index 223ec98..c5121fe 100644 --- a/src/main/java/com/inteligr8/github/ApiGateway.java +++ b/src/main/java/com/inteligr8/github/ApiGateway.java @@ -25,6 +25,7 @@ import com.inteligr8.http.PreemptiveAuthInterceptor; public class ApiGateway { private final Logger logger = LoggerFactory.getLogger(ApiGateway.class); + private final String baseUrl = "https://api.github.com"; private ObjectMapper omapper = new ObjectMapper(); private CredentialsProvider credProvider; @@ -32,29 +33,29 @@ public class ApiGateway { this.credProvider = credProvider; } - public Response get(String uri, Map paramMap, Class responseType) throws IOException { - return this.execute(HttpGet.METHOD_NAME, uri, paramMap, null, responseType); + public Response get(String uriPath, Map paramMap, Class responseType) throws IOException { + return this.execute(HttpGet.METHOD_NAME, uriPath, paramMap, null, responseType); } - public Response post(String uri, Request requestObject, Class responseType) throws IOException { - return this.execute(HttpPost.METHOD_NAME, uri, null, requestObject, responseType); + public Response post(String uriPath, Request requestObject, Class responseType) throws IOException { + return this.execute(HttpPost.METHOD_NAME, uriPath, null, requestObject, responseType); } - public Response put(String uri, Request requestObject, Class responseType) throws IOException { - return this.execute(HttpPost.METHOD_NAME, uri, null, requestObject, responseType); + public Response put(String uriPath, Request requestObject, Class responseType) throws IOException { + return this.execute(HttpPost.METHOD_NAME, uriPath, null, requestObject, responseType); } - public Response delete(String uri, Map paramMap, Class responseType) throws IOException { - return this.execute(HttpDelete.METHOD_NAME, uri, paramMap, null, responseType); + public Response delete(String uriPath, Map paramMap, Class responseType) throws IOException { + return this.execute(HttpDelete.METHOD_NAME, uriPath, paramMap, null, responseType); } - private Response execute(String method, String uri, Map paramMap, Request requestObject, Class responseType) throws IOException { + private Response execute(String method, String uriPath, Map paramMap, Request requestObject, Class responseType) throws IOException { if (this.logger.isTraceEnabled()) - this.logger.trace("execute('" + method + "', '" + uri + "')"); + this.logger.trace("execute('" + method + "', '" + uriPath + "')"); RequestBuilder builder = RequestBuilder .create(method) - .setUri(uri); + .setUri(this.baseUrl + uriPath); if (paramMap != null) { for (Entry param : paramMap.entrySet()) @@ -65,14 +66,14 @@ public class ApiGateway { if (requestObject != null) { String requestJson = this.omapper.writeValueAsString(requestObject); if (this.logger.isTraceEnabled()) - this.logger.trace("execute('" + method + "', '" + uri + "'): " + requestJson); + this.logger.trace("execute('" + method + "', '" + uriPath + "'): " + requestJson); builder.setEntity(new StringEntity(requestJson, ContentType.APPLICATION_JSON)); } HttpUriRequest request = builder.build(); if (this.logger.isDebugEnabled()) - this.logger.debug("Prepared request for " + method + " to: " + uri); + this.logger.debug("Prepared request for " + method + " to: " + uriPath); HttpResponse response = HttpClientBuilder .create() diff --git a/src/main/java/com/inteligr8/github/model/CreatePullRequest.java b/src/main/java/com/inteligr8/github/model/CreatePullRequest.java index ee9c37e..6f1e6ca 100644 --- a/src/main/java/com/inteligr8/github/model/CreatePullRequest.java +++ b/src/main/java/com/inteligr8/github/model/CreatePullRequest.java @@ -9,6 +9,10 @@ public class CreatePullRequest { private CreatePullRequest() { } + public static String constructRequestPath(String repoName) { + return "/repos/" + repoName + "/" + httpPath; + } + public static String httpPath = "pulls"; @JsonIgnoreProperties(ignoreUnknown = true) diff --git a/src/main/java/com/inteligr8/github/model/CreateReference.java b/src/main/java/com/inteligr8/github/model/CreateReference.java index 24d5eb7..000ae92 100644 --- a/src/main/java/com/inteligr8/github/model/CreateReference.java +++ b/src/main/java/com/inteligr8/github/model/CreateReference.java @@ -9,6 +9,10 @@ public class CreateReference { private CreateReference() { } + public static String constructRequestPath(String repoName) { + return "/repos/" + repoName + "/" + httpPath; + } + public static String httpPath = "git/refs"; @JsonIgnoreProperties(ignoreUnknown = true)