diff --git a/Octokit.Reactive/Clients/IObservableRepositoryDeployKeysClient.cs b/Octokit.Reactive/Clients/IObservableRepositoryDeployKeysClient.cs new file mode 100644 index 00000000..5ec11405 --- /dev/null +++ b/Octokit.Reactive/Clients/IObservableRepositoryDeployKeysClient.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +using System.Reactive; +using System.Text; +using System.Threading.Tasks; + +namespace Octokit.Reactive +{ + public interface IObservableRepositoryDeployKeysClient + { + /// + /// 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. + [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")] + IObservable Get(string owner, string name, int 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. + IObservable GetAll(string owner, string name); + + /// + /// 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. + /// + IObservable Create(string owner, string name, NewDeployKey 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. + /// + IObservable Delete(string owner, string name, int number); + } +} diff --git a/Octokit.Reactive/Clients/ObservableRepositoryDeployKeysClient.cs b/Octokit.Reactive/Clients/ObservableRepositoryDeployKeysClient.cs new file mode 100644 index 00000000..282ba1b7 --- /dev/null +++ b/Octokit.Reactive/Clients/ObservableRepositoryDeployKeysClient.cs @@ -0,0 +1,102 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reactive; +using System.Reactive.Threading.Tasks; +using System.Text; +using System.Threading.Tasks; +using Octokit.Reactive.Internal; + +namespace Octokit.Reactive +{ + public class ObservableRepositoryDeployKeysClient : IObservableRepositoryDeployKeysClient + { + readonly IRepositoryDeployKeysClient _client; + readonly IConnection _connection; + + public ObservableRepositoryDeployKeysClient(IGitHubClient client) + { + Ensure.ArgumentNotNull(client, "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 number) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + return _client.Get(owner, name, number).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, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + return _connection.GetAndFlattenAllPages(ApiUrls.RepositoryDeployKeys(owner, name)); + } + + /// + /// 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, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(newDeployKey, "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(); + } + + /// + /// 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 number) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + return _client.Delete(owner, name, number).ToObservable(); + } + } +} diff --git a/Octokit.Reactive/Octokit.Reactive.csproj b/Octokit.Reactive/Octokit.Reactive.csproj index 453b88ae..fd8288d4 100644 --- a/Octokit.Reactive/Octokit.Reactive.csproj +++ b/Octokit.Reactive/Octokit.Reactive.csproj @@ -75,6 +75,8 @@ + +