Sludge Vohaul 22 Posted September 5, 2017 Share Posted September 5, 2017 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 More sharing options...
Luke 37099 Posted September 5, 2017 Share Posted September 5, 2017 The javascript version is essentially our master apiclient: https://github.com/MediaBrowser/Emby.ApiClient.Javascript/blob/master/apiclient.js The methods get added to the other platforms on as-needed basis. Up until this point it probably has just not been added to the c# version. Link to comment Share on other sites More sharing options...
Sludge Vohaul 22 Posted September 5, 2017 Author Share Posted September 5, 2017 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 More sharing options...
Luke 37099 Posted September 5, 2017 Share Posted September 5, 2017 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 More sharing options...
Sludge Vohaul 22 Posted September 5, 2017 Author Share Posted September 5, 2017 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... 1 Link to comment Share on other sites More sharing options...
Luke 37099 Posted September 5, 2017 Share Posted September 5, 2017 Looks great, thanks for the tip ! Link to comment Share on other sites More sharing options...
Sludge Vohaul 22 Posted September 5, 2017 Author Share Posted September 5, 2017 It's your code, I stole it Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now