private void buildContext() { workingContext.addPayload("name", name).addPayload("userData", userData) .setPath("face/v1.0/persongroups/${id}").addPathVariable("id", personGroupId) .httpMethod(HttpMethod.PUT); }
private void buildContext() { workingContext.setPath("face/v1.0/persongroups/${personGroupId}").addPathVariable("personGroupId", personGroupId) .httpMethod(HttpMethod.GET); }
private void buildContext() { workingContext.setPath("face/v1.0/group") .httpMethod(HttpMethod.POST).addPayload("faceIds", faceIds); }
private T doWork() { try { setupErrorHandlers(); WorkingContext workingContext = workingContext(); HttpRequest builtRequest = buildUnirest(workingContext) .queryString(workingContext.getQueryParams()) .headers(workingContext.getHeaders()).header("Ocp-Apim-Subscription-Key", cognitiveContext.subscriptionKey); if (!workingContext.getHttpMethod().equals(HttpMethod.GET) && workingContext().getPayload().size() > 0) { buildBody((HttpRequestWithBody) builtRequest); } HttpResponse response; if (typedResponse() == InputStream.class) response = builtRequest.asBinary(); else response = builtRequest.asString(); checkForError(response); return postProcess(typeResponse(response.getBody())); } catch (UnirestException | IOException e) { throw new CognitiveException(e); } }
private void buildContext() { workingContext.setPath("vision/v1.0/models") .httpMethod(HttpMethod.GET); }
private HttpRequest buildUnirest(WorkingContext workingContext) { String url = String.format("%s%s", PROJECTOXFORD_AI, workingContext.getPathBuilt()); switch (workingContext.getHttpMethod()) { case GET: return Unirest.get(url); case PUT: return Unirest.put(url); case DELETE: return Unirest.delete(url); case PATCH: return Unirest.patch(url); } return Unirest.post(url); }
private void buildBody(HttpRequestWithBody builtRequest) throws IOException { if (workingContext().getPayload().containsKey(IMAGE_INPUT_STREAM_KEY)) { builtRequest.header("content-type", "application/octet-stream").body(IOUtils.toByteArray((InputStream) workingContext().getPayload().get(IMAGE_INPUT_STREAM_KEY))); } else { builtRequest.header("content-type", "application/json").body(new JSONObject(workingContext().getPayload())); } }
private void buildContext() { workingContext.setPath("face/v1.0/persongroups/${personGroupId}/train").addPathVariable("personGroupId", personGroupId) .httpMethod(HttpMethod.POST); }
private void buildContext() { workingContext.setPath("face/v1.0/identify") .httpMethod(HttpMethod.POST).addPayload("personGroupId", personGroupId).addPayload("faceIds", faceIds) .addPayload("maxNumOfCandidatesReturned", maxNumOfCandidatesReturned); }
private void buildContext() { workingContext.setPath("face/v1.0/facelists") .httpMethod(HttpMethod.GET); }
private void buildContext() { workingContext.addPayload("name", name).addPayload("userData", userData) .setPath("face/v1.0/facelists/${faceListId}").addPathVariable("faceListId", faceListId) .httpMethod(HttpMethod.PUT); }
private void buildContext(String id) { workingContext.setPath("face/v1.0/persongroups/${id}").addPathVariable("id", id) .httpMethod(HttpMethod.DELETE); }
private void buildContext() { workingContext.setPath("face/v1.0/verify") .httpMethod(HttpMethod.POST).addPayload("faceId1", faceId1).addPayload("faceId2", faceId2); }
private void buildContext() { workingContext.setPath("face/v1.0/persongroups") .httpMethod(HttpMethod.GET); }
private void buildContext() { workingContext.addPayload("name", name).addPayload("userData", userData) .setPath("face/v1.0/persongroups/${personGroupId}/persons/${personId}").addPathVariable("personGroupId", personGroupId) .addPathVariable("personId", personId).httpMethod(HttpMethod.PATCH); }
private void buildContext(String id) { workingContext.setPath("face/v1.0/persongroups/${personGroupId}/persons/${personId}") .addPathVariable("personGroupId", id).addPathVariable("personId", personId) .httpMethod(HttpMethod.DELETE); }
private void buildContext(Object image) { workingContext.setPath("vision/v1.0/tag") .httpMethod(HttpMethod.POST); if (image instanceof String) workingContext.addPayload("url", String.valueOf(image)); if (image instanceof InputStream) workingContext.addPayload(IMAGE_INPUT_STREAM_KEY, image); }
private void buildContext() { workingContext.addPayload("name", name).addPayload("userData", userData) .setPath("face/v1.0/facelists/${faceListId}").addPathVariable("faceListId", faceListId) .httpMethod(HttpMethod.PATCH); }
private void buildContext(String id) { workingContext.setPath("face/v1.0/persongroups/${personGroupId}/persons/${personId}") .addPathVariable("personGroupId", id).addPathVariable("personId", personId) .httpMethod(HttpMethod.GET); }
private void buildContext() { workingContext.setPath("face/v1.0/findsimilars") .httpMethod(HttpMethod.POST).addPayload("faceId", faceId).addPayload("maxNumOfCandidatesReturned", maxNumOfCandidates); if (Utils.isNotEmpty(faceIds)) workingContext().addPayload("faceIds", faceIds); else workingContext().addPayload("faceListId", faceListId); }