mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-03 03:01:31 +00:00
Moved Queued Wait into IApiConnection
This commit is contained in:
@@ -25,14 +25,12 @@ namespace Octokit.Tests.Clients
|
||||
{
|
||||
var expectedEndPoint = new Uri("/repos/username/repositoryName/stats/contributors", UriKind.Relative);
|
||||
|
||||
var connection = Substitute.For<IConnection>();
|
||||
var client = Substitute.For<IApiConnection>();
|
||||
client.Connection.Returns(connection);
|
||||
var statisticsClient = new StatisticsClient(client);
|
||||
|
||||
statisticsClient.GetContributors("username","repositoryName");
|
||||
|
||||
connection.Received().GetAsync<IEnumerable<Contributor>>(expectedEndPoint);
|
||||
client.Received().GetQueuedOperation<IEnumerable<Contributor>>(expectedEndPoint);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -57,14 +55,12 @@ namespace Octokit.Tests.Clients
|
||||
{
|
||||
var expectedEndPoint = new Uri("/repos/username/repositoryName/stats/commit_activity", UriKind.Relative);
|
||||
|
||||
var connection = Substitute.For<IConnection>();
|
||||
var client = Substitute.For<IApiConnection>();
|
||||
client.Connection.Returns(connection);
|
||||
var statisticsClient = new StatisticsClient(client);
|
||||
|
||||
statisticsClient.GetCommitActivityForTheLastYear("username", "repositoryName");
|
||||
|
||||
connection.Received().GetAsync<IEnumerable<WeeklyCommitActivity>>(expectedEndPoint);
|
||||
client.Received().GetQueuedOperation<IEnumerable<WeeklyCommitActivity>>(expectedEndPoint);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -89,14 +85,12 @@ namespace Octokit.Tests.Clients
|
||||
{
|
||||
var expectedEndPoint = new Uri("/repos/username/repositoryName/stats/code_frequency", UriKind.Relative);
|
||||
|
||||
var connection = Substitute.For<IConnection>();
|
||||
var client = Substitute.For<IApiConnection>();
|
||||
client.Connection.Returns(connection);
|
||||
var statisticsClient = new StatisticsClient(client);
|
||||
|
||||
statisticsClient.GetAdditionsAndDeletionsPerWeek("username", "repositoryName");
|
||||
|
||||
connection.Received().GetAsync<IEnumerable<int[]>>(expectedEndPoint);
|
||||
client.Received().GetQueuedOperation<IEnumerable<int[]>>(expectedEndPoint);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -121,14 +115,12 @@ namespace Octokit.Tests.Clients
|
||||
{
|
||||
var expectedEndPoint = new Uri("/repos/username/repositoryName/stats/participation", UriKind.Relative);
|
||||
|
||||
var connection = Substitute.For<IConnection>();
|
||||
var client = Substitute.For<IApiConnection>();
|
||||
client.Connection.Returns(connection);
|
||||
var statisticsClient = new StatisticsClient(client);
|
||||
|
||||
statisticsClient.GetCommitCountsPerWeek("username", "repositoryName");
|
||||
|
||||
connection.Received().GetAsync<WeeklyCommitCounts>(expectedEndPoint);
|
||||
client.Received().GetQueuedOperation<WeeklyCommitCounts>(expectedEndPoint);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -153,14 +145,12 @@ namespace Octokit.Tests.Clients
|
||||
{
|
||||
var expectedEndPoint = new Uri("/repos/username/repositoryName/stats/punch_card", UriKind.Relative);
|
||||
|
||||
var connection = Substitute.For<IConnection>();
|
||||
var client = Substitute.For<IApiConnection>();
|
||||
client.Connection.Returns(connection);
|
||||
var statisticsClient = new StatisticsClient(client);
|
||||
|
||||
statisticsClient.GetCommitPerHour("username", "repositoryName");
|
||||
|
||||
connection.Received().GetAsync<IEnumerable<int[]>>(expectedEndPoint);
|
||||
client.Received().GetQueuedOperation<IEnumerable<int[]>>(expectedEndPoint);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Octokit
|
||||
@@ -27,7 +25,7 @@ namespace Octokit
|
||||
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");
|
||||
|
||||
var endpoint = "/repos/{0}/{1}/stats/contributors".FormatUri(owner, repositoryName);
|
||||
return await WaitForResponse<IEnumerable<Contributor>>(endpoint);
|
||||
return await ApiConnection.GetQueuedOperation<IEnumerable<Contributor>>(endpoint);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -42,7 +40,7 @@ namespace Octokit
|
||||
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");
|
||||
|
||||
var endpoint = "/repos/{0}/{1}/stats/commit_activity".FormatUri(owner, repositoryName);
|
||||
return await WaitForResponse<IEnumerable<WeeklyCommitActivity>>(endpoint);
|
||||
return await ApiConnection.GetQueuedOperation<IEnumerable<WeeklyCommitActivity>>(endpoint);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -57,7 +55,7 @@ namespace Octokit
|
||||
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");
|
||||
|
||||
var endpoint = "/repos/{0}/{1}/stats/code_frequency".FormatUri(owner, repositoryName);
|
||||
return await WaitForResponse<IEnumerable<int[]>>(endpoint);
|
||||
return await ApiConnection.GetQueuedOperation<IEnumerable<int[]>>(endpoint);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -72,7 +70,7 @@ namespace Octokit
|
||||
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");
|
||||
|
||||
var endpoint = "/repos/{0}/{1}/stats/participation".FormatUri(owner, repositoryName);
|
||||
return await WaitForResponse<WeeklyCommitCounts>(endpoint);
|
||||
return await ApiConnection.GetQueuedOperation<WeeklyCommitCounts>(endpoint);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -87,18 +85,7 @@ namespace Octokit
|
||||
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");
|
||||
|
||||
var endpoint = "/repos/{0}/{1}/stats/punch_card".FormatUri(owner, repositoryName);
|
||||
return await WaitForResponse<IEnumerable<int[]>>(endpoint);
|
||||
}
|
||||
|
||||
async Task<T> WaitForResponse<T>(Uri endpoint)
|
||||
{
|
||||
var response = await Connection.GetAsync<T>(endpoint);
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.Accepted)
|
||||
{
|
||||
return await WaitForResponse<T>(endpoint);
|
||||
}
|
||||
return response.BodyAsObject;
|
||||
return await ApiConnection.GetQueuedOperation<IEnumerable<int[]>>(endpoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Octokit.Internal;
|
||||
|
||||
@@ -246,6 +247,24 @@ namespace Octokit
|
||||
return Connection.DeleteAsync(uri);
|
||||
}
|
||||
|
||||
public async Task<T> GetQueuedOperation<T>(Uri uri)
|
||||
{
|
||||
Ensure.ArgumentNotNull(uri, "uri");
|
||||
|
||||
var response = await Connection.GetAsync<T>(uri);
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.Accepted)
|
||||
{
|
||||
return await GetQueuedOperation<T>(uri);
|
||||
}
|
||||
|
||||
if (response.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
return response.BodyAsObject;
|
||||
}
|
||||
throw new ApiException("Queued Operations expect status codes of Accepted or OK.",response.StatusCode);
|
||||
}
|
||||
|
||||
async Task<IReadOnlyPagedCollection<T>> GetPage<T>(
|
||||
Uri uri,
|
||||
IDictionary<string, string> parameters,
|
||||
|
||||
@@ -144,5 +144,7 @@ namespace Octokit
|
||||
/// <param name="uri">URI of the API resource to delete</param>
|
||||
/// <returns>A <see cref="Task"/> for the request's execution.</returns>
|
||||
Task Delete(Uri uri);
|
||||
|
||||
Task<T> GetQueuedOperation<T>(Uri uri);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user