Add ObservableUserGpgKeysClient and fixes to satisfy convention tests

This commit is contained in:
Henrik Andersson
2016-06-05 15:09:13 +10:00
parent 06700b21f5
commit 3ad22b5d9d
13 changed files with 233 additions and 13 deletions
@@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reactive;
using System.Text;
using System.Threading.Tasks;
namespace Octokit.Reactive
{
/// <summary>
/// A client for GitHub's UserUser GPG Keys API.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/users/gpg_keys/">User GPG Keys documentation</a> for more information.
/// </remarks>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Gpg")]
public interface IObservableUserGpgKeysClient
{
/// <summary>
/// Gets all GPG keys for the authenticated user.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/users/gpg_keys/#list-your-gpg-keys">API documentation</a> for more information.
/// </remarks>
/// <returns>A <see cref="IReadOnlyList{GpgKey}"/> of <see cref="GpgKey"/>s for the current user.</returns>
IObservable<GpgKey> GetAllForCurrent();
/// <summary>
/// Gets all GPG keys for the authenticated user.
/// </summary>
/// <param name="options">Options for changing the API response</param>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/users/gpg_keys/#list-your-gpg-keys">API documentation</a> for more information.
/// </remarks>
/// <returns>A <see cref="IReadOnlyList{GpgKey}"/> of <see cref="GpgKey"/>s for the current user.</returns>
IObservable<GpgKey> GetAllForCurrent(ApiOptions options);
/// <summary>
/// View extended details of the <see cref="GpgKey"/> for the specified id.
/// </summary>
/// <param name="id">The ID of the GPG key</param>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/users/gpg_keys/#get-a-single-gpg-key">API documentation</a> for more information.
/// </remarks>
/// <returns>The <see cref="GpgKey"/> for the specified ID.</returns>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")]
IObservable<GpgKey> Get(int id);
/// <summary>
/// Creates a new <see cref="GpgKey"/> for the authenticated user.
/// </summary>
/// <param name="newGpgKey">The new GPG key to add.</param>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/users/gpg_keys/#create-a-gpg-key">API documentation</a> for more information.
/// </remarks>
/// <returns>The newly created <see cref="GpgKey"/>.</returns>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Gpg")]
IObservable<GpgKey> Create(NewGpgKey newGpgKey);
/// <summary>
/// Deletes the GPG key for the specified ID.
/// </summary>
/// <param name="id">The ID of the GPG key to delete.</param>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/users/gpg_keys/#delete-a-gpg-key">API documentation</a> for more information.
/// </remarks>
/// <returns></returns>
IObservable<Unit> Delete(int id);
}
}
@@ -52,6 +52,15 @@ namespace Octokit.Reactive
///</remarks>
IObservableUserKeysClient Keys { get; }
/// <summary>
/// A client for GitHub's UserUser GPG Keys API.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/users/gpg_keys/">User GPG Keys documentation</a> for more information.
/// </remarks>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Gpg")]
IObservableUserGpgKeysClient GpgKeys { get; }
/// <summary>
/// A client for GitHub's User Administration API
/// </summary>
@@ -0,0 +1,99 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reactive;
using System.Reactive.Linq;
using System.Reactive.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using Octokit.Reactive.Internal;
namespace Octokit.Reactive
{
/// <summary>
/// A client for GitHub's UserUser GPG Keys API.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/users/gpg_keys/">User GPG Keys documentation</a> for more information.
/// </remarks>
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Gpg")]
public class ObservableUserGpgKeysClient : IObservableUserGpgKeysClient
{
readonly IUserGpgKeysClient _client;
public ObservableUserGpgKeysClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, "client");
_client = client.User.GpgKeys;
}
/// <summary>
/// Gets all GPG keys for the authenticated user.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/users/gpg_keys/#list-your-gpg-keys">API documentation</a> for more information.
/// </remarks>
/// <returns>A <see cref="IReadOnlyList{GpgKey}"/> of <see cref="GpgKey"/>s for the current user.</returns>
public IObservable<GpgKey> GetAllForCurrent()
{
return GetAllForCurrent(ApiOptions.None);
}
/// <summary>
/// Gets all GPG keys for the authenticated user.
/// </summary>
/// <param name="options">Options for changing the API response</param>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/users/gpg_keys/#list-your-gpg-keys">API documentation</a> for more information.
/// </remarks>
/// <returns>A <see cref="IReadOnlyList{GpgKey}"/> of <see cref="GpgKey"/>s for the current user.</returns>
public IObservable<GpgKey> GetAllForCurrent(ApiOptions options)
{
return _client.GetAllForCurrent(options).ToObservable().SelectMany(k => k);
}
/// <summary>
/// View extended details of the <see cref="GpgKey"/> for the specified id.
/// </summary>
/// <param name="id">The ID of the GPG key</param>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/users/gpg_keys/#get-a-single-gpg-key">API documentation</a> for more information.
/// </remarks>
/// <returns>The <see cref="GpgKey"/> for the specified ID.</returns>
public IObservable<GpgKey> Get(int id)
{
return _client.Get(id).ToObservable();
}
/// <summary>
/// Creates a new <see cref="GpgKey"/> for the authenticated user.
/// </summary>
/// <param name="newGpgKey">The new GPG key to add.</param>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/users/gpg_keys/#create-a-gpg-key">API documentation</a> for more information.
/// </remarks>
/// <returns>The newly created <see cref="GpgKey"/>.</returns>
public IObservable<GpgKey> Create(NewGpgKey newGpgKey)
{
Ensure.ArgumentNotNull(newGpgKey, "newGpgKey");
return _client.Create(newGpgKey).ToObservable();
}
/// <summary>
/// Deletes the GPG key for the specified ID.
/// </summary>
/// <param name="id">The ID of the GPG key to delete.</param>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/users/gpg_keys/#delete-a-gpg-key">API documentation</a> for more information.
/// </remarks>
/// <returns></returns>
public IObservable<Unit> Delete(int id)
{
return _client.Delete(id).ToObservable();
}
}
}
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reactive.Threading.Tasks;
namespace Octokit.Reactive
@@ -16,6 +17,7 @@ namespace Octokit.Reactive
Followers = new ObservableFollowersClient(client);
Email = new ObservableUserEmailsClient(client);
Keys = new ObservableUserKeysClient(client);
GpgKeys = new ObservableUserGpgKeysClient(client);
Administration = new ObservableUserAdministrationClient(client);
}
@@ -77,6 +79,15 @@ namespace Octokit.Reactive
///</remarks>
public IObservableUserKeysClient Keys { get; private set; }
/// <summary>
/// A client for GitHub's UserUser GPG Keys API.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/users/gpg_keys/">User GPG Keys documentation</a> for more information.
/// </remarks>
public IObservableUserGpgKeysClient GpgKeys { get; private set; }
/// <summary>
/// A client for GitHub's User Administration API
/// </summary>
@@ -180,6 +180,8 @@
<Compile Include="Clients\IObservableMigrationsClient.cs" />
<Compile Include="Clients\ObservableMigrationClient.cs" />
<Compile Include="Clients\ObservableMigrationsClient.cs" />
<Compile Include="Clients\IObservableUserGpgKeysClient.cs" />
<Compile Include="Clients\ObservableUserGpgKeysClient.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
@@ -188,4 +190,4 @@
<Name>Octokit-Mono</Name>
</ProjectReference>
</ItemGroup>
</Project>
</Project>
@@ -188,6 +188,8 @@
<Compile Include="Clients\IObservableMigrationsClient.cs" />
<Compile Include="Clients\ObservableMigrationClient.cs" />
<Compile Include="Clients\ObservableMigrationsClient.cs" />
<Compile Include="Clients\IObservableUserGpgKeysClient.cs" />
<Compile Include="Clients\ObservableUserGpgKeysClient.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
<ItemGroup>
@@ -196,4 +198,4 @@
<Name>Octokit-MonoAndroid</Name>
</ProjectReference>
</ItemGroup>
</Project>
</Project>
@@ -184,6 +184,8 @@
<Compile Include="Clients\IObservableMigrationsClient.cs" />
<Compile Include="Clients\ObservableMigrationClient.cs" />
<Compile Include="Clients\ObservableMigrationsClient.cs" />
<Compile Include="Clients\IObservableUserGpgKeysClient.cs" />
<Compile Include="Clients\ObservableUserGpgKeysClient.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
@@ -192,4 +194,4 @@
<Name>Octokit-Monotouch</Name>
</ProjectReference>
</ItemGroup>
</Project>
</Project>
+2
View File
@@ -98,6 +98,7 @@
<Compile Include="Clients\IObservableRepositoryDeployKeysClient.cs" />
<Compile Include="Clients\IObservableRepositoryPagesClient.cs" />
<Compile Include="Clients\IObservableUserAdministrationClient.cs" />
<Compile Include="Clients\IObservableUserGpgKeysClient.cs" />
<Compile Include="Clients\IObservableUserKeysClient.cs" />
<Compile Include="Clients\ObservableMigrationsClient.cs" />
<Compile Include="Clients\ObservableMergingClient.cs" />
@@ -179,6 +180,7 @@
<Compile Include="Clients\ObservableFollowersClient.cs" />
<Compile Include="Clients\ObservableUserAdministrationClient.cs" />
<Compile Include="Clients\ObservableUserEmailsClient.cs" />
<Compile Include="Clients\ObservableUserGpgKeysClient.cs" />
<Compile Include="Clients\ObservableUserKeysClient.cs" />
<Compile Include="Clients\ObservableUsersClient.cs" />
<Compile Include="Clients\IObservableAssigneesClient.cs" />
@@ -10,6 +10,16 @@ namespace Octokit.Tests.Clients
{
public class UserGpgKeysClientTests
{
public class TheCtor
{
[Fact]
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new UserGpgKeysClient(null));
}
}
public class TheGetAllForCurrentMethod
{
[Fact]
@@ -105,14 +115,5 @@ namespace Octokit.Tests.Clients
Arg.Is<string>(s => s == AcceptHeaders.GpgKeysPreview));
}
}
public class TheCtor
{
[Fact]
public void EnsuresNonNullArgument()
{
Assert.Throws<ArgumentNullException>(() => new UserGpgKeysClient(null));
}
}
}
}
+3
View File
@@ -27,6 +27,9 @@ namespace Octokit
///</remarks>
IUserKeysClient Keys { get; }
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Gpg")]
IUserGpgKeysClient GpgKeys { get; }
/// <summary>
/// Returns the user specified by the login.
/// </summary>
+10
View File
@@ -22,6 +22,8 @@ namespace Octokit
Email = new UserEmailsClient(apiConnection);
Followers = new FollowersClient(apiConnection);
Keys = new UserKeysClient(apiConnection);
GpgKeys = new UserGpgKeysClient(apiConnection);
Administration = new UserAdministrationClient(apiConnection);
}
@@ -41,6 +43,14 @@ namespace Octokit
///</remarks>
public IUserKeysClient Keys { get; private set; }
/// <summary>
/// A client for GitHub's UserUser GPG Keys API.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/users/gpg_keys/">User GPG Keys documentation</a> for more information.
/// </remarks>
public IUserGpgKeysClient GpgKeys { get; private set; }
/// <summary>
/// Returns the user specified by the login.
/// </summary>
+1 -1
View File
@@ -10,7 +10,7 @@ using System.Threading.Tasks;
namespace Octokit
{
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Gpg")]
[DebuggerDisplay("{DebuggerDisplay,nq")]
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class NewGpgKey
{
public NewGpgKey()
+8
View File
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -8,6 +10,7 @@ using Octokit.Internal;
namespace Octokit
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Gpg")]
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class GpgKey
{
public int Id { get; protected set; }
@@ -23,5 +26,10 @@ namespace Octokit
public bool CanCertify { get; protected set; }
public DateTimeOffset CreatedAt { get; protected set; }
public DateTimeOffset? ExpiresAt { get; protected set; }
internal string DebuggerDisplay
{
get { return string.Format(CultureInfo.InvariantCulture, "Id: {0} Key: {1}", Id, PublicKey); }
}
}
}