Skip to content

Commit

Permalink
Merge pull request #91 from mohibsheth/master
Browse files Browse the repository at this point in the history
* Add support for "pull"
  • Loading branch information
mfilippov authored Aug 26, 2017
2 parents f140d83 + cbc05c3 commit 39ce0a5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
8 changes: 8 additions & 0 deletions src/VimeoDotNet.Tests/VimeoClientAsyncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,14 @@ public void Integration_VimeoClient_UploadEntireFile_UploadsFile_InvalidStreams(
Should.ThrowAsync<InvalidOperationException>(async () => await nonSeekablefile.ReadAsync(10, 20), "Content cannot be advanced to the specified start index: 10");
}

[Fact]
public async Task Integration_VimeoClient_UploadPullLink()
{
var client = CreateAuthenticatedClient();
var video = await client.UploadPullLinkAsync("http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4");
video.ShouldNotBeNull();
}

[Fact]
public async Task Integration_VimeoClient_DeleteVideo_DeletesVideo()
{
Expand Down
48 changes: 39 additions & 9 deletions src/VimeoDotNet/VimeoClient_Upload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,37 @@ public async Task<IUploadRequest> UploadEntireFileAsync(IBinaryContent fileConte
return uploadRequest;
}

/// <inheritdoc />
/// <summary>
/// Create new upload ticket asynchronously
/// </summary>
/// <returns>Upload ticket</returns>
public async Task<Video> UploadPullLinkAsync(string link)
{
try
{
var request = GenerateUploadTicketRequest("pull");
request.Query.Add("link", link);
var response = await request.ExecuteRequestAsync<Video>();
UpdateRateLimit(response);
CheckStatusCodeError(null, response, "Error generating upload ticket.");

return response.Content;
}
catch (Exception ex)
{
if (ex is VimeoApiException)
{
throw;
}
throw new VimeoUploadException("Error generating upload ticket.", null, ex);
}
}

/// <summary>
/// Verify upload file part asynchronously
/// </summary>
/// <param name="uploadRequest">UploadRequest</param>
/// <returns>Verification reponse</returns>
public async Task<VerifyUploadResponse> VerifyUploadFileAsync(IUploadRequest uploadRequest)
{
try
Expand All @@ -248,17 +278,17 @@ public async Task<VerifyUploadResponse> VerifyUploadFileAsync(IUploadRequest upl
return verify;
var match = RangeRegex.Match(response.Headers.GetValues("Range").First());
// ReSharper disable once InvertIf
if (match.Success
if (match.Success
&& long.TryParse(match.Groups["start"].Value, out var startIndex)
&& long.TryParse(match.Groups["end"].Value, out var endIndex))
{
verify.BytesWritten = endIndex - startIndex;
if (verify.BytesWritten == uploadRequest.FileLength)
{
verify.Status = UploadStatusEnum.Completed;
verify.BytesWritten = endIndex - startIndex;
if (verify.BytesWritten == uploadRequest.FileLength)
{
verify.Status = UploadStatusEnum.Completed;
}
}
}
}
else
{
verify.Status = UploadStatusEnum.NotFound;
Expand Down Expand Up @@ -324,14 +354,14 @@ private async Task<IApiRequest> GenerateFileStreamRequest(IBinaryContent fileCon
return request;
}

private IApiRequest GenerateUploadTicketRequest()
private IApiRequest GenerateUploadTicketRequest(string type = "streaming")
{
ThrowIfUnauthorized();

IApiRequest request = ApiRequestFactory.GetApiRequest(AccessToken);
request.Method = HttpMethod.Post;
request.Path = Endpoints.UploadTicket;
request.Query.Add("type", "streaming");
request.Query.Add("type", type);
return request;
}

Expand Down

0 comments on commit 39ce0a5

Please sign in to comment.