From 38a93cd9cc3595bb0b3caa841f9146adba2a1951 Mon Sep 17 00:00:00 2001 From: Quirijn Date: Mon, 16 Sep 2024 20:03:09 +0200 Subject: [PATCH 1/4] v3-platform (#94) * targetframework now net8.0, packages upgraded * updated gitignore to the toptotal standard, added launchSettings to help developers run the samples --- .gitignore | 406 ++++++++++++++++++- Bynder/Sample/Bynder.Sample.csproj | 4 +- Bynder/Sample/Properties/launchSettings.json | 40 ++ Bynder/Sdk/Bynder.Sdk.csproj | 6 +- Bynder/Test/Bynder.Test.csproj | 14 +- 5 files changed, 449 insertions(+), 21 deletions(-) create mode 100644 Bynder/Sample/Properties/launchSettings.json diff --git a/.gitignore b/.gitignore index 0250353..d1d96e7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,17 +1,405 @@ -# General macOS -.DS_Store -.AppleDouble -.LSOverride +# Created by https://www.toptal.com/developers/gitignore/api/visualstudio +# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudio + +### VisualStudio ### +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* # Build results -bin/ -obj/ +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ # Visual Studio 2015/2017 cache/options directory .vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ -# The packages folder can be ignored because of Package Restore -packages/* +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info # Visual Studio code coverage results -coverage.opencover.xml +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider +*.sln.iml + +### VisualStudio Patch ### +# Additional files built by Visual Studio + +# End of https://www.toptal.com/developers/gitignore/api/visualstudio \ No newline at end of file diff --git a/Bynder/Sample/Bynder.Sample.csproj b/Bynder/Sample/Bynder.Sample.csproj index 36371fd..2efc672 100644 --- a/Bynder/Sample/Bynder.Sample.csproj +++ b/Bynder/Sample/Bynder.Sample.csproj @@ -1,7 +1,7 @@ Exe - net5.0 + net8.0 2.0.0 2.0.0 Bynder @@ -9,7 +9,7 @@ Copyright © Bynder - + diff --git a/Bynder/Sample/Properties/launchSettings.json b/Bynder/Sample/Properties/launchSettings.json new file mode 100644 index 0000000..865d3b8 --- /dev/null +++ b/Bynder/Sample/Properties/launchSettings.json @@ -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" + }, + } +} \ No newline at end of file diff --git a/Bynder/Sdk/Bynder.Sdk.csproj b/Bynder/Sdk/Bynder.Sdk.csproj index da92461..fc3d907 100644 --- a/Bynder/Sdk/Bynder.Sdk.csproj +++ b/Bynder/Sdk/Bynder.Sdk.csproj @@ -1,6 +1,6 @@ - netstandard2.1;net48 + net8.0 2.2.12.0 2.2.12.0 Bynder @@ -25,8 +25,8 @@ true - - + + diff --git a/Bynder/Test/Bynder.Test.csproj b/Bynder/Test/Bynder.Test.csproj index 960e55f..94b52dc 100644 --- a/Bynder/Test/Bynder.Test.csproj +++ b/Bynder/Test/Bynder.Test.csproj @@ -1,6 +1,6 @@  - net5.0 + net8.0 true 2.0.0 2.0.0 @@ -9,15 +9,15 @@ Copyright © Bynder - runtime; build; native; contentfiles; analyzers; buildtransitive + runtime; build; native; contentfiles; analyzers; buildtransitive all - - + + - - - runtime; build; native; contentfiles; analyzers; buildtransitive + + + runtime; build; native; contentfiles; analyzers; buildtransitive all From f6791cecbd1c01b47fce3c1df9334428fabc0eb3 Mon Sep 17 00:00:00 2001 From: Quirijn Date: Mon, 16 Sep 2024 21:00:31 +0200 Subject: [PATCH 2/4] v3-width height (#100) * targetframework now net8.0, packages upgraded * updated gitignore to the toptotal standard, added launchSettings to help developers run the samples * ignoring null values in json response --- Bynder/Sdk/Api/RequestSender/ApiRequestSender.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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) From f3edc7ac2559214c7f3864b97dbb9af98c13e303 Mon Sep 17 00:00:00 2001 From: Quirijn Date: Mon, 16 Sep 2024 23:07:44 +0200 Subject: [PATCH 3/4] v3-delete-asset (#95) * 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 --- Bynder/Sample/MediaSample.cs | 7 +++++++ Bynder/Sdk/Service/Asset/AssetService.cs | 13 +++++++++++++ Bynder/Sdk/Service/Asset/IAssetService.cs | 8 ++++++++ Bynder/Test/Service/Asset/AssetServiceTest.cs | 18 ++++++++++++++++++ 4 files changed, 46 insertions(+) diff --git a/Bynder/Sample/MediaSample.cs b/Bynder/Sample/MediaSample.cs index 501d496..1840902 100644 --- a/Bynder/Sample/MediaSample.cs +++ b/Bynder/Sample/MediaSample.cs @@ -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) diff --git a/Bynder/Sdk/Service/Asset/AssetService.cs b/Bynder/Sdk/Service/Asset/AssetService.cs index f94f779..d5e15ba 100644 --- a/Bynder/Sdk/Service/Asset/AssetService.cs +++ b/Bynder/Sdk/Service/Asset/AssetService.cs @@ -232,5 +232,18 @@ public async Task DeleteAssetUsage(AssetUsageQuery query) Query = query }).ConfigureAwait(false); } + + /// + /// Check for more information + /// + /// Check for more information + 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 8f0a7d8..17b687a 100644 --- a/Bynder/Sdk/Service/Asset/IAssetService.cs +++ b/Bynder/Sdk/Service/Asset/IAssetService.cs @@ -122,5 +122,13 @@ public interface IAssetService /// Can be thrown when requests to server can't be completed or HTTP code returned by server is an error Task DeleteAssetUsage(AssetUsageQuery 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 8b2d497..4b633c8 100644 --- a/Bynder/Test/Service/Asset/AssetServiceTest.cs +++ b/Bynder/Test/Service/Asset/AssetServiceTest.cs @@ -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>())) + .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 + ) + )); + } } } From b87e130eeed27b1e0fa580785d89aaeaeb43da66 Mon Sep 17 00:00:00 2001 From: Quirijn Date: Tue, 17 Sep 2024 19:30:21 +0200 Subject: [PATCH 4/4] v3-asset type (#99) * targetframework now net8.0, packages upgraded * updated gitignore to the toptotal standard, added launchSettings to help developers run the samples * made AssetType obsolete and read it from the PropertyOptionsDictionary instead --- Bynder/Sample/MediaSample.cs | 9 +++++++++ Bynder/Sdk/Model/Media.cs | 12 +++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Bynder/Sample/MediaSample.cs b/Bynder/Sample/MediaSample.cs index 1840902..bfd3dd3 100644 --- a/Bynder/Sample/MediaSample.cs +++ b/Bynder/Sample/MediaSample.cs @@ -50,6 +50,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: "); 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