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 verified public keys for a user.
///
///
/// https://developer.github.com/v3/users/keys/#list-public-keys-for-a-user
///
/// The @ handle of the user.
/// Lists the verified public keys for a user.
[ManualRoute("GET", "/users/{username}/keys")]
public Task> GetAll(string userName)
{
Ensure.ArgumentNotNullOrEmptyString(userName, nameof(userName));
return GetAll(userName, ApiOptions.None);
}
///
/// Gets all verified public keys for a user.
///
///
/// https://developer.github.com/v3/users/keys/#list-public-keys-for-a-user
///
/// The @ handle of the user.
/// Options to change API's behavior.
/// Lists the verified public keys for a user.
[ManualRoute("GET", "/users/{username}/keys")]
public Task> GetAll(string userName, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(userName, nameof(userName));
Ensure.ArgumentNotNull(options, nameof(options));
return ApiConnection.GetAll(ApiUrls.Keys(userName), options);
}
///
/// Gets all public keys for the authenticated user.
///
///
/// https://developer.github.com/v3/users/keys/#list-your-public-keys
///
/// Lists the current user's keys.
[ManualRoute("GET", "/user/keys")]
public Task> GetAllForCurrent()
{
return GetAllForCurrent(ApiOptions.None);
}
///
/// Gets all public keys for the authenticated user.
///
///
/// https://developer.github.com/v3/users/keys/#list-your-public-keys
///
/// Options to change API's behavior.
/// Lists the current user's keys.
[ManualRoute("GET", "/user/keys")]
public Task> GetAllForCurrent(ApiOptions options)
{
Ensure.ArgumentNotNull(options, nameof(options));
return ApiConnection.GetAll(ApiUrls.Keys(), options);
}
///
/// Retrieves the for the specified id.
///
///
/// https://developer.github.com/v3/users/keys/#get-a-single-public-key
///
/// The Id of the SSH key
///
[ManualRoute("GET", "/user/keys/{key_id}")]
public Task Get(int keyId)
{
return ApiConnection.Get(ApiUrls.Keys(keyId));
}
///
/// Create a public key .
///
///
/// https://developer.github.com/v3/users/keys/#create-a-public-key
///
/// The SSH Key contents
///
[ManualRoute("POST", "/user/keys")]
public Task Create(NewPublicKey newKey)
{
Ensure.ArgumentNotNull(newKey, nameof(newKey));
return ApiConnection.Post(ApiUrls.Keys(), newKey);
}
///
/// Delete a public key.
///
///
/// https://developer.github.com/v3/users/keys/#delete-a-public-key
///
/// The id of the key to delete
///
[ManualRoute("DELETE", "/user/keys/{key_id}")]
public Task Delete(int keyId)
{
return ApiConnection.Delete(ApiUrls.Keys(keyId));
}
}
}