using System;
using System.Threading.Tasks;
using System.Collections.Generic;
namespace Octokit
{
///
/// A client for GitHub's Repository Deploy Keys API.
///
///
/// See the Deploy Keys API documentation for more information.
///
public class RepositoryDeployKeysClient : ApiClient, IRepositoryDeployKeysClient
{
///
/// Instantiates a new GitHub repository deploy keys API client.
///
/// The API connection.
public RepositoryDeployKeysClient(IApiConnection apiConnection)
: base(apiConnection)
{
}
///
/// Get a single deploy key by number for a repository.
///
///
/// See the API documentation for more information.
///
/// The owner of the repository.
/// The name of the repository.
/// The id of the deploy key.
[ManualRoute("GET", "/repos/{owner}/{repo}/keys/{number}")]
public Task Get(string owner, string name, int number)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
return ApiConnection.Get(ApiUrls.RepositoryDeployKey(owner, name, number));
}
///
/// Get a single deploy key by number for a repository.
///
///
/// See the API documentation for more information.
///
/// The Id of the repository.
/// The id of the deploy key.
[ManualRoute("GET", "/repositories/{id}/keys/{number}")]
public Task Get(long repositoryId, int number)
{
return ApiConnection.Get(ApiUrls.RepositoryDeployKey(repositoryId, number));
}
///
/// Get all deploy keys for a repository.
///
///
/// See the API documentation for more information.
///
/// The owner of the repository.
/// The name of the repository.
[ManualRoute("GET", "/repos/{owner}/{repo}/keys")]
public Task> GetAll(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
return GetAll(owner, name, ApiOptions.None);
}
///
/// Get all deploy keys for a repository.
///
///
/// See the API documentation for more information.
///
/// The Id of the repository.
[ManualRoute("GET", "/repositories/{id}/keys")]
public Task> GetAll(long repositoryId)
{
return GetAll(repositoryId, ApiOptions.None);
}
///
/// Get all deploy keys for a repository.
///
///
/// See the API documentation for more information.
///
/// The owner of the repository.
/// The name of the repository.
/// Options for changing the API response
[ManualRoute("GET", "/repos/{owner}/{repo}/keys")]
public Task> GetAll(string owner, string name, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNull(options, nameof(options));
return ApiConnection.GetAll(ApiUrls.RepositoryDeployKeys(owner, name), options);
}
///
/// Get all deploy keys for a repository.
///
///
/// See the API documentation for more information.
///
/// The Id of the repository.
/// Options for changing the API response
[ManualRoute("GET", "/repositories/{id}/keys")]
public Task> GetAll(long repositoryId, ApiOptions options)
{
Ensure.ArgumentNotNull(options, nameof(options));
return ApiConnection.GetAll(ApiUrls.RepositoryDeployKeys(repositoryId), options);
}
///
/// Creates a new deploy key for a repository.
///
///
/// See the API documentation for more information.
///
/// The owner of the repository.
/// The name of the repository.
/// The deploy key to create for the repository.
[ManualRoute("POST", "/repos/{owner}/{repo}/keys")]
public Task Create(string owner, string name, NewDeployKey newDeployKey)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNull(newDeployKey, nameof(newDeployKey));
if (string.IsNullOrWhiteSpace(newDeployKey.Title))
throw new ArgumentException("The new deploy key's title must not be null.");
if (string.IsNullOrWhiteSpace(newDeployKey.Key))
throw new ArgumentException("The new deploy key's key must not be null.");
return ApiConnection.Post(ApiUrls.RepositoryDeployKeys(owner, name), newDeployKey);
}
///
/// Creates a new deploy key for a repository.
///
///
/// See the API documentation for more information.
///
/// The Id of the repository.
/// The deploy key to create for the repository.
[ManualRoute("POST", "/repositories/{id}/keys")]
public Task Create(long repositoryId, NewDeployKey newDeployKey)
{
Ensure.ArgumentNotNull(newDeployKey, nameof(newDeployKey));
if (string.IsNullOrWhiteSpace(newDeployKey.Title))
throw new ArgumentException("The new deploy key's title must not be null.");
if (string.IsNullOrWhiteSpace(newDeployKey.Key))
throw new ArgumentException("The new deploy key's key must not be null.");
return ApiConnection.Post(ApiUrls.RepositoryDeployKeys(repositoryId), newDeployKey);
}
///
/// Deletes a deploy key from a repository.
///
///
/// See the API documentation for more information.
///
/// The owner of the repository.
/// The name of the repository.
/// The id of the deploy key to delete.
[ManualRoute("DELETE", "/repositories/{id}/keys/{number}")]
public Task Delete(string owner, string name, int number)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
return ApiConnection.Delete(ApiUrls.RepositoryDeployKey(owner, name, number));
}
///
/// Deletes a deploy key from a repository.
///
///
/// See the API documentation for more information.
///
/// The Id of the repository.
/// The id of the deploy key to delete.
[ManualRoute("DELETE", "/repositories/{id}/keys/{number}")]
public Task Delete(long repositoryId, int number)
{
return ApiConnection.Delete(ApiUrls.RepositoryDeployKey(repositoryId, number));
}
}
}