using System; using System.Reactive; using System.Reactive.Threading.Tasks; using Octokit.Reactive.Internal; namespace Octokit.Reactive { /// /// A client for GitHub's Repository Deploy Keys API. /// /// /// See the Deploy Keys API documentation for more information. /// public class ObservableRepositoryDeployKeysClient : IObservableRepositoryDeployKeysClient { readonly IRepositoryDeployKeysClient _client; readonly IConnection _connection; public ObservableRepositoryDeployKeysClient(IGitHubClient client) { Ensure.ArgumentNotNull(client, nameof(client)); _client = client.Repository.DeployKeys; _connection = client.Connection; } /// /// 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. public IObservable Get(string owner, string name, int deployKeyId) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); return _client.Get(owner, name, deployKeyId).ToObservable(); } /// /// 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. public IObservable Get(long repositoryId, int deployKeyId) { return _client.Get(repositoryId, deployKeyId).ToObservable(); } /// /// Get all deploy keys for a repository. /// /// /// See the API documentation for more information. /// /// The owner of the repository. /// The name of the repository. public IObservable 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. public IObservable 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 public IObservable GetAll(string owner, string name, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNull(options, nameof(options)); return _connection.GetAndFlattenAllPages(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 public IObservable GetAll(long repositoryId, ApiOptions options) { Ensure.ArgumentNotNull(options, nameof(options)); return _connection.GetAndFlattenAllPages(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. public IObservable 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 _client.Create(owner, name, newDeployKey).ToObservable(); } /// /// 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. public IObservable 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 _client.Create(repositoryId, newDeployKey).ToObservable(); } /// /// 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. public IObservable Delete(string owner, string name, int deployKeyId) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); return _client.Delete(owner, name, deployKeyId).ToObservable(); } /// /// 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. public IObservable Delete(long repositoryId, int deployKeyId) { return _client.Delete(repositoryId, deployKeyId).ToObservable(); } } }