using System;
using System.Reactive;
using System.Reactive.Linq;
using System.Reactive.Threading.Tasks;
using Octokit.Reactive.Internal;
namespace Octokit.Reactive
{
///
/// A client for GitHub's Issue Labels API.
///
///
/// See the Issue Labels API documentation for more information.
///
public class ObservableIssuesLabelsClient : IObservableIssuesLabelsClient
{
readonly IIssuesLabelsClient _client;
readonly IConnection _connection;
public ObservableIssuesLabelsClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, nameof(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 issue number
public IObservable GetAllForIssue(string owner, string name, int issueNumber)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
return GetAllForIssue(owner, name, issueNumber, ApiOptions.None);
}
///
/// Gets all labels for the issue.
///
///
/// See the API documentation for more information.
///
/// The Id of the repository
/// The issue number
public IObservable GetAllForIssue(long repositoryId, int issueNumber)
{
return GetAllForIssue(repositoryId, issueNumber, 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 issue number
/// Options for changing the API response
public IObservable GetAllForIssue(string owner, string name, int issueNumber, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNull(options, nameof(options));
return _connection.GetAndFlattenAllPages(ApiUrls.IssueLabels(owner, name, issueNumber), options);
}
///
/// Gets all labels for the issue.
///
///
/// See the API documentation for more information.
///
/// The Id of the repository
/// The issue number
/// Options for changing the API response
public IObservable GetAllForIssue(long repositoryId, int issueNumber, ApiOptions options)
{
Ensure.ArgumentNotNull(options, nameof(options));
return _connection.GetAndFlattenAllPages(ApiUrls.IssueLabels(repositoryId, issueNumber), options);
}
///
/// Gets all labels for the repository.
///
///
/// See the API documentation for more information.
///
/// 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 labels for the repository.
///
///
/// See the API documentation for more information.
///
/// The Id of the repository
public IObservable GetAllForRepository(long 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
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.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
public IObservable GetAllForRepository(long repositoryId, ApiOptions options)
{
Ensure.ArgumentNotNull(options, nameof(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 milestoneNumber)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
return GetAllForMilestone(owner, name, milestoneNumber, 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(long repositoryId, int milestoneNumber)
{
return GetAllForMilestone(repositoryId, milestoneNumber, 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 milestoneNumber, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNull(options, nameof(options));
return _connection.GetAndFlattenAllPages(ApiUrls.MilestoneLabels(owner, name, milestoneNumber), 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(long repositoryId, int milestoneNumber, ApiOptions options)
{
Ensure.ArgumentNotNull(options, nameof(options));
return _connection.GetAndFlattenAllPages(ApiUrls.MilestoneLabels(repositoryId, milestoneNumber), 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
public IObservable Get(string owner, string name, string labelName)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(labelName, nameof(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
public IObservable Get(long repositoryId, string labelName)
{
Ensure.ArgumentNotNullOrEmptyString(labelName, nameof(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, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(labelName, nameof(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(long repositoryId, string labelName)
{
Ensure.ArgumentNotNullOrEmptyString(labelName, nameof(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
public IObservable Create(string owner, string name, NewLabel newLabel)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNull(newLabel, nameof(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
public IObservable Create(long repositoryId, NewLabel newLabel)
{
Ensure.ArgumentNotNull(newLabel, nameof(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
public IObservable Update(string owner, string name, string labelName, LabelUpdate labelUpdate)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(labelName, nameof(labelName));
Ensure.ArgumentNotNull(labelUpdate, nameof(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
public IObservable Update(long repositoryId, string labelName, LabelUpdate labelUpdate)
{
Ensure.ArgumentNotNullOrEmptyString(labelName, nameof(labelName));
Ensure.ArgumentNotNull(labelUpdate, nameof(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 issue number
/// The names of the labels to add
public IObservable AddToIssue(string owner, string name, int issueNumber, string[] labels)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNull(labels, nameof(labels));
return _client.AddToIssue(owner, name, issueNumber, 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 issue number
/// The names of the labels to add
public IObservable AddToIssue(long repositoryId, int issueNumber, string[] labels)
{
Ensure.ArgumentNotNull(labels, nameof(labels));
return _client.AddToIssue(repositoryId, issueNumber, 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 issue number
/// The name of the label to remove
public IObservable RemoveFromIssue(string owner, string name, int issueNumber, string labelName)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNullOrEmptyString(labelName, nameof(labelName));
return _client.RemoveFromIssue(owner, name, issueNumber, labelName)
.ToObservable()
.SelectMany(x => x); // HACK: DELETE is not compatible with GetAndFlattenPages
}
///
/// Removes a label from an issue
///
///
/// See the API documentation for more information.
///
/// The Id of the repository
/// The issue number
/// The name of the label to remove
public IObservable RemoveFromIssue(long repositoryId, int issueNumber, string labelName)
{
Ensure.ArgumentNotNullOrEmptyString(labelName, nameof(labelName));
return _client.RemoveFromIssue(repositoryId, issueNumber, labelName)
.ToObservable()
.SelectMany(x => x); // HACK: DELETE is not compatible with GetAndFlattenPages
}
///
/// 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 issue number
/// The names of the labels to set
public IObservable ReplaceAllForIssue(string owner, string name, int issueNumber, string[] labels)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNull(labels, nameof(labels));
return _client.ReplaceAllForIssue(owner, name, issueNumber, 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 issue number
/// The names of the labels to set
public IObservable ReplaceAllForIssue(long repositoryId, int issueNumber, string[] labels)
{
Ensure.ArgumentNotNull(labels, nameof(labels));
return _client.ReplaceAllForIssue(repositoryId, issueNumber, 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 issue number
public IObservable RemoveAllFromIssue(string owner, string name, int issueNumber)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
return _client.RemoveAllFromIssue(owner, name, issueNumber).ToObservable();
}
///
/// Removes all labels from an issue
///
///
/// See the API documentation for more information.
///
/// The Id of the repository
/// The issue number
public IObservable RemoveAllFromIssue(long repositoryId, int issueNumber)
{
return _client.RemoveAllFromIssue(repositoryId, issueNumber).ToObservable();
}
}
}