Merge pull request #742 from octokit/overloads-for-getallforcurrent

Add filter parameters for RepositoryClient.GetAllForCurrent
This commit is contained in:
Brendan Forster
2015-03-06 11:32:29 +10:30
13 changed files with 236 additions and 5 deletions
@@ -61,7 +61,20 @@ namespace Octokit.Reactive
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate",
Justification = "Makes a network request")]
IObservable<Repository> GetAllForCurrent();
/// <summary>
/// Retrieves every <see cref="Repository"/> that belongs to the current user.
/// </summary>
/// <remarks>
/// The default page size on GitHub.com is 30.
/// </remarks>
/// <param name="request">Search parameters to filter results on</param>
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
/// <returns>A <see cref="IReadOnlyPagedCollection{Repository}"/> of <see cref="Repository"/>.</returns>
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate",
Justification = "Makes a network request")]
IObservable<Repository> GetAllForCurrent(RepositoryRequest request);
/// <summary>
/// Retrieves every <see cref="Repository"/> that belongs to the specified user.
/// </summary>
@@ -115,6 +115,22 @@ namespace Octokit.Reactive
return _connection.GetAndFlattenAllPages<Repository>(ApiUrls.Repositories());
}
/// <summary>
/// Retrieves every <see cref="Repository"/> that belongs to the current user.
/// </summary>
/// <remarks>
/// The default page size on GitHub.com is 30.
/// </remarks>
/// <param name="request">Search parameters to filter results on</param>
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
/// <returns>A <see cref="IReadOnlyPagedCollection{Repository}"/> of <see cref="Repository"/>.</returns>
public IObservable<Repository> GetAllForCurrent(RepositoryRequest request)
{
Ensure.ArgumentNotNull(request, "request");
return _connection.GetAndFlattenAllPages<Repository>(ApiUrls.Repositories(), request.ToParametersDictionary());
}
/// <summary>
/// Retrieves every <see cref="Repository"/> that belongs to the specified user.
/// </summary>
@@ -615,6 +615,62 @@ public class RepositoriesClientTests
}
}
public class TheGetAllForCurrentMethod
{
[IntegrationTest]
public async Task CanRetrieveResults()
{
var github = Helper.GetAuthenticatedClient();
var repositories = await github.Repository.GetAllForCurrent();
Assert.NotEmpty(repositories);
}
[IntegrationTest]
public async Task CanSortResults()
{
var github = Helper.GetAuthenticatedClient();
var request = new RepositoryRequest
{
Sort = RepositorySort.Created
};
var reposByCreated = await github.Repository.GetAllForCurrent(request);
request.Sort = RepositorySort.FullName;
var reposByFullName = await github.Repository.GetAllForCurrent(request);
Assert.NotEmpty(reposByCreated);
Assert.NotEmpty(reposByFullName);
Assert.NotEqual(reposByCreated, reposByFullName);
}
[IntegrationTest]
public async Task CanChangeSortDirection()
{
var github = Helper.GetAuthenticatedClient();
var request = new RepositoryRequest
{
Direction = SortDirection.Ascending
};
var reposAscending = await github.Repository.GetAllForCurrent(request);
request.Direction = SortDirection.Ascending;
var reposDescending = await github.Repository.GetAllForCurrent(request);
Assert.NotEmpty(reposAscending);
Assert.NotEmpty(reposDescending);
Assert.NotEqual(reposAscending, reposDescending);
}
}
public class TheGetAllLanguagesMethod
{
[IntegrationTest]
@@ -288,6 +288,68 @@ namespace Octokit.Tests.Clients
connection.Received()
.GetAll<Repository>(Arg.Is<Uri>(u => u.ToString() == "user/repos"));
}
[Fact]
public void CanFilterByType()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoriesClient(connection);
var request = new RepositoryRequest
{
Type = RepositoryType.All
};
client.GetAllForCurrent(request);
connection.Received()
.GetAll<Repository>(
Arg.Is<Uri>(u => u.ToString() == "user/repos"),
Arg.Is<Dictionary<string,string>>(d => d["type"] == "all"));
}
[Fact]
public void CanFilterBySort()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoriesClient(connection);
var request = new RepositoryRequest
{
Type = RepositoryType.Private,
Sort = RepositorySort.FullName
};
client.GetAllForCurrent(request);
connection.Received()
.GetAll<Repository>(
Arg.Is<Uri>(u => u.ToString() == "user/repos"),
Arg.Is<Dictionary<string, string>>(d =>
d["type"] == "private" && d["sort"] == "full_name"));
}
[Fact]
public void CanFilterBySortDirection()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoriesClient(connection);
var request = new RepositoryRequest
{
Type = RepositoryType.Member,
Sort = RepositorySort.Updated,
Direction = SortDirection.Ascending
};
client.GetAllForCurrent(request);
connection.Received()
.GetAll<Repository>(
Arg.Is<Uri>(u => u.ToString() == "user/repos"),
Arg.Is<Dictionary<string, string>>(d =>
d["type"] == "member" && d["sort"] == "updated" && d["direction"] == "asc"));
}
}
public class TheGetAllForUserMethod
+17 -2
View File
@@ -108,7 +108,7 @@ namespace Octokit
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate",
Justification = "Makes a network request")]
Task<IReadOnlyList<Repository>> GetAllPublic();
/// <summary>
/// Gets all repositories owned by the current user.
/// </summary>
@@ -122,7 +122,22 @@ namespace Octokit
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate",
Justification = "Makes a network request")]
Task<IReadOnlyList<Repository>> GetAllForCurrent();
/// <summary>
/// Gets all repositories owned by the current user.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/#list-your-repositories">API documentation</a> for more information.
/// The default page size on GitHub.com is 30.
/// </remarks>
/// <param name="request">Search parameters to filter results on</param>
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>A <see cref="IReadOnlyPagedCollection{Repository}"/> of <see cref="Repository"/>.</returns>
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate",
Justification = "Makes a network request")]
Task<IReadOnlyList<Repository>> GetAllForCurrent(RepositoryRequest request);
/// <summary>
/// Gets all repositories owned by the specified user.
/// </summary>
+18
View File
@@ -204,6 +204,24 @@ namespace Octokit
return ApiConnection.GetAll<Repository>(ApiUrls.Repositories());
}
/// <summary>
/// Gets all repositories owned by the current user.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/#list-your-repositories">API documentation</a> for more information.
/// The default page size on GitHub.com is 30.
/// </remarks>
/// <param name="request">Search parameters to filter results on</param>
/// <exception cref="AuthorizationException">Thrown if the client is not authenticated.</exception>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>A <see cref="IReadOnlyPagedCollection{Repository}"/> of <see cref="Repository"/>.</returns>
public Task<IReadOnlyList<Repository>> GetAllForCurrent(RepositoryRequest request)
{
Ensure.ArgumentNotNull(request, "request");
return ApiConnection.GetAll<Repository>(ApiUrls.Repositories(), request.ToParametersDictionary());
}
/// <summary>
/// Gets all repositories owned by the specified user.
/// </summary>
@@ -0,0 +1,45 @@
using System;
using System.Diagnostics;
using System.Globalization;
using Octokit.Internal;
namespace Octokit
{
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class RepositoryRequest : RequestParameters
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1721:PropertyNamesShouldNotMatchGetMethods")]
public RepositoryType Type { get; set; }
public RepositorySort Sort { get; set; }
public SortDirection Direction { get; set; }
internal string DebuggerDisplay
{
get
{
return String.Format(CultureInfo.InvariantCulture, "Type: {0}, Sort: {1}, Direction: {2}", Type, Sort, Direction);
}
}
}
public enum RepositoryType
{
All,
Owner,
Public,
Private,
Member
}
public enum RepositorySort
{
Created,
Updated,
Pushed,
[Parameter(Value = "full_name")]
FullName
}
}
+1
View File
@@ -368,6 +368,7 @@
<Compile Include="Http\Response.cs" />
<Compile Include="Models\Response\PublicKey.cs" />
<Compile Include="Models\Request\ReleaseAssetUpload.cs" />
<Compile Include="Models\Request\RepositoryRequest.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
+1
View File
@@ -380,6 +380,7 @@
<Compile Include="Models\Request\GistFileUpdate.cs" />
<Compile Include="Models\Response\AccountType.cs" />
<Compile Include="Models\Request\ReleaseAssetUpload.cs" />
<Compile Include="Models\Request\RepositoryRequest.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
</Project>
+2 -1
View File
@@ -373,7 +373,8 @@
<Compile Include="Models\Request\GistFileUpdate.cs" />
<Compile Include="Models\Response\AccountType.cs" />
<Compile Include="Models\Request\ReleaseAssetUpload.cs" />
<Compile Include="Models\Request\RepositoryRequest.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.MonoTouch.CSharp.targets" />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
</Project>
+2 -1
View File
@@ -366,6 +366,7 @@
<Compile Include="Models\Response\PublicKey.cs" />
<Compile Include="Models\Request\GistFileUpdate.cs" />
<Compile Include="Models\Request\ReleaseAssetUpload.cs" />
<Compile Include="Models\Request\RepositoryRequest.cs" />
</ItemGroup>
<ItemGroup>
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">
@@ -396,4 +397,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
+1
View File
@@ -370,6 +370,7 @@
<Compile Include="Models\Response\PublicKey.cs" />
<Compile Include="Models\Request\GistFileUpdate.cs" />
<Compile Include="Models\Request\ReleaseAssetUpload.cs" />
<Compile Include="Models\Request\RepositoryRequest.cs" />
</ItemGroup>
<ItemGroup>
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">
+1
View File
@@ -84,6 +84,7 @@
<Compile Include="Models\Request\GistFileUpdate.cs" />
<Compile Include="Models\Request\NewMerge.cs" />
<Compile Include="Models\Request\ReleaseAssetUpload.cs" />
<Compile Include="Models\Request\RepositoryRequest.cs" />
<Compile Include="Models\Request\Signature.cs" />
<Compile Include="Models\Request\CreateFileRequest.cs" />
<Compile Include="Http\Response.cs" />