diff --git a/Octokit.Reactive/Clients/IObservableUserKeysClient.cs b/Octokit.Reactive/Clients/IObservableUserKeysClient.cs new file mode 100644 index 00000000..a26686e0 --- /dev/null +++ b/Octokit.Reactive/Clients/IObservableUserKeysClient.cs @@ -0,0 +1,31 @@ +using System; + +namespace Octokit.Reactive +{ + /// + /// A client for GitHub's User Keys API. + /// + /// + /// See the User Keys API documentation for more information. + /// + public interface IObservableUserKeysClient + { + /// + /// Gets all public keys for the authenticated user. + /// + /// + /// https://developer.github.com/v3/users/keys/#list-your-public-keys + /// + /// The s for the authenticated user. + IObservable GetAll(); + + /// + /// Gets all verified public keys for a user. + /// + /// + /// https://developer.github.com/v3/users/keys/#list-public-keys-for-a-user + /// + /// The s for the user. + IObservable GetAll(string userName); + } +} diff --git a/Octokit.Reactive/Clients/IObservableUsersClient.cs b/Octokit.Reactive/Clients/IObservableUsersClient.cs index 2cc3ceb0..20ab684d 100644 --- a/Octokit.Reactive/Clients/IObservableUsersClient.cs +++ b/Octokit.Reactive/Clients/IObservableUsersClient.cs @@ -43,5 +43,13 @@ namespace Octokit.Reactive /// See the Emails API documentation for more information. /// IObservableUserEmailsClient Email { get; } + + /// + /// A client for GitHub's User Keys API + /// + /// + /// See the Keys API documentation for more information. + /// + IObservableUserKeysClient Keys { get; } } } diff --git a/Octokit.Reactive/Clients/ObservableUserKeysClient.cs b/Octokit.Reactive/Clients/ObservableUserKeysClient.cs new file mode 100644 index 00000000..8e43bdd8 --- /dev/null +++ b/Octokit.Reactive/Clients/ObservableUserKeysClient.cs @@ -0,0 +1,48 @@ +using System; +using System.Reactive.Linq; +using System.Reactive.Threading.Tasks; + +namespace Octokit.Reactive +{ + /// + /// A client for GitHub's User Keys API. + /// + /// + /// See the User Keys API documentation for more information. + /// + public class ObservableUserKeysClient : IObservableUserKeysClient + { + readonly IUserKeysClient _client; + + public ObservableUserKeysClient(IGitHubClient client) + { + Ensure.ArgumentNotNull(client, "client"); + + _client = client.User.Keys; + } + + /// + /// Gets all public keys for the authenticated user. + /// + /// + /// https://developer.github.com/v3/users/keys/#list-your-public-keys + /// + /// The s for the authenticated user. + public IObservable GetAll() + { + return _client.GetAll().ToObservable().SelectMany(k => k); + } + + /// + /// Gets all verified public keys for a user. + /// + /// + /// https://developer.github.com/v3/users/keys/#list-public-keys-for-a-user + /// + /// The s for the user. + public IObservable GetAll(string userName) + { + return _client.GetAll(userName).ToObservable().SelectMany(k => k); + } + } +} \ No newline at end of file diff --git a/Octokit.Reactive/Clients/ObservableUsersClient.cs b/Octokit.Reactive/Clients/ObservableUsersClient.cs index 4b8f7ace..1d6b9c6e 100644 --- a/Octokit.Reactive/Clients/ObservableUsersClient.cs +++ b/Octokit.Reactive/Clients/ObservableUsersClient.cs @@ -15,6 +15,7 @@ namespace Octokit.Reactive Followers = new ObservableFollowersClient(client); Email = new ObservableUserEmailsClient(client); + Keys = new ObservableUserKeysClient(client); } /// @@ -66,5 +67,13 @@ namespace Octokit.Reactive /// See the Emails API documentation for more information. /// public IObservableUserEmailsClient Email { get; private set; } + + /// + /// A client for GitHub's User Keys API + /// + /// + /// See the Keys API documentation for more information. + /// + public IObservableUserKeysClient Keys { get; private set; } } } diff --git a/Octokit.Reactive/Octokit.Reactive-Mono.csproj b/Octokit.Reactive/Octokit.Reactive-Mono.csproj index 153a4e0e..e952a858 100644 --- a/Octokit.Reactive/Octokit.Reactive-Mono.csproj +++ b/Octokit.Reactive/Octokit.Reactive-Mono.csproj @@ -144,6 +144,8 @@ + + diff --git a/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj b/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj index dac209cf..33dfb655 100644 --- a/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj +++ b/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj @@ -153,6 +153,8 @@ + + diff --git a/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj b/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj index 581837d2..03e99810 100644 --- a/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj +++ b/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj @@ -148,6 +148,8 @@ + + diff --git a/Octokit.Reactive/Octokit.Reactive.csproj b/Octokit.Reactive/Octokit.Reactive.csproj index fd8288d4..18f89bee 100644 --- a/Octokit.Reactive/Octokit.Reactive.csproj +++ b/Octokit.Reactive/Octokit.Reactive.csproj @@ -76,6 +76,7 @@ + @@ -144,6 +145,7 @@ + diff --git a/Octokit.Tests.Integration/Clients/UserKeysClientTests.cs b/Octokit.Tests.Integration/Clients/UserKeysClientTests.cs new file mode 100644 index 00000000..8d61050e --- /dev/null +++ b/Octokit.Tests.Integration/Clients/UserKeysClientTests.cs @@ -0,0 +1,44 @@ +using System.Threading.Tasks; +using Xunit; + +namespace Octokit.Tests.Integration.Clients +{ + public class UserKeysClientTests + { + [IntegrationTest] + public async Task GetAll() + { + var github = new GitHubClient(new ProductHeaderValue("OctokitTests")) + { + Credentials = Helper.Credentials + }; + + var keys = await github.User.Keys.GetAll(); + Assert.NotEmpty(keys); + + var first = keys[0]; + Assert.NotNull(first.Id); + Assert.NotNull(first.Key); + Assert.NotNull(first.Title); + Assert.NotNull(first.Url); + } + + [IntegrationTest] + public async Task GetAllForGivenUser() + { + var github = new GitHubClient(new ProductHeaderValue("OctokitTests")) + { + Credentials = Helper.Credentials + }; + + var keys = await github.User.Keys.GetAll("shiftkey"); + Assert.NotEmpty(keys); + + var first = keys[0]; + Assert.NotNull(first.Id); + Assert.NotNull(first.Key); + Assert.Null(first.Title); + Assert.Null(first.Url); + } + } +} diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index 97d9eff0..6ab0b6e6 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -78,6 +78,7 @@ + diff --git a/Octokit/Clients/IUserKeysClient.cs b/Octokit/Clients/IUserKeysClient.cs new file mode 100644 index 00000000..d04c9546 --- /dev/null +++ b/Octokit/Clients/IUserKeysClient.cs @@ -0,0 +1,32 @@ +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Octokit +{ + /// + /// A client for GitHub's User Keys API. + /// + /// + /// See the User Keys API documentation for more information. + /// + public interface IUserKeysClient + { + /// + /// Gets all public keys for the authenticated user. + /// + /// + /// https://developer.github.com/v3/users/keys/#list-your-public-keys + /// + /// The s for the authenticated user. + Task> GetAll(); + + /// + /// Gets all verified public keys for a user. + /// + /// + /// https://developer.github.com/v3/users/keys/#list-public-keys-for-a-user + /// + /// The s for the user. + Task> GetAll(string userName); + } +} diff --git a/Octokit/Clients/IUsersClient.cs b/Octokit/Clients/IUsersClient.cs index 607e849b..1e2cefe5 100644 --- a/Octokit/Clients/IUsersClient.cs +++ b/Octokit/Clients/IUsersClient.cs @@ -19,6 +19,14 @@ namespace Octokit /// IUserEmailsClient Email { get; } + /// + /// A client for GitHub's User Keys API + /// + /// + /// See the Keys API documentation for more information. + /// + IUserKeysClient Keys { get; } + /// /// Returns the user specified by the login. /// diff --git a/Octokit/Clients/UserKeysClient.cs b/Octokit/Clients/UserKeysClient.cs new file mode 100644 index 00000000..29cc3fb7 --- /dev/null +++ b/Octokit/Clients/UserKeysClient.cs @@ -0,0 +1,43 @@ +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Octokit +{ + /// + /// A client for GitHub's User Keys API. + /// + /// + /// See the User Keys API documentation for more information. + /// + public class UserKeysClient : ApiClient, IUserKeysClient + { + public UserKeysClient(IApiConnection apiConnection) + : base(apiConnection) + { + } + + /// + /// Gets all public keys for the authenticated user. + /// + /// + /// https://developer.github.com/v3/users/keys/#list-your-public-keys + /// + /// The s for the authenticated user. + public Task> GetAll() + { + return ApiConnection.GetAll(ApiUrls.Keys()); + } + + /// + /// Gets all verified public keys for a user. + /// + /// + /// https://developer.github.com/v3/users/keys/#list-public-keys-for-a-user + /// + /// The s for the user. + public Task> GetAll(string userName) + { + return ApiConnection.GetAll(ApiUrls.Keys(userName)); + } + } +} \ No newline at end of file diff --git a/Octokit/Clients/UsersClient.cs b/Octokit/Clients/UsersClient.cs index 54e185d3..03429382 100644 --- a/Octokit/Clients/UsersClient.cs +++ b/Octokit/Clients/UsersClient.cs @@ -21,6 +21,7 @@ namespace Octokit { Email = new UserEmailsClient(apiConnection); Followers = new FollowersClient(apiConnection); + Keys = new UserKeysClient(apiConnection); } /// @@ -31,6 +32,14 @@ namespace Octokit /// public IUserEmailsClient Email { get; private set; } + /// + /// A client for GitHub's User Keys API + /// + /// + /// See the Keys API documentation for more information. + /// + public IUserKeysClient Keys { get; private set; } + /// /// Returns the user specified by the login. /// diff --git a/Octokit/Helpers/ApiUrls.Keys.cs b/Octokit/Helpers/ApiUrls.Keys.cs new file mode 100644 index 00000000..b936322e --- /dev/null +++ b/Octokit/Helpers/ApiUrls.Keys.cs @@ -0,0 +1,19 @@ +using System; + +namespace Octokit +{ + public static partial class ApiUrls + { + static readonly Uri _currentUserKeysUrl = new Uri("user/keys", UriKind.Relative); + + public static Uri Keys() + { + return _currentUserKeysUrl; + } + + public static Uri Keys(string userName) + { + return "users/{0}/keys".FormatUri(userName); + } + } +} diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index 39021fd8..44dc39e2 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -5,7 +5,7 @@ namespace Octokit /// /// Class for retrieving GitHub ApI URLs /// - public static class ApiUrls + public static partial class ApiUrls { static readonly Uri _currentUserRepositoriesUrl = new Uri("user/repos", UriKind.Relative); static readonly Uri _currentUserOrganizationsUrl = new Uri("user/orgs", UriKind.Relative); diff --git a/Octokit/Models/Request/PublicKey.cs b/Octokit/Models/Request/PublicKey.cs new file mode 100644 index 00000000..925fd2a3 --- /dev/null +++ b/Octokit/Models/Request/PublicKey.cs @@ -0,0 +1,31 @@ +using System; +using System.Diagnostics; +using System.Globalization; + +namespace Octokit +{ + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class PublicKey + { + public int Id { get; set; } + public string Key { get; set; } + + /// + /// Only visible for the current user, or with the correct OAuth scope + /// + public string Url { get; set; } + + /// + /// Only visible for the current user, or with the correct OAuth scope + /// + public string Title { get; set; } + + internal string DebuggerDisplay + { + get + { + return String.Format(CultureInfo.InvariantCulture, "ID: {0} Key: {1}", Id, Key); + } + } + } +} diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index e2a34b78..cf135ed5 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -324,6 +324,10 @@ + + + + diff --git a/Octokit/Octokit-MonoAndroid.csproj b/Octokit/Octokit-MonoAndroid.csproj index 32316b15..bb4b6d1f 100644 --- a/Octokit/Octokit-MonoAndroid.csproj +++ b/Octokit/Octokit-MonoAndroid.csproj @@ -334,6 +334,10 @@ + + + + diff --git a/Octokit/Octokit-Monotouch.csproj b/Octokit/Octokit-Monotouch.csproj index 57bed6ab..09c2666f 100644 --- a/Octokit/Octokit-Monotouch.csproj +++ b/Octokit/Octokit-Monotouch.csproj @@ -329,6 +329,10 @@ + + + + diff --git a/Octokit/Octokit-Portable.csproj b/Octokit/Octokit-Portable.csproj index a0e014be..7cf66edd 100644 --- a/Octokit/Octokit-Portable.csproj +++ b/Octokit/Octokit-Portable.csproj @@ -321,6 +321,10 @@ + + + + diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index a4fbbca9..8ab09384 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -325,6 +325,10 @@ + + + + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 47539cbb..46051948 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -57,6 +57,7 @@ + @@ -64,14 +65,17 @@ + + +