Class AbstractRequest<T>

java.lang.Object
se.michaelthelin.spotify.requests.AbstractRequest<T>
Type Parameters:
T - The response type.
All Implemented Interfaces:
IRequest<T>
Direct Known Subclasses:
AbstractAuthorizationRequest, AbstractDataRequest, AuthorizationCodePKCERefreshRequest, AuthorizationCodePKCERequest, AuthorizationCodeUriRequest

public abstract class AbstractRequest<T> extends Object implements IRequest<T>
Abstract base class for all requests.
  • Constructor Details

    • AbstractRequest

      protected AbstractRequest(AbstractRequest.Builder<T,?> builder)
      Protected constructor for requests.
      Parameters:
      builder - The builder instance.
  • Method Details

    • executeAsync

      public CompletableFuture<T> executeAsync()
      Get something asynchronously.
      Specified by:
      executeAsync in interface IRequest<T>
      Returns:
      A CompletableFuture for a generic.
    • initializeBody

      public void initializeBody()
      Initialize the request body based on content type.
    • bodyParametersToJson

      public String bodyParametersToJson(List<org.apache.hc.core5.http.NameValuePair> bodyParameters)
      Convert body parameters to JSON string.
      Parameters:
      bodyParameters - The body parameters to convert.
      Returns:
      JSON string representation.
    • getJson

      public String getJson() throws IOException, SpotifyWebApiException, org.apache.hc.core5.http.ParseException
      Description copied from interface: IRequest
      Get JSON response as string.
      Specified by:
      getJson in interface IRequest<T>
      Returns:
      JSON response string.
      Throws:
      IOException - If an I/O error occurs.
      SpotifyWebApiException - If a Spotify Web API error occurs.
      org.apache.hc.core5.http.ParseException - If a parsing error occurs.
    • postJson

      public String postJson() throws IOException, SpotifyWebApiException, org.apache.hc.core5.http.ParseException
      Description copied from interface: IRequest
      Execute POST request and get JSON response.
      Specified by:
      postJson in interface IRequest<T>
      Returns:
      JSON response string.
      Throws:
      IOException - If an I/O error occurs.
      SpotifyWebApiException - If a Spotify Web API error occurs.
      org.apache.hc.core5.http.ParseException - If a parsing error occurs.
    • putJson

      public String putJson() throws IOException, SpotifyWebApiException, org.apache.hc.core5.http.ParseException
      Description copied from interface: IRequest
      Execute PUT request and get JSON response.
      Specified by:
      putJson in interface IRequest<T>
      Returns:
      JSON response string.
      Throws:
      IOException - If an I/O error occurs.
      SpotifyWebApiException - If a Spotify Web API error occurs.
      org.apache.hc.core5.http.ParseException - If a parsing error occurs.
    • deleteJson

      public String deleteJson() throws IOException, SpotifyWebApiException, org.apache.hc.core5.http.ParseException
      Description copied from interface: IRequest
      Execute DELETE request and get JSON response.
      Specified by:
      deleteJson in interface IRequest<T>
      Returns:
      JSON response string.
      Throws:
      IOException - If an I/O error occurs.
      SpotifyWebApiException - If a Spotify Web API error occurs.
      org.apache.hc.core5.http.ParseException - If a parsing error occurs.
    • getHttpManager

      public IHttpManager getHttpManager()
      Description copied from interface: IRequest
      Get the HTTP manager for this request.
      Specified by:
      getHttpManager in interface IRequest<T>
      Returns:
      The HTTP manager.
    • getUri

      public URI getUri()
      Description copied from interface: IRequest
      Get the URI for this request.
      Specified by:
      getUri in interface IRequest<T>
      Returns:
      The request URI.
    • getHeaders

      public List<org.apache.hc.core5.http.Header> getHeaders()
      Description copied from interface: IRequest
      Get the headers for this request.
      Specified by:
      getHeaders in interface IRequest<T>
      Returns:
      List of headers.
    • getContentType

      public org.apache.hc.core5.http.ContentType getContentType()
      Description copied from interface: IRequest
      Get the content type for this request.
      Specified by:
      getContentType in interface IRequest<T>
      Returns:
      The content type.
    • getBody

      public org.apache.hc.core5.http.HttpEntity getBody()
      Description copied from interface: IRequest
      Get the request body.
      Specified by:
      getBody in interface IRequest<T>
      Returns:
      The HTTP entity body.
    • getBodyParameters

      public List<org.apache.hc.core5.http.NameValuePair> getBodyParameters()
      Description copied from interface: IRequest
      Get the body parameters for this request.
      Specified by:
      getBodyParameters in interface IRequest<T>
      Returns:
      List of body parameters.