-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API-1823 Add sample files for existing methods in the SDK and updatin…
…g README
- Loading branch information
1 parent
bf704f9
commit 4c52984
Showing
9 changed files
with
736 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.