-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #114 from mfilippov/tag-support
Add support for tags #112
- Loading branch information
Showing
9 changed files
with
485 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using System.Threading.Tasks; | ||
using Shouldly; | ||
using Xunit; | ||
|
||
namespace VimeoDotNet.Tests | ||
{ | ||
public class TagTests : BaseTest | ||
{ | ||
private static async Task CleanupTags(IVimeoClient client, long clipId) | ||
{ | ||
var tags = await client.GetVideoTags(clipId); | ||
foreach (var tag in tags.Data) | ||
{ | ||
await client.DeleteVideoTagAsync(clipId, tag.Id); | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task ShouldCorrectlyAddTagVideoTag() | ||
{ | ||
var client = CreateAuthenticatedClient(); | ||
await CleanupTags(client, VimeoSettings.VideoId); | ||
var video = await client.GetVideoAsync(VimeoSettings.VideoId); | ||
video.Tags.Count.ShouldBe(0); | ||
var tag = await client.AddVideoTagAsync(VimeoSettings.VideoId, "test-tag1"); | ||
tag.ShouldNotBeNull(); | ||
tag.Id.ShouldBe("test-tag1"); | ||
tag.Name.ShouldBe("test-tag1"); | ||
tag.Canonical.ShouldBe("test-tag1"); | ||
tag.Uri.ShouldNotBeEmpty(); | ||
tag.Metadata.ShouldNotBeNull(); | ||
tag.Metadata.Connections.ShouldNotBeNull(); | ||
tag.Metadata.Connections.Videos.Uri.ShouldNotBeEmpty(); | ||
tag.Metadata.Connections.Videos.Options.ShouldNotBeEmpty(); | ||
tag.Metadata.Connections.Videos.Total.ShouldBeGreaterThan(0); | ||
video = await client.GetVideoAsync(VimeoSettings.VideoId); | ||
video.Tags.Count.ShouldBe(1); | ||
|
||
await CleanupTags(client, VimeoSettings.VideoId); | ||
video = await client.GetVideoAsync(VimeoSettings.VideoId); | ||
video.Tags.Count.ShouldBe(0); | ||
} | ||
|
||
[Fact] | ||
public async Task ShouldCorrectlyGetVideoTag() | ||
{ | ||
var client = CreateAuthenticatedClient(); | ||
await CleanupTags(client, VimeoSettings.VideoId); | ||
var video = await client.GetVideoAsync(VimeoSettings.VideoId); | ||
video.Tags.Count.ShouldBe(0); | ||
|
||
await client.AddVideoTagAsync(VimeoSettings.VideoId, "test-tag1"); | ||
|
||
var result = await client.GetVideoTagAsync("test-tag1"); | ||
result.Id.ShouldBe("test-tag1"); | ||
|
||
await CleanupTags(client, VimeoSettings.VideoId); | ||
video = await client.GetVideoAsync(VimeoSettings.VideoId); | ||
video.Tags.Count.ShouldBe(0); | ||
} | ||
|
||
[Fact] | ||
public async Task ShouldCorrectlyGetVideobyTag() | ||
{ | ||
var client = CreateAuthenticatedClient(); | ||
var result = await client.GetVideoByTag("test", 1, 10, GetVideoByTagSort.Name, | ||
GetVideoByTagDirection.Asc, new[] {"uri", "name"}); | ||
result.Page.ShouldBe(1); | ||
result.PerPage.ShouldBe(10); | ||
result.Data.Count.ShouldBeGreaterThan(0); | ||
result.Data[0].Name.ShouldNotBeEmpty(); | ||
result.Data[0].Uri.ShouldNotBeEmpty(); | ||
} | ||
} | ||
} |
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,46 @@ | ||
using System; | ||
using JetBrains.Annotations; | ||
|
||
namespace VimeoDotNet | ||
{ | ||
/// <summary> | ||
/// Get video by tag direction type | ||
/// </summary> | ||
[PublicAPI] | ||
public enum GetVideoByTagDirection | ||
{ | ||
/// <summary> | ||
/// Ascending | ||
/// </summary> | ||
Asc, | ||
/// <summary> | ||
/// Descending | ||
/// </summary> | ||
Desc | ||
} | ||
|
||
/// <summary> | ||
/// Get video by tag direction type | ||
/// </summary> | ||
internal static class GetVideoByTagDirectionEx | ||
{ | ||
/// <summary> | ||
/// Return string representation for enum value | ||
/// </summary> | ||
/// <param name="direction">Value</param> | ||
/// <returns>String representation</returns> | ||
/// <exception cref="ArgumentOutOfRangeException">Throw if value not handled.</exception> | ||
public static string GetStringValue(this GetVideoByTagDirection direction) | ||
{ | ||
switch (direction) | ||
{ | ||
case GetVideoByTagDirection.Asc: | ||
return "asc"; | ||
case GetVideoByTagDirection.Desc: | ||
return "desc"; | ||
default: | ||
throw new ArgumentOutOfRangeException(nameof(direction), direction, null); | ||
} | ||
} | ||
} | ||
} |
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,51 @@ | ||
using System; | ||
using JetBrains.Annotations; | ||
|
||
namespace VimeoDotNet | ||
{ | ||
/// <summary> | ||
/// Get video by tag sort type | ||
/// </summary> | ||
[PublicAPI] | ||
public enum GetVideoByTagSort | ||
{ | ||
/// <summary> | ||
/// By created time | ||
/// </summary> | ||
CreatedTime, | ||
|
||
/// <summary> | ||
/// By duration | ||
/// </summary> | ||
Duration, | ||
|
||
/// <summary> | ||
/// By name | ||
/// </summary> | ||
Name | ||
} | ||
|
||
internal static class GetVideoByTagSortEx | ||
{ | ||
/// <summary> | ||
/// Return string representation for enum value | ||
/// </summary> | ||
/// <param name="sort">Value</param> | ||
/// <returns>String representation</returns> | ||
/// <exception cref="ArgumentOutOfRangeException">Throw if value not handled.</exception> | ||
public static string GetStringValue(this GetVideoByTagSort sort) | ||
{ | ||
switch (sort) | ||
{ | ||
case GetVideoByTagSort.CreatedTime: | ||
return "created_time"; | ||
case GetVideoByTagSort.Duration: | ||
return "duration"; | ||
case GetVideoByTagSort.Name: | ||
return "name"; | ||
default: | ||
throw new ArgumentOutOfRangeException(nameof(sort), sort, null); | ||
} | ||
} | ||
} | ||
} |
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
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,15 @@ | ||
using JetBrains.Annotations; | ||
using Newtonsoft.Json; | ||
|
||
namespace VimeoDotNet.Models | ||
{ | ||
public class TagMetadata | ||
{ | ||
/// <summary> | ||
/// Tag connections | ||
/// </summary> | ||
[PublicAPI] | ||
[JsonProperty(PropertyName = "connections")] | ||
public TagMetadataConnections Connections { get; set; } | ||
} | ||
} |
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,15 @@ | ||
using JetBrains.Annotations; | ||
using Newtonsoft.Json; | ||
|
||
namespace VimeoDotNet.Models | ||
{ | ||
public class TagMetadataConnections | ||
{ | ||
/// <summary> | ||
/// Video connections | ||
/// </summary> | ||
[PublicAPI] | ||
[JsonProperty(PropertyName = "videos")] | ||
public VideoConnectionsEntry Videos { get; set; } | ||
} | ||
} |
Oops, something went wrong.