Skip to content

Commit

Permalink
Modifying a media endpoint
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
alz-milestone authored and JoanM committed Mar 27, 2018
1 parent c30e025 commit 7865e63
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Bynder/Api/Bynder.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<Compile Include="Impl\AssetBankManager.cs" />
<Compile Include="Impl\Upload\IAmazonApi.cs" />
<Compile Include="Queries\APIField.cs" />
<Compile Include="Queries\Collections\PermissionOptions\SharingPermssion.cs" />
<Compile Include="Queries\Collections\PermissionOptions\SharingPermission.cs" />
<Compile Include="Queries\Collections\CreateCollectionQuery.cs" />
<Compile Include="Queries\Collections\GetCollectionsQuery.cs" />
<Compile Include="Queries\Collections\AddMediaQuery.cs" />
Expand All @@ -80,6 +80,7 @@
<Compile Include="Queries\Collections\ShareQuery.cs" />
<Compile Include="Queries\DownloadMediaQuery.cs" />
<Compile Include="Queries\MediaInformationQuery.cs" />
<Compile Include="Queries\ModifyMediaQuery.cs" />
<Compile Include="Settings.cs" />
<Compile Include="Converters\ITypeToStringConverter.cs" />
<Compile Include="Converters\ListConverter.cs" />
Expand Down
8 changes: 8 additions & 0 deletions Bynder/Api/IAssetBankManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,13 @@ public interface IAssetBankManager
/// <exception cref="HttpRequestException">Can be thrown when requests to server can't be completed or HTTP code returned by server is an error</exception>
/// <exception cref="BynderUploadException">Can be thrown when upload does not finish within expected time</exception>
Task UploadFileAsync(UploadQuery query);

/// <summary>
/// Modifies a media
/// </summary>
/// <param name="query">Information needed to modify a media</param>
/// <returns>Task</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 ModifyMediaAsync(ModifyMediaQuery query);
}
}
18 changes: 18 additions & 0 deletions Bynder/Api/Impl/AssetBankManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,23 @@ public Task<Media> RequestMediaInfoAsync(MediaInformationQuery query)

return _requestSender.SendRequestAsync(request);
}

/// <summary>
/// Check <see cref="IAssetBankManager"/> for more information
/// </summary>
/// <param name="query">Check <see cref="IAssetBankManager"/> for more information</param>
/// <returns>Check <see cref="IAssetBankManager"/> for more information</returns>
public Task ModifyMediaAsync(ModifyMediaQuery query)
{
var request = new Request<string>
{
Uri = $"/api/v4/media/{query.MediaId}/",
HTTPMethod = HttpMethod.Post,
Query = query,
DeserializeResponse = false
};

return _requestSender.SendRequestAsync(request);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Bynder.Api.Queries.Collections.PermissionOptions
/// <summary>
/// Enum for Permission Options for sharing a collection
/// </summary>
public enum SharingPermssion
public enum SharingPermission
{
/// <summary>
/// Allows only viewing the collection
Expand Down
4 changes: 2 additions & 2 deletions Bynder/Api/Queries/Collections/ShareQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class ShareQuery
/// <param name="collectionId">The collection to be shared</param>
/// <param name="recipients">Email addresses of the people to share the collection with</param>
/// <param name="permission">permission rights of the recipients</param>
public ShareQuery(string collectionId, IList<string> recipients, SharingPermssion permission)
public ShareQuery(string collectionId, IList<string> recipients, SharingPermission permission)
{
CollectionId = collectionId;
Recipients = recipients;
Expand All @@ -41,7 +41,7 @@ public ShareQuery(string collectionId, IList<string> recipients, SharingPermssio
/// Permission rights of the recipients
/// </summary>
[APIField("collectionOptions", Converter = typeof(LowerCaseEnumConverter))]
public SharingPermssion Permission { get; private set; }
public SharingPermission Permission { get; private set; }

/// <summary>
/// Flags if the recipients should login to view the collection
Expand Down
57 changes: 57 additions & 0 deletions Bynder/Api/Queries/ModifyMediaQuery.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using Bynder.Api.Converters;

namespace Bynder.Api.Queries
{
/// <summary>
/// Query to modify a media with
/// </summary>
public class ModifyMediaQuery
{
/// <summary>
/// Initializes the class with required information
/// </summary>
/// <param name="mediaId">The media to be modified</param>
public ModifyMediaQuery(string mediaId)
{
MediaId = mediaId;
}

/// <summary>
/// Id of the media to modify
/// </summary>
public string MediaId { get; private set; }

/// <summary>
/// Name of the media
/// </summary>
[APIField("name")]
public string Name { get; set; }

/// <summary>
/// Description of the media
/// </summary>
[APIField("description")]
public string Description { get; set; }

/// <summary>
/// Copyright information for the media
/// </summary>
[APIField("copyright")]
public string Copyright { get; set; }

/// <summary>
/// Indicates if the media is archived
/// </summary>
[APIField("archive")]
public bool Archive { get; set; }

/// <summary>
/// Indicates if the media is public
/// </summary>
[APIField("isPublic")]
public bool IsPublic { get; set; }
}
}

14 changes: 14 additions & 0 deletions Bynder/Models/Media.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Collections.Generic;
using Newtonsoft.Json;
using Bynder.Models.Converter;

namespace Bynder.Models
{
Expand Down Expand Up @@ -131,5 +132,18 @@ public class Media
/// </summary>
[JsonProperty("tags")]
public IList<string> Tags { get; set; }

/// <summary>
/// Indicates if the media item is public
/// </summary>
[JsonProperty("isPublic", ItemConverterType = typeof(BooleanJsonConverter))]
public bool IsPublic { get; set; }

/// <summary>
/// URL to Bynder CDN for the original
/// </summary>
[JsonProperty("original")]
public string Original { get; set; }

}
}
4 changes: 2 additions & 2 deletions Bynder/Test/Collections/CollectionsManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public async Task WhenShareAsyncCalledContainsExpectedResult(string id, string e
{
IList<string> recipients = emailAddresses.Split(',');

var query = new ShareQuery(id, recipients, SharingPermssion.View);
var query = new ShareQuery(id, recipients, SharingPermission.View);

IList<string> mediaList = new List<string>();
var mock = new Mock<IOauthRequestSender>();
Expand All @@ -167,7 +167,7 @@ public async Task WhenShareAsyncCalledContainsExpectedResult(string id, string e
=> reqSenderMock.SendRequestAsync(It.Is<Request<string>>(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)));
}
}
}

0 comments on commit 7865e63

Please sign in to comment.