Merge pull request #525 from octokit/shiftkey/user-keys-client

started user keys support
This commit is contained in:
Brendan Forster
2014-07-10 10:40:47 +09:30
23 changed files with 316 additions and 1 deletions
@@ -0,0 +1,31 @@
using System;
namespace Octokit.Reactive
{
/// <summary>
/// A client for GitHub's User Keys API.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/users/keys/">User Keys API documentation</a> for more information.
/// </remarks>
public interface IObservableUserKeysClient
{
/// <summary>
/// Gets all public keys for the authenticated user.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/users/keys/#list-your-public-keys
/// </remarks>
/// <returns>The <see cref="PublicKey"/>s for the authenticated user.</returns>
IObservable<PublicKey> GetAll();
/// <summary>
/// Gets all verified public keys for a user.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/users/keys/#list-public-keys-for-a-user
/// </remarks>
/// <returns>The <see cref="PublicKey"/>s for the user.</returns>
IObservable<PublicKey> GetAll(string userName);
}
}
@@ -43,5 +43,13 @@ namespace Octokit.Reactive
/// See the <a href="http://developer.github.com/v3/users/emails/">Emails API documentation</a> for more information.
///</remarks>
IObservableUserEmailsClient Email { get; }
/// <summary>
/// A client for GitHub's User Keys API
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/users/keys/">Keys API documentation</a> for more information.
///</remarks>
IObservableUserKeysClient Keys { get; }
}
}
@@ -0,0 +1,48 @@
using System;
using System.Reactive.Linq;
using System.Reactive.Threading.Tasks;
namespace Octokit.Reactive
{
/// <summary>
/// A client for GitHub's User Keys API.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/users/keys/">User Keys API documentation</a> for more information.
/// </remarks>
public class ObservableUserKeysClient : IObservableUserKeysClient
{
readonly IUserKeysClient _client;
public ObservableUserKeysClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, "client");
_client = client.User.Keys;
}
/// <summary>
/// Gets all public keys for the authenticated user.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/users/keys/#list-your-public-keys
/// </remarks>
/// <returns>The <see cref="PublicKey"/>s for the authenticated user.</returns>
public IObservable<PublicKey> GetAll()
{
return _client.GetAll().ToObservable().SelectMany(k => k);
}
/// <summary>
/// Gets all verified public keys for a user.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/users/keys/#list-public-keys-for-a-user
/// </remarks>
/// <returns>The <see cref="PublicKey"/>s for the user.</returns>
public IObservable<PublicKey> GetAll(string userName)
{
return _client.GetAll(userName).ToObservable().SelectMany(k => k);
}
}
}
@@ -15,6 +15,7 @@ namespace Octokit.Reactive
Followers = new ObservableFollowersClient(client);
Email = new ObservableUserEmailsClient(client);
Keys = new ObservableUserKeysClient(client);
}
/// <summary>
@@ -66,5 +67,13 @@ namespace Octokit.Reactive
/// See the <a href="http://developer.github.com/v3/users/emails/">Emails API documentation</a> for more information.
///</remarks>
public IObservableUserEmailsClient Email { get; private set; }
/// <summary>
/// A client for GitHub's User Keys API
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/users/keys/">Keys API documentation</a> for more information.
///</remarks>
public IObservableUserKeysClient Keys { get; private set; }
}
}
@@ -144,6 +144,8 @@
<Compile Include="Clients\ObservableOauthClient.cs" />
<Compile Include="Clients\IObservableRepositoryDeployKeysClient.cs" />
<Compile Include="Clients\ObservableRepositoryDeployKeysClient.cs" />
<Compile Include="Clients\IObservableUserKeysClient.cs" />
<Compile Include="Clients\ObservableUserKeysClient.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
@@ -153,6 +153,8 @@
<Compile Include="Clients\ObservableOauthClient.cs" />
<Compile Include="Clients\IObservableRepositoryDeployKeysClient.cs" />
<Compile Include="Clients\ObservableRepositoryDeployKeysClient.cs" />
<Compile Include="Clients\IObservableUserKeysClient.cs" />
<Compile Include="Clients\ObservableUserKeysClient.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
<ItemGroup>
@@ -148,6 +148,8 @@
<Compile Include="Clients\ObservableOauthClient.cs" />
<Compile Include="Clients\IObservableRepositoryDeployKeysClient.cs" />
<Compile Include="Clients\ObservableRepositoryDeployKeysClient.cs" />
<Compile Include="Clients\IObservableUserKeysClient.cs" />
<Compile Include="Clients\ObservableUserKeysClient.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
+2
View File
@@ -76,6 +76,7 @@
<Compile Include="Clients\IObservableOauthClient.cs" />
<Compile Include="Clients\IObservableRepositoryCommitsClients.cs" />
<Compile Include="Clients\IObservableRepositoryDeployKeysClient.cs" />
<Compile Include="Clients\IObservableUserKeysClient.cs" />
<Compile Include="Clients\ObservableRepositoryDeployKeysClient.cs" />
<Compile Include="Clients\ObservableOauthClient.cs" />
<Compile Include="Clients\ObservableRepositoryCommentsClient.cs" />
@@ -144,6 +145,7 @@
<Compile Include="Clients\ObservableTreesClient.cs" />
<Compile Include="Clients\ObservableFollowersClient.cs" />
<Compile Include="Clients\ObservableUserEmailsClient.cs" />
<Compile Include="Clients\ObservableUserKeysClient.cs" />
<Compile Include="Clients\ObservableUsersClient.cs" />
<Compile Include="Clients\IObservableAssigneesClient.cs" />
<Compile Include="Clients\IObservableNotificationsClient.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);
}
}
}
@@ -78,6 +78,7 @@
<Compile Include="Clients\TreeClientTests.cs" />
<Compile Include="Clients\UserEmailsClientTests.cs" />
<Compile Include="Clients\FollowersClientTests.cs" />
<Compile Include="Clients\UserKeysClientTests.cs" />
<Compile Include="HttpClientAdapterTests.cs" />
<Compile Include="Clients\TeamsClientTests.cs" />
<Compile Include="IntegrationTestAttribute.cs" />
+32
View File
@@ -0,0 +1,32 @@
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Octokit
{
/// <summary>
/// A client for GitHub's User Keys API.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/users/keys/">User Keys API documentation</a> for more information.
/// </remarks>
public interface IUserKeysClient
{
/// <summary>
/// Gets all public keys for the authenticated user.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/users/keys/#list-your-public-keys
/// </remarks>
/// <returns>The <see cref="PublicKey"/>s for the authenticated user.</returns>
Task<IReadOnlyList<PublicKey>> GetAll();
/// <summary>
/// Gets all verified public keys for a user.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/users/keys/#list-public-keys-for-a-user
/// </remarks>
/// <returns>The <see cref="PublicKey"/>s for the user.</returns>
Task<IReadOnlyList<PublicKey>> GetAll(string userName);
}
}
+8
View File
@@ -19,6 +19,14 @@ namespace Octokit
///</remarks>
IUserEmailsClient Email { get; }
/// <summary>
/// A client for GitHub's User Keys API
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/users/keys/">Keys API documentation</a> for more information.
///</remarks>
IUserKeysClient Keys { get; }
/// <summary>
/// Returns the user specified by the login.
/// </summary>
+43
View File
@@ -0,0 +1,43 @@
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Octokit
{
/// <summary>
/// A client for GitHub's User Keys API.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/users/keys/">User Keys API documentation</a> for more information.
/// </remarks>
public class UserKeysClient : ApiClient, IUserKeysClient
{
public UserKeysClient(IApiConnection apiConnection)
: base(apiConnection)
{
}
/// <summary>
/// Gets all public keys for the authenticated user.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/users/keys/#list-your-public-keys
/// </remarks>
/// <returns>The <see cref="PublicKey"/>s for the authenticated user.</returns>
public Task<IReadOnlyList<PublicKey>> GetAll()
{
return ApiConnection.GetAll<PublicKey>(ApiUrls.Keys());
}
/// <summary>
/// Gets all verified public keys for a user.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/users/keys/#list-public-keys-for-a-user
/// </remarks>
/// <returns>The <see cref="PublicKey"/>s for the user.</returns>
public Task<IReadOnlyList<PublicKey>> GetAll(string userName)
{
return ApiConnection.GetAll<PublicKey>(ApiUrls.Keys(userName));
}
}
}
+9
View File
@@ -21,6 +21,7 @@ namespace Octokit
{
Email = new UserEmailsClient(apiConnection);
Followers = new FollowersClient(apiConnection);
Keys = new UserKeysClient(apiConnection);
}
/// <summary>
@@ -31,6 +32,14 @@ namespace Octokit
///</remarks>
public IUserEmailsClient Email { get; private set; }
/// <summary>
/// A client for GitHub's User Keys API
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/users/keys/">Keys API documentation</a> for more information.
///</remarks>
public IUserKeysClient Keys { get; private set; }
/// <summary>
/// Returns the user specified by the login.
/// </summary>
+19
View File
@@ -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);
}
}
}
+1 -1
View File
@@ -5,7 +5,7 @@ namespace Octokit
/// <summary>
/// Class for retrieving GitHub ApI URLs
/// </summary>
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);
+31
View File
@@ -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; }
/// <remarks>
/// Only visible for the current user, or with the correct OAuth scope
/// </remarks>
public string Url { get; set; }
/// <remarks>
/// Only visible for the current user, or with the correct OAuth scope
/// </remarks>
public string Title { get; set; }
internal string DebuggerDisplay
{
get
{
return String.Format(CultureInfo.InvariantCulture, "ID: {0} Key: {1}", Id, Key);
}
}
}
}
+4
View File
@@ -324,6 +324,10 @@
<Compile Include="Clients\RepositoryDeployKeysClient.cs" />
<Compile Include="Models\Request\NewDeployKey.cs" />
<Compile Include="Models\Response\DeployKey.cs" />
<Compile Include="Clients\IUserKeysClient.cs" />
<Compile Include="Clients\UserKeysClient.cs" />
<Compile Include="Models\Request\PublicKey.cs" />
<Compile Include="Helpers\ApiUrls.Keys.cs" />
<Compile Include="Helpers\SerializeNullAttribute.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+4
View File
@@ -334,6 +334,10 @@
<Compile Include="Clients\RepositoryDeployKeysClient.cs" />
<Compile Include="Models\Request\NewDeployKey.cs" />
<Compile Include="Models\Response\DeployKey.cs" />
<Compile Include="Clients\IUserKeysClient.cs" />
<Compile Include="Clients\UserKeysClient.cs" />
<Compile Include="Models\Request\PublicKey.cs" />
<Compile Include="Helpers\ApiUrls.Keys.cs" />
<Compile Include="Helpers\SerializeNullAttribute.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
+4
View File
@@ -329,6 +329,10 @@
<Compile Include="Clients\RepositoryDeployKeysClient.cs" />
<Compile Include="Models\Request\NewDeployKey.cs" />
<Compile Include="Models\Response\DeployKey.cs" />
<Compile Include="Clients\IUserKeysClient.cs" />
<Compile Include="Clients\UserKeysClient.cs" />
<Compile Include="Models\Request\PublicKey.cs" />
<Compile Include="Helpers\ApiUrls.Keys.cs" />
<Compile Include="Helpers\SerializeNullAttribute.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+4
View File
@@ -321,6 +321,10 @@
<Compile Include="Clients\RepositoryDeployKeysClient.cs" />
<Compile Include="Models\Request\NewDeployKey.cs" />
<Compile Include="Models\Response\DeployKey.cs" />
<Compile Include="Clients\IUserKeysClient.cs" />
<Compile Include="Clients\UserKeysClient.cs" />
<Compile Include="Models\Request\PublicKey.cs" />
<Compile Include="Helpers\ApiUrls.Keys.cs" />
<Compile Include="Helpers\SerializeNullAttribute.cs" />
</ItemGroup>
<ItemGroup>
+4
View File
@@ -325,6 +325,10 @@
<Compile Include="Clients\RepositoryDeployKeysClient.cs" />
<Compile Include="Models\Request\NewDeployKey.cs" />
<Compile Include="Models\Response\DeployKey.cs" />
<Compile Include="Clients\IUserKeysClient.cs" />
<Compile Include="Clients\UserKeysClient.cs" />
<Compile Include="Models\Request\PublicKey.cs" />
<Compile Include="Helpers\ApiUrls.Keys.cs" />
<Compile Include="Helpers\SerializeNullAttribute.cs" />
</ItemGroup>
<ItemGroup>
+4
View File
@@ -57,6 +57,7 @@
<Compile Include="Clients\IOAuthClient.cs" />
<Compile Include="Clients\IRepositoryCommitsClient.cs" />
<Compile Include="Clients\IRepositoryDeployKeysClient.cs" />
<Compile Include="Clients\IUserKeysClient.cs" />
<Compile Include="Clients\OAuthClient.cs" />
<Compile Include="Clients\RepositoryCommentsClient.cs" />
<Compile Include="Clients\IRepositoryCommentsClient.cs" />
@@ -64,14 +65,17 @@
<Compile Include="Clients\IFeedsClient.cs" />
<Compile Include="Clients\RepositoryCommitsClient.cs" />
<Compile Include="Clients\RepositoryDeployKeysClient.cs" />
<Compile Include="Clients\UserKeysClient.cs" />
<Compile Include="Exceptions\PrivateRepositoryQuotaExceededException.cs" />
<Compile Include="Exceptions\RepositoryExistsException.cs" />
<Compile Include="Helpers\ApiErrorExtensions.cs" />
<Compile Include="Helpers\ApiUrls.Keys.cs" />
<Compile Include="Helpers\ConcurrentCache.cs" />
<Compile Include="Helpers\HttpClientExtensions.cs" />
<Compile Include="Helpers\SerializeNullAttribute.cs" />
<Compile Include="Http\ProductHeaderValue.cs" />
<Compile Include="Models\Request\NewDeployKey.cs" />
<Compile Include="Models\Request\PublicKey.cs" />
<Compile Include="Models\Response\DeployKey.cs" />
<Compile Include="Models\Request\OauthLoginRequest.cs" />
<Compile Include="Models\Request\OauthTokenRequest.cs" />