From 4c529840dbd08a84ec4c07be9c7638d9b55b59dd Mon Sep 17 00:00:00 2001 From: Dennis Ku Date: Tue, 12 Dec 2023 13:31:32 -0800 Subject: [PATCH] API-1823 Add sample files for existing methods in the SDK and updating README --- Bynder/Sample/ApiSample.cs | 135 ++++++++----------------- Bynder/Sample/AssetUsageSample.cs | 64 ++++++++++++ Bynder/Sample/BrandsSample.cs | 53 ++++++++++ Bynder/Sample/CollectionsSample.cs | 138 ++++++++++++++++++++++++++ Bynder/Sample/MediaSample.cs | 91 +++++++++++++++++ Bynder/Sample/MetapropertiesSample.cs | 86 ++++++++++++++++ Bynder/Sample/TagsSample.cs | 71 +++++++++++++ Bynder/Sample/UploadSample.cs | 63 ++++++++++++ README.md | 128 +++++++++++++++++++++++- 9 files changed, 736 insertions(+), 93 deletions(-) create mode 100644 Bynder/Sample/AssetUsageSample.cs create mode 100644 Bynder/Sample/BrandsSample.cs create mode 100644 Bynder/Sample/CollectionsSample.cs create mode 100644 Bynder/Sample/MediaSample.cs create mode 100644 Bynder/Sample/MetapropertiesSample.cs create mode 100644 Bynder/Sample/TagsSample.cs create mode 100644 Bynder/Sample/UploadSample.cs diff --git a/Bynder/Sample/ApiSample.cs b/Bynder/Sample/ApiSample.cs index 18d9a66..6c566c9 100644 --- a/Bynder/Sample/ApiSample.cs +++ b/Bynder/Sample/ApiSample.cs @@ -28,103 +28,56 @@ public class ApiSample /// arguments to main public static async Task Main(string[] args) { - var configuration = Configuration.FromJson("Config.json"); - var apiSample = new ApiSample(configuration); - await apiSample.AuthenticateWithOAuth2Async( - useClientCredentials: configuration.RedirectUri == null - ); - await apiSample.ListItemsAsync(); - await apiSample.UploadFileAsync("/path/to/file.ext"); - } - - private ApiSample(Configuration configuration) { - _bynderClient = ClientFactory.Create(configuration); - } - - private async Task ListItemsAsync() - { - var brands = await _bynderClient.GetAssetService().GetBrandsAsync(); - Console.WriteLine($"Brands: [{string.Join(", ", brands.Select(m => m.Name))}]"); - - var mediaList = await _bynderClient.GetAssetService().GetMediaListAsync( - new MediaQuery - { - Type = AssetType.Image, - Limit = 10, - Page = 1, - } - ); - Console.WriteLine($"Assets: [{string.Join(", ", mediaList.Select(m => m.Name))}]"); - - var collectionList = await _bynderClient.GetCollectionService().GetCollectionsAsync( - new GetCollectionsQuery - { - Limit = 10, - Page = 1, - } - ); - Console.WriteLine($"Collections: [{string.Join(", ", mediaList.Select(m => m.Name))}]"); - } - - private async Task UploadFileAsync(string uploadPath) - { - var assetService = _bynderClient.GetAssetService(); - - var brands = await assetService.GetBrandsAsync(); - if (!brands.Any()) + if (args.Length == 0) { - Console.Error.WriteLine("No brands found in this account."); + Console.WriteLine("Please enter the sample Class to run."); + Console.WriteLine("Usage: dotnet run -- BrandsSample"); return; } - await assetService.UploadFileAsync(new UploadQuery { Filepath = uploadPath, BrandId = brands.First().Id }); - - //TODO: This can be done instead when UploadFileToNewAssetAsync gets the correct response type - //var saveMediaResponse = await assetService.UploadFileToNewAssetAsync(uploadPath, brands.First().Id); - //Console.WriteLine($"Asset uploaded: {saveMediaResponse.MediaId}"); - // - //Media media = null; - //for (int iterations = 10; iterations > 0; --iterations) - //{ - // try - // { - // media = await assetService.GetMediaInfoAsync( - // new MediaInformationQuery - // { - // MediaId = saveMediaResponse.MediaId, - // } - // ); - - // } - // catch (HttpRequestException) - // { - // await Task.Delay(1000).ConfigureAwait(false); - // } - //} - //if (media == null) - //{ - // Console.Error.WriteLine("The asset could not be retrieved"); - // return; - //} - - //var saveMediaVersionResponse = await assetService.UploadFileToExistingAssetAsync(uploadPath, media.Id); - //Console.WriteLine($"New asset version uploaded: {saveMediaVersionResponse.MediaId}"); - } - - private async Task AuthenticateWithOAuth2Async(bool useClientCredentials) - { - if (useClientCredentials) - { - await _bynderClient.GetOAuthService().GetAccessTokenAsync(); + Console.WriteLine(args[0]); + // Run samples related to brands + if (args[0].Equals("BrandsSample")) { + Console.WriteLine("Running samples for brands..."); + await BrandsSample.BrandsSampleAsync(); + return; } - else - { - Browser.Launch(_bynderClient.GetOAuthService().GetAuthorisationUrl("state example")); - Console.WriteLine("Insert the code: "); - var code = Console.ReadLine(); - await _bynderClient.GetOAuthService().GetAccessTokenAsync(code); + // Run samples related to metaproperties + if (args[0].Equals("MetapropertiesSample")) { + Console.WriteLine("Running samples for metaproperties..."); + await MetapropertiesSample.MetapropertiesSampleAsync(); + return; + } + // Run samples related to media + if (args[0].Equals("MediaSample")) { + Console.WriteLine("Running samples for media..."); + await MediaSample.MediaSampleAsync(); + return; + } + // Run samples related to collections + if (args[0].Equals("CollectionsSample")) { + Console.WriteLine("Running samples for collections..."); + await CollectionsSample.CollectionsSampleAsync(); + return; + } + // Run samples related to tags + if (args[0].Equals("TagsSample")) { + Console.WriteLine("Running samples for tags..."); + await TagsSample.TagsSampleAsync(); + return; + } + // Run samples related to upload + if (args[0].Equals("UploadSample")) { + Console.WriteLine("Running samples for upload..."); + await UploadSample.UploadSampleAsync(); + return; + } + // Run samples related to asset usage + if (args[0].Equals("AssetUsageSample")) { + Console.WriteLine("Running samples for asset usage..."); + await AssetUsageSample.AssetUsageSampleAsync(); + return; } } - } } diff --git a/Bynder/Sample/AssetUsageSample.cs b/Bynder/Sample/AssetUsageSample.cs new file mode 100644 index 0000000..ea75f3f --- /dev/null +++ b/Bynder/Sample/AssetUsageSample.cs @@ -0,0 +1,64 @@ +// Copyright (c) Bynder. All rights reserved. +// Licensed under the MIT License. See LICENSE file in the project root for full license information. + +using System; +using Bynder.Sdk.Service; +using Bynder.Sample.Utils; +using Bynder.Sdk.Settings; +using System.Threading.Tasks; +using System.Linq; +using Bynder.Sdk.Query.Asset; + +namespace Bynder.Sample +{ + public class AssetUsageSample + { + private IBynderClient _bynderClient; + + public static async Task AssetUsageSampleAsync() + { + var configuration = Configuration.FromJson("Config.json"); + var apiSample = new AssetUsageSample(configuration); + await apiSample.AuthenticateWithOAuth2Async( + useClientCredentials: configuration.RedirectUri == null + ); + await apiSample.RunAssetUsageSampleAsync(); + } + + private AssetUsageSample(Configuration configuration) { + _bynderClient = ClientFactory.Create(configuration); + } + + private async Task RunAssetUsageSampleAsync() + { + Console.WriteLine("Enter the media ID to create asset usage for: "); + var createAssetUsageMediaId = Console.ReadLine(); + Console.WriteLine("Enter the integration ID to create the asset usage for: "); + var createAssetUsageIntegrationId = Console.ReadLine(); + await _bynderClient.GetAssetService().CreateAssetUsage(new AssetUsageQuery(createAssetUsageIntegrationId, createAssetUsageMediaId)); + + + Console.WriteLine("Enter the media ID to create delete usage from: "); + var deleteAssetUsageMediaId = Console.ReadLine(); + Console.WriteLine("Enter the integration ID to delete the asset usage from: "); + var deleteAssetUsageIntegrationId = Console.ReadLine(); + await _bynderClient.GetAssetService().DeleteAssetUsage(new AssetUsageQuery(deleteAssetUsageIntegrationId, deleteAssetUsageMediaId)); + } + + private async Task AuthenticateWithOAuth2Async(bool useClientCredentials) + { + if (useClientCredentials) + { + await _bynderClient.GetOAuthService().GetAccessTokenAsync(); + } + else + { + Browser.Launch(_bynderClient.GetOAuthService().GetAuthorisationUrl("state example")); + Console.WriteLine("Insert the code: "); + var code = Console.ReadLine(); + await _bynderClient.GetOAuthService().GetAccessTokenAsync(code); + } + } + + } +} diff --git a/Bynder/Sample/BrandsSample.cs b/Bynder/Sample/BrandsSample.cs new file mode 100644 index 0000000..5642f6c --- /dev/null +++ b/Bynder/Sample/BrandsSample.cs @@ -0,0 +1,53 @@ +// Copyright (c) Bynder. All rights reserved. +// Licensed under the MIT License. See LICENSE file in the project root for full license information. + +using System; +using Bynder.Sdk.Service; +using Bynder.Sample.Utils; +using Bynder.Sdk.Settings; +using System.Threading.Tasks; +using System.Linq; + +namespace Bynder.Sample +{ + public class BrandsSample + { + private IBynderClient _bynderClient; + + public static async Task BrandsSampleAsync() + { + var configuration = Configuration.FromJson("Config.json"); + var apiSample = new BrandsSample(configuration); + await apiSample.AuthenticateWithOAuth2Async( + useClientCredentials: configuration.RedirectUri == null + ); + await apiSample.RunBrandsSampleAsync(); + } + + private BrandsSample(Configuration configuration) { + _bynderClient = ClientFactory.Create(configuration); + } + + private async Task RunBrandsSampleAsync() + { + var brands = await _bynderClient.GetAssetService().GetBrandsAsync(); + Console.WriteLine($"Brands: [{string.Join(", ", brands.Select(m => m.Name))}]"); + } + + private async Task AuthenticateWithOAuth2Async(bool useClientCredentials) + { + if (useClientCredentials) + { + await _bynderClient.GetOAuthService().GetAccessTokenAsync(); + } + else + { + Browser.Launch(_bynderClient.GetOAuthService().GetAuthorisationUrl("state example")); + Console.WriteLine("Insert the code: "); + var code = Console.ReadLine(); + await _bynderClient.GetOAuthService().GetAccessTokenAsync(code); + } + } + + } +} diff --git a/Bynder/Sample/CollectionsSample.cs b/Bynder/Sample/CollectionsSample.cs new file mode 100644 index 0000000..01bc273 --- /dev/null +++ b/Bynder/Sample/CollectionsSample.cs @@ -0,0 +1,138 @@ +// Copyright (c) Bynder. All rights reserved. +// Licensed under the MIT License. See LICENSE file in the project root for full license information. + +using System; +using Bynder.Sdk.Service; +using Bynder.Sample.Utils; +using Bynder.Sdk.Settings; +using System.Threading.Tasks; +using System.Linq; +using System.Collections.Generic; +using Bynder.Sdk.Query.Collection; +using Bynder.Sdk.Model; + +namespace Bynder.Sample +{ + public class CollectionsSample + { + private IBynderClient _bynderClient; + + public static async Task CollectionsSampleAsync() + { + var configuration = Configuration.FromJson("Config.json"); + var apiSample = new CollectionsSample(configuration); + await apiSample.AuthenticateWithOAuth2Async( + useClientCredentials: configuration.RedirectUri == null + ); + await apiSample.RunCollectionsSampleAsync(); + } + + private CollectionsSample(Configuration configuration) { + _bynderClient = ClientFactory.Create(configuration); + } + + private async Task RunCollectionsSampleAsync() + { + // Get collections with a limit of 10 + Console.WriteLine("Getting collections with a limit of 10: "); + var collections = await _bynderClient.GetCollectionService().GetCollectionsAsync(new GetCollectionsQuery{ + Limit = 10 + }); + foreach(Collection collection in collections) { + Console.WriteLine($"ID: {collection.Id}"); + Console.WriteLine($"Name: {collection.Name}"); + Console.WriteLine($"Media Count: {collection.MediaCount}"); + } + + // Get one collection by ID + Console.WriteLine("Enter the collection ID to get the collection info for: "); + var getCollectionId = Console.ReadLine(); + var collectionInfo = await _bynderClient.GetCollectionService().GetCollectionAsync(getCollectionId.Trim()); + Console.WriteLine($"ID: {collectionInfo.Id}"); + Console.WriteLine($"Name: {collectionInfo.Name}"); + Console.WriteLine($"Media Count: {collectionInfo.MediaCount}"); + + // Create a collection + Console.WriteLine("Enter the name for the collection to be created: "); + var createCollectionName = Console.ReadLine(); + await _bynderClient.GetCollectionService().CreateCollectionAsync(new CreateCollectionQuery(createCollectionName.Trim())); + collections = await _bynderClient.GetCollectionService().GetCollectionsAsync(new GetCollectionsQuery{ + Limit = 10 + }); + foreach(Collection collection in collections) { + Console.WriteLine($"ID: {collection.Id}"); + Console.WriteLine($"Name: {collection.Name}"); + Console.WriteLine($"Media Count: {collection.MediaCount}"); + } + + // Share a collection + Console.WriteLine("Enter the collection ID to share: "); + var shareCollectionId = Console.ReadLine(); + Console.WriteLine("Enter the email recipient to share the collection to: "); + var recipient = Console.ReadLine(); + List recipients = new List + { + recipient + }; + var shareQuery = new ShareQuery(shareCollectionId.Trim(),recipients, SharingPermission.View){ + LoginRequired = false, + Message = "test", + SendMail = true + }; + await _bynderClient.GetCollectionService().ShareCollectionAsync(shareQuery); + + // Delete a collection + Console.WriteLine("Enter the ID for the collection to be deleted: "); + var deleteCollectionId = Console.ReadLine(); + await _bynderClient.GetCollectionService().DeleteCollectionAsync(deleteCollectionId.Trim()); + + // Add media to collection + Console.WriteLine("Enter the collection ID to add a media to: "); + var collectionIdAddMedia = Console.ReadLine(); + Console.WriteLine("Enter the media ID to add to the collection: "); + var collectionIdAddMediaId = Console.ReadLine(); + + List mediaAdd = new List + { + collectionIdAddMediaId.Trim() + }; + await _bynderClient.GetCollectionService().AddMediaAsync(new AddMediaQuery(collectionIdAddMedia.Trim(), mediaAdd)); + + // Get media IDs from collection ID + Console.WriteLine("Enter the collection ID to get a medias from: "); + var collectionIdGetMedia = Console.ReadLine(); + var collectionMedia = await _bynderClient.GetCollectionService().GetMediaAsync(new GetMediaQuery(collectionIdGetMedia.Trim())); + foreach(string media in collectionMedia) { + Console.WriteLine($"Collection Media: {media}"); + } + + // Remove media from collection + Console.WriteLine("Enter the collection ID to remove a media from: "); + var collectionIdRemoveMedia = Console.ReadLine(); + Console.WriteLine("Enter the media ID to remove from the collection: "); + var collectionIdRemoveMediaId = Console.ReadLine(); + + List mediaRemove = new List + { + collectionIdRemoveMediaId.Trim() + }; + await _bynderClient.GetCollectionService().RemoveMediaAsync(new RemoveMediaQuery(collectionIdRemoveMedia.Trim(), mediaRemove)); + } + + private async Task AuthenticateWithOAuth2Async(bool useClientCredentials) + { + if (useClientCredentials) + { + await _bynderClient.GetOAuthService().GetAccessTokenAsync(); + } + else + { + Browser.Launch(_bynderClient.GetOAuthService().GetAuthorisationUrl("state example")); + Console.WriteLine("Insert the code: "); + var code = Console.ReadLine(); + await _bynderClient.GetOAuthService().GetAccessTokenAsync(code); + } + } + + } +} diff --git a/Bynder/Sample/MediaSample.cs b/Bynder/Sample/MediaSample.cs new file mode 100644 index 0000000..501d496 --- /dev/null +++ b/Bynder/Sample/MediaSample.cs @@ -0,0 +1,91 @@ +// Copyright (c) Bynder. All rights reserved. +// Licensed under the MIT License. See LICENSE file in the project root for full license information. + +using System; +using Bynder.Sdk.Service; +using Bynder.Sample.Utils; +using Bynder.Sdk.Settings; +using System.Threading.Tasks; +using System.Linq; +using Bynder.Sdk.Query.Asset; +using Bynder.Sdk.Model; + +namespace Bynder.Sample +{ + public class MediaSample + { + private IBynderClient _bynderClient; + + public static async Task MediaSampleAsync() + { + var configuration = Configuration.FromJson("Config.json"); + var apiSample = new MediaSample(configuration); + await apiSample.AuthenticateWithOAuth2Async( + useClientCredentials: configuration.RedirectUri == null + ); + await apiSample.RunMediaSampleAsync(); + } + + private MediaSample(Configuration configuration) { + _bynderClient = ClientFactory.Create(configuration); + } + + private async Task RunMediaSampleAsync() + { + // Get a list of media with limit 10 + Console.WriteLine("Listing media with limit of 10: "); + var mediaList = await _bynderClient.GetAssetService().GetMediaListAsync(new MediaQuery{Limit=10}); + foreach(Media media in mediaList) { + Console.WriteLine($"Media ID: {media.Id}"); + Console.WriteLine($"Media Name: {media.Name}"); + } + + // Get the media info + Console.WriteLine("Enter the media ID to get the media info for: "); + var mediaIdForInfo = Console.ReadLine(); + var mediaInformationQuery = new MediaInformationQuery{ + MediaId = mediaIdForInfo.Trim() + }; + var mediaInfo = await _bynderClient.GetAssetService().GetMediaInfoAsync(mediaInformationQuery); + Console.WriteLine($"ID: {mediaInfo.Id}"); + Console.WriteLine($"Name: {mediaInfo.Name}"); + Console.WriteLine($"Brand Id: {mediaInfo.BrandId}"); + + // Get the media download URL + Console.WriteLine("Enter the media ID to get the media download URL for: "); + var mediaIdForDownloadUrl = Console.ReadLine(); + var downloadMediaQuery = new DownloadMediaQuery{ + MediaId = mediaIdForDownloadUrl.Trim() + }; + var download = await _bynderClient.GetAssetService().GetDownloadFileUrlAsync(downloadMediaQuery); + Console.WriteLine($"Media Download URL: {download}"); + + + // Modify a media with a new description + Console.WriteLine("Enter the media ID to modify: "); + var mediaIdForModify = Console.ReadLine(); + Console.WriteLine("Enter new description to modify for the media: "); + var updatedDescription = Console.ReadLine(); + var modifyMediaQuery = new ModifyMediaQuery(mediaIdForModify){ + Description = updatedDescription + }; + await _bynderClient.GetAssetService().ModifyMediaAsync(modifyMediaQuery); + } + + private async Task AuthenticateWithOAuth2Async(bool useClientCredentials) + { + if (useClientCredentials) + { + await _bynderClient.GetOAuthService().GetAccessTokenAsync(); + } + else + { + Browser.Launch(_bynderClient.GetOAuthService().GetAuthorisationUrl("state example")); + Console.WriteLine("Insert the code: "); + var code = Console.ReadLine(); + await _bynderClient.GetOAuthService().GetAccessTokenAsync(code); + } + } + + } +} diff --git a/Bynder/Sample/MetapropertiesSample.cs b/Bynder/Sample/MetapropertiesSample.cs new file mode 100644 index 0000000..724856f --- /dev/null +++ b/Bynder/Sample/MetapropertiesSample.cs @@ -0,0 +1,86 @@ +// Copyright (c) Bynder. All rights reserved. +// Licensed under the MIT License. See LICENSE file in the project root for full license information. + +using System; +using Bynder.Sdk.Service; +using Bynder.Sample.Utils; +using Bynder.Sdk.Settings; +using System.Threading.Tasks; +using System.Linq; +using Bynder.Sdk.Model; +using System.Collections.Generic; +using Bynder.Sdk.Query.Asset; + +namespace Bynder.Sample +{ + public class MetapropertiesSample + { + private IBynderClient _bynderClient; + + public static async Task MetapropertiesSampleAsync() + { + var configuration = Configuration.FromJson("Config.json"); + var apiSample = new MetapropertiesSample(configuration); + await apiSample.AuthenticateWithOAuth2Async( + useClientCredentials: configuration.RedirectUri == null + ); + await apiSample.RunMetapropertiesSampleAsync(); + } + + private MetapropertiesSample(Configuration configuration) { + _bynderClient = ClientFactory.Create(configuration); + } + + private async Task RunMetapropertiesSampleAsync() + { + // Sample to list metaproperties + var metapropertiesList = await _bynderClient.GetAssetService().GetMetapropertiesAsync(); + foreach (KeyValuePair metaproperty in metapropertiesList) { + Console.WriteLine($"ID: {metaproperty.Value.Id}"); + Console.WriteLine($"Name: {metaproperty.Value.Name}"); + Console.WriteLine($"Label: {metaproperty.Value.Label}"); + if(metaproperty.Value.Options.Count > 0) { + Console.WriteLine("Metaproperty Options:"); + foreach (MetapropertyOption option in metaproperty.Value.Options) + { + Console.WriteLine($" ID: {option.Id}"); + Console.WriteLine($" Name: {option.Name}"); + Console.WriteLine($" Label: {option.Label}"); + Console.WriteLine(" "); + } + } + Console.WriteLine(" "); + } + + // Get metaproperty by ID + Console.WriteLine("Enter the metaproperty ID to get info for: "); + var metapropertyIdGetInfo = Console.ReadLine(); + var metapropertyInfo = await _bynderClient.GetAssetService().GetMetapropertyAsync(new MetapropertyQuery(metapropertyIdGetInfo.Trim())); + Console.WriteLine($"ID: {metapropertyInfo.Id}"); + Console.WriteLine($"Name: {metapropertyInfo.Name}"); + Console.WriteLine($"Label: {metapropertyInfo.Label}"); + + // Get metaproperty dependencies by metaproperty ID + Console.WriteLine("Enter the metaproperty ID to get dependencies for: "); + var metapropertyIdGetDependencies = Console.ReadLine(); + var metapropertyDependencies = await _bynderClient.GetAssetService().GetMetapropertyDependenciesAsync(new MetapropertyQuery(metapropertyIdGetDependencies.Trim())); + Console.WriteLine($"Metaproperty Dependencies: [{string.Join(", ", metapropertyDependencies)}]"); + } + + private async Task AuthenticateWithOAuth2Async(bool useClientCredentials) + { + if (useClientCredentials) + { + await _bynderClient.GetOAuthService().GetAccessTokenAsync(); + } + else + { + Browser.Launch(_bynderClient.GetOAuthService().GetAuthorisationUrl("state example")); + Console.WriteLine("Insert the code: "); + var code = Console.ReadLine(); + await _bynderClient.GetOAuthService().GetAccessTokenAsync(code); + } + } + + } +} diff --git a/Bynder/Sample/TagsSample.cs b/Bynder/Sample/TagsSample.cs new file mode 100644 index 0000000..e64cbba --- /dev/null +++ b/Bynder/Sample/TagsSample.cs @@ -0,0 +1,71 @@ +// Copyright (c) Bynder. All rights reserved. +// Licensed under the MIT License. See LICENSE file in the project root for full license information. + +using System; +using Bynder.Sdk.Service; +using Bynder.Sample.Utils; +using Bynder.Sdk.Settings; +using System.Threading.Tasks; +using System.Linq; +using System.Collections.Generic; +using Bynder.Sdk.Query.Asset; +using Bynder.Sdk.Model; + +namespace Bynder.Sample +{ + public class TagsSample + { + private IBynderClient _bynderClient; + + public static async Task TagsSampleAsync() + { + var configuration = Configuration.FromJson("Config.json"); + var apiSample = new TagsSample(configuration); + await apiSample.AuthenticateWithOAuth2Async( + useClientCredentials: configuration.RedirectUri == null + ); + await apiSample.RunTagsSampleAsync(); + } + + private TagsSample(Configuration configuration) { + _bynderClient = ClientFactory.Create(configuration); + } + + private async Task RunTagsSampleAsync() + { + Console.WriteLine("Getting tags with a limit of 10: "); + var tags = await _bynderClient.GetAssetService().GetTagsAsync(new GetTagsQuery{Limit = 10}); + foreach(Tag tag in tags){ + Console.WriteLine($"Tag Id: {tag.ID}"); + Console.WriteLine($"Tag Name: {tag.TagName}"); + Console.WriteLine($"Tag MediaCount: {tag.MediaCount}"); + } + + Console.WriteLine("Enter the media ID to add a tag to: "); + var mediaIdAddTag = Console.ReadLine(); + Console.WriteLine("Enter the tag ID to add to the media: "); + var tagIdAddToMedia = Console.ReadLine(); + List mediasAddTag = new List + { + mediaIdAddTag + }; + await _bynderClient.GetAssetService().AddTagToMediaAsync(new AddTagToMediaQuery(tagIdAddToMedia, mediasAddTag)); + } + + private async Task AuthenticateWithOAuth2Async(bool useClientCredentials) + { + if (useClientCredentials) + { + await _bynderClient.GetOAuthService().GetAccessTokenAsync(); + } + else + { + Browser.Launch(_bynderClient.GetOAuthService().GetAuthorisationUrl("state example")); + Console.WriteLine("Insert the code: "); + var code = Console.ReadLine(); + await _bynderClient.GetOAuthService().GetAccessTokenAsync(code); + } + } + + } +} diff --git a/Bynder/Sample/UploadSample.cs b/Bynder/Sample/UploadSample.cs new file mode 100644 index 0000000..826279f --- /dev/null +++ b/Bynder/Sample/UploadSample.cs @@ -0,0 +1,63 @@ +// Copyright (c) Bynder. All rights reserved. +// Licensed under the MIT License. See LICENSE file in the project root for full license information. + +using System; +using Bynder.Sdk.Service; +using Bynder.Sample.Utils; +using Bynder.Sdk.Settings; +using System.Threading.Tasks; +using System.Linq; +using Bynder.Sdk.Query.Upload; +namespace Bynder.Sample +{ + public class UploadSample + { + private IBynderClient _bynderClient; + + public static async Task UploadSampleAsync() + { + var configuration = Configuration.FromJson("Config.json"); + var apiSample = new UploadSample(configuration); + await apiSample.AuthenticateWithOAuth2Async( + useClientCredentials: configuration.RedirectUri == null + ); + await apiSample.RunUploadSampleAsync(); + } + + private UploadSample(Configuration configuration) { + _bynderClient = ClientFactory.Create(configuration); + } + + private async Task RunUploadSampleAsync() + { + Console.WriteLine("Enter the path of the file to upload: "); + var uploadPath = Console.ReadLine(); + var assetService = _bynderClient.GetAssetService(); + + var brands = await assetService.GetBrandsAsync(); + if (!brands.Any()) + { + Console.Error.WriteLine("No brands found in this account."); + return; + } + + await assetService.UploadFileAsync(new UploadQuery { Filepath = uploadPath, BrandId = brands.First().Id }); + } + + private async Task AuthenticateWithOAuth2Async(bool useClientCredentials) + { + if (useClientCredentials) + { + await _bynderClient.GetOAuthService().GetAccessTokenAsync(); + } + else + { + Browser.Launch(_bynderClient.GetOAuthService().GetAuthorisationUrl("state example")); + Console.WriteLine("Insert the code: "); + var code = Console.ReadLine(); + await _bynderClient.GetOAuthService().GetAccessTokenAsync(code); + } + } + + } +} diff --git a/README.md b/README.md index 8dee6ee..9541efa 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,130 @@ Task RemoveMediaAsync(RemoveMediaQuery query); Task ShareCollectionAsync(ShareQuery query); ``` -## Sample +### Sample Files Functionality Testing -To see how to use the SDK, please check [ApiSample.cs](Bynder/Sample/ApiSample.cs) +Classes within `Sample` contain code to execute corresponding functionalities. The purpose is to demonstrate how methods +are called and provide a convenient method to execute functions. + +Executing the code in each file will prompt you in the terminal to enter in various IDs (media, collection, brand, tag, etc) to pass into each of the functions being run. + +Within `Bynder/Sample` create an `Config.json` file or modify with the correct values. This file will be referenced from sample files. Depending on the sample file, you will need to have the correct scopes granted. + +Example `Config.json` file content: + +```json +{ + "base_url": "https://example.bynder.com", + "client_id": "your oauth app client id", + "client_secret": "your oauth app client secret", + "redirect_uri": "your oauth app redirect uri", + "scopes": "offline asset:read asset:write collection:read collection:write asset.usage:read asset.usage:write meta.assetbank:read meta.assetbank:write meta.workflow:read" +} +``` +Within each sample file, OAuth credentials are read in from `Config.json`. +This will prompt the browser to open to retrieve an access code and then redirected to the redirect URI. +Access code is then provided to terminal prompt to retrieve an access token for API calls afterward. + + +#### Setting up .NET (dotnet) and building the project + +Make sure you have .NET 5.0 set up and installed. If you are developing on a Mac OS, the fastest method is to download the C# Dev Kit in Visual Studio Code and download .NET 5.0 from https://dotnet.microsoft.com/en-us/download/dotnet/5.0. + +From `Bynder/Sample` directory, the project can be built using command from `Bynder.Sample.csproj`: +```bash +dotnet build +``` + + +#### Brands Sample + +Execute `BrandsSample.cs` file with command + +```bash +dotnet run -- BrandsSample +``` + +Methods Used: +* GetBrandsAsync() + + +#### Collections Sample + +Execute `CollectionsSample.cs` file with command + +```bash +dotnet run -- CollectionsSample +``` + +Methods Used: +* GetCollectionsAsync(GetCollectionsQuery) +* GetCollectionAsync(collectionId) +* CreateCollectionAsync(CreateCollectionQuery) +* ShareCollectionAsync(ShareQuery) +* DeleteCollectionAsync(collectionId) +* AddMediaAsync(AddMediaQuery) +* GetMediaAsync(GetMediaQuery) +* RemoveMediaAsync(RemoveMediaQuery) + + +#### Media Sample + +Execute `MediaSample.cs` file with comman + +```bash +dotnet run -- MediaSample +``` + +Methods Used: + +* GetMediaListAsync(MediaQuery) +* GetMediaInfoAsync(MediaInformationQuery) +* GetDownloadFileUrlAsync(DownloadMediaQuery) +* ModifyMediaAsync(ModifyMediaQuery) + +#### Metaproperties Sample + +Execute `MetapropertiesSample.cs` file with comman + +```bash +dotnet run -- MetapropertiesSample +``` + +Methods Used: +* GetMetapropertiesAsync() +* GetMetapropertyAsync(MetapropertyQuery) +* GetMetapropertyDependenciesAsync(GetMetapropertyDependenciesAsync) + +#### Tags Sample + +Execute `TagsSample.cs` file with comman + +```bash +dotnet run -- TagsSample +``` + +Methods Used: +* GetTagsAsync(GetTagsQuery) +* AddTagToMediaAsync(AddTagToMediaQuery) + +#### Upload Sample + +Execute `UploadSample.cs` file with comman + +```bash +dotnet run -- UploadSample +``` + +Methods Used: +* UploadFileAsync(UploadQuery) + +#### Asset Usage Sample + +Execute `AssetUsage.cs` file with comman + +```bash +dotnet run -- AssetUsage +``` +Methods Used: +* CreateAssetUsage(AssetUsageQuery) +* DeleteAssetUsage(AssetUsageQuery)