Move Releases API to RepositoriesClient.

Releases are grouped under Repositories on developer.github.com.
This commit is contained in:
Matt Burke
2013-10-02 10:36:40 -04:00
committed by Haacked
parent 56406646e3
commit 903fb84d97
14 changed files with 96 additions and 73 deletions
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Xunit;
@@ -89,5 +90,22 @@ namespace Octokit.Tests.Integration
Assert.Contains("<p><strong>WARNING: This is some haacky code.", readMeHtml);
}
}
public class TheGetReleasesMethod
{
[IntegrationTest]
public async Task ReturnsReleases()
{
var github = new GitHubClient
{
Credentials = AutomationSettings.Current.GitHubCredentials
};
var releases = await github.Repository.GetReleases("git-tfs", "git-tfs");
Assert.True(releases.Count > 5);
Assert.True(releases.Any(release => release.TagName == "v0.18.0"));
}
}
}
}
@@ -1,40 +0,0 @@
using System;
using System.Threading.Tasks;
using NSubstitute;
using Octokit.Clients;
using Octokit.Http;
using Octokit.Tests.Helpers;
using Xunit;
namespace Octokit.Tests.Clients
{
/// <summary>
/// Client tests mostly just need to make sure they call the IApiConnection with the correct
/// relative Uri. No need to fake up the response. All *those* tests are in ApiConnectionTests.cs.
/// </summary>
public class ReleasesClientTests
{
public class TheGetAllMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var client = Substitute.For<IApiConnection<Release>>();
var repositoriesClient = new ReleasesClient(client);
repositoriesClient.GetAll("fake", "repo");
client.Received().GetAll(Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/releases"), null);
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var repositoriesClient = new ReleasesClient(Substitute.For<IApiConnection<Release>>());
await AssertEx.Throws<ArgumentNullException>(async () => await repositoriesClient.GetAll(null, "name"));
await AssertEx.Throws<ArgumentNullException>(async () => await repositoriesClient.GetAll("owner", null));
}
}
}
}
@@ -139,5 +139,28 @@ namespace Octokit.Tests.Clients
client.Received().GetHtml(Arg.Is<Uri>(u => u.ToString() == "https://github.example.com/readme"), null);
}
}
public class TheGetReleasesMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var client = Substitute.For<IApiConnection<Repository>>();
var repositoriesClient = new RepositoriesClient(client);
repositoriesClient.GetReleases("fake", "repo");
client.Received().GetAll<Release>(Arg.Is<Uri>(u => u.ToString() == "/repos/fake/repo/releases"), null);
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var repositoriesClient = new RepositoriesClient(Substitute.For<IApiConnection<Repository>>());
await AssertEx.Throws<ArgumentNullException>(async () => await repositoriesClient.GetReleases(null, "name"));
await AssertEx.Throws<ArgumentNullException>(async () => await repositoriesClient.GetReleases("owner", null));
}
}
}
}
-1
View File
@@ -51,7 +51,6 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Authentication\CredentialsTests.cs" />
<Compile Include="Clients\ReleasesClientTests.cs" />
<Compile Include="Clients\SshKeysClientTests.cs" />
<Compile Include="Exceptions\ApiValidationExceptionTests.cs" />
<Compile Include="Helpers\UriExtensionsTests.cs" />
+8
View File
@@ -26,6 +26,14 @@ namespace Octokit
return connection.GetAll(endpoint, null);
}
public static Task<IReadOnlyCollection<TOther>> GetAll<TOther, T>(this IApiConnection<T> connection, Uri endpoint)
{
Ensure.ArgumentNotNull(connection, "connection");
Ensure.ArgumentNotNull(endpoint, "endpoint");
return connection.GetAll<TOther>(endpoint, null);
}
public static Task<string> GetHtml<T>(this IApiConnection<T> connection, Uri endpoint)
{
Ensure.ArgumentNotNull(connection, "connection");
+13
View File
@@ -26,5 +26,18 @@ namespace Octokit.Clients
}
return new ReadOnlyCollection<T>(allItems);
}
public async Task<IReadOnlyCollection<TOther>> GetAllPages<TOther>(Func<Task<IReadOnlyPagedCollection<TOther>>> getFirstPage)
{
Ensure.ArgumentNotNull(getFirstPage, "getFirstPage");
var page = await getFirstPage();
var allItems = new List<TOther>(page);
while ((page = await page.GetNextPage()) != null)
{
allItems.AddRange(page);
}
return new ReadOnlyCollection<TOther>(allItems);
}
}
}
-21
View File
@@ -1,21 +0,0 @@
using System.Threading.Tasks;
using Octokit.Http;
namespace Octokit.Clients
{
public class ReleasesClient : ApiClient<Release>, IReleasesClient
{
public ReleasesClient(IApiConnection<Release> client) : base(client)
{
}
public async Task<IReadOnlyCollection<Release>> GetAll(string owner, string repository)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repository, "repository");
var endpoint = "/repos/{0}/{1}/releases".FormatUri(owner, repository);
return await Client.GetAll(endpoint);
}
}
}
+9
View File
@@ -53,5 +53,14 @@ namespace Octokit.Clients
var readmeInfo = await Client.GetItem<ReadmeResponse>(endpoint, null);
return new Readme(readmeInfo, Client);
}
public async Task<IReadOnlyCollection<Release>> GetReleases(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "repository");
var endpoint = "/repos/{0}/{1}/releases".FormatUri(owner, name);
return await Client.GetAll<Release, Repository>(endpoint);
}
}
}
+15
View File
@@ -54,6 +54,13 @@ namespace Octokit.Http
return await pagination.GetAllPages(async () => await GetPage(endpoint, parameters));
}
public async Task<IReadOnlyCollection<TOther>> GetAll<TOther>(Uri endpoint, IDictionary<string, string> parameters)
{
Ensure.ArgumentNotNull(endpoint, "endpoint");
return await pagination.GetAllPages<TOther>(async () => await GetPage<TOther>(endpoint, parameters));
}
public async Task<T> Create(Uri endpoint, object data)
{
Ensure.ArgumentNotNull(endpoint, "endpoint");
@@ -99,5 +106,13 @@ namespace Octokit.Http
return new ReadOnlyPagedCollection<T>(response, Connection);
}
async Task<IReadOnlyPagedCollection<TOther>> GetPage<TOther>(Uri endpoint, IDictionary<string, string> parameters)
{
Ensure.ArgumentNotNull(endpoint, "endpoint");
var response = await Connection.GetAsync<List<TOther>>(endpoint, parameters);
return new ReadOnlyPagedCollection<TOther>(response, Connection);
}
}
}
+1
View File
@@ -17,6 +17,7 @@ namespace Octokit.Http
Task<TOther> GetItem<TOther>(Uri endpoint, IDictionary<string, string> parameters);
Task<string> GetHtml(Uri endpoint, IDictionary<string, string> parameters);
Task<IReadOnlyCollection<T>> GetAll(Uri endpoint, IDictionary<string, string> parameters);
Task<IReadOnlyCollection<TOther>> GetAll<TOther>(Uri endpoint, IDictionary<string, string> parameters);
Task<T> Create(Uri endpoint, object data);
Task<T> Update(Uri endpoint, object data);
Task Delete(Uri endpoint);
+1
View File
@@ -7,5 +7,6 @@ namespace Octokit
public interface IApiPagination<T>
{
Task<IReadOnlyCollection<T>> GetAllPages(Func<Task<IReadOnlyPagedCollection<T>>> getFirstPage);
Task<IReadOnlyCollection<TOther>> GetAllPages<TOther>(Func<Task<IReadOnlyPagedCollection<TOther>>> getFirstPage);
}
}
-9
View File
@@ -1,9 +0,0 @@
using System.Threading.Tasks;
namespace Octokit
{
public interface IReleasesClient
{
Task<IReadOnlyCollection<Release>> GetAll(string owner, string repository);
}
}
+8
View File
@@ -56,5 +56,13 @@ namespace Octokit
/// <param name="name">The name of the repository.</param>
/// <returns></returns>
Task<Readme> GetReadme(string owner, string name);
/// <summary>
/// Retrieves every <see cref="Release"/> for the specified repository.
/// </summary>
/// <param name="owner">The owner of the repository.</param>
/// <param name="name">The name of the reposiitory</param>
/// <returns>A <see cref="IReadonlyPagedCollection{Release}"/> of <see cref="Release"/>.</returns>
Task<IReadOnlyCollection<Release>> GetReleases(string owner, string name);
}
}
-2
View File
@@ -83,7 +83,6 @@
<Compile Include="Clients\AuthorizationsClient.cs" />
<Compile Include="Clients\ApiPagination.cs" />
<Compile Include="Clients\AutoCompleteClient.cs" />
<Compile Include="Clients\ReleasesClient.cs" />
<Compile Include="Clients\OrganizationsClient.cs" />
<Compile Include="Authentication\AnonymousAuthenticator.cs" />
<Compile Include="Authentication\Authenticator.cs" />
@@ -107,7 +106,6 @@
<Compile Include="IAuthorizationsClient.cs" />
<Compile Include="IAutoCompleteClient.cs" />
<Compile Include="IGitHubClient.cs" />
<Compile Include="IReleasesClient.cs" />
<Compile Include="ISshKeysClient.cs" />
<Compile Include="IOrganizationsClient.cs" />
<Compile Include="IReadOnlyPagedCollection.cs" />