java.lang.Object
io.github.evisentin.wordpress.client.adapter.apache.modules.MediaApiClientModule
All Implemented Interfaces:
MediaAPIs

public class MediaApiClientModule extends Object implements MediaAPIs
Apache HttpClient implementation of MediaAPIs.

Provides access to WordPress media resources through the /wp/v2/media endpoint, including binary file upload support.

  • Constructor Details

    • MediaApiClientModule

      public MediaApiClientModule(@NonNull @NonNull String apiUrl, @NonNull @NonNull org.apache.hc.client5.http.impl.classic.CloseableHttpClient httpClient, @NonNull @NonNull com.fasterxml.jackson.databind.ObjectMapper mapper)
  • Method Details

    • create

      public WpMedia create(@NonNull @NonNull File file, @NonNull @NonNull String fileName, @NonNull @NonNull String mimeType)
      Description copied from interface: MediaAPIs
      Creates a new media item.

      Uploads a media file to WordPress using the provided file content and metadata.

      The uploaded file is sent to the WordPress media endpoint and results in the creation of a new WpMedia attachment resource.

      Specified by:
      create in interface MediaAPIs
      Parameters:
      file - the file to upload; must not be null
      fileName - the filename to associate with the uploaded media item; must not be null
      mimeType - the MIME type of the uploaded file, for example image/png; must not be null
      Returns:
      the created WpMedia
    • delete

      public WpMediaDeletionResponse delete(long id)
      Description copied from interface: MediaAPIs
      Deletes a media item by its unique identifier.
      Specified by:
      delete in interface MediaAPIs
      Parameters:
      id - the ID of the media item to delete
      Returns:
      the media item deletion response
    • get

      public WpMedia get(long id, WpContext context)
      Description copied from interface: MediaAPIs
      Retrieves a media item by its unique identifier using the given context.

      The context determines which fields are included in the response, for example WpContext.VIEW, WpContext.EDIT, or WpContext.EMBED.

      Specified by:
      get in interface MediaAPIs
      Parameters:
      id - the ID of the media item to retrieve
      context - the retrieval context; may be null, in which case WpContext.VIEW is used
      Returns:
      the matching WpMedia
    • list

      public WpPagedResponse<WpMedia> list(@NonNull @NonNull WpPagingQuery pageQuery, WpMediaQuery mediaQuery)
      Description copied from interface: MediaAPIs
      Retrieves a paginated list of media items using optional filtering and sorting criteria.

      The result set can be refined using WpMediaQuery, for example by filtering on parent, search term, include or exclude lists, or sort order.

      Specified by:
      list in interface MediaAPIs
      Parameters:
      pageQuery - the pagination settings, including page number and page size; must not be null
      mediaQuery - additional media query parameters; may be null when no extra filtering is needed
      Returns:
      a paginated response containing WpMedia items
    • update

      public WpMedia update(long id, @NonNull @NonNull WpMediaUpdateRequest updateRequest)
      Description copied from interface: MediaAPIs
      Updates an existing media item.

      Updates a media item in WordPress using the provided request payload.

      Specified by:
      update in interface MediaAPIs
      Parameters:
      id - the ID of the media item to update
      updateRequest - the category update request; must not be null
      Returns:
      the updated WpMedia