Add pagination support (ApiOptions overloads) to UserKeys client. (#1278)

This commit is contained in:
Devesh Khandelwal
2016-04-29 09:47:24 +05:30
committed by Brendan Forster
parent 63a8c1d70a
commit e35f237214
6 changed files with 160 additions and 43 deletions

View File

@@ -13,14 +13,14 @@ namespace Octokit.Reactive
public interface IObservableUserKeysClient
{
/// <summary>
/// Gets all public keys for the authenticated user.
/// Gets all verified public keys for a user.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/users/keys/#list-your-public-keys
/// https://developer.github.com/v3/users/keys/#list-public-keys-for-a-user
/// </remarks>
/// <returns></returns>
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
IObservable<PublicKey> GetAllForCurrent();
/// <param name="userName">The @ handle of the user.</param>
/// <returns>Lists the verified public keys for a user.</returns>
IObservable<PublicKey> GetAll(string userName);
/// <summary>
/// Gets all verified public keys for a user.
@@ -28,8 +28,31 @@ namespace Octokit.Reactive
/// <remarks>
/// https://developer.github.com/v3/users/keys/#list-public-keys-for-a-user
/// </remarks>
/// <returns></returns>
IObservable<PublicKey> GetAll(string userName);
/// <param name="userName">The @ handle of the user.</param>
/// <param name="options">Options to change API's behavior.</param>
/// <returns>Lists the verified public keys for a user.</returns>
IObservable<PublicKey> GetAll(string userName, ApiOptions options);
/// <summary>
/// Gets all public keys for the authenticated user.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/users/keys/#list-your-public-keys
/// </remarks>
/// <returns>Lists the current user's keys.</returns>
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
IObservable<PublicKey> GetAllForCurrent();
/// <summary>
/// Gets all public keys for the authenticated user.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/users/keys/#list-your-public-keys
/// </remarks>
/// <param name="options">Options to change API's behavior.</param>
/// <returns>Lists the current user's keys.</returns>
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
IObservable<PublicKey> GetAllForCurrent(ApiOptions options);
/// <summary>
/// Retrieves the <see cref="PublicKey"/> for the specified id.
@@ -38,7 +61,7 @@ namespace Octokit.Reactive
/// https://developer.github.com/v3/users/keys/#get-a-single-public-key
/// </remarks>
/// <param name="id">The ID of the SSH key</param>
/// <returns></returns>
/// <returns>View extended details for a single public key.</returns>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")]
IObservable<PublicKey> Get(int id);
@@ -49,7 +72,7 @@ namespace Octokit.Reactive
/// https://developer.github.com/v3/users/keys/#create-a-public-key
/// </remarks>
/// <param name="newKey">The SSH Key contents</param>
/// <returns></returns>
/// <returns>Creates a public key.</returns>
IObservable<PublicKey> Create(NewPublicKey newKey);
/// <summary>
@@ -59,7 +82,7 @@ namespace Octokit.Reactive
/// https://developer.github.com/v3/users/keys/#delete-a-public-key
/// </remarks>
/// <param name="id">The id of the key to delete</param>
/// <returns></returns>
/// <returns>Removes a public key.</returns>
IObservable<Unit> Delete(int id);
}
}

View File

@@ -23,15 +23,18 @@ namespace Octokit.Reactive
}
/// <summary>
/// Gets all public keys for the authenticated user.
/// Gets all verified public keys for a user.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/users/keys/#list-your-public-keys
/// https://developer.github.com/v3/users/keys/#list-public-keys-for-a-user
/// </remarks>
/// <returns></returns>
public IObservable<PublicKey> GetAllForCurrent()
/// <param name="userName">The @ handle of the user.</param>
/// <returns>Lists the verified public keys for a user.</returns>
public IObservable<PublicKey> GetAll(string userName)
{
return _client.GetAllForCurrent().ToObservable().SelectMany(k => k);
Ensure.ArgumentNotNullOrEmptyString(userName, "userName");
return GetAll(userName, ApiOptions.None);
}
/// <summary>
@@ -40,10 +43,42 @@ namespace Octokit.Reactive
/// <remarks>
/// https://developer.github.com/v3/users/keys/#list-public-keys-for-a-user
/// </remarks>
/// <returns></returns>
public IObservable<PublicKey> GetAll(string userName)
/// <param name="userName">The @ handle of the user.</param>
/// <param name="options">Options to change API's behavior.</param>
/// <returns>Lists the verified public keys for a user.</returns>
public IObservable<PublicKey> GetAll(string userName, ApiOptions options)
{
return _client.GetAll(userName).ToObservable().SelectMany(k => k);
Ensure.ArgumentNotNullOrEmptyString(userName, "userName");
Ensure.ArgumentNotNull(options, "options");
return _client.GetAll(userName, options).ToObservable().SelectMany(k => k);
}
/// <summary>
/// Gets all public keys for the authenticated user.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/users/keys/#list-your-public-keys
/// </remarks>
/// <returns>Lists the current user's keys.</returns>
public IObservable<PublicKey> GetAllForCurrent()
{
return GetAllForCurrent(ApiOptions.None);
}
/// <summary>
/// Gets all public keys for the authenticated user.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/users/keys/#list-your-public-keys
/// </remarks>
/// <param name="options">Options to change API's behavior.</param>
/// <returns>Lists the current user's keys.</returns>
public IObservable<PublicKey> GetAllForCurrent(ApiOptions options)
{
Ensure.ArgumentNotNull(options, "options");
return _client.GetAllForCurrent(options).ToObservable().SelectMany(k => k);
}
/// <summary>
@@ -53,7 +88,7 @@ namespace Octokit.Reactive
/// https://developer.github.com/v3/users/keys/#get-a-single-public-key
/// </remarks>
/// <param name="id">The ID of the SSH key</param>
/// <returns></returns>
/// <returns>View extended details for a single public key.</returns>
public IObservable<PublicKey> Get(int id)
{
return _client.Get(id).ToObservable();
@@ -66,7 +101,7 @@ namespace Octokit.Reactive
/// https://developer.github.com/v3/users/keys/#create-a-public-key
/// </remarks>
/// <param name="newKey">The SSH Key contents</param>
/// <returns></returns>
/// <returns>Creates a public key.</returns>
public IObservable<PublicKey> Create(NewPublicKey newKey)
{
Ensure.ArgumentNotNull(newKey, "newKey");
@@ -81,7 +116,7 @@ namespace Octokit.Reactive
/// https://developer.github.com/v3/users/keys/#delete-a-public-key
/// </remarks>
/// <param name="id">The id of the key to delete</param>
/// <returns></returns>
/// <returns>Removes a public key.</returns>
public IObservable<Unit> Delete(int id)
{
return _client.Delete(id).ToObservable();

View File

@@ -19,7 +19,8 @@ namespace Octokit.Tests.Clients
client.GetAllForCurrent();
connection.Received().GetAll<PublicKey>(
Arg.Is<Uri>(u => u.ToString() == expectedUri));
Arg.Is<Uri>(u => u.ToString() == expectedUri),
Arg.Any<ApiOptions>());
}
}
@@ -30,6 +31,7 @@ namespace Octokit.Tests.Clients
{
var client = new UserKeysClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll("fake", null));
}
[Fact]
@@ -50,7 +52,8 @@ namespace Octokit.Tests.Clients
client.GetAll("auser");
connection.Received().GetAll<PublicKey>(
Arg.Is<Uri>(u => u.ToString() == expectedUri));
Arg.Is<Uri>(u => u.ToString() == expectedUri),
Arg.Any<ApiOptions>());
}
}

View File

@@ -17,7 +17,7 @@ namespace Octokit.Tests.Reactive
client.GetAllForCurrent();
gitHubClient.User.Keys.Received().GetAllForCurrent();
gitHubClient.User.Keys.Received().GetAllForCurrent(Arg.Any<ApiOptions>());
}
}
@@ -31,7 +31,7 @@ namespace Octokit.Tests.Reactive
client.GetAll("auser");
gitHubClient.User.Keys.Received().GetAll("auser");
gitHubClient.User.Keys.Received().GetAll("auser", Arg.Any<ApiOptions>());
}
}

View File

@@ -13,14 +13,14 @@ namespace Octokit
public interface IUserKeysClient
{
/// <summary>
/// Gets all public keys for the authenticated user.
/// Gets all verified public keys for a user.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/users/keys/#list-your-public-keys
/// https://developer.github.com/v3/users/keys/#list-public-keys-for-a-user
/// </remarks>
/// <returns></returns>
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
Task<IReadOnlyList<PublicKey>> GetAllForCurrent();
/// <param name="userName">The @ handle of the user.</param>
/// <returns>Lists the verified public keys for a user.</returns>
Task<IReadOnlyList<PublicKey>> GetAll(string userName);
/// <summary>
/// Gets all verified public keys for a user.
@@ -28,8 +28,31 @@ namespace Octokit
/// <remarks>
/// https://developer.github.com/v3/users/keys/#list-public-keys-for-a-user
/// </remarks>
/// <returns></returns>
Task<IReadOnlyList<PublicKey>> GetAll(string userName);
/// <param name="userName">The @ handle of the user.</param>
/// <param name="options">Options to change API's behavior.</param>
/// <returns>Lists the verified public keys for a user.</returns>
Task<IReadOnlyList<PublicKey>> GetAll(string userName, ApiOptions options);
/// <summary>
/// Gets all public keys for the authenticated user.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/users/keys/#list-your-public-keys
/// </remarks>
/// <returns>Lists the current user's keys.</returns>
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
Task<IReadOnlyList<PublicKey>> GetAllForCurrent();
/// <summary>
/// Gets all public keys for the authenticated user.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/users/keys/#list-your-public-keys
/// </remarks>
/// <param name="options">Options to change API's behavior.</param>
/// <returns>Lists the current user's keys.</returns>
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
Task<IReadOnlyList<PublicKey>> GetAllForCurrent(ApiOptions options);
/// <summary>
/// Retrieves the <see cref="PublicKey"/> for the specified id.
@@ -38,7 +61,7 @@ namespace Octokit
/// https://developer.github.com/v3/users/keys/#get-a-single-public-key
/// </remarks>
/// <param name="id">The ID of the SSH key</param>
/// <returns></returns>
/// <returns>View extended details for a single public key.</returns>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")]
Task<PublicKey> Get(int id);
@@ -49,7 +72,7 @@ namespace Octokit
/// https://developer.github.com/v3/users/keys/#create-a-public-key
/// </remarks>
/// <param name="newKey">The SSH Key contents</param>
/// <returns></returns>
/// <returns>Creates a public key.</returns>
Task<PublicKey> Create(NewPublicKey newKey);
/// <summary>
@@ -59,7 +82,7 @@ namespace Octokit
/// https://developer.github.com/v3/users/keys/#delete-a-public-key
/// </remarks>
/// <param name="id">The id of the key to delete</param>
/// <returns></returns>
/// <returns>Removes a public key.</returns>
Task Delete(int id);
}
}

View File

@@ -17,15 +17,18 @@ namespace Octokit
}
/// <summary>
/// Gets all public keys for the authenticated user.
/// Gets all verified public keys for a user.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/users/keys/#list-your-public-keys
/// https://developer.github.com/v3/users/keys/#list-public-keys-for-a-user
/// </remarks>
/// <returns></returns>
public Task<IReadOnlyList<PublicKey>> GetAllForCurrent()
/// <param name="userName">The @ handle of the user.</param>
/// <returns>Lists the verified public keys for a user.</returns>
public Task<IReadOnlyList<PublicKey>> GetAll(string userName)
{
return ApiConnection.GetAll<PublicKey>(ApiUrls.Keys());
Ensure.ArgumentNotNullOrEmptyString(userName, "userName");
return GetAll(userName, ApiOptions.None);
}
/// <summary>
@@ -34,12 +37,42 @@ namespace Octokit
/// <remarks>
/// https://developer.github.com/v3/users/keys/#list-public-keys-for-a-user
/// </remarks>
/// <returns></returns>
public Task<IReadOnlyList<PublicKey>> GetAll(string userName)
/// <param name="userName">The @ handle of the user.</param>
/// <param name="options">Options to change API's behavior.</param>
/// <returns>Lists the verified public keys for a user.</returns>
public Task<IReadOnlyList<PublicKey>> GetAll(string userName, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(userName, "userName");
Ensure.ArgumentNotNull(options, "options");
return ApiConnection.GetAll<PublicKey>(ApiUrls.Keys(userName));
return ApiConnection.GetAll<PublicKey>(ApiUrls.Keys(userName), options);
}
/// <summary>
/// Gets all public keys for the authenticated user.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/users/keys/#list-your-public-keys
/// </remarks>
/// <returns>Lists the current user's keys.</returns>
public Task<IReadOnlyList<PublicKey>> GetAllForCurrent()
{
return GetAllForCurrent(ApiOptions.None);
}
/// <summary>
/// Gets all public keys for the authenticated user.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/users/keys/#list-your-public-keys
/// </remarks>
/// <param name="options">Options to chagne API's behavior.</param>
/// <returns>Lists the current user's keys.</returns>
public Task<IReadOnlyList<PublicKey>> GetAllForCurrent(ApiOptions options)
{
Ensure.ArgumentNotNull(options, "options");
return ApiConnection.GetAll<PublicKey>(ApiUrls.Keys(), options);
}
/// <summary>