Skip to content

Commit

Permalink
fixed merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
quirijnslings committed Sep 18, 2024
2 parents ec6a52b + b87e130 commit 5ea743b
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 2 deletions.
16 changes: 16 additions & 0 deletions Bynder/Sample/MediaSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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: ");
Expand All @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion Bynder/Sdk/Api/RequestSender/ApiRequestSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,15 @@ public async Task<T> SendRequestAsync<T>(Request<T> 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<T>(responseString);
return JsonConvert.DeserializeObject<T>(responseString, settings);
}

private async Task<HttpResponseMessage> CreateHttpRequestAsync<T>(Request<T> request)
Expand Down
12 changes: 11 additions & 1 deletion Bynder/Sdk/Model/Media.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -23,7 +25,15 @@ public class Media
/// Property asset types assigned to media
/// </summary>
[JsonProperty("property_assettype")]
public IList<string> PropertyAssetType { get; set; }
[JsonIgnore]
[Obsolete("Use PropertyOptionsDictionary?[\"property_assettype\"] instead")]
public IList<string> PropertyAssetType
{
get
{
return PropertyOptionsDictionary?["property_assettype"].Values().Select(v => v.ToString()).ToList() ?? null;
}
}

/// <summary>
/// Active focus point in the original media item, defined
Expand Down
9 changes: 9 additions & 0 deletions Bynder/Sdk/Service/Asset/AssetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,5 +266,14 @@ private static MediaQueryFull CloneIntoFullMediaQuery(MediaQuery query)
Total = true
};
}

public async Task<Status> DeleteAssetAsync(string assetId)
{
return await _requestSender.SendRequestAsync(new ApiRequest<Status>
{
Path = "/api/v4/media/" + assetId,
HTTPMethod = HttpMethod.Delete,
}).ConfigureAwait(false);
}
}
}
8 changes: 8 additions & 0 deletions Bynder/Sdk/Service/Asset/IAssetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,13 @@ public interface IAssetService
/// <exception cref="HttpRequestException">Can be thrown when requests to server can't be completed or HTTP code returned by server is an error</exception>
/// <remarks>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</remarks>
Task<MediaFullResult> GetMediaFullResultAsync(MediaQuery query);

/// Delete an asset
/// </summary>
/// <param name="assetId">Id of the asset to remove</param>
/// <returns>Task representing the operation</returns>
/// <exception cref="HttpRequestException">Can be thrown when requests to server can't be completed or HTTP code returned by server is an error</exception>
Task<Status> DeleteAssetAsync(string assetId);

}
}
18 changes: 18 additions & 0 deletions Bynder/Test/Service/Asset/AssetServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ApiRequest<Status>>()))
.ReturnsAsync(result);

var assetId = "asset-id";
await _assetService.DeleteAssetAsync(assetId);

_apiRequestSenderMock.Verify(sender => sender.SendRequestAsync(
It.Is<ApiRequest<Status>>(req =>
req.Path == $"/api/v4/media/" + assetId
&& req.HTTPMethod == HttpMethod.Delete
)
));
}
}
}

0 comments on commit 5ea743b

Please sign in to comment.