Compare commits
No commits in common. "stable" and "v1.1.0" have entirely different histories.
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,6 +1,5 @@
|
|||||||
# Maven
|
# Maven
|
||||||
target
|
target
|
||||||
pom.xml.versionsBackup
|
|
||||||
|
|
||||||
# Eclipse
|
# Eclipse
|
||||||
.project
|
.project
|
||||||
|
2
pom.xml
2
pom.xml
@ -5,7 +5,7 @@
|
|||||||
<groupId>com.inteligr8</groupId>
|
<groupId>com.inteligr8</groupId>
|
||||||
<artifactId>github-api</artifactId>
|
<artifactId>github-api</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<version>1.1.1</version>
|
<version>1.1.0</version>
|
||||||
|
|
||||||
<name>GitHub API & Utilities</name>
|
<name>GitHub API & Utilities</name>
|
||||||
|
|
||||||
|
@ -19,13 +19,12 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.inteligr8.github.http.BaseResponse;
|
import com.inteligr8.http.BaseResponse;
|
||||||
import com.inteligr8.github.http.PreemptiveAuthInterceptor;
|
import com.inteligr8.http.PreemptiveAuthInterceptor;
|
||||||
|
|
||||||
public class ApiGateway {
|
public class ApiGateway {
|
||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(ApiGateway.class);
|
private final Logger logger = LoggerFactory.getLogger(ApiGateway.class);
|
||||||
private final String baseUrl = "https://api.github.com";
|
|
||||||
private ObjectMapper omapper = new ObjectMapper();
|
private ObjectMapper omapper = new ObjectMapper();
|
||||||
private CredentialsProvider credProvider;
|
private CredentialsProvider credProvider;
|
||||||
|
|
||||||
@ -33,29 +32,29 @@ public class ApiGateway {
|
|||||||
this.credProvider = credProvider;
|
this.credProvider = credProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <Response extends BaseResponse> Response get(String uriPath, Map<String, Object> paramMap, Class<Response> responseType) throws IOException {
|
public <Response extends BaseResponse> Response get(String uri, Map<String, Object> paramMap, Class<Response> responseType) throws IOException {
|
||||||
return this.execute(HttpGet.METHOD_NAME, uriPath, paramMap, null, responseType);
|
return this.execute(HttpGet.METHOD_NAME, uri, paramMap, null, responseType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public <Request, Response extends BaseResponse> Response post(String uriPath, Request requestObject, Class<Response> responseType) throws IOException {
|
public <Request, Response extends BaseResponse> Response post(String uri, Request requestObject, Class<Response> responseType) throws IOException {
|
||||||
return this.execute(HttpPost.METHOD_NAME, uriPath, null, requestObject, responseType);
|
return this.execute(HttpPost.METHOD_NAME, uri, null, requestObject, responseType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public <Request, Response extends BaseResponse> Response put(String uriPath, Request requestObject, Class<Response> responseType) throws IOException {
|
public <Request, Response extends BaseResponse> Response put(String uri, Request requestObject, Class<Response> responseType) throws IOException {
|
||||||
return this.execute(HttpPost.METHOD_NAME, uriPath, null, requestObject, responseType);
|
return this.execute(HttpPost.METHOD_NAME, uri, null, requestObject, responseType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public <Response extends BaseResponse> Response delete(String uriPath, Map<String, Object> paramMap, Class<Response> responseType) throws IOException {
|
public <Response extends BaseResponse> Response delete(String uri, Map<String, Object> paramMap, Class<Response> responseType) throws IOException {
|
||||||
return this.execute(HttpDelete.METHOD_NAME, uriPath, paramMap, null, responseType);
|
return this.execute(HttpDelete.METHOD_NAME, uri, paramMap, null, responseType);
|
||||||
}
|
}
|
||||||
|
|
||||||
private <Request, Response extends BaseResponse> Response execute(String method, String uriPath, Map<String, Object> paramMap, Request requestObject, Class<Response> responseType) throws IOException {
|
private <Request, Response extends BaseResponse> Response execute(String method, String uri, Map<String, Object> paramMap, Request requestObject, Class<Response> responseType) throws IOException {
|
||||||
if (this.logger.isTraceEnabled())
|
if (this.logger.isTraceEnabled())
|
||||||
this.logger.trace("execute('" + method + "', '" + uriPath + "')");
|
this.logger.trace("execute('" + method + "', '" + uri + "')");
|
||||||
|
|
||||||
RequestBuilder builder = RequestBuilder
|
RequestBuilder builder = RequestBuilder
|
||||||
.create(method)
|
.create(method)
|
||||||
.setUri(this.baseUrl + uriPath);
|
.setUri(uri);
|
||||||
|
|
||||||
if (paramMap != null) {
|
if (paramMap != null) {
|
||||||
for (Entry<String, Object> param : paramMap.entrySet())
|
for (Entry<String, Object> param : paramMap.entrySet())
|
||||||
@ -66,14 +65,14 @@ public class ApiGateway {
|
|||||||
if (requestObject != null) {
|
if (requestObject != null) {
|
||||||
String requestJson = this.omapper.writeValueAsString(requestObject);
|
String requestJson = this.omapper.writeValueAsString(requestObject);
|
||||||
if (this.logger.isTraceEnabled())
|
if (this.logger.isTraceEnabled())
|
||||||
this.logger.trace("execute('" + method + "', '" + uriPath + "'): " + requestJson);
|
this.logger.trace("execute('" + method + "', '" + uri + "'): " + requestJson);
|
||||||
|
|
||||||
builder.setEntity(new StringEntity(requestJson, ContentType.APPLICATION_JSON));
|
builder.setEntity(new StringEntity(requestJson, ContentType.APPLICATION_JSON));
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpUriRequest request = builder.build();
|
HttpUriRequest request = builder.build();
|
||||||
if (this.logger.isDebugEnabled())
|
if (this.logger.isDebugEnabled())
|
||||||
this.logger.debug("Prepared request for " + method + " to: " + uriPath);
|
this.logger.debug("Prepared request for " + method + " to: " + uri);
|
||||||
|
|
||||||
HttpResponse response = HttpClientBuilder
|
HttpResponse response = HttpClientBuilder
|
||||||
.create()
|
.create()
|
||||||
@ -84,21 +83,15 @@ public class ApiGateway {
|
|||||||
if (this.logger.isDebugEnabled())
|
if (this.logger.isDebugEnabled())
|
||||||
this.logger.debug("Received response from " + method + ": " + response.getStatusLine().getStatusCode());
|
this.logger.debug("Received response from " + method + ": " + response.getStatusLine().getStatusCode());
|
||||||
|
|
||||||
Response responseObject = null;
|
InputStream istream = response.getEntity().getContent();
|
||||||
if (response.getEntity() != null) {
|
try {
|
||||||
InputStream istream = response.getEntity().getContent();
|
Response responseObject = this.omapper.readerFor(responseType).readValue(istream);
|
||||||
try {
|
responseObject.setHttpStatusCode(response.getStatusLine().getStatusCode());
|
||||||
responseObject = this.omapper.readerFor(responseType).readValue(istream);
|
responseObject.setHttpStatusReason(response.getStatusLine().getReasonPhrase());
|
||||||
} finally {
|
return responseObject;
|
||||||
istream.close();
|
} finally {
|
||||||
}
|
istream.close();
|
||||||
} else {
|
|
||||||
responseObject = this.omapper.readerFor(responseType).readValue("{}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
responseObject.setHttpStatusCode(response.getStatusLine().getStatusCode());
|
|
||||||
responseObject.setHttpStatusReason(response.getStatusLine().getReasonPhrase());
|
|
||||||
return responseObject;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,17 +2,13 @@ package com.inteligr8.github.model;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import com.inteligr8.github.http.BaseResponse;
|
import com.inteligr8.http.BaseResponse;
|
||||||
|
|
||||||
public class CreatePullRequest {
|
public class CreatePullRequest {
|
||||||
|
|
||||||
private CreatePullRequest() {
|
private CreatePullRequest() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String constructRequestPath(String repoName) {
|
|
||||||
return "/repos/" + repoName + "/" + httpPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String httpPath = "pulls";
|
public static String httpPath = "pulls";
|
||||||
|
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
|
@ -2,17 +2,13 @@ package com.inteligr8.github.model;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import com.inteligr8.github.http.BaseResponse;
|
import com.inteligr8.http.BaseResponse;
|
||||||
|
|
||||||
public class CreateReference {
|
public class CreateReference {
|
||||||
|
|
||||||
private CreateReference() {
|
private CreateReference() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String constructRequestPath(String repoName) {
|
|
||||||
return "/repos/" + repoName + "/" + httpPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String httpPath = "git/refs";
|
public static String httpPath = "git/refs";
|
||||||
|
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
package com.inteligr8.github.model;
|
|
||||||
|
|
||||||
public class DeleteReference {
|
|
||||||
|
|
||||||
private DeleteReference() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String constructRequestPath(String repoName, String ref) {
|
|
||||||
return "/repos/" + repoName + "/" + httpPath + "/" + ref;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String constructRequestPathByBranch(String repoName, String branchName) {
|
|
||||||
return constructRequestPath(repoName, "refs/heads/" + branchName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String httpPath = "git";
|
|
||||||
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
package com.inteligr8.github.http;
|
package com.inteligr8.http;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package com.inteligr8.github.http;
|
package com.inteligr8.http;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user