Skip to content

Commit

Permalink
v3-delete-asset (#95)
Browse files Browse the repository at this point in the history
* targetframework now net8.0, packages upgraded

* add IAssetService.DeleteAssetAsync with implementation, sample and test

* updated gitignore to the toptotal standard, added launchSettings to help developers run the samples
  • Loading branch information
quirijnslings authored Sep 16, 2024
1 parent f6791ce commit f3edc7a
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
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
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);

}
}
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
)
));
}
}
}

0 comments on commit f3edc7a

Please sign in to comment.