using System;
using System.Reactive;
using System.Reactive.Linq;
using System.Reactive.Threading.Tasks;
using Octokit.Reactive.Internal;
namespace Octokit.Reactive
{
public class ObservableIssuesLabelsClient : IObservableIssuesLabelsClient
{
readonly IIssuesLabelsClient _client;
readonly IConnection _connection;
public ObservableIssuesLabelsClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, "client");
_connection = client.Connection;
_client = client.Issue.Labels;
}
///
/// Gets all labels for the issue.
///
///
/// See the API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// The number of the issue
/// The list of labels
public IObservable GetAllForIssue(string owner, string name, int number)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return GetAllForIssue(owner, name, number, ApiOptions.None);
}
///
/// Gets all labels for the issue.
///
///
/// See the API documentation for more information.
///
/// The ID of the repository
/// The number of the issue
/// The list of labels
public IObservable GetAllForIssue(int repositoryId, int number)
{
return GetAllForIssue(repositoryId, number, ApiOptions.None);
}
///
/// Gets all labels for the issue.
///
///
/// See the API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// The number of the issue
/// Options for changing the API response
/// The list of labels
public IObservable GetAllForIssue(string owner, string name, int number, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages(ApiUrls.IssueLabels(owner, name, number), options);
}
///
/// Gets all labels for the issue.
///
///
/// See the API documentation for more information.
///
/// The ID of the repository
/// The number of the issue
/// Options for changing the API response
/// The list of labels
public IObservable GetAllForIssue(int repositoryId, int number, ApiOptions options)
{
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages(ApiUrls.IssueLabels(repositoryId, number), options);
}
///
/// Gets all labels for the repository.
///
///
/// See the API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// The list of labels
public IObservable GetAllForRepository(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return GetAllForRepository(owner, name, ApiOptions.None);
}
///
/// Gets all labels for the repository.
///
///
/// See the API documentation for more information.
///
/// The ID of the repository
/// The list of labels
public IObservable GetAllForRepository(int repositoryId)
{
return GetAllForRepository(repositoryId, ApiOptions.None);
}
///
/// Gets all labels for the repository.
///
///
/// See the API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// Options for changing the API response
/// The list of labels
public IObservable GetAllForRepository(string owner, string name, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages(ApiUrls.Labels(owner, name), options);
}
///
/// Gets all labels for the repository.
///
///
/// See the API documentation for more information.
///
/// The ID of the repository
/// Options for changing the API response
/// The list of labels
public IObservable GetAllForRepository(int repositoryId, ApiOptions options)
{
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages(ApiUrls.Labels(repositoryId), options);
}
///
/// Gets labels for every issue in a milestone
///
///
/// See the API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// The number of the milestone
///
public IObservable GetAllForMilestone(string owner, string name, int number)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return GetAllForMilestone(owner, name, number, ApiOptions.None);
}
///
/// Gets labels for every issue in a milestone
///
///
/// See the API documentation for more information.
///
/// The ID of the repository
/// The number of the milestone
///
public IObservable GetAllForMilestone(int repositoryId, int number)
{
return GetAllForMilestone(repositoryId, number, ApiOptions.None);
}
///
/// Gets labels for every issue in a milestone
///
///
/// See the API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// The number of the milestone
/// Options for changing the API response
///
public IObservable GetAllForMilestone(string owner, string name, int number, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages(ApiUrls.MilestoneLabels(owner, name, number), options);
}
///
/// Gets labels for every issue in a milestone
///
///
/// See the API documentation for more information.
///
/// The ID of the repository
/// The number of the milestone
/// Options for changing the API response
///
public IObservable GetAllForMilestone(int repositoryId, int number, ApiOptions options)
{
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages(ApiUrls.MilestoneLabels(repositoryId, number), options);
}
///
/// Gets a single Label by name.
///
///
/// See the API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// The name of the label
/// The label
public IObservable Get(string owner, string name, string labelName)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNullOrEmptyString(labelName, "labelName");
return _client.Get(owner, name, labelName).ToObservable();
}
///
/// Gets a single Label by name.
///
///
/// See the API documentation for more information.
///
/// The ID of the repository
/// The name of the label
/// The label
public IObservable Get(int repositoryId, string labelName)
{
Ensure.ArgumentNotNullOrEmptyString(labelName, "labelName");
return _client.Get(repositoryId, labelName).ToObservable();
}
///
/// Deletes a label.
///
///
/// See the API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// The name of the label
///
public IObservable Delete(string owner, string name, string labelName)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNullOrEmptyString(labelName, "labelName");
return _client.Delete(owner, name, labelName).ToObservable();
}
///
/// Deletes a label.
///
///
/// See the API documentation for more information.
///
/// The ID of the repository
/// The name of the label
///
public IObservable Delete(int repositoryId, string labelName)
{
Ensure.ArgumentNotNullOrEmptyString(labelName, "labelName");
return _client.Delete(repositoryId, labelName).ToObservable();
}
///
/// Creates a label.
///
///
/// See the API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// The data for the label to be created
/// The created label
public IObservable Create(string owner, string name, NewLabel newLabel)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(newLabel, "newLabel");
return _client.Create(owner, name, newLabel).ToObservable();
}
///
/// Creates a label.
///
///
/// See the API documentation for more information.
///
/// The ID of the repository
/// The data for the label to be created
/// The created label
public IObservable Create(int repositoryId, NewLabel newLabel)
{
Ensure.ArgumentNotNull(newLabel, "newLabel");
return _client.Create(repositoryId, newLabel).ToObservable();
}
///
/// Updates a label.
///
///
/// See the API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// The name of the label
/// The data for the label to be updated
/// The updated label
public IObservable Update(string owner, string name, string labelName, LabelUpdate labelUpdate)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(labelName, "labelName");
Ensure.ArgumentNotNull(labelUpdate, "labelUpdate");
return _client.Update(owner, name, labelName, labelUpdate).ToObservable();
}
///
/// Updates a label.
///
///
/// See the API documentation for more information.
///
/// The ID of the repository
/// The name of the label
/// The data for the label to be updated
/// The updated label
public IObservable Update(int repositoryId, string labelName, LabelUpdate labelUpdate)
{
Ensure.ArgumentNotNull(labelName, "labelName");
Ensure.ArgumentNotNull(labelUpdate, "labelUpdate");
return _client.Update(repositoryId, labelName, labelUpdate).ToObservable();
}
///
/// Adds a label to an issue
///
///
/// See the API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// The number of the issue
/// The names of the labels to add
///
public IObservable AddToIssue(string owner, string name, int number, string[] labels)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(labels, "labels");
return _client.AddToIssue(owner, name, number, labels)
.ToObservable()
.SelectMany(x => x); // HACK: POST is not compatible with GetAndFlattenPages
}
///
/// Adds a label to an issue
///
///
/// See the API documentation for more information.
///
/// The ID of the repository
/// The number of the issue
/// The names of the labels to add
///
public IObservable AddToIssue(int repositoryId, int number, string[] labels)
{
return _client.AddToIssue(repositoryId, number, labels)
.ToObservable()
.SelectMany(x => x); // HACK: POST is not compatible with GetAndFlattenPages
}
///
/// Removes a label from an issue
///
///
/// See the API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// The number of the issue
/// The name of the label to remove
///
public IObservable RemoveFromIssue(string owner, string name, int number, string labelName)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNullOrEmptyString(labelName, "labelName");
return _client.RemoveFromIssue(owner, name, number, labelName).ToObservable();
}
///
/// Removes a label from an issue
///
///
/// See the API documentation for more information.
///
/// The ID of the repository
/// The number of the issue
/// The name of the label to remove
///
public IObservable RemoveFromIssue(int repositoryId, int number, string labelName)
{
Ensure.ArgumentNotNullOrEmptyString(labelName, "labelName");
return _client.RemoveFromIssue(repositoryId, number, labelName).ToObservable();
}
///
/// Replaces all labels on the specified issues with the provided labels
///
///
/// See the API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// The number of the issue
/// The names of the labels to set
///
public IObservable ReplaceAllForIssue(string owner, string name, int number, string[] labels)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(labels, "labels");
return _client.ReplaceAllForIssue(owner, name, number, labels)
.ToObservable()
.SelectMany(x => x); // HACK: PUT is not compatible with GetAndFlattenPages
}
///
/// Replaces all labels on the specified issues with the provided labels
///
///
/// See the API documentation for more information.
///
/// The ID of the repository
/// The number of the issue
/// The names of the labels to set
///
public IObservable ReplaceAllForIssue(int repositoryId, int number, string[] labels)
{
Ensure.ArgumentNotNull(labels, "labels");
return _client.ReplaceAllForIssue(repositoryId, number, labels)
.ToObservable()
.SelectMany(x => x); // HACK: PUT is not compatible with GetAndFlattenPages
}
///
/// Removes all labels from an issue
///
///
/// See the API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// The number of the issue
///
public IObservable RemoveAllFromIssue(string owner, string name, int number)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return _client.RemoveAllFromIssue(owner, name, number).ToObservable();
}
///
/// Removes all labels from an issue
///
///
/// See the API documentation for more information.
///
/// The ID of the repository
/// The number of the issue
///
public IObservable RemoveAllFromIssue(int repositoryId, int number)
{
return _client.RemoveAllFromIssue(repositoryId, number).ToObservable();
}
}
}