using System.Reactive.Threading.Tasks; using System; using System.Reactive; using System.Reactive.Linq; namespace Octokit.Reactive { /// /// A client for GitHub's Repository Custom Property Values API. /// /// /// See the Custom Properties API documentation for more information. /// public class ObservableRepositoryCustomPropertiesClient : IObservableRepositoryCustomPropertiesClient { readonly IRepositoryCustomPropertiesClient _client; readonly IConnection _connection; public ObservableRepositoryCustomPropertiesClient(IGitHubClient client) { Ensure.ArgumentNotNull(client, nameof(client)); _client = client.Repository.CustomProperty; _connection = client.Connection; } /// /// Get all custom property values for 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. public IObservable GetAll(string owner, string repoName) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(repoName, nameof(repoName)); return _client.GetAll(owner, repoName).ToObservable().SelectMany(p => p); } /// /// Create new or update existing custom property values for a repository. Using a value of null for a custom property will remove or 'unset' the property value from the repository. /// /// /// See the API documentation for more information. /// /// The owner of the repository /// The name of the repository /// The custom property values to create or update /// Thrown when a general API error occurs. public IObservable CreateOrUpdate(string owner, string repoName, UpsertRepositoryCustomPropertyValues propertyValues) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(repoName, nameof(repoName)); Ensure.ArgumentNotNull(propertyValues, nameof(propertyValues)); Ensure.ArgumentNotNullOrEmptyEnumerable(propertyValues.Properties, nameof(propertyValues.Properties)); return _client.CreateOrUpdate(owner, repoName, propertyValues).ToObservable(); } } }