mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-07 20:30:41 +00:00
Add SshKeysEndpoint
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Octopi.Http;
|
||||
|
||||
namespace Octopi.Endpoints
|
||||
{
|
||||
public class SshKeysEndpoint : ApiEndpoint<SshKey>, ISshKeysEndpoint
|
||||
{
|
||||
public SshKeysEndpoint(IConnection connection) : base(connection)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<SshKey> Get(long id)
|
||||
{
|
||||
var endpoint = new Uri(string.Format("/user/keys/{0}", id), UriKind.Relative);
|
||||
|
||||
return await Get(endpoint);
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyCollection<SshKey>> GetAll(string user)
|
||||
{
|
||||
var endpoint = new Uri(string.Format("/users/{0}/keys", user), UriKind.Relative);
|
||||
|
||||
return await GetAll(endpoint);
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyCollection<SshKey>> GetAllForCurrent()
|
||||
{
|
||||
var endpoint = new Uri("/user/keys", UriKind.Relative);
|
||||
|
||||
return await GetAll(endpoint);
|
||||
}
|
||||
|
||||
public async Task<SshKey> Create(SshKeyUpdate key)
|
||||
{
|
||||
Ensure.ArgumentNotNull(key, "key");
|
||||
|
||||
var endpoint = new Uri("/user/keys", UriKind.Relative);
|
||||
return await Create(endpoint, key);
|
||||
}
|
||||
|
||||
public async Task<SshKey> Update(long id, SshKeyUpdate key)
|
||||
{
|
||||
Ensure.ArgumentNotNull(key, "key");
|
||||
|
||||
var endpoint = new Uri(string.Format("/user/keys/{0}", id), UriKind.Relative);
|
||||
return await Update(endpoint, key);
|
||||
}
|
||||
|
||||
public async Task Delete(long id)
|
||||
{
|
||||
var endpoint = new Uri(string.Format("/user/keys/{0}", id), UriKind.Relative);
|
||||
|
||||
await Delete(endpoint);
|
||||
}
|
||||
}
|
||||
}
|
||||
+36
-1
@@ -285,7 +285,42 @@ namespace Octopi
|
||||
/// The api URL for this organization.
|
||||
/// </summary>
|
||||
public string Url { get; set; }
|
||||
|
||||
}
|
||||
|
||||
public class SshKey
|
||||
{
|
||||
/// <summary>
|
||||
/// The system-wide unique Id for this user.
|
||||
/// </summary>
|
||||
public long Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The SSH Key
|
||||
/// </summary>
|
||||
public string Key { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The title of the SSH key
|
||||
/// </summary>
|
||||
public string Title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The api URL for this organization.
|
||||
/// </summary>
|
||||
public string Url { get; set; }
|
||||
}
|
||||
|
||||
public class SshKeyUpdate
|
||||
{
|
||||
/// <summary>
|
||||
/// The SSH Key
|
||||
/// </summary>
|
||||
public string Key { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The title of the SSH key
|
||||
/// </summary>
|
||||
public string Title { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Octopi
|
||||
{
|
||||
public interface ISshKeysEndpoint
|
||||
{
|
||||
/// <summary>
|
||||
/// Retrieves the <see cref="SshKey"/> for the specified id.
|
||||
/// </summary>
|
||||
/// <param name="id">The ID of the SSH key.</param>
|
||||
/// <returns>A <see cref="SshKey"/></returns>
|
||||
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")]
|
||||
Task<SshKey> Get(long id);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the <see cref="SshKey"/> for the specified id.
|
||||
/// </summary>
|
||||
/// <param name="user">The login of the user.</param>
|
||||
/// <returns>A <see cref="IReadOnlyPagedCollection{SshKey}"/> of <see cref="SshKey"/>.</returns>
|
||||
Task<IReadOnlyCollection<SshKey>> GetAll(string user);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the <see cref="SshKey"/> for the specified id.
|
||||
/// </summary>
|
||||
/// <exception cref="AuthenticationException">Thrown if the client is not authenticated.</exception>
|
||||
/// <returns>A <see cref="IReadOnlyPagedCollection{SshKey}"/> of <see cref="SshKey"/>.</returns>
|
||||
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate",
|
||||
Justification = "Makes a network request")]
|
||||
Task<IReadOnlyCollection<SshKey>> GetAllForCurrent();
|
||||
|
||||
/// <summary>
|
||||
/// Update the specified <see cref="UserUpdate"/>.
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <exception cref="AuthenticationException">Thrown if the client is not authenticated.</exception>
|
||||
/// <returns>A <see cref="User"/></returns>
|
||||
Task<SshKey> Create(SshKeyUpdate key);
|
||||
|
||||
/// <summary>
|
||||
/// Update the specified <see cref="UserUpdate"/>.
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="key"></param>
|
||||
/// <exception cref="AuthenticationException">Thrown if the client is not authenticated.</exception>
|
||||
/// <returns>A <see cref="User"/></returns>
|
||||
Task<SshKey> Update(long id, SshKeyUpdate key);
|
||||
|
||||
/// <summary>
|
||||
/// Update the specified <see cref="UserUpdate"/>.
|
||||
/// </summary>
|
||||
/// <param name="id">The id of the SSH key</param>
|
||||
/// <exception cref="AuthenticationException">Thrown if the client is not authenticated.</exception>
|
||||
/// <returns>A <see cref="User"/></returns>
|
||||
Task Delete(long id);
|
||||
}
|
||||
}
|
||||
@@ -48,6 +48,7 @@
|
||||
<Compile Include="Endpoints\SearchEndpoint.cs" />
|
||||
<Compile Include="Authentication\AnonymousAuthenticator.cs" />
|
||||
<Compile Include="Authentication\Authenticator.cs" />
|
||||
<Compile Include="Endpoints\SshKeysEndpoint.cs" />
|
||||
<Compile Include="Helpers\CollectionExtensions.cs" />
|
||||
<Compile Include="Http\IHttpClient.cs" />
|
||||
<Compile Include="Http\JsonHttpPipeline.cs" />
|
||||
@@ -61,6 +62,7 @@
|
||||
<Compile Include="IApiPagination.cs" />
|
||||
<Compile Include="IAuthorizationsEndpoint.cs" />
|
||||
<Compile Include="IGitHubClient.cs" />
|
||||
<Compile Include="ISshKeysEndpoint.cs" />
|
||||
<Compile Include="IOrganizationsEndpoint.cs" />
|
||||
<Compile Include="IReadOnlyPagedCollection.cs" />
|
||||
<Compile Include="IRepositoriesEndpoint.cs" />
|
||||
|
||||
@@ -114,6 +114,7 @@
|
||||
<Compile Include="Endpoints\OrganizationsEndpoint.cs" />
|
||||
<Compile Include="Endpoints\PullRequestsEndpoint.cs" />
|
||||
<Compile Include="Endpoints\SearchEndpoint.cs" />
|
||||
<Compile Include="Endpoints\SshKeysEndpoint.cs" />
|
||||
<Compile Include="Helpers\CollectionExtensions.cs" />
|
||||
<Compile Include="Http\ApiResponse.cs" />
|
||||
<Compile Include="Http\Credentials.cs" />
|
||||
@@ -130,6 +131,7 @@
|
||||
<Compile Include="IOrganizationsEndpoint.cs" />
|
||||
<Compile Include="IReadOnlyPagedCollection.cs" />
|
||||
<Compile Include="IRepositoriesEndpoint.cs" />
|
||||
<Compile Include="ISshKeysEndpoint.cs" />
|
||||
<Compile Include="IUsersEndpoint.cs" />
|
||||
<Compile Include="Http\ApiInfoExtensions.cs" />
|
||||
<Compile Include="Http\ApiInfoParser.cs">
|
||||
|
||||
Reference in New Issue
Block a user