コード例 #1
0
  /**
   * Creates a {@link Builder} for executing a bulk {@code DELETE} request, and wrap the
   * X-result-count header as a integer response.
   *
   * @param apiKey the authorization token for accessing the EVRYTHNG API
   * @param uri the {@link URI} holding the absolute URL
   * @param responseStatus the expected {@link HttpResponse} status
   * @return an EVRYTHNG API-ready {@link Builder}
   */
  public static Builder<Long> deleteMultiple(
      final String apiKey, final URI uri, final Status responseStatus) {

    return new CheckedBuilder<Long>(
        apiKey, HttpMethodBuilder.httpDelete(), 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 DELETE} request.
   *
   * @param apiKey the authorization token for accessing the EVRYTHNG API
   * @param uri the {@link URI} holding the absolute URL
   * @param responseStatus the expected {@link HttpResponse} status
   * @return an EVRYTHNG API-ready {@link Builder}
   */
  public static Builder<Boolean> delete(
      final String apiKey, final URI uri, final Status responseStatus) {

    return new CheckedBuilder<Boolean>(
        apiKey,
        HttpMethodBuilder.httpDelete(),
        uri,
        responseStatus,
        new TypeReference<Boolean>() {}) {

      /**
       * {@code true} if the request has been successfully executed (i.e. returned response status
       * code equals {@link Status#OK}), {@code false} otherwise
       */
      @Override
      public Boolean execute() throws EvrythngException {
        // Perform request (response status code will be automatically checked):
        return request() != null;
      }
    };
  }