using Octokit.Reactive.Internal; using System; using System.Diagnostics.CodeAnalysis; using System.Reactive.Threading.Tasks; using System.Collections.Generic; namespace Octokit.Reactive { /// /// A client for GitHub's Repository Projects API. /// /// /// See the Repository Projects API documentation for more information. /// public class ObservableProjectsClient : IObservableProjectsClient { readonly IProjectsClient _client; readonly IConnection _connection; public ObservableProjectsClient(IGitHubClient client) { Ensure.ArgumentNotNull(client, "client"); _client = client.Repository.Project; _connection = client.Connection; Card = new ObservableProjectCardsClient(client); Column = new ObservableProjectColumnsClient(client); } /// /// Get all projects for the specified 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) { return GetAllForRepository(owner, name, ApiOptions.None); } /// /// Get all projects for the specified 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, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(options, "options"); var url = ApiUrls.RepositoryProjects(owner, name); return _connection.GetAndFlattenAllPages(url, new Dictionary(), AcceptHeaders.ProjectsApiPreview, options); } /// /// Get all projects for the specified repository. /// /// /// See the API documentation for more information. /// /// The owner of the repository /// The name of the repository /// Used to filter the list of projects returned public IObservable GetAllForRepository(string owner, string name, ProjectRequest request) { return GetAllForRepository(owner, name, request, ApiOptions.None); } /// /// Get all projects for the specified repository. /// /// /// See the API documentation for more information. /// /// The owner of the repository /// The name of the repository /// Used to filter the list of projects returned /// Options for changing the API response public IObservable GetAllForRepository(string owner, string name, ProjectRequest request, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(request, "request"); Ensure.ArgumentNotNull(options, "options"); var url = ApiUrls.RepositoryProjects(owner, name); return _connection.GetAndFlattenAllPages(url, request.ToParametersDictionary(), AcceptHeaders.ProjectsApiPreview, options); } /// /// Get all projects for the specified repository. /// /// /// See the API documentation for more information. /// /// The Id of the repository public IObservable GetAllForRepository(long repositoryId) { return GetAllForRepository(repositoryId, ApiOptions.None); } /// /// Get all projects for the specified 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, "options"); var url = ApiUrls.RepositoryProjects(repositoryId); return _connection.GetAndFlattenAllPages(url, new Dictionary(), AcceptHeaders.ProjectsApiPreview, options); } /// /// Get all projects for the specified repository. /// /// /// See the API documentation for more information. /// /// The Id of the repository /// Used to filter the list of projects returned public IObservable GetAllForRepository(long repositoryId, ProjectRequest request) { return GetAllForRepository(repositoryId, request, ApiOptions.None); } /// /// Get all projects for the specified repository. /// /// /// See the API documentation for more information. /// /// The Id of the repository /// Used to filter the list of projects returned /// Options for changing the API response public IObservable GetAllForRepository(long repositoryId, ProjectRequest request, ApiOptions options) { Ensure.ArgumentNotNull(request, "request"); Ensure.ArgumentNotNull(options, "options"); var url = ApiUrls.RepositoryProjects(repositoryId); return _connection.GetAndFlattenAllPages(url, request.ToParametersDictionary(), AcceptHeaders.ProjectsApiPreview, options); } /// /// Get all projects for the specified organization. /// /// /// See the API documentation for more information. /// /// The name of the organization public IObservable GetAllForOrganization(string organization) { return GetAllForOrganization(organization, ApiOptions.None); } /// /// Get all projects for the specified organization. /// /// /// See the API documentation for more information. /// /// The name of the organziation /// Options for changing the API response public IObservable GetAllForOrganization(string organization, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(organization, "organization"); Ensure.ArgumentNotNull(options, "options"); var url = ApiUrls.OrganizationProjects(organization); return _connection.GetAndFlattenAllPages(url, new Dictionary(), AcceptHeaders.ProjectsApiPreview, options); } /// /// Get all projects for the specified organization. /// /// /// See the API documentation for more information. /// /// The name of the organziation /// Used to filter the list of projects returned public IObservable GetAllForOrganization(string organization, ProjectRequest request) { return GetAllForOrganization(organization, request, ApiOptions.None); } /// /// Get all projects for the specified organization. /// /// /// See the API documentation for more information. /// /// The name of the organziation /// Used to filter the list of projects returned /// Options for changing the API response public IObservable GetAllForOrganization(string organization, ProjectRequest request, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(organization, "organization"); Ensure.ArgumentNotNull(request, "request"); Ensure.ArgumentNotNull(options, "options"); var url = ApiUrls.OrganizationProjects(organization); return _connection.GetAndFlattenAllPages(url, request.ToParametersDictionary(), AcceptHeaders.ProjectsApiPreview, options); } /// /// Gets a single project for the specified repository. /// /// /// See the API documentation for more information. /// /// The Id of the project [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")] public IObservable Get(int id) { return _client.Get(id).ToObservable(); } /// /// Creates a project for the specified repository. /// /// /// See the API documentation for more information. /// /// The Id of the repository /// The new project to create for the specified repository public IObservable CreateForRepository(long repositoryId, NewProject newProject) { Ensure.ArgumentNotNull(newProject, "newProject"); return _client.CreateForRepository(repositoryId, newProject).ToObservable(); } /// /// Creates a project for the specified organization. /// /// /// See the API documentation for more information. /// /// The name of the organization /// The new project to create for the specified repository public IObservable CreateForOrganization(string organization, NewProject newProject) { Ensure.ArgumentNotNullOrEmptyString(organization, "organization"); Ensure.ArgumentNotNull(newProject, "newProject"); return _client.CreateForOrganization(organization, newProject).ToObservable(); } /// /// Updates a project for the specified repository. /// /// /// See the API documentation for more information. /// /// The Id of the project /// The modified project public IObservable Update(int id, ProjectUpdate projectUpdate) { Ensure.ArgumentNotNull(projectUpdate, "projectUpdate"); return _client.Update(id, projectUpdate).ToObservable(); } /// /// Deletes a project. /// /// /// See the API documentation for more information. /// /// The Id of the project public IObservable Delete(int id) { return _client.Delete(id).ToObservable(); } /// /// A client for GitHub's Project Cards API. /// /// /// See the Repository Projects API documentation for more information. /// public IObservableProjectCardsClient Card { get; private set; } /// /// A client for GitHub's Project Columns API. /// /// /// See the Repository Projects API documentation for more information. /// public IObservableProjectColumnsClient Column { get; private set; } } }