From 7865e63fac8eff51f98cacd0596f2f382c490585 Mon Sep 17 00:00:00 2001
From: alz-milestone <37327644+alz-milestone@users.noreply.github.com>
Date: Tue, 27 Mar 2018 13:00:52 +0300
Subject: [PATCH] Modifying a media endpoint
* Fixed a typo in SharingPermission.
* Added a method for modifying a media in AssetBankManager.
* Specified an ItemConverterType for the IsPublic property on the Media model.
---
Bynder/Api/Bynder.Api.csproj | 3 +-
Bynder/Api/IAssetBankManager.cs | 8 +++
Bynder/Api/Impl/AssetBankManager.cs | 18 ++++++
...aringPermssion.cs => SharingPermission.cs} | 2 +-
Bynder/Api/Queries/Collections/ShareQuery.cs | 4 +-
Bynder/Api/Queries/ModifyMediaQuery.cs | 57 +++++++++++++++++++
Bynder/Models/Media.cs | 14 +++++
.../Collections/CollectionsManagerTest.cs | 4 +-
8 files changed, 104 insertions(+), 6 deletions(-)
rename Bynder/Api/Queries/Collections/PermissionOptions/{SharingPermssion.cs => SharingPermission.cs} (93%)
create mode 100644 Bynder/Api/Queries/ModifyMediaQuery.cs
diff --git a/Bynder/Api/Bynder.Api.csproj b/Bynder/Api/Bynder.Api.csproj
index 0da93cd..4ced9dd 100644
--- a/Bynder/Api/Bynder.Api.csproj
+++ b/Bynder/Api/Bynder.Api.csproj
@@ -71,7 +71,7 @@
-
+
@@ -80,6 +80,7 @@
+
diff --git a/Bynder/Api/IAssetBankManager.cs b/Bynder/Api/IAssetBankManager.cs
index f14b5d9..c14e567 100644
--- a/Bynder/Api/IAssetBankManager.cs
+++ b/Bynder/Api/IAssetBankManager.cs
@@ -63,5 +63,13 @@ public interface IAssetBankManager
/// Can be thrown when requests to server can't be completed or HTTP code returned by server is an error
/// Can be thrown when upload does not finish within expected time
Task UploadFileAsync(UploadQuery query);
+
+ ///
+ /// Modifies a media
+ ///
+ /// Information needed to modify a media
+ /// Task
+ /// Can be thrown when requests to server can't be completed or HTTP code returned by server is an error
+ Task ModifyMediaAsync(ModifyMediaQuery query);
}
}
diff --git a/Bynder/Api/Impl/AssetBankManager.cs b/Bynder/Api/Impl/AssetBankManager.cs
index f1d9f83..35427e3 100644
--- a/Bynder/Api/Impl/AssetBankManager.cs
+++ b/Bynder/Api/Impl/AssetBankManager.cs
@@ -137,5 +137,23 @@ public Task RequestMediaInfoAsync(MediaInformationQuery query)
return _requestSender.SendRequestAsync(request);
}
+
+ ///
+ /// Check for more information
+ ///
+ /// Check for more information
+ /// Check for more information
+ public Task ModifyMediaAsync(ModifyMediaQuery query)
+ {
+ var request = new Request
+ {
+ Uri = $"/api/v4/media/{query.MediaId}/",
+ HTTPMethod = HttpMethod.Post,
+ Query = query,
+ DeserializeResponse = false
+ };
+
+ return _requestSender.SendRequestAsync(request);
+ }
}
}
diff --git a/Bynder/Api/Queries/Collections/PermissionOptions/SharingPermssion.cs b/Bynder/Api/Queries/Collections/PermissionOptions/SharingPermission.cs
similarity index 93%
rename from Bynder/Api/Queries/Collections/PermissionOptions/SharingPermssion.cs
rename to Bynder/Api/Queries/Collections/PermissionOptions/SharingPermission.cs
index 61cb33c..dd8c0df 100644
--- a/Bynder/Api/Queries/Collections/PermissionOptions/SharingPermssion.cs
+++ b/Bynder/Api/Queries/Collections/PermissionOptions/SharingPermission.cs
@@ -6,7 +6,7 @@ namespace Bynder.Api.Queries.Collections.PermissionOptions
///
/// Enum for Permission Options for sharing a collection
///
- public enum SharingPermssion
+ public enum SharingPermission
{
///
/// Allows only viewing the collection
diff --git a/Bynder/Api/Queries/Collections/ShareQuery.cs b/Bynder/Api/Queries/Collections/ShareQuery.cs
index f004e58..081712c 100644
--- a/Bynder/Api/Queries/Collections/ShareQuery.cs
+++ b/Bynder/Api/Queries/Collections/ShareQuery.cs
@@ -19,7 +19,7 @@ public class ShareQuery
/// The collection to be shared
/// Email addresses of the people to share the collection with
/// permission rights of the recipients
- public ShareQuery(string collectionId, IList recipients, SharingPermssion permission)
+ public ShareQuery(string collectionId, IList recipients, SharingPermission permission)
{
CollectionId = collectionId;
Recipients = recipients;
@@ -41,7 +41,7 @@ public ShareQuery(string collectionId, IList recipients, SharingPermssio
/// Permission rights of the recipients
///
[APIField("collectionOptions", Converter = typeof(LowerCaseEnumConverter))]
- public SharingPermssion Permission { get; private set; }
+ public SharingPermission Permission { get; private set; }
///
/// Flags if the recipients should login to view the collection
diff --git a/Bynder/Api/Queries/ModifyMediaQuery.cs b/Bynder/Api/Queries/ModifyMediaQuery.cs
new file mode 100644
index 0000000..6932775
--- /dev/null
+++ b/Bynder/Api/Queries/ModifyMediaQuery.cs
@@ -0,0 +1,57 @@
+using System;
+using System.Collections.Generic;
+using Bynder.Api.Converters;
+
+namespace Bynder.Api.Queries
+{
+ ///
+ /// Query to modify a media with
+ ///
+ public class ModifyMediaQuery
+ {
+ ///
+ /// Initializes the class with required information
+ ///
+ /// The media to be modified
+ public ModifyMediaQuery(string mediaId)
+ {
+ MediaId = mediaId;
+ }
+
+ ///
+ /// Id of the media to modify
+ ///
+ public string MediaId { get; private set; }
+
+ ///
+ /// Name of the media
+ ///
+ [APIField("name")]
+ public string Name { get; set; }
+
+ ///
+ /// Description of the media
+ ///
+ [APIField("description")]
+ public string Description { get; set; }
+
+ ///
+ /// Copyright information for the media
+ ///
+ [APIField("copyright")]
+ public string Copyright { get; set; }
+
+ ///
+ /// Indicates if the media is archived
+ ///
+ [APIField("archive")]
+ public bool Archive { get; set; }
+
+ ///
+ /// Indicates if the media is public
+ ///
+ [APIField("isPublic")]
+ public bool IsPublic { get; set; }
+ }
+}
+
diff --git a/Bynder/Models/Media.cs b/Bynder/Models/Media.cs
index f2116a2..8295a06 100644
--- a/Bynder/Models/Media.cs
+++ b/Bynder/Models/Media.cs
@@ -3,6 +3,7 @@
using System.Collections.Generic;
using Newtonsoft.Json;
+using Bynder.Models.Converter;
namespace Bynder.Models
{
@@ -131,5 +132,18 @@ public class Media
///
[JsonProperty("tags")]
public IList Tags { get; set; }
+
+ ///
+ /// Indicates if the media item is public
+ ///
+ [JsonProperty("isPublic", ItemConverterType = typeof(BooleanJsonConverter))]
+ public bool IsPublic { get; set; }
+
+ ///
+ /// URL to Bynder CDN for the original
+ ///
+ [JsonProperty("original")]
+ public string Original { get; set; }
+
}
}
diff --git a/Bynder/Test/Collections/CollectionsManagerTest.cs b/Bynder/Test/Collections/CollectionsManagerTest.cs
index 6110e47..7c74847 100644
--- a/Bynder/Test/Collections/CollectionsManagerTest.cs
+++ b/Bynder/Test/Collections/CollectionsManagerTest.cs
@@ -154,7 +154,7 @@ public async Task WhenShareAsyncCalledContainsExpectedResult(string id, string e
{
IList recipients = emailAddresses.Split(',');
- var query = new ShareQuery(id, recipients, SharingPermssion.View);
+ var query = new ShareQuery(id, recipients, SharingPermission.View);
IList mediaList = new List();
var mock = new Mock();
@@ -167,7 +167,7 @@ public async Task WhenShareAsyncCalledContainsExpectedResult(string id, string e
=> reqSenderMock.SendRequestAsync(It.Is>(req => req.Uri == $"/api/v4/collections/{id}/share/"
&& req.HTTPMethod == HttpMethod.Post
&& ((ShareQuery)req.Query).Recipients.Count == recipients.Count
- && ((ShareQuery)req.Query).Permission == SharingPermssion.View)));
+ && ((ShareQuery)req.Query).Permission == SharingPermission.View)));
}
}
}