mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-18 21:25:12 +00:00
Add UserGpgKeysClient
This commit is contained in:
71
Octokit/Clients/IUserGpgKeysClient.cs
Normal file
71
Octokit/Clients/IUserGpgKeysClient.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
/// <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 IUserGpgKeysClient
|
||||
{
|
||||
/// <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>
|
||||
Task<IReadOnlyList<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>
|
||||
Task<IReadOnlyList<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",
|
||||
Justification = "Method makes a network request")]
|
||||
Task<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")]
|
||||
Task<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>
|
||||
Task Delete(int id);
|
||||
}
|
||||
}
|
||||
88
Octokit/Clients/UserGpgKeysClient.cs
Normal file
88
Octokit/Clients/UserGpgKeysClient.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
/// <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 UserGpgKeysClient : ApiClient, IUserGpgKeysClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Instatiates a new GitHub User GPG Keys API client.
|
||||
/// </summary>
|
||||
/// <param name="apiConnection">The API connection.</param>
|
||||
public UserGpgKeysClient(IApiConnection apiConnection) : base(apiConnection)
|
||||
{
|
||||
}
|
||||
|
||||
/// <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 Task<IReadOnlyList<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 Task<IReadOnlyList<GpgKey>> GetAllForCurrent(ApiOptions options)
|
||||
{
|
||||
return ApiConnection.GetAll<GpgKey>(ApiUrls.GpgKeys(), null, AcceptHeaders.GpgKeysPreview, 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>
|
||||
public Task<GpgKey> Get(int id)
|
||||
{
|
||||
return ApiConnection.Get<GpgKey>(ApiUrls.GpgKeys(id), null, AcceptHeaders.GpgKeysPreview);
|
||||
}
|
||||
|
||||
/// <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 Task<GpgKey> Create(NewGpgKey newGpgKey)
|
||||
{
|
||||
return ApiConnection.Post<GpgKey>(ApiUrls.GpgKeys(), 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>
|
||||
public Task Delete(int id)
|
||||
{
|
||||
return ApiConnection.Delete(ApiUrls.GpgKeys(id));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
@@ -10,6 +11,7 @@ namespace Octokit
|
||||
static readonly Uri _currentUserRepositoriesUrl = new Uri("user/repos", UriKind.Relative);
|
||||
static readonly Uri _currentUserOrganizationsUrl = new Uri("user/orgs", UriKind.Relative);
|
||||
static readonly Uri _currentUserSshKeys = new Uri("user/keys", UriKind.Relative);
|
||||
static readonly Uri _currentUserGpgKeys = new Uri("user/gpg_keys", UriKind.Relative);
|
||||
static readonly Uri _currentUserStars = new Uri("user/starred", UriKind.Relative);
|
||||
static readonly Uri _currentUserWatched = new Uri("user/subscriptions", UriKind.Relative);
|
||||
static readonly Uri _currentUserEmailsEndpoint = new Uri("user/emails", UriKind.Relative);
|
||||
@@ -2146,6 +2148,27 @@ namespace Octokit
|
||||
return "repositories/{0}/events".FormatUri(repositoryId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the <see cref="Uri"/> that returns all the GPG Keys for the authenticated user.
|
||||
/// </summary>
|
||||
/// <returns>The <see cref="Uri"/> that returns all the GPG Keys for the authenticated user.</returns>
|
||||
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Gpg")]
|
||||
public static Uri GpgKeys()
|
||||
{
|
||||
return _currentUserGpgKeys;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the <see cref="Uri"/> that returns the GPG Key for the authenticated user for the specified ID.
|
||||
/// </summary>
|
||||
/// <param name="id">The <see cref="Uri"/> that returns the GPG Key for the authenticated user for the specified ID.</param>
|
||||
/// <returns></returns>
|
||||
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Gpg")]
|
||||
public static Uri GpgKeys(int id)
|
||||
{
|
||||
return "user/gpg_keys/{0}".FormatUri(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the <see cref="Uri"/> for the specified issue.
|
||||
/// </summary>
|
||||
|
||||
34
Octokit/Models/Request/NewGpgKey.cs
Normal file
34
Octokit/Models/Request/NewGpgKey.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Gpg")]
|
||||
[DebuggerDisplay("{DebuggerDisplay,nq")]
|
||||
public class NewGpgKey
|
||||
{
|
||||
public NewGpgKey()
|
||||
{
|
||||
}
|
||||
|
||||
public NewGpgKey(string publicKey)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(publicKey, "publicKey");
|
||||
|
||||
ArmoredPublicKey = publicKey;
|
||||
}
|
||||
|
||||
public string ArmoredPublicKey { get; set; }
|
||||
|
||||
internal string DebuggerDisplay
|
||||
{
|
||||
get { return string.Format(CultureInfo.InvariantCulture, "ArmoredPublicKey: {0}", ArmoredPublicKey); }
|
||||
}
|
||||
}
|
||||
}
|
||||
27
Octokit/Models/Response/GpgKey.cs
Normal file
27
Octokit/Models/Response/GpgKey.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Octokit.Internal;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Gpg")]
|
||||
public class GpgKey
|
||||
{
|
||||
public int Id { get; protected set; }
|
||||
public int? PrimaryKeyId { get; protected set; }
|
||||
public string KeyId { get; protected set; }
|
||||
public string PublicKey { get; protected set; }
|
||||
public IReadOnlyList<EmailAddress> Emails { get; protected set; }
|
||||
public IReadOnlyList<GpgKey> Subkeys { get; protected set; }
|
||||
public bool CanSign { get; protected set; }
|
||||
[Parameter(Key = "can_encrypt_comms")]
|
||||
public bool CanEncryptCommunications { get; protected set; }
|
||||
public bool CanEncryptStorage { get; protected set; }
|
||||
public bool CanCertify { get; protected set; }
|
||||
public DateTimeOffset CreatedAt { get; protected set; }
|
||||
public DateTimeOffset? ExpiresAt { get; protected set; }
|
||||
}
|
||||
}
|
||||
@@ -467,6 +467,10 @@
|
||||
<Compile Include="Models\Request\StartMigrationRequest.cs" />
|
||||
<Compile Include="Models\Response\Migration.cs" />
|
||||
<Compile Include="Models\Request\RepositoryPermissionRequest.cs" />
|
||||
<Compile Include="Clients\IUserGpgKeysClient.cs" />
|
||||
<Compile Include="Clients\UserGpgKeysClient.cs" />
|
||||
<Compile Include="Models\Request\NewGpgKey.cs" />
|
||||
<Compile Include="Models\Response\GpgKey.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -478,6 +478,10 @@
|
||||
<Compile Include="Models\Request\StartMigrationRequest.cs" />
|
||||
<Compile Include="Models\Response\Migration.cs" />
|
||||
<Compile Include="Models\Request\RepositoryPermissionRequest.cs" />
|
||||
<Compile Include="Clients\IUserGpgKeysClient.cs" />
|
||||
<Compile Include="Clients\UserGpgKeysClient.cs" />
|
||||
<Compile Include="Models\Request\NewGpgKey.cs" />
|
||||
<Compile Include="Models\Response\GpgKey.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -474,6 +474,10 @@
|
||||
<Compile Include="Models\Request\StartMigrationRequest.cs" />
|
||||
<Compile Include="Models\Response\Migration.cs" />
|
||||
<Compile Include="Models\Request\RepositoryPermissionRequest.cs" />
|
||||
<Compile Include="Clients\IUserGpgKeysClient.cs" />
|
||||
<Compile Include="Clients\UserGpgKeysClient.cs" />
|
||||
<Compile Include="Models\Request\NewGpgKey.cs" />
|
||||
<Compile Include="Models\Response\GpgKey.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.MonoTouch.CSharp.targets" />
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
|
||||
@@ -464,6 +464,10 @@
|
||||
<Compile Include="Models\Request\StartMigrationRequest.cs" />
|
||||
<Compile Include="Models\Response\Migration.cs" />
|
||||
<Compile Include="Models\Request\RepositoryPermissionRequest.cs" />
|
||||
<Compile Include="Clients\IUserGpgKeysClient.cs" />
|
||||
<Compile Include="Clients\UserGpgKeysClient.cs" />
|
||||
<Compile Include="Models\Request\NewGpgKey.cs" />
|
||||
<Compile Include="Models\Response\GpgKey.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">
|
||||
|
||||
@@ -471,6 +471,10 @@
|
||||
<Compile Include="Models\Request\StartMigrationRequest.cs" />
|
||||
<Compile Include="Models\Response\Migration.cs" />
|
||||
<Compile Include="Models\Request\RepositoryPermissionRequest.cs" />
|
||||
<Compile Include="Clients\IUserGpgKeysClient.cs" />
|
||||
<Compile Include="Clients\UserGpgKeysClient.cs" />
|
||||
<Compile Include="Models\Request\NewGpgKey.cs" />
|
||||
<Compile Include="Models\Response\GpgKey.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">
|
||||
|
||||
@@ -58,6 +58,7 @@
|
||||
<Link>Properties\SolutionInfo.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="Clients\ActivitiesClient.cs" />
|
||||
<Compile Include="Clients\IUserGpgKeysClient.cs" />
|
||||
<Compile Include="Clients\MigrationsClient.cs" />
|
||||
<Compile Include="Clients\Enterprise\EnterpriseAdminStatsClient.cs" />
|
||||
<Compile Include="Clients\Enterprise\EnterpriseLdapClient.cs" />
|
||||
@@ -93,6 +94,7 @@
|
||||
<Compile Include="Clients\RepositoryDeployKeysClient.cs" />
|
||||
<Compile Include="Clients\RepositoryPagesClient.cs" />
|
||||
<Compile Include="Clients\UserAdministrationClient.cs" />
|
||||
<Compile Include="Clients\UserGpgKeysClient.cs" />
|
||||
<Compile Include="Clients\UserKeysClient.cs" />
|
||||
<Compile Include="Clients\RepositoryContentsClient.cs" />
|
||||
<Compile Include="Exceptions\InvalidGitIgnoreTemplateException.cs" />
|
||||
@@ -120,6 +122,7 @@
|
||||
<Compile Include="Http\RequestBody.cs" />
|
||||
<Compile Include="Models\Request\BranchUpdate.cs" />
|
||||
<Compile Include="Models\Request\ApiOptions.cs" />
|
||||
<Compile Include="Models\Request\NewGpgKey.cs" />
|
||||
<Compile Include="Models\Request\NewImpersonationToken.cs" />
|
||||
<Compile Include="Models\Request\Enterprise\NewLdapMapping.cs" />
|
||||
<Compile Include="Models\Request\GistFileUpdate.cs" />
|
||||
@@ -173,6 +176,7 @@
|
||||
<Compile Include="Models\Response\Enterprise\LicenseInfo.cs" />
|
||||
<Compile Include="Models\Response\Enterprise\AdminStatsUsers.cs" />
|
||||
<Compile Include="Models\Response\GitIgnoreTemplate.cs" />
|
||||
<Compile Include="Models\Response\GpgKey.cs" />
|
||||
<Compile Include="Models\Response\License.cs" />
|
||||
<Compile Include="Models\Response\LicenseMetadata.cs" />
|
||||
<Compile Include="Models\Response\Merge.cs" />
|
||||
|
||||
Reference in New Issue
Block a user