public static Builder<AcceptedResourceResponse> postAsynchronously( final String apiKey, final URI uri, final Object data, final Pattern extractor) { return new CheckedBuilder<AcceptedResourceResponse>( apiKey, HttpMethodBuilder.httpPost(data), uri, Status.ACCEPTED, new TypeReference<AcceptedResourceResponse>() {}) { @Override public AcceptedResourceResponse execute() throws EvrythngException { // Perform request (response status code will be automatically checked): HttpResponse response = request(); String location = null; Header header = response.getFirstHeader("location"); String id = null; if (header != null) { location = header.getValue(); if (location != null) { Matcher match = extractor.matcher(location); if (match.matches() && match.groupCount() > 0) { id = match.group(1); } } } return new AcceptedResourceResponse(id, location); } }; }
/** * Creates a {@link CheckedBuilder} for executing a {@code POST} request. * * @param apiKey the authorization token for accessing the EVRYTHNG API * @param uri the {@link URI} holding the absolute URL * @param data the content data that will be associated with the POST request * @param responseStatus the expected {@link HttpResponse} status * @param responseType the native type to which the {@link HttpResponse} will be mapped to * @return an EVRYTHNG API-ready {@link CheckedBuilder} */ public static <T> Builder<T> post( final String apiKey, final URI uri, final Object data, final Status responseStatus, final TypeReference<T> responseType) { return new CheckedBuilder<>( apiKey, HttpMethodBuilder.httpPost(data), uri, responseStatus, responseType); }