コード例 #1
0
  /**
   * Create a {@link Builder} for executing a {@code PUT} request, expecting no result payload. But
   * a {@link ApiConfiguration#HTTP_HEADER_RESULT_COUNT} header which contains the amount of
   * document updated.
   *
   * @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 PUT request
   * @param responseStatus the expected {@link HttpResponse} status. More likely 204 No Content
   * @return an EVRYTHNG API-ready {@link Builder}
   */
  public static Builder<Long> putMultiple(
      final String apiKey, final URI uri, final Object data, final Status responseStatus) {

    return new CheckedBuilder<Long>(
        apiKey,
        HttpMethodBuilder.httpPut(data),
        uri,
        responseStatus,
        new TypeReference<Long>() {}) {

      @Override
      public Long execute() throws EvrythngException {
        // Perform request (response status code will be automatically checked):
        HttpResponse response = request();
        Header header = response.getFirstHeader(ApiConfiguration.HTTP_HEADER_RESULT_COUNT);
        Long result = null;
        if (header != null) {
          try {
            result = Long.parseLong(header.getValue());
          } catch (NumberFormatException ex) {
            logger.warn(
                "Invalid numeric value in header {} : {}",
                ApiConfiguration.HTTP_HEADER_RESULT_COUNT,
                header.getValue());
          }
        }
        return result;
      }
    };
  }
コード例 #2
0
  /**
   * Creates a {@link Builder} for executing a {@code PUT} 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 returnType the native type to which the {@link HttpResponse} will be mapped to
   * @return an EVRYTHNG API-ready {@link Builder}
   */
  public static <T> Builder<T> put(
      final String apiKey,
      final URI uri,
      final Object data,
      final Status responseStatus,
      final TypeReference<T> returnType) {

    return new CheckedBuilder<>(
        apiKey, HttpMethodBuilder.httpPut(data), uri, responseStatus, returnType);
  }