Skip to content

Commit

Permalink
Added missing TransformBaseUrl property on Media class and implemente…
Browse files Browse the repository at this point in the history
…d Asset Usage operations. (#69)

* Added missing TransformBaseUrl property on Media class.

* Implemented Asset Usage operations

* Update Bynder/Sdk/Query/Asset/AssetUsageQuery.cs

Co-authored-by: Huib Piguillet <[email protected]>

* Update Bynder/Sdk/Query/Asset/AssetUsageQuery.cs

Co-authored-by: Huib Piguillet <[email protected]>

* Update Bynder/Sdk/Service/Asset/AssetService.cs

Co-authored-by: Huib Piguillet <[email protected]>

* Update AssetUsageQuery.cs

* Fixed, built and tested in VS

Co-authored-by: Ruud van Falier <[email protected]>
Co-authored-by: Huib Piguillet <[email protected]>
  • Loading branch information
3 people authored Dec 1, 2021
1 parent 926c5a9 commit b772d7d
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Bynder/Sdk/Api/RequestSender/ApiRequestSender.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Bynder. All rights reserved.
// Copyright (c) Bynder. All rights reserved.
// Licensed under the MIT License. See LICENSE file in the project root for full license information.

using System;
Expand Down Expand Up @@ -135,7 +135,7 @@ internal static HttpRequestMessage Create(
{
var builder = new UriBuilder(baseUrl).AppendPath(urlPath);

if (HttpMethod.Get == method)
if (HttpMethod.Get == method || HttpMethod.Delete == method)
{
builder.Query = Utils.Url.ConvertToQuery(requestParams);
}
Expand Down
8 changes: 7 additions & 1 deletion Bynder/Sdk/Model/Media.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Bynder. All rights reserved.
// Copyright (c) Bynder. All rights reserved.
// Licensed under the MIT License. See LICENSE file in the project root for full license information.

using System.Collections.Generic;
Expand Down Expand Up @@ -207,6 +207,12 @@ public class Media
[JsonProperty("original")]
public string Original { get; set; }

/// <summary>
/// Dynamic Asset Transformation base URL.
/// </summary>
[JsonProperty("transformBaseUrl")]
public string TransformBaseUrl { get; set; }

/// <summary>
/// A dictionary representation of properties
/// </summary>
Expand Down
55 changes: 55 additions & 0 deletions Bynder/Sdk/Query/Asset/AssetUsageQuery.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using Bynder.Sdk.Api.Converters;
using Bynder.Sdk.Query.Decoder;
using System;
using System.Collections.Generic;
using System.Text;

namespace Bynder.Sdk.Query.Asset
{
/// <summary>
/// Operation on the Asset Usage API.
/// </summary>
public class AssetUsageQuery
{
/// <summary>
/// Initializes the class with asset usage information.
/// </summary>
/// <param name="integrationId">ID of the integration that the usage applies to.</param>
/// <param name="assetId">ID of the asset that the usage applies to.</param>
public AssetUsageQuery(string integrationId, string assetId)
{
IntegrationId = integrationId;
AssetId = assetId;
}

/// <summary>
/// ID of the integration that the usage applies to.
/// </summary>
[ApiField("integration_id")]
public string IntegrationId { get; set; }

/// <summary>
/// ID of the asset that the usage applies to.
/// </summary>
[ApiField("asset_id")]
public string AssetId { get; set; }

/// <summary>
/// Timestamp of the operation.
/// </summary>
[ApiField("timestamp", Converter = typeof(DateTimeOffsetConverter))]
public DateTimeOffset? Timestamp { get; set; }

/// <summary>
/// Location of the asset usage.
/// </summary>
[ApiField("uri")]
public string Uri { get; set; }

/// <summary>
/// Additional information.
/// </summary>
[ApiField("additional")]
public string Additional { get; set; }
}
}
32 changes: 32 additions & 0 deletions Bynder/Sdk/Service/Asset/AssetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,5 +200,37 @@ public async Task<Status> AddTagToMediaAsync(AddTagToMediaQuery query)
Query = query,
}).ConfigureAwait(false);
}

/// <summary>
/// Create an asset usage operation to track usage of Bynder assets in third party applications.
/// </summary>
/// <param name="query">Information about the asset usage</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>
public async Task<Status> CreateAssetUsage(AssetUsageQuery query)
{
return await _requestSender.SendRequestAsync(new ApiRequest
{
Path = $"/api/media/usage/",
HTTPMethod = HttpMethod.Post,
Query = query,
}).ConfigureAwait(false);
}

/// <summary>
/// Delete an asset usage operation to track usage of Bynder assets in third party applications.
/// </summary>
/// <param name="query">Information about the asset usage</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>
public async Task<Status> DeleteAssetUsage(AssetUsageQuery query)
{
return await _requestSender.SendRequestAsync(new ApiRequest
{
Path = $"/api/media/usage/",
HTTPMethod = HttpMethod.Delete,
Query = query
}).ConfigureAwait(false);
}
}
}
17 changes: 17 additions & 0 deletions Bynder/Sdk/Service/Asset/IAssetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,22 @@ public interface IAssetService
/// <returns>Task representing the upload</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> AddTagToMediaAsync(AddTagToMediaQuery query);

/// <summary>
/// Create an asset usage operation to track usage of Bynder assets in third party applications.
/// </summary>
/// <param name="query">Information about the asset usage</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> CreateAssetUsage(AssetUsageQuery query);

/// <summary>
/// Delete an asset usage operation to track usage of Bynder assets in third party applications.
/// </summary>
/// <param name="query">Information about the asset usage</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> DeleteAssetUsage(AssetUsageQuery query);

}
}
37 changes: 37 additions & 0 deletions Bynder/Test/Service/Asset/AssetServiceTest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 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 System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
Expand Down Expand Up @@ -220,5 +221,41 @@ public async Task AddTagToMediaCallsRequestSenderWithValidRequest()
));
}

[Fact]
public async Task CreateAssetUsageCallsRequestSenderWithValidRequest()
{
var result = new Status { Message = "Accepted", StatusCode = 200 };
_apiRequestSenderMock.Setup(sender => sender.SendRequestAsync(It.IsAny<ApiRequest>()))
.ReturnsAsync(result);
var query = new AssetUsageQuery("integrationId", "assetId");
await _assetService.CreateAssetUsage(query);

_apiRequestSenderMock.Verify(sender => sender.SendRequestAsync(
It.Is<ApiRequest>(req =>
req.Path == $"/api/media/usage/"
&& req.HTTPMethod == HttpMethod.Post
&& req.Query == query
)
));
}

[Fact]
public async Task DeleteAssetUsageCallsRequestSenderWithValidRequest()
{
var result = new Status { Message = "Accepted", StatusCode = 204 };
_apiRequestSenderMock.Setup(sender => sender.SendRequestAsync(It.IsAny<ApiRequest>()))
.ReturnsAsync(result);

var query = new AssetUsageQuery("integrationId", "assetId") { Uri = "/test/test.jpg" };
await _assetService.DeleteAssetUsage(query);

_apiRequestSenderMock.Verify(sender => sender.SendRequestAsync(
It.Is<ApiRequest>(req =>
req.Path == $"/api/media/usage/"
&& req.HTTPMethod == HttpMethod.Delete
&& req.Query == query
)
));
}
}
}

0 comments on commit b772d7d

Please sign in to comment.