diff --git a/Bynder/Sample/MediaSample.cs b/Bynder/Sample/MediaSample.cs index a6e1398..ed92cad 100644 --- a/Bynder/Sample/MediaSample.cs +++ b/Bynder/Sample/MediaSample.cs @@ -54,6 +54,15 @@ private async Task RunMediaSampleAsync() Console.WriteLine($"ID: {mediaInfo.Id}"); Console.WriteLine($"Name: {mediaInfo.Name}"); Console.WriteLine($"Brand Id: {mediaInfo.BrandId}"); + Console.WriteLine($"Asset type: {string.Join(',', mediaInfo.PropertyAssetType)}"); + if (mediaInfo.PropertyOptionsDictionary != null) + { + foreach (var propertyKey in mediaInfo.PropertyOptionsDictionary.Keys) + { + Console.Write($"Property option in dictionary: {propertyKey}: {mediaInfo.PropertyOptionsDictionary[propertyKey].ToString()}"); + } + } + // Get the media download URL Console.WriteLine("Enter the media ID to get the media download URL for: "); @@ -74,6 +83,13 @@ private async Task RunMediaSampleAsync() Description = updatedDescription }; await _bynderClient.GetAssetService().ModifyMediaAsync(modifyMediaQuery); + + + // Modify a media with a new description + Console.WriteLine("Enter the media ID to delete: "); + var mediaIdForDelete = Console.ReadLine(); + await _bynderClient.GetAssetService().DeleteAssetAsync(mediaIdForDelete); + } private async Task AuthenticateWithOAuth2Async(bool useClientCredentials) diff --git a/Bynder/Sdk/Api/RequestSender/ApiRequestSender.cs b/Bynder/Sdk/Api/RequestSender/ApiRequestSender.cs index 56bb0a3..461bfcc 100644 --- a/Bynder/Sdk/Api/RequestSender/ApiRequestSender.cs +++ b/Bynder/Sdk/Api/RequestSender/ApiRequestSender.cs @@ -90,8 +90,15 @@ public async Task SendRequestAsync(Request request) { return default; } + // Note: for powerpoints, a pdf is automatically generated by Bynder and stored as a second MediaItem. + // However, this MediaItem has a Height and Width of null, which cannot be converted to an int so it breaks. + // The below setting fixes this + var settings = new JsonSerializerSettings + { + NullValueHandling = NullValueHandling.Ignore + }; - return JsonConvert.DeserializeObject(responseString); + return JsonConvert.DeserializeObject(responseString, settings); } private async Task CreateHttpRequestAsync(Request request) diff --git a/Bynder/Sdk/Model/Media.cs b/Bynder/Sdk/Model/Media.cs index 2c28193..c336d85 100644 --- a/Bynder/Sdk/Model/Media.cs +++ b/Bynder/Sdk/Model/Media.cs @@ -5,6 +5,8 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Bynder.Sdk.Api.Converters; +using System; +using System.Linq; namespace Bynder.Sdk.Model { @@ -23,7 +25,15 @@ public class Media /// Property asset types assigned to media /// [JsonProperty("property_assettype")] - public IList PropertyAssetType { get; set; } + [JsonIgnore] + [Obsolete("Use PropertyOptionsDictionary?[\"property_assettype\"] instead")] + public IList PropertyAssetType + { + get + { + return PropertyOptionsDictionary?["property_assettype"].Values().Select(v => v.ToString()).ToList() ?? null; + } + } /// /// Active focus point in the original media item, defined diff --git a/Bynder/Sdk/Service/Asset/AssetService.cs b/Bynder/Sdk/Service/Asset/AssetService.cs index ef16019..8a958cb 100644 --- a/Bynder/Sdk/Service/Asset/AssetService.cs +++ b/Bynder/Sdk/Service/Asset/AssetService.cs @@ -279,6 +279,13 @@ private static MediaQueryFull CloneIntoFullMediaQuery(MediaQuery query) Total = true }; } - + public async Task DeleteAssetAsync(string assetId) + { + return await _requestSender.SendRequestAsync(new ApiRequest + { + Path = "/api/v4/media/" + assetId, + HTTPMethod = HttpMethod.Delete, + }).ConfigureAwait(false); + } } } diff --git a/Bynder/Sdk/Service/Asset/IAssetService.cs b/Bynder/Sdk/Service/Asset/IAssetService.cs index 50ce12c..1d1b0ab 100644 --- a/Bynder/Sdk/Service/Asset/IAssetService.cs +++ b/Bynder/Sdk/Service/Asset/IAssetService.cs @@ -143,5 +143,12 @@ public interface IAssetService /// Can be thrown when requests to server can't be completed or HTTP code returned by server is an error /// This method can be used to implement pagination in your app. The MediaFullResult that gets returned has a Total.Count property, which contains the total number of matching assets, not just the number of assets in the current result page Task GetMediaFullResultAsync(MediaQuery query); + + /// Delete an asset + /// + /// Id of the asset to remove + /// Task representing the operation + /// Can be thrown when requests to server can't be completed or HTTP code returned by server is an error + Task DeleteAssetAsync(string assetId); } } diff --git a/Bynder/Test/Service/Asset/AssetServiceTest.cs b/Bynder/Test/Service/Asset/AssetServiceTest.cs index e881e29..c89cb43 100644 --- a/Bynder/Test/Service/Asset/AssetServiceTest.cs +++ b/Bynder/Test/Service/Asset/AssetServiceTest.cs @@ -321,5 +321,23 @@ public async Task DeleteAssetUsageCallsRequestSenderWithValidRequest() ) )); } + + [Fact] + public async Task DeleteAssetCallsRequestSenderWithValidRequest() + { + var result = new Status { Message = "Accepted", StatusCode = 204 }; + _apiRequestSenderMock.Setup(sender => sender.SendRequestAsync(It.IsAny>())) + .ReturnsAsync(result); + + var assetId = "asset-id"; + await _assetService.DeleteAssetAsync(assetId); + + _apiRequestSenderMock.Verify(sender => sender.SendRequestAsync( + It.Is>(req => + req.Path == $"/api/v4/media/" + assetId + && req.HTTPMethod == HttpMethod.Delete + ) + )); + } } }