Skip to content

Commit

Permalink
Merge pull request #97 from RobMalvern/master
Browse files Browse the repository at this point in the history
WIP for filtering
  • Loading branch information
mfilippov authored Sep 24, 2017
2 parents 1a1ff1f + eaaedbd commit e483dc2
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 57 deletions.
53 changes: 53 additions & 0 deletions src/VimeoDotNet.Tests/VimeoClientAsyncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,17 @@ public async Task Integration_VimeoClient_GetAccountVideo_RetrievesVideo()
video.pictures.uri.ShouldNotBeNull();
}

[Fact]
public async Task Integration_VimeoClient_GetAccountVideoWithFields_RetrievesVideo()
{
var client = CreateAuthenticatedClient();
var video = await client.GetVideoAsync(_vimeoSettings.VideoId, new []{"uri", "name"});
video.ShouldNotBeNull();
video.uri.ShouldNotBeNull();
video.name.ShouldNotBeNull();
video.pictures.ShouldBeNull();
}

[Fact]
public async Task Integration_VimeoClient_GetAccountAlbumVideos_RetrievesCurrentAccountAlbumVideos()
{
Expand All @@ -333,6 +344,15 @@ public async Task Integration_VimeoClient_GetAccountAlbumVideos_RetrievesCurrent
videos.data.Count.ShouldBeGreaterThan(0);
}

[Fact]
public async Task Integration_VimeoClient_GetAccountAlbumVideosWithFields_RetrievesCurrentAccountAlbumVideos()
{
var client = CreateAuthenticatedClient();
var videos = await client.GetAlbumVideosAsync(_vimeoSettings.AlbumId, 1, null, fields: new[] { "uri", "name" });
videos.ShouldNotBeNull();
videos.data.Count.ShouldBeGreaterThan(0);
}

[Fact]
public async Task Integration_VimeoClient_GetAccountAlbumVideo_RetrievesVideo()
{
Expand All @@ -341,6 +361,14 @@ public async Task Integration_VimeoClient_GetAccountAlbumVideo_RetrievesVideo()
video.ShouldNotBeNull();
}

[Fact]
public async Task Integration_VimeoClient_GetAccountAlbumVideoWithFields_RetrievesVideo()
{
var client = CreateAuthenticatedClient();
var video = await client.GetAlbumVideoAsync(_vimeoSettings.AlbumId, _vimeoSettings.VideoId, new[] { "uri", "name" });
video.ShouldNotBeNull();
}

[Fact]
public async Task Integration_VimeoClient_GetUserAlbumVideos_RetrievesUserAlbumVideos()
{
Expand All @@ -350,6 +378,15 @@ public async Task Integration_VimeoClient_GetUserAlbumVideos_RetrievesUserAlbumV
videos.data.Count.ShouldBeGreaterThan(0);
}

[Fact]
public async Task Integration_VimeoClient_GetUserAlbumVideosWithFields_RetrievesUserAlbumVideos()
{
var client = CreateAuthenticatedClient();
var videos = await client.GetUserAlbumVideosAsync(_vimeoSettings.UserId, _vimeoSettings.AlbumId, new []{"name", "link"});
videos.ShouldNotBeNull();
videos.data.Count.ShouldBeGreaterThan(0);
}

[Fact]
public async Task Integration_VimeoClient_GetUserAlbumVideo_RetrievesVideo()
{
Expand All @@ -358,6 +395,14 @@ public async Task Integration_VimeoClient_GetUserAlbumVideo_RetrievesVideo()
video.ShouldNotBeNull();
}

[Fact]
public async Task Integration_VimeoClient_GetUserAlbumVideoWithFields_RetrievesVideo()
{
var client = CreateAuthenticatedClient();
var video = await client.GetUserAlbumVideoAsync(_vimeoSettings.UserId, _vimeoSettings.AlbumId, _vimeoSettings.VideoId, new []{"uri", "name"});
video.ShouldNotBeNull();
}

[Fact]
public async Task Integration_VimeoClient_GetAccountAlbums_NotNull()
{
Expand All @@ -366,6 +411,14 @@ public async Task Integration_VimeoClient_GetAccountAlbums_NotNull()
albums.ShouldNotBeNull();
}

[Fact]
public async Task Integration_VimeoClientWithFields_GetAccountAlbums_NotNull()
{
var client = CreateAuthenticatedClient();
var albums = await client.GetAlbumsAsync(fields: new []{"name"});
albums.ShouldNotBeNull();
}

[Fact]
public async Task Integration_VimeoClient_AlbumVideoManagement()
{
Expand Down
55 changes: 36 additions & 19 deletions src/VimeoDotNet/IVimeoClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,17 @@ public interface IVimeoClient
/// Get video by ClipId
/// </summary>
/// <param name="clipId">ClipId</param>
/// <param name="fields"></param>
/// <returns>Video</returns>
Video GetVideo(long clipId);
Video GetVideo(long clipId, string[] fields = null);

/// <summary>
/// Get video by ClipId asynchronously
/// </summary>
/// <param name="clipId">ClipId</param>
/// <param name="fields"></param>
/// <returns>Video</returns>
Task<Video> GetVideoAsync(long clipId);
Task<Video> GetVideoAsync(long clipId, string[] fields = null);


// ...for current account
Expand All @@ -81,13 +83,13 @@ public interface IVimeoClient
/// Get paginated video for current account
/// </summary>
/// <returns>Paginated videos</returns>
Paginated<Video> GetVideos();
Paginated<Video> GetVideos(string[] fields = null);

/// <summary>
/// Get paginated video for current account asynchronously
/// </summary>
/// <returns>Paginated videos</returns>
Task<Paginated<Video>> GetVideosAsync(int? page, int? perPage);
Task<Paginated<Video>> GetVideosAsync(int? page, int? perPage, string[] fields = null);


// ...for another account
Expand All @@ -97,52 +99,58 @@ public interface IVimeoClient
/// </summary>
/// <param name="userId">UserId</param>
/// <param name="clipId">ClipId</param>
/// <param name="fields"></param>
/// <returns>Video</returns>
Video GetUserVideo(long userId, long clipId);
Video GetUserVideo(long userId, long clipId, string[] fields = null);

/// <summary>
/// Get video by ClipId for UserId asynchronously
/// </summary>
/// <param name="userId">UserId</param>
/// <param name="clipId">ClipId</param>
/// <param name="fields"></param>
/// <returns>Video</returns>
Task<Video> GetUserVideoAsync(long userId, long clipId);
Task<Video> GetUserVideoAsync(long userId, long clipId, string[] fields = null);

/// <summary>
/// Get videos by UserId and query
/// </summary>
/// <param name="userId">UserId</param>
/// <param name="query">Search query</param>
/// <param name="fields"></param>
/// <returns>Paginated videos</returns>
Paginated<Video> GetUserVideos(long userId, string query = null);
Paginated<Video> GetUserVideos(long userId, string query = null, string[] fields = null);

/// <summary>
/// Get videos by UserId and query asynchronously
/// </summary>
/// <param name="userId">UserId</param>
/// <param name="query">Search query</param>
/// <param name="fields"></param>
/// <returns>Paginated videos</returns>
Task<Paginated<Video>> GetUserVideosAsync(long userId, string query = null);
Task<Paginated<Video>> GetUserVideosAsync(long userId, string query = null, string[] fields = null);

/// <summary>
/// Get videos by UserId and query and page parameters
/// </summary>
/// <param name="userId">UserId</param>
/// <param name="perPage">Number of items to show on each page. Max 50</param>
/// <param name="query">Search query</param>
/// <param name="fields"></param>
/// <param name="page">The page number to show</param>
/// <returns>Paginated videos</returns>
Paginated<Video> GetUserVideos(long userId, int? page, int? perPage, string query = null);
Paginated<Video> GetUserVideos(long userId, int? page, int? perPage, string query = null, string[] fields = null);

/// <summary>
/// Get videos by UserId and query and page parameters asynchronously
/// </summary>
/// <param name="userId">UserId</param>
/// <param name="perPage">Number of items to show on each page. Max 50</param>
/// <param name="query">Search query</param>
/// <param name="fields"></param>
/// <param name="page">The page number to show</param>
/// <returns>Paginated videos</returns>
Task<Paginated<Video>> GetUserVideosAsync(long userId, int? page, int? perPage, string query = null);
Task<Paginated<Video>> GetUserVideosAsync(long userId, int? page, int? perPage, string query = null, string[] fields = null);


// ...for an album
Expand All @@ -155,9 +163,10 @@ public interface IVimeoClient
/// <param name="perPage">Number of items to show on each page. Max 50</param>
/// <param name="sort">The default sort order of an Album's videos</param>
/// <param name="direction">The direction that the results are sorted</param>
/// <param name="fields"></param>
/// <returns>Paginated videos</returns>
Paginated<Video> GetAlbumVideos(long albumId, int? page, int? perPage,
string sort = null, string direction = null);
string sort = null, string direction = null, string[] fields = null);

/// <summary>
/// Get videos by AlbumId asynchronously
Expand All @@ -167,59 +176,66 @@ Paginated<Video> GetAlbumVideos(long albumId, int? page, int? perPage,
/// <param name="perPage">Number of items to show on each page. Max 50.</param>
/// <param name="sort">The default sort order of an Album's videos</param>
/// <param name="direction">The direction that the results are sorted.</param>
/// <param name="fields">JSON filter, as per https://developer.vimeo.com/api/common-formats#json-filter </param>
/// <returns>Paginated videos</returns>
Task<Paginated<Video>> GetAlbumVideosAsync(long albumId, int? page, int? perPage,
string sort = null, string direction = null);
string sort = null, string direction = null, string[] fields = null);

/// <summary>
/// Get video from album by AlbumId and ClipId
/// </summary>
/// <param name="albumId">AlbumId</param>
/// <param name="clipId">ClipId</param>
/// <param name="fields"></param>
/// <returns>Video</returns>
Video GetAlbumVideo(long albumId, long clipId);
Video GetAlbumVideo(long albumId, long clipId, string[] fields = null);

/// <summary>
/// Get video from album by AlbumId and ClipId asynchronously
/// </summary>
/// <param name="albumId">AlbumId</param>
/// <param name="clipId">ClipId</param>
/// <param name="fields"></param>
/// <returns>Video</returns>
Task<Video> GetAlbumVideoAsync(long albumId, long clipId);
Task<Video> GetAlbumVideoAsync(long albumId, long clipId, string[] fields = null);

/// <summary>
/// Get videos from album by AlbumId and UserId
/// </summary>
/// <param name="userId">UserId</param>
/// <param name="albumId">AlbumId</param>
/// <param name="fields"></param>
/// <returns>Paginated videos</returns>
Paginated<Video> GetUserAlbumVideos(long userId, long albumId);
Paginated<Video> GetUserAlbumVideos(long userId, long albumId, string[] fields = null);

/// <summary>
/// Get videos from album by AlbumId and UserId asynchronously
/// </summary>
/// <param name="userId">UserId</param>
/// <param name="albumId">AlbumId</param>
/// <param name="fields"></param>
/// <returns>Paginated videos</returns>
Task<Paginated<Video>> GetUserAlbumVideosAsync(long userId, long albumId);
Task<Paginated<Video>> GetUserAlbumVideosAsync(long userId, long albumId, string[] fields = null);

/// <summary>
/// Get video from album by AlbumId and UserId and ClipId
/// </summary>
/// <param name="userId">AlbumId</param>
/// <param name="albumId">UserId</param>
/// <param name="clipId">ClipId</param>
/// <param name="fields"></param>
/// <returns>Video</returns>
Video GetUserAlbumVideo(long userId, long albumId, long clipId);
Video GetUserAlbumVideo(long userId, long albumId, long clipId, string[] fields = null);

/// <summary>
/// Get video from album by AlbumId and UserId and ClipId asynchronously
/// </summary>
/// <param name="userId">AlbumId</param>
/// <param name="albumId">UserId</param>
/// <param name="clipId">ClipId</param>
/// <param name="fields"></param>
/// <returns>Video</returns>
Task<Video> GetUserAlbumVideoAsync(long userId, long albumId, long clipId);
Task<Video> GetUserAlbumVideoAsync(long userId, long albumId, long clipId, string[] fields = null);

/// <summary>
/// Update allowed domain for clip
Expand Down Expand Up @@ -446,8 +462,9 @@ Task<IUploadRequest> StartUploadFileAsync(IBinaryContent fileContent,
/// Get album by parameters asynchronously
/// </summary>
/// <param name="parameters">GetAlbumsParameters</param>
/// <param name="fields"></param>
/// <returns>Paginated albums</returns>
Task<Paginated<Album>> GetAlbumsAsync(GetAlbumsParameters parameters = null);
Task<Paginated<Album>> GetAlbumsAsync(GetAlbumsParameters parameters = null, string[] fields = null);

/// <summary>
/// Get album by UserId and parameters
Expand Down
13 changes: 13 additions & 0 deletions src/VimeoDotNet/Net/ApiRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class ApiRequest : IApiRequest
private readonly Dictionary<string, string> _hashValues = new Dictionary<string, string>();
private readonly Dictionary<string, string> _queryString = new Dictionary<string, string>();
private readonly Dictionary<string, string> _urlSegments = new Dictionary<string, string>();
private readonly List<string> _fields = new List<string>();
private static readonly JsonSerializerSettings DateFormatSettings = new JsonSerializerSettings
{
DateFormatString = "yyyy-MM-ddTHH:mm:sszzz",
Expand Down Expand Up @@ -97,6 +98,14 @@ public IDictionary<string, string> Query
get { return _queryString; }
}

/// <summary>
///
/// </summary>
public List<string> Fields
{
get { return _fields; }
}

/// <summary>
///
/// </summary>
Expand Down Expand Up @@ -440,6 +449,10 @@ protected string BuildUrl()
path = path.Replace($"{{{urlSegment.Key}}}", urlSegment.Value);
}
sb.Append(path);
if (_fields.Count > 0)
{
Query.Add("fields", string.Join(",", _fields));
}
if (Query.Keys.Count == 0)
return sb.ToString();
sb.Append("?");
Expand Down
4 changes: 4 additions & 0 deletions src/VimeoDotNet/Net/IApiRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public interface IApiRequest
/// </summary>
bool ExcludeAuthorizationHeader { get; set; }
/// <summary>
///
/// </summary>
List<string> Fields { get; }
/// <summary>
///
/// </summary>
IDictionary<string, string> Query { get; }
Expand Down
11 changes: 10 additions & 1 deletion src/VimeoDotNet/VimeoClient_Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,9 @@ public async Task<User> GetUserInformationAsync(long userId)
/// Get album by parameters asynchronously
/// </summary>
/// <param name="parameters">GetAlbumsParameters</param>
/// <param name="fields"></param>
/// <returns>Paginated albums</returns>
public async Task<Paginated<Album>> GetAlbumsAsync(GetAlbumsParameters parameters = null)
public async Task<Paginated<Album>> GetAlbumsAsync(GetAlbumsParameters parameters = null, string[] fields = null)
{
var request = ApiRequestFactory.AuthorizedRequest(
AccessToken,
Expand All @@ -239,6 +240,14 @@ public async Task<Paginated<Album>> GetAlbumsAsync(GetAlbumsParameters parameter
parameters
);

if (fields != null)
{
foreach (var field in fields)
{
request.Fields.Add(field);
}
}

return await ExecuteApiRequest<Paginated<Album>>(request);
}

Expand Down
Loading

0 comments on commit e483dc2

Please sign in to comment.