using System; using System.Reactive; using System.Reactive.Threading.Tasks; using Octokit.Reactive.Internal; namespace Octokit.Reactive { /// /// A client for GitHub's Collaborators on a Repository. /// /// /// See the Collaborators API documentation for more details. /// public class ObservableRepoCollaboratorsClient : IObservableRepoCollaboratorsClient { readonly IRepoCollaboratorsClient _client; readonly IConnection _connection; /// /// Initializes a new GitHub Repo Collaborators API client. /// /// An IGitHubClient client. public ObservableRepoCollaboratorsClient(IGitHubClient client) { Ensure.ArgumentNotNull(client, "client"); _client = client.Repository.Collaborator; _connection = client.Connection; } /// /// Gets all the collaborators on a repository. /// /// /// See the API documentation for more information. /// /// The owner of the repository /// The name of the repository /// Thrown when a general API error occurs. public IObservable GetAll(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); return GetAll(owner, name, ApiOptions.None); } /// /// Gets all the collaborators on a repository. /// /// /// See the API documentation for more information. /// /// The id of the repository /// Thrown when a general API error occurs. public IObservable GetAll(int repositoryId) { return GetAll(repositoryId, ApiOptions.None); } /// /// Gets all the collaborators on 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 /// Thrown when a general API error occurs. public IObservable GetAll(string owner, string name, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(options, "options"); return _connection.GetAndFlattenAllPages(ApiUrls.RepoCollaborators(owner, name), options); } /// /// Gets all the collaborators on a repository. /// /// /// See the API documentation for more information. /// /// The id of the repository /// Options for changing the API response /// Thrown when a general API error occurs. public IObservable GetAll(int repositoryId, ApiOptions options) { Ensure.ArgumentNotNull(options, "options"); return _connection.GetAndFlattenAllPages(ApiUrls.RepoCollaborators(repositoryId), options); } /// /// Checks if a user is a collaborator on a repository. /// /// /// See the API documentation for more information. /// /// The owner of the repository /// The name of the repository /// Username of the prospective collaborator /// Thrown when a general API error occurs. public IObservable IsCollaborator(string owner, string name, string user) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNullOrEmptyString(user, "user"); return _client.IsCollaborator(owner, name, user).ToObservable(); } /// /// Checks if a user is a collaborator on a repository. /// /// /// See the API documentation for more information. /// /// The id of the repository /// Username of the prospective collaborator /// Thrown when a general API error occurs. public IObservable IsCollaborator(int repositoryId, string user) { Ensure.ArgumentNotNullOrEmptyString(user, "user"); return _client.IsCollaborator(repositoryId, user).ToObservable(); } /// /// Adds a new collaborator to the repository. /// /// /// See the API documentation for more information. /// /// The owner of the repository /// The name of the repository /// Username of the new collaborator /// Thrown when a general API error occurs. public IObservable Add(string owner, string name, string user) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNullOrEmptyString(user, "user"); return _client.Add(owner, name, user).ToObservable(); } /// /// Adds a new collaborator to the repository. /// /// /// See the API documentation for more information. /// /// The id of the repository /// Username of the new collaborator /// Thrown when a general API error occurs. public IObservable Add(int repositoryId, string user) { Ensure.ArgumentNotNullOrEmptyString(user, "user"); return _client.Add(repositoryId, user).ToObservable(); } /// /// Deletes a collaborator from the repository. /// /// /// See the API documentation for more information. /// /// The owner of the repository /// The name of the repository /// Username of the deleted collaborator /// Thrown when a general API error occurs. public IObservable Delete(string owner, string name, string user) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNullOrEmptyString(user, "user"); return _client.Delete(owner, name, user).ToObservable(); } /// /// Deletes a collaborator from the repository. /// /// /// See the API documentation for more information. /// /// The id of the repository /// Username of the deleted collaborator /// Thrown when a general API error occurs. public IObservable Delete(int repositoryId, string user) { Ensure.ArgumentNotNullOrEmptyString(user, "user"); return _client.Delete(repositoryId, user).ToObservable(); } } }