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, nameof(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, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNull(options, nameof(options));
var url = ApiUrls.RepositoryProjects(owner, name);
return _connection.GetAndFlattenAllPages(url, new Dictionary(), 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, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNull(request, nameof(request));
Ensure.ArgumentNotNull(options, nameof(options));
var url = ApiUrls.RepositoryProjects(owner, name);
return _connection.GetAndFlattenAllPages(url, request.ToParametersDictionary(), 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, nameof(options));
var url = ApiUrls.RepositoryProjects(repositoryId);
return _connection.GetAndFlattenAllPages(url, new Dictionary(), 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, nameof(request));
Ensure.ArgumentNotNull(options, nameof(options));
var url = ApiUrls.RepositoryProjects(repositoryId);
return _connection.GetAndFlattenAllPages(url, request.ToParametersDictionary(), 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 organization
/// Options for changing the API response
public IObservable GetAllForOrganization(string organization, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(organization, nameof(organization));
Ensure.ArgumentNotNull(options, nameof(options));
var url = ApiUrls.OrganizationProjects(organization);
return _connection.GetAndFlattenAllPages(url, new Dictionary(), options);
}
///
/// Get all projects for the specified organization.
///
///
/// See the API documentation for more information.
///
/// The name of the organization
/// 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 organization
/// 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, nameof(organization));
Ensure.ArgumentNotNull(request, nameof(request));
Ensure.ArgumentNotNull(options, nameof(options));
var url = ApiUrls.OrganizationProjects(organization);
return _connection.GetAndFlattenAllPages(url, request.ToParametersDictionary(), 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, nameof(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, nameof(organization));
Ensure.ArgumentNotNull(newProject, nameof(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 projectId, ProjectUpdate projectUpdate)
{
Ensure.ArgumentNotNull(projectUpdate, nameof(projectUpdate));
return _client.Update(projectId, projectUpdate).ToObservable();
}
///
/// Deletes a project.
///
///
/// See the API documentation for more information.
///
/// The Id of the project
public IObservable Delete(int projectId)
{
return _client.Delete(projectId).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; }
}
}