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, nameof(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, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(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(long 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, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNull(options, nameof(options)); return GetAll(owner, name, new RepositoryCollaboratorListRequest(), 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(long repositoryId, ApiOptions options) { Ensure.ArgumentNotNull(options, nameof(options)); return GetAll(repositoryId, new RepositoryCollaboratorListRequest(), options); } /// /// Gets all the collaborators on a repository. /// /// /// See the API documentation for more information. /// /// The owner of the repository /// The name of the repository /// Used to request and filter a list of repository collaborators /// Thrown when a general API error occurs. public IObservable GetAll(string owner, string name, RepositoryCollaboratorListRequest request) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNull(request, nameof(request)); return GetAll(owner, name, request, ApiOptions.None); } /// /// Gets all the collaborators on a repository. /// /// /// See the API documentation for more information. /// /// The id of the repository /// Used to request and filter a list of repository collaborators /// Thrown when a general API error occurs. public IObservable GetAll(long repositoryId, RepositoryCollaboratorListRequest request) { Ensure.ArgumentNotNull(request, nameof(request)); return GetAll(repositoryId, request, 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 /// Used to request and filter a list of repository collaborators /// Options for changing the API response /// Thrown when a general API error occurs. public IObservable GetAll(string owner, string name, RepositoryCollaboratorListRequest request, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNull(request, nameof(request)); Ensure.ArgumentNotNull(options, nameof(options)); return _connection.GetAndFlattenAllPages(ApiUrls.RepoCollaborators(owner, name), request.ToParametersDictionary(), options); } /// /// Gets all the collaborators on a repository. /// /// /// See the API documentation for more information. /// /// The id of the repository /// Used to request and filter a list of repository collaborators /// Options for changing the API response /// Thrown when a general API error occurs. public IObservable GetAll(long repositoryId, RepositoryCollaboratorListRequest request, ApiOptions options) { Ensure.ArgumentNotNull(request, nameof(request)); Ensure.ArgumentNotNull(options, nameof(options)); return _connection.GetAndFlattenAllPages(ApiUrls.RepoCollaborators(repositoryId), request.ToParametersDictionary(), 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, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNullOrEmptyString(user, nameof(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(long repositoryId, string user) { Ensure.ArgumentNotNullOrEmptyString(user, nameof(user)); return _client.IsCollaborator(repositoryId, user).ToObservable(); } /// /// Review a user's permission level in a repository /// /// /// See the API documentation for more information. /// /// The owner of the repository /// The name of the repository /// Username of the collaborator to check permission for /// Thrown when a general API error occurs. public IObservable ReviewPermission(string owner, string name, string user) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNullOrEmptyString(user, nameof(user)); return _client.ReviewPermission(owner, name, user).ToObservable(); } /// /// Review a user's permission level in a repository /// /// /// See the API documentation for more information. /// /// The id of the repository /// Username of the collaborator to check permission for /// Thrown when a general API error occurs. public IObservable ReviewPermission(long repositoryId, string user) { Ensure.ArgumentNotNullOrEmptyString(user, nameof(user)); return _client.ReviewPermission(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, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNullOrEmptyString(user, nameof(user)); return _client.Add(owner, name, 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 /// The permission to set. Only valid on organization-owned repositories. /// Thrown when a general API error occurs. public IObservable Add(string owner, string name, string user, CollaboratorRequest permission) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNullOrEmptyString(user, nameof(user)); Ensure.ArgumentNotNull(permission, nameof(permission)); return _client.Add(owner, name, user, permission).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(long repositoryId, string user) { Ensure.ArgumentNotNullOrEmptyString(user, nameof(user)); return _client.Add(repositoryId, 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 /// The permission to set. Only valid on organization-owned repositories. /// Thrown when a general API error occurs. public IObservable Add(long repositoryId, string user, CollaboratorRequest permission) { Ensure.ArgumentNotNullOrEmptyString(user, nameof(user)); Ensure.ArgumentNotNull(permission, nameof(permission)); return _client.Add(repositoryId, user, permission).ToObservable(); } /// /// Invites a user as a collaborator to a repository. /// /// /// See the API documentation for more information. /// /// The owner of the repository /// The name of the repository /// The username of the prospective collaborator public IObservable Invite(string owner, string name, string user) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNullOrEmptyString(user, nameof(user)); return _client.Invite(owner, name, user).ToObservable(); } /// /// Invites a user as a collaborator to a repository. /// /// /// See the API documentation for more information. /// /// The owner of the repository /// The name of the repository /// The username of the prospective collaborator /// The permission to set. Only valid on organization-owned repositories. public IObservable Invite(string owner, string name, string user, CollaboratorRequest permission) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNullOrEmptyString(user, nameof(user)); Ensure.ArgumentNotNull(permission, nameof(permission)); return _client.Invite(owner, name, user, permission).ToObservable(); } /// /// Invites a user as a collaborator to a repository. /// /// /// See the API documentation for more information. /// /// The id of the repository /// The username of the prospective collaborator public IObservable Invite(long repositoryId, string user) { Ensure.ArgumentNotNullOrEmptyString(user, nameof(user)); return _client.Invite(repositoryId, user).ToObservable(); } /// /// Invites a user as a collaborator to a repository. /// /// /// See the API documentation for more information. /// /// The id of the repository /// The username of the prospective collaborator /// The permission to set. Only valid on organization-owned repositories. public IObservable Invite(long repositoryId, string user, CollaboratorRequest permission) { Ensure.ArgumentNotNullOrEmptyString(user, nameof(user)); Ensure.ArgumentNotNull(permission, nameof(permission)); return _client.Invite(repositoryId, user, permission).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, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNullOrEmptyString(user, nameof(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(long repositoryId, string user) { Ensure.ArgumentNotNullOrEmptyString(user, nameof(user)); return _client.Delete(repositoryId, user).ToObservable(); } } }