mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-05-13 03:15:33 +00:00
202 lines
9.1 KiB
C#
202 lines
9.1 KiB
C#
using System;
|
|
using System.Reactive;
|
|
using System.Reactive.Threading.Tasks;
|
|
using Octokit.Reactive.Internal;
|
|
|
|
namespace Octokit.Reactive
|
|
{
|
|
/// <summary>
|
|
/// A client for GitHub's Collaborators on a Repository.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// See the <a href="http://developer.github.com/v3/repos/collaborators/">Collaborators API documentation</a> for more details.
|
|
/// </remarks>
|
|
public class ObservableRepoCollaboratorsClient : IObservableRepoCollaboratorsClient
|
|
{
|
|
readonly IRepoCollaboratorsClient _client;
|
|
readonly IConnection _connection;
|
|
|
|
/// <summary>
|
|
/// Initializes a new GitHub Repo Collaborators API client.
|
|
/// </summary>
|
|
/// <param name="client">An IGitHubClient client.</param>
|
|
public ObservableRepoCollaboratorsClient(IGitHubClient client)
|
|
{
|
|
Ensure.ArgumentNotNull(client, "client");
|
|
|
|
_client = client.Repository.Collaborator;
|
|
_connection = client.Connection;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets all the collaborators on a repository.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// See the <a href="http://developer.github.com/v3/repos/collaborators/#list">API documentation</a> for more information.
|
|
/// </remarks>
|
|
/// <param name="owner">The owner of the repository</param>
|
|
/// <param name="name">The name of the repository</param>
|
|
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
|
public IObservable<User> GetAll(string owner, string name)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
|
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
|
|
|
return GetAll(owner, name, ApiOptions.None);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets all the collaborators on a repository.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// See the <a href="http://developer.github.com/v3/repos/collaborators/#list">API documentation</a> for more information.
|
|
/// </remarks>
|
|
/// <param name="repositoryId">The id of the repository</param>
|
|
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
|
public IObservable<User> GetAll(int repositoryId)
|
|
{
|
|
return GetAll(repositoryId, ApiOptions.None);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets all the collaborators on a repository.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// See the <a href="http://developer.github.com/v3/repos/collaborators/#list">API documentation</a> for more information.
|
|
/// </remarks>
|
|
/// <param name="owner">The owner of the repository</param>
|
|
/// <param name="name">The name of the repository</param>
|
|
/// <param name="options">Options for changing the API response</param>
|
|
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
|
public IObservable<User> GetAll(string owner, string name, ApiOptions options)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
|
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
|
Ensure.ArgumentNotNull(options, "options");
|
|
|
|
return _connection.GetAndFlattenAllPages<User>(ApiUrls.RepoCollaborators(owner, name), options);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets all the collaborators on a repository.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// See the <a href="http://developer.github.com/v3/repos/collaborators/#list">API documentation</a> for more information.
|
|
/// </remarks>
|
|
/// <param name="repositoryId">The id of the repository</param>
|
|
/// <param name="options">Options for changing the API response</param>
|
|
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
|
public IObservable<User> GetAll(int repositoryId, ApiOptions options)
|
|
{
|
|
Ensure.ArgumentNotNull(options, "options");
|
|
|
|
return _connection.GetAndFlattenAllPages<User>(ApiUrls.RepoCollaborators(repositoryId), options);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Checks if a user is a collaborator on a repository.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// See the <a href="http://developer.github.com/v3/repos/collaborators/#list">API documentation</a> for more information.
|
|
/// </remarks>
|
|
/// <param name="owner">The owner of the repository</param>
|
|
/// <param name="name">The name of the repository</param>
|
|
/// <param name="user">Username of the prospective collaborator</param>
|
|
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
|
public IObservable<bool> 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();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Checks if a user is a collaborator on a repository.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// See the <a href="http://developer.github.com/v3/repos/collaborators/#get">API documentation</a> for more information.
|
|
/// </remarks>
|
|
/// <param name="repositoryId">The id of the repository</param>
|
|
/// <param name="user">Username of the prospective collaborator</param>
|
|
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
|
public IObservable<bool> IsCollaborator(int repositoryId, string user)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(user, "user");
|
|
|
|
return _client.IsCollaborator(repositoryId, user).ToObservable();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adds a new collaborator to the repository.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// See the <a href="http://developer.github.com/v3/repos/collaborators/#list">API documentation</a> for more information.
|
|
/// </remarks>
|
|
/// <param name="owner">The owner of the repository</param>
|
|
/// <param name="name">The name of the repository</param>
|
|
/// <param name="user">Username of the new collaborator</param>
|
|
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
|
public IObservable<Unit> 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();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adds a new collaborator to the repository.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// See the <a href="http://developer.github.com/v3/repos/collaborators/#add-collaborator">API documentation</a> for more information.
|
|
/// </remarks>
|
|
/// <param name="repositoryId">The id of the repository</param>
|
|
/// <param name="user">Username of the new collaborator</param>
|
|
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
|
public IObservable<Unit> Add(int repositoryId, string user)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(user, "user");
|
|
|
|
return _client.Add(repositoryId, user).ToObservable();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Deletes a collaborator from the repository.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// See the <a href="http://developer.github.com/v3/repos/collaborators/#list">API documentation</a> for more information.
|
|
/// </remarks>
|
|
/// <param name="owner">The owner of the repository</param>
|
|
/// <param name="name">The name of the repository</param>
|
|
/// <param name="user">Username of the deleted collaborator</param>
|
|
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
|
public IObservable<Unit> 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();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Deletes a collaborator from the repository.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// See the <a href="http://developer.github.com/v3/repos/collaborators/#remove-collaborator">API documentation</a> for more information.
|
|
/// </remarks>
|
|
/// <param name="repositoryId">The id of the repository</param>
|
|
/// <param name="user">Username of the deleted collaborator</param>
|
|
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
|
|
public IObservable<Unit> Delete(int repositoryId, string user)
|
|
{
|
|
Ensure.ArgumentNotNullOrEmptyString(user, "user");
|
|
|
|
return _client.Delete(repositoryId, user).ToObservable();
|
|
}
|
|
}
|
|
}
|