using System.Collections.Generic;
using System.Threading.Tasks;
namespace Octokit
{
///
/// A client for GitHub's Collaborators on a Repository.
///
///
/// See the Collaborators API documentation for more details.
///
public class RepoCollaboratorsClient : ApiClient, IRepoCollaboratorsClient
{
///
/// Initializes a new GitHub Repo Collaborators API client.
///
/// An API connection.
public RepoCollaboratorsClient(IApiConnection apiConnection)
: base(apiConnection)
{
}
///
/// 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.
[ManualRoute("GET", "/repos/{owner}/{repo}/collaborators")]
public Task> 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.
[ManualRoute("GET", "/repository/{id}/collaborators")]
public Task> 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.
[ManualRoute("GET", "/repos/{owner}/{repo}/collaborators")]
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 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.
[ManualRoute("GET", "/repository/{id}/collaborators")]
public Task> 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.
[ManualRoute("GET", "/repos/{owner}/{repo}/collaborators")]
public Task> 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.
[ManualRoute("GET", "/repository/{id}/collaborators")]
public Task> 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.
[ManualRoute("GET", "/repos/{owner}/{repo}/collaborators")]
public Task> 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 ApiConnection.GetAll(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.
[ManualRoute("GET", "/repository/{id}/collaborators")]
public Task> GetAll(long repositoryId, RepositoryCollaboratorListRequest request, ApiOptions options)
{
Ensure.ArgumentNotNull(request, nameof(request));
Ensure.ArgumentNotNull(options, nameof(options));
return ApiConnection.GetAll(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.
[ManualRoute("GET", "/repos/{owner}/{repo}/collaborators/{username}")]
public async Task IsCollaborator(string owner, string name, string user)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(user, nameof(user));
try
{
var response = await Connection.Get