From 3ad22b5d9da1ff6e6d3b6776b939d9d4622942c7 Mon Sep 17 00:00:00 2001 From: Henrik Andersson Date: Sun, 5 Jun 2016 15:09:13 +1000 Subject: [PATCH] Add ObservableUserGpgKeysClient and fixes to satisfy convention tests --- .../Clients/IObservableUserGpgKeysClient.cs | 71 +++++++++++++ .../Clients/IObservableUsersClient.cs | 9 ++ .../Clients/ObservableUserGpgKeysClient.cs | 99 +++++++++++++++++++ .../Clients/ObservableUsersClient.cs | 11 +++ Octokit.Reactive/Octokit.Reactive-Mono.csproj | 4 +- .../Octokit.Reactive-MonoAndroid.csproj | 4 +- .../Octokit.Reactive-Monotouch.csproj | 4 +- Octokit.Reactive/Octokit.Reactive.csproj | 2 + .../Clients/UserGpgKeysClientTests.cs | 19 ++-- Octokit/Clients/IUsersClient.cs | 3 + Octokit/Clients/UsersClient.cs | 10 ++ Octokit/Models/Request/NewGpgKey.cs | 2 +- Octokit/Models/Response/GpgKey.cs | 8 ++ 13 files changed, 233 insertions(+), 13 deletions(-) create mode 100644 Octokit.Reactive/Clients/IObservableUserGpgKeysClient.cs create mode 100644 Octokit.Reactive/Clients/ObservableUserGpgKeysClient.cs diff --git a/Octokit.Reactive/Clients/IObservableUserGpgKeysClient.cs b/Octokit.Reactive/Clients/IObservableUserGpgKeysClient.cs new file mode 100644 index 00000000..bd3ce360 --- /dev/null +++ b/Octokit.Reactive/Clients/IObservableUserGpgKeysClient.cs @@ -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 +{ + /// + /// A client for GitHub's UserUser GPG Keys API. + /// + /// + /// See the User GPG Keys documentation for more information. + /// + [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Gpg")] + public interface IObservableUserGpgKeysClient + { + /// + /// Gets all GPG keys for the authenticated user. + /// + /// + /// See the API documentation for more information. + /// + /// A of s for the current user. + IObservable GetAllForCurrent(); + + /// + /// Gets all GPG keys for the authenticated user. + /// + /// Options for changing the API response + /// + /// See the API documentation for more information. + /// + /// A of s for the current user. + IObservable GetAllForCurrent(ApiOptions options); + + /// + /// View extended details of the for the specified id. + /// + /// The ID of the GPG key + /// + /// See the API documentation for more information. + /// + /// The for the specified ID. + [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")] + IObservable Get(int id); + + /// + /// Creates a new for the authenticated user. + /// + /// The new GPG key to add. + /// + /// See the API documentation for more information. + /// + /// The newly created . + [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Gpg")] + IObservable Create(NewGpgKey newGpgKey); + + /// + /// Deletes the GPG key for the specified ID. + /// + /// The ID of the GPG key to delete. + /// + /// See the API documentation for more information. + /// + /// + IObservable Delete(int id); + } +} diff --git a/Octokit.Reactive/Clients/IObservableUsersClient.cs b/Octokit.Reactive/Clients/IObservableUsersClient.cs index 6672974a..faa0d502 100644 --- a/Octokit.Reactive/Clients/IObservableUsersClient.cs +++ b/Octokit.Reactive/Clients/IObservableUsersClient.cs @@ -52,6 +52,15 @@ namespace Octokit.Reactive /// IObservableUserKeysClient Keys { get; } + /// + /// A client for GitHub's UserUser GPG Keys API. + /// + /// + /// See the User GPG Keys documentation for more information. + /// + [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Gpg")] + IObservableUserGpgKeysClient GpgKeys { get; } + /// /// A client for GitHub's User Administration API /// diff --git a/Octokit.Reactive/Clients/ObservableUserGpgKeysClient.cs b/Octokit.Reactive/Clients/ObservableUserGpgKeysClient.cs new file mode 100644 index 00000000..5031b560 --- /dev/null +++ b/Octokit.Reactive/Clients/ObservableUserGpgKeysClient.cs @@ -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 +{ + /// + /// A client for GitHub's UserUser GPG Keys API. + /// + /// + /// See the User GPG Keys documentation for more information. + /// + [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; + } + + /// + /// Gets all GPG keys for the authenticated user. + /// + /// + /// See the API documentation for more information. + /// + /// A of s for the current user. + public IObservable GetAllForCurrent() + { + return GetAllForCurrent(ApiOptions.None); + } + + /// + /// Gets all GPG keys for the authenticated user. + /// + /// Options for changing the API response + /// + /// See the API documentation for more information. + /// + /// A of s for the current user. + public IObservable GetAllForCurrent(ApiOptions options) + { + return _client.GetAllForCurrent(options).ToObservable().SelectMany(k => k); + } + + /// + /// View extended details of the for the specified id. + /// + /// The ID of the GPG key + /// + /// See the API documentation for more information. + /// + /// The for the specified ID. + public IObservable Get(int id) + { + return _client.Get(id).ToObservable(); + } + + /// + /// Creates a new for the authenticated user. + /// + /// The new GPG key to add. + /// + /// See the API documentation for more information. + /// + /// The newly created . + public IObservable Create(NewGpgKey newGpgKey) + { + Ensure.ArgumentNotNull(newGpgKey, "newGpgKey"); + + return _client.Create(newGpgKey).ToObservable(); + } + + /// + /// Deletes the GPG key for the specified ID. + /// + /// The ID of the GPG key to delete. + /// + /// See the API documentation for more information. + /// + /// + public IObservable Delete(int id) + { + return _client.Delete(id).ToObservable(); + } + } +} diff --git a/Octokit.Reactive/Clients/ObservableUsersClient.cs b/Octokit.Reactive/Clients/ObservableUsersClient.cs index 7db13d3e..e5ba4f94 100644 --- a/Octokit.Reactive/Clients/ObservableUsersClient.cs +++ b/Octokit.Reactive/Clients/ObservableUsersClient.cs @@ -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 /// public IObservableUserKeysClient Keys { get; private set; } + /// + /// A client for GitHub's UserUser GPG Keys API. + /// + /// + /// See the User GPG Keys documentation for more information. + /// + public IObservableUserGpgKeysClient GpgKeys { get; private set; } + + /// /// A client for GitHub's User Administration API /// diff --git a/Octokit.Reactive/Octokit.Reactive-Mono.csproj b/Octokit.Reactive/Octokit.Reactive-Mono.csproj index 9601cc8d..1144a674 100644 --- a/Octokit.Reactive/Octokit.Reactive-Mono.csproj +++ b/Octokit.Reactive/Octokit.Reactive-Mono.csproj @@ -180,6 +180,8 @@ + + @@ -188,4 +190,4 @@ Octokit-Mono - + \ No newline at end of file diff --git a/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj b/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj index bf75c3bf..40d5e7c5 100644 --- a/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj +++ b/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj @@ -188,6 +188,8 @@ + + @@ -196,4 +198,4 @@ Octokit-MonoAndroid - + \ No newline at end of file diff --git a/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj b/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj index 065807bc..b8c011cc 100644 --- a/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj +++ b/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj @@ -184,6 +184,8 @@ + + @@ -192,4 +194,4 @@ Octokit-Monotouch - + \ No newline at end of file diff --git a/Octokit.Reactive/Octokit.Reactive.csproj b/Octokit.Reactive/Octokit.Reactive.csproj index 920aefbe..be972db3 100644 --- a/Octokit.Reactive/Octokit.Reactive.csproj +++ b/Octokit.Reactive/Octokit.Reactive.csproj @@ -98,6 +98,7 @@ + @@ -179,6 +180,7 @@ + diff --git a/Octokit.Tests/Clients/UserGpgKeysClientTests.cs b/Octokit.Tests/Clients/UserGpgKeysClientTests.cs index 4e5d49ae..73fe4df7 100644 --- a/Octokit.Tests/Clients/UserGpgKeysClientTests.cs +++ b/Octokit.Tests/Clients/UserGpgKeysClientTests.cs @@ -10,6 +10,16 @@ namespace Octokit.Tests.Clients { public class UserGpgKeysClientTests { + + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws(() => new UserGpgKeysClient(null)); + } + } + public class TheGetAllForCurrentMethod { [Fact] @@ -105,14 +115,5 @@ namespace Octokit.Tests.Clients Arg.Is(s => s == AcceptHeaders.GpgKeysPreview)); } } - - public class TheCtor - { - [Fact] - public void EnsuresNonNullArgument() - { - Assert.Throws(() => new UserGpgKeysClient(null)); - } - } } } diff --git a/Octokit/Clients/IUsersClient.cs b/Octokit/Clients/IUsersClient.cs index d08b41c6..046441ae 100644 --- a/Octokit/Clients/IUsersClient.cs +++ b/Octokit/Clients/IUsersClient.cs @@ -27,6 +27,9 @@ namespace Octokit /// IUserKeysClient Keys { get; } + [SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Gpg")] + IUserGpgKeysClient GpgKeys { get; } + /// /// Returns the user specified by the login. /// diff --git a/Octokit/Clients/UsersClient.cs b/Octokit/Clients/UsersClient.cs index 4e835142..e041615a 100644 --- a/Octokit/Clients/UsersClient.cs +++ b/Octokit/Clients/UsersClient.cs @@ -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 /// public IUserKeysClient Keys { get; private set; } + /// + /// A client for GitHub's UserUser GPG Keys API. + /// + /// + /// See the User GPG Keys documentation for more information. + /// + public IUserGpgKeysClient GpgKeys { get; private set; } + /// /// Returns the user specified by the login. /// diff --git a/Octokit/Models/Request/NewGpgKey.cs b/Octokit/Models/Request/NewGpgKey.cs index 428779b7..13d47736 100644 --- a/Octokit/Models/Request/NewGpgKey.cs +++ b/Octokit/Models/Request/NewGpgKey.cs @@ -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() diff --git a/Octokit/Models/Response/GpgKey.cs b/Octokit/Models/Response/GpgKey.cs index e7d6b9fa..616d91c5 100644 --- a/Octokit/Models/Response/GpgKey.cs +++ b/Octokit/Models/Response/GpgKey.cs @@ -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); } + } } }