Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3-delete-asset #95

Merged
merged 4 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
406 changes: 397 additions & 9 deletions .gitignore

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Bynder/Sample/Bynder.Sample.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<AssemblyVersion>2.0.0</AssemblyVersion>
<FileVersion>2.0.0</FileVersion>
<Company>Bynder</Company>
<Product>Bynder.Sample</Product>
<Copyright>Copyright © Bynder</Copyright>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Sdk\Bynder.Sdk.csproj" />
Expand Down
7 changes: 7 additions & 0 deletions Bynder/Sample/MediaSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,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
40 changes: 40 additions & 0 deletions Bynder/Sample/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"profiles": {
"WSL": {
"commandName": "WSL2",
"distributionName": ""
},
"Run MediaSample": {
"commandName": "Project",
"commandLineArgs": "MediaSample"
},
"Run MetapropertyToMediaSample": {
"commandName": "Project",
"commandLineArgs": "MetapropertyToMediaSample"
},
"Run BrandsSample": {
"commandName": "Project",
"commandLineArgs": "BrandsSample"
},
"Run MetapropertiesSample": {
"commandName": "Project",
"commandLineArgs": "MetapropertiesSample"
},
"Run CollectionsSample": {
"commandName": "Project",
"commandLineArgs": "CollectionsSample"
},
"Run TagsSample": {
"commandName": "Project",
"commandLineArgs": "TagsSample"
},
"Run UploadSample": {
"commandName": "Project",
"commandLineArgs": "UploadSample"
},
"Run AssetUsageSample": {
"commandName": "Project",
"commandLineArgs": "AssetUsageSample"
},
}
}
6 changes: 3 additions & 3 deletions Bynder/Sdk/Bynder.Sdk.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.1;net48</TargetFrameworks>
<TargetFramework>net8.0</TargetFramework>
<AssemblyVersion>2.2.12.0</AssemblyVersion>
<FileVersion>2.2.12.0</FileVersion>
<Company>Bynder</Company>
Expand All @@ -25,8 +25,8 @@
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="6.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
Expand Down
13 changes: 13 additions & 0 deletions Bynder/Sdk/Service/Asset/AssetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,5 +232,18 @@ public async Task<Status> DeleteAssetUsage(AssetUsageQuery query)
Query = query
}).ConfigureAwait(false);
}

/// <summary>
/// Check <see cref="IAssetService"/> for more information
/// </summary>
/// <returns>Check <see cref="IAssetService"/> for more information</returns>
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 @@ -122,5 +122,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>
Task<Status> DeleteAssetUsage(AssetUsageQuery query);

/// <summary>
/// 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);

}
}
14 changes: 7 additions & 7 deletions Bynder/Test/Bynder.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<IsTestProject>true</IsTestProject>
<AssemblyVersion>2.0.0</AssemblyVersion>
<FileVersion>2.0.0</FileVersion>
Expand All @@ -9,15 +9,15 @@
<Copyright>Copyright © Bynder</Copyright>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="3.1.0"><IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PackageReference Include="coverlet.msbuild" Version="6.0.2"><IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="Moq.Sequences" Version="2.2.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"><IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2"><IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
Expand Down
18 changes: 18 additions & 0 deletions Bynder/Test/Service/Asset/AssetServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,5 +257,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
)
));
}
}
}