use of net.sf.json.groovy.JsonSlurper in project phabricator-jenkins-plugin by uber.
the class ConduitAPIClient method perform.
/**
* Call the conduit API of Phabricator
* @param action Name of the API call
* @param params The data to send to Harbormaster
* @return The result as a JSONObject
* @throws IOException If there was a problem reading the response
* @throws ConduitAPIException If there was an error calling conduit
*/
public JSONObject perform(String action, JSONObject params) throws IOException, ConduitAPIException {
CloseableHttpClient client = HttpClientBuilder.create().build();
HttpUriRequest request = createRequest(action, params);
HttpResponse response;
try {
response = client.execute(request);
} catch (ClientProtocolException e) {
throw new ConduitAPIException(e.getMessage());
}
InputStream responseBody = response.getEntity().getContent();
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
throw new ConduitAPIException(responseBody.toString(), response.getStatusLine().getStatusCode());
}
JsonSlurper jsonParser = new JsonSlurper();
return (JSONObject) jsonParser.parse(responseBody);
}
use of net.sf.json.groovy.JsonSlurper in project phabricator-jenkins-plugin by uber.
the class UberallsClient method getParentCoverage.
public CodeCoverageMetrics getParentCoverage(String sha) {
if (sha == null) {
return null;
}
try {
String coverageJSON = getCoverage(sha);
JsonSlurper jsonParser = new JsonSlurper();
JSON responseJSON = jsonParser.parseText(coverageJSON);
if (responseJSON instanceof JSONNull) {
return null;
}
JSONObject coverage = (JSONObject) responseJSON;
return new CodeCoverageMetrics(((Double) coverage.getDouble(PACKAGE_COVERAGE_KEY)).floatValue(), ((Double) coverage.getDouble(FILES_COVERAGE_KEY)).floatValue(), ((Double) coverage.getDouble(CLASSES_COVERAGE_KEY)).floatValue(), ((Double) coverage.getDouble(METHOD_COVERAGE_KEY)).floatValue(), ((Double) coverage.getDouble(LINE_COVERAGE_KEY)).floatValue(), ((Double) coverage.getDouble(CONDITIONAL_COVERAGE_KEY)).floatValue());
} catch (Exception e) {
e.printStackTrace(logger.getStream());
}
return null;
}
Aggregations