Class Endpoint<O,I>

java.lang.Object
masecla.modrinth4j.endpoints.generic.Endpoint<O,I>
Type Parameters:
O - The output type.
I - The input type.
Direct Known Subclasses:
AddFilesToVersion, AddMemberToTeam, BulkModifyProjects, ChangeProjectIcon, ChangeUserIcon, CheckSlugAvailability, CreateGalleryImage, CreateProject, CreateVersion, DeleteFileByHash, DeleteGalleryImage, DeleteProject, DeleteProjectIcon, DeleteUser, DeleteVersion, FollowProject, GetCategories, GetDonationPlatforms, GetGameVersions, GetLicenses, GetLoaders, GetMultipleProjects, GetProject, GetProjectDependencies, GetProjectIdBySlug, GetProjectLatestVersionFromHash, GetProjectLatestVersionsFromHashes, GetProjectTeamMembers, GetProjectVersions, GetRandomProjects, GetReportTypes, GetSelf, GetTeamMembers, GetTeamsMembers, GetUser, GetUserFollowedProjects, GetUserNotifications, GetUserProjects, GetUsers, GetVersion, GetVersionByHash, GetVersionByVersionNumber, GetVersions, GetVersionsFromHashes, JoinTeam, ModifyGalleryImage, ModifyProject, ModifyTeamMemberInfo, ModifyUser, ModifyVersion, PaginatedEndpoint, RemoveMemberFromTeam, ReportProjectUserOrVersion, ScheduleProject, ScheduleVersion, TransferOwnership, UnfollowProject

public abstract class Endpoint<O,I> extends Object
Represents a generic endpoint.
  • Constructor Details

    • Endpoint

      public Endpoint()
  • Method Details

    • getEndpoint

      public abstract String getEndpoint()
      Returns the endpoint of the request.
      Returns:
      - The endpoint of the request.
    • isJsonBody

      public boolean isJsonBody()
      Whether or not the request body should be JSON. If this is false, the request will embed the parameters in the URL.
      Returns:
      - Whether or not the request body should be JSON.
    • requiresBody

      public boolean requiresBody()
      If this is false, the request will not have a body.
      Returns:
      - Whether or not the request requires a body.
    • getReplacedUrl

      protected String getReplacedUrl(I request, Map<String,String> parameters)
      This will replace the URL based on a certain request.
      Parameters:
      request - - The request to use.
      parameters - - The parameters to use.
      Returns:
      - The replaced URL.
    • sendRequest

      public CompletableFuture<O> sendRequest(I request)
      Sends the request.
      Parameters:
      request - - The request to use
      Returns:
      - A CompletableFuture that will return the response.
      See Also:
    • sendRequest

      public CompletableFuture<O> sendRequest(I request, Map<String,String> urlParams)
      Sends the request.
      Parameters:
      request - - The request to use.
      urlParams - - The URL parameters to use.
      Returns:
      - A CompletableFuture that will return the response.
    • executeRequest

      protected okhttp3.Response executeRequest(okhttp3.Request.Builder request)
      This will execute the given request with this endpoint's HTTP client.
      Parameters:
      request - - The request to execute.
      Returns:
      - The response.
    • checkBodyForErrors

      protected O checkBodyForErrors(okhttp3.ResponseBody body)
      Checks a response body for errors.
      Parameters:
      body - - The body to check.
      Returns:
      - The parsed response.
    • readStream

      protected byte[] readStream(InputStream stream)
      Reads a stream into a byte array.
      Parameters:
      stream - - The stream to read.
      Returns:
      - The byte array.
    • readFile

      protected byte[] readFile(File file)
      Reads a file into a byte array.
      Parameters:
      file - - The file to read.
      Returns:
      - The byte array.
    • getMethod

      public String getMethod()
      Returns the method to use.
      Returns:
      - The method to use.
    • getResponseClass

      public abstract com.google.gson.reflect.TypeToken<O> getResponseClass()
      Returns the TypeToken of the response;
      Returns:
      - The TypeToken of the response.
    • getRequestClass

      public abstract com.google.gson.reflect.TypeToken<I> getRequestClass()
      Returns the TypeToken of the request.
      Returns:
      - The TypeToken of the request.