Jump to content

ApiClient; How to delete an item


Sludge Vohaul

Recommended Posts

Sludge Vohaul

Hi,

 

how am I supposed to delete items programmatically?

 

E.g. I would like to delete all Backdrop images of an item.

I would expect to find a Emby.ApiInteraction.ApiClient.DeleteAsync() method (PostAsync() analogy)

which is indeed there, but it's private.

 

What am I missing?

 

Thanks,

sv

Link to comment
Share on other sites

Sludge Vohaul

Actually it has already been added, and it is also used throughout ApiClient.cs.

But is is private.

 

Is there any reason for the method being marked as private?

Link to comment
Share on other sites

I'm not sure but if i had to guess because it's not finished, or perhaps there was a problem and we didn't want to deal with it at the time so we marked it private. or it could have just been human error.

Link to comment
Share on other sites

Sludge Vohaul

Yes, stupid question...

 

In case anyone else gets into this, I've added a DeleteAsync() method to "my" EmbyClient-class. Seems to work as expected in my use case (deleting a image of provided type from a movie):

 

My client class implementation:

public class EmbyClient : ApiClient, IEmbyClient
{
  ...

  /// <remarks>
  /// This is a copy of the Emby.ApiInteraction.ApiClient.DeleteAsync() method, since the original is private, for whatever reasons.
  /// The also private method SendAsync is replaced with IAsyncHttpClient.SendAsync which "seems" to work...
  /// TODO - Once the ApiClient.DeleteAsync() method is public this method should be deleted.
  /// </remarks>
  public async Task<T> DeleteAsync<T>(string url, CancellationToken cancellationToken = default(CancellationToken)) where T : class
  {
    url = AddDataFormat(url);

    using (var stream = await HttpClient.SendAsync(new HttpRequest
    {
      Url = url,
      CancellationToken = cancellationToken,
      RequestHeaders = HttpHeaders,
      Method = "DELETE"

    }).ConfigureAwait(false))
    {
      return DeserializeFromStream<T>(stream);
    }
  }
}
Usage:

public async Task DeleteImagesFromMovieAsync(IEmbyClient client, string movieId, ImageType imageType)
{
  // TODO - This does not delete all images of the provided type.
  // TODO - With default index, only the image at index=0 (the leftmost in browser UI) is deleted.
  var url = client.GetApiUrl($"Items/{movieId}/Images/{imageType}");
  await client.DeleteAsync<EmptyRequestResult>(url);
}
HTH someone...
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...