using System;
using System.Reactive.Threading.Tasks;
using Octokit.Reactive.Internal;
namespace Octokit.Reactive
{
///
/// A client for GitHub's Issue Assignees API.
///
///
/// See the Issue Assignees API documentation for more information.
///
public class ObservableAssigneesClient : IObservableAssigneesClient
{
readonly IAssigneesClient _client;
readonly IConnection _connection;
public ObservableAssigneesClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, nameof(client));
_client = client.Issue.Assignee;
_connection = client.Connection;
}
///
/// Gets all the available assignees (owner + collaborators) to which issues may be assigned.
///
/// The owner of the repository
/// The name of the repository
public IObservable GetAllForRepository(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
return GetAllForRepository(owner, name, ApiOptions.None);
}
///
/// Gets all the available assignees (owner + collaborators) to which issues may be assigned.
///
/// The Id of the repository
public IObservable GetAllForRepository(long repositoryId)
{
return GetAllForRepository(repositoryId, ApiOptions.None);
}
///
/// Gets all the available assignees (owner + collaborators) to which issues may be assigned.
///
/// The owner of the repository
/// The name of the repository
/// The options to change API's behaviour.
public IObservable GetAllForRepository(string owner, string name, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNull(options, nameof(options));
return _connection.GetAndFlattenAllPages(ApiUrls.Assignees(owner, name), options);
}
///
/// Gets all the available assignees (owner + collaborators) to which issues may be assigned.
///
/// The Id of the repository
/// The options to change API's behaviour.
public IObservable GetAllForRepository(long repositoryId, ApiOptions options)
{
Ensure.ArgumentNotNull(options, nameof(options));
return _connection.GetAndFlattenAllPages(ApiUrls.Assignees(repositoryId), options);
}
///
/// Checks to see if a user is an assignee for a repository.
///
/// The owner of the repository
/// The name of the repository
/// Username of the prospective assignee
public IObservable CheckAssignee(string owner, string name, string assignee)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(assignee, nameof(assignee));
return _client.CheckAssignee(owner, name, assignee).ToObservable();
}
///
/// Add assignees to a specified Issue.
///
/// The owner of the repository
/// The name of the repository
/// The issue number
/// List of names of assignees to add
public IObservable AddAssignees(string owner, string name, int issueNumber, AssigneesUpdate assignees)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNull(assignees, nameof(assignees));
return _client.AddAssignees(owner, name, issueNumber, assignees).ToObservable();
}
///
/// Remove assignees from a specified Issue.
///
/// The owner of the repository
/// The name of the repository
/// The issue number
/// List of assignees to remove
///
public IObservable RemoveAssignees(string owner, string name, int issueNumber, AssigneesUpdate assignees)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNull(assignees, nameof(assignees));
return _client.RemoveAssignees(owner, name, issueNumber, assignees).ToObservable();
}
///
/// Checks to see if a user is an assignee for a repository.
///
/// The Id of the repository
/// Username of the prospective assignee
public IObservable CheckAssignee(long repositoryId, string assignee)
{
Ensure.ArgumentNotNullOrEmptyString(assignee, nameof(assignee));
return _client.CheckAssignee(repositoryId, assignee).ToObservable();
}
}
}