コード例 #1
0
  private Response<T> handleResponse(final String response) {
    if (response.contains("Bad API request")) {
      return Responses.failed(response);
    }

    @SuppressWarnings("unchecked")
    final Response<T> successResponse = (Response<T>) Responses.success(response);
    return successResponse;
  }
コード例 #2
0
  public Response<T> executeAsGet() {
    HttpURLConnection connection = null;

    try {
      connection = openConnection(endpoint + "?" + parameters.toUrlFormat());
      final String response = buildResponse(connection.getInputStream());
      return handleResponse(response);
    } catch (final IOException e) {
      return Responses.failed("Unable to connect to Pastebin endpoint!");
    } finally {
      if (connection != null) {
        connection.disconnect();
      }
    }
  }
コード例 #3
0
  public Response<T> executeAsPost() {
    HttpURLConnection connection = null;

    try {
      connection = openConnection(endpoint);
      connection.setDoOutput(true);
      connection.setRequestMethod("POST");

      sendParameters(connection.getOutputStream(), parameters);

      final String response = buildResponse(connection.getInputStream());
      return handleResponse(response);
    } catch (final IOException e) {
      return Responses.failed("Unable to connect to Pastebin endpoint!");
    } finally {
      if (connection != null) {
        connection.disconnect();
      }
    }
  }