Skip to content

Commit

Permalink
Merge pull request #103 from mfilippov/fix-pictures-api
Browse files Browse the repository at this point in the history
Fix some issues
  • Loading branch information
mfilippov authored Sep 29, 2017
2 parents a4035fc + b3d53a6 commit 3d2ac02
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 16 deletions.
21 changes: 21 additions & 0 deletions src/VimeoDotNet.Tests/VimeoClientAsyncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,19 @@ public async Task Integration_VimeoClient_GetAccountAlbumVideo_RetrievesVideo()
var video = await client.GetAlbumVideoAsync(_vimeoSettings.AlbumId, _vimeoSettings.VideoId);
video.ShouldNotBeNull();
}

[Fact]
public async Task Integration_VimeoClient_GetAccountAlbumVideo_GetThumbnails()
{
var client = CreateAuthenticatedClient();
var pictures = await client.GetPicturesAsync(_vimeoSettings.VideoId);
pictures.ShouldNotBeNull();
pictures.data.Count.ShouldBeGreaterThan(0);
var uriParts = pictures.data[0].uri.Split('/');
var pictureId = long.Parse(uriParts[uriParts.Length - 1]);
var picture = await client.GetPictureAsync(_vimeoSettings.VideoId, pictureId);
picture.ShouldNotBeNull();
}

[Fact]
public async Task Integration_VimeoClient_GetAccountAlbumVideoWithFields_RetrievesVideo()
Expand Down Expand Up @@ -410,6 +423,14 @@ public async Task Integration_VimeoClient_GetAccountAlbums_NotNull()
var albums = await client.GetAlbumsAsync();
albums.ShouldNotBeNull();
}

[Fact]
public async Task Integration_VimeoClient_GetAccountAlbums_WithParameters()
{
var client = CreateAuthenticatedClient();
var albums = await client.GetAlbumsAsync(new GetAlbumsParameters { PerPage = 50 });
albums.ShouldNotBeNull();
}

[Fact]
public async Task Integration_VimeoClientWithFields_GetAccountAlbums_NotNull()
Expand Down
1 change: 1 addition & 0 deletions src/VimeoDotNet/Constants/Endpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ internal static class Endpoints
public const string TextTracks = "/videos/{clipId}/texttracks/";
public const string TextTrack = "/videos/{clipId}/texttracks/{trackId}";

public const string Picture = "/videos/{clipId}/pictures/{pictureId}";
public const string Pictures = "/videos/{clipId}/pictures";

public static string GetCurrentUserEndpoint(string endpoint)
Expand Down
16 changes: 14 additions & 2 deletions src/VimeoDotNet/Net/ApiRequestFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,22 @@ public IApiRequest AuthorizedRequest(string accessToken, HttpMethod method, stri
request.UrlSegments.Add(item);
}
}

// Add query or body parameters if present...
if (additionalParameters != null)
request.Body = new FormUrlEncodedContent(additionalParameters.GetParameterValues());
{
if (method == HttpMethod.Get)
{
foreach (var parameter in additionalParameters.GetParameterValues())
{
request.Query.Add(parameter);
}
}
else
{
request.Body = new FormUrlEncodedContent(additionalParameters.GetParameterValues());
}
}

return request;
}
Expand Down
8 changes: 4 additions & 4 deletions src/VimeoDotNet/VimeoClient_Sync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -735,10 +735,10 @@ public Picture UploadThumbnail(long clipId, IBinaryContent fileContent)
{
try
{
Picture pic = GetPictureAsync(clipId).RunSynchronouslyWithCurrentCulture();
UploadPictureAsync(fileContent, pic.link).RunSynchronouslyWithCurrentCulture();
SetThumbnailActiveAsync(pic.uri).RunSynchronouslyWithCurrentCulture();
return pic;
var pics = GetPicturesAsync(clipId).RunSynchronouslyWithCurrentCulture().data;
UploadPictureAsync(fileContent, pics[0].link).RunSynchronouslyWithCurrentCulture();
SetThumbnailActiveAsync(pics[0].uri).RunSynchronouslyWithCurrentCulture();
return pics[0];
}
catch (AggregateException ex)
{
Expand Down
8 changes: 4 additions & 4 deletions src/VimeoDotNet/VimeoClient_Upload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,10 @@ public async Task<Picture> UploadThumbnailAsync(long clipId, IBinaryContent file
{
try
{
Picture pic = await GetPictureAsync(clipId);
await UploadPictureAsync(fileContent, pic.link);
await SetThumbnailActiveAsync(pic.uri);
return pic;
var pics = await GetPicturesAsync(clipId);
await UploadPictureAsync(fileContent, pics.data[0].link);
await SetThumbnailActiveAsync(pics.data[0].uri);
return pics.data[0];
}
catch (Exception ex)
{
Expand Down
50 changes: 44 additions & 6 deletions src/VimeoDotNet/VimeoClient_Videos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -523,23 +523,61 @@ private IApiRequest GenerateVideoAllowedDomainPatchRequest(long clipId, string d
}

/// <summary>
///
/// Get a video thumbnail
/// </summary>
/// <param name="clipId">clipdId</param>
/// <param name="pictureId">pictureId</param>
/// <returns></returns>
public async Task<Picture> GetPictureAsync(long clipId, long pictureId)
{
try
{
ThrowIfUnauthorized();
var request = ApiRequestFactory.GetApiRequest(AccessToken);
request.Method = HttpMethod.Get;
request.Path = Endpoints.Picture;
request.UrlSegments.Add("clipId", clipId.ToString());
request.UrlSegments.Add("pictureId", clipId.ToString());

var response = await request.ExecuteRequestAsync<Picture>();
UpdateRateLimit(response);
CheckStatusCodeError(response, "Error retrieving video picture.", HttpStatusCode.NotFound);

if (response.StatusCode == HttpStatusCode.NotFound)
{
return null;
}

return response.Content;
}
catch (Exception ex)
{
if (ex is VimeoApiException)
{
throw;
}
throw new VimeoApiException("Error retrieving video picture.", ex);
}
}

/// <summary>
/// Get all thumbnails on a video
/// </summary>
/// <param name="clipId"></param>
/// <returns></returns>
public async Task<Picture> GetPictureAsync(long clipId)
public async Task<Paginated<Picture>> GetPicturesAsync(long clipId)
{
try
{
ThrowIfUnauthorized();
IApiRequest request = ApiRequestFactory.GetApiRequest(AccessToken);
request.Method = HttpMethod.Post;
request.Method = HttpMethod.Get;
request.Path = Endpoints.Pictures;
request.UrlSegments.Add("clipId", clipId.ToString());

var response = await request.ExecuteRequestAsync<Picture>();
var response = await request.ExecuteRequestAsync<Paginated<Picture>>();
UpdateRateLimit(response);
CheckStatusCodeError(response, "Error retrieving account video.", HttpStatusCode.NotFound);
CheckStatusCodeError(response, "Error retrieving video picture.", HttpStatusCode.NotFound);

if (response.StatusCode == HttpStatusCode.NotFound)
{
Expand All @@ -554,7 +592,7 @@ public async Task<Picture> GetPictureAsync(long clipId)
{
throw;
}
throw new VimeoApiException("Error retrieving account video.", ex);
throw new VimeoApiException("Error retrieving video picture.", ex);
}
}

Expand Down

0 comments on commit 3d2ac02

Please sign in to comment.