using Octokit.Reactive.Internal; using System; using System.Reactive.Threading.Tasks; namespace Octokit.Reactive { /// /// A client for GitHub's Project Cards API. /// /// /// See the Repository Projects API documentation for more information. /// public class ObservableProjectCardsClient : IObservableProjectCardsClient { readonly IProjectCardsClient _client; readonly IConnection _connection; public ObservableProjectCardsClient(IGitHubClient client) { Ensure.ArgumentNotNull(client, nameof(client)); _client = client.Repository.Project.Card; _connection = client.Connection; } /// /// Gets all cards for this project. /// /// /// See the API documentation for more information. /// /// The id of the column public IObservable GetAll(int columnId) { return GetAll(columnId, ApiOptions.None); } /// /// Gets all cards for this project. /// /// /// See the API documentation for more information. /// /// The id of the column /// Options for changing the API response public IObservable GetAll(int columnId, ApiOptions options) { Ensure.ArgumentNotNull(options, nameof(options)); return GetAll(columnId, new ProjectCardRequest(), options); } /// /// Gets all cards. /// /// /// See the API documentation for more information. /// /// The id of the column /// Used to filter the list of project cards returned public IObservable GetAll(int columnId, ProjectCardRequest request) { Ensure.ArgumentNotNull(request, nameof(request)); return GetAll(columnId, request, ApiOptions.None); } /// /// Gets all cards. /// /// /// See the API documentation for more information. /// /// The id of the column /// Used to filter the list of project cards returned /// Options for changing the API response public IObservable GetAll(int columnId, ProjectCardRequest request, ApiOptions options) { Ensure.ArgumentNotNull(request, nameof(request)); Ensure.ArgumentNotNull(options, nameof(options)); var url = ApiUrls.ProjectCards(columnId); return _connection.GetAndFlattenAllPages(url, request.ToParametersDictionary(), options); } /// /// Gets a single card. /// /// /// See the API documentation for more information. /// /// The id of the card public IObservable Get(long id) { return _client.Get(id).ToObservable(); } /// /// Creates a card. /// /// /// See the API documentation for more information. /// /// The id of the column /// The card to create public IObservable Create(int columnId, NewProjectCard newProjectCard) { Ensure.ArgumentNotNull(newProjectCard, nameof(newProjectCard)); return _client.Create(columnId, newProjectCard).ToObservable(); } /// /// Updates a card. /// /// /// See the API documentation for more information. /// /// The id of the card /// New values to update the card with public IObservable Update(long id, ProjectCardUpdate projectCardUpdate) { Ensure.ArgumentNotNull(projectCardUpdate, nameof(projectCardUpdate)); return _client.Update(id, projectCardUpdate).ToObservable(); } /// /// Deletes a card. /// /// /// See the API documentation for more information. /// /// The id of the card public IObservable Delete(long id) { return _client.Delete(id).ToObservable(); } /// /// Moves a card. /// /// /// See the API documentation for more information. /// /// The id of the card /// The position to move the card public IObservable Move(long id, ProjectCardMove position) { Ensure.ArgumentNotNull(position, nameof(position)); return _client.Move(id, position).ToObservable(); } } }