using System.Collections.Generic; using System.Net; using System.Threading.Tasks; namespace Octokit { /// /// A client for GitHub's Project Columns API. /// /// /// See the Repository Projects API documentation for more information. /// public class ProjectColumnsClient : ApiClient, IProjectColumnsClient { public ProjectColumnsClient(IApiConnection apiConnection) : base(apiConnection) { } /// /// Gets all columns for this project. /// /// /// See the API documentation for more information. /// /// The Id of the project [ManualRoute("GET", "/projects/{project_id}/columns")] public Task> GetAll(int projectId) { return GetAll(projectId, ApiOptions.None); } /// /// Gets all columns for this project. /// /// /// See the API documentation for more information. /// /// The Id of the project /// Options for changing the API response [ManualRoute("GET", "/projects/{project_id}/columns")] public Task> GetAll(int projectId, ApiOptions options) { Ensure.ArgumentNotNull(options, nameof(options)); return ApiConnection.GetAll(ApiUrls.ProjectColumns(projectId), new Dictionary(), options); } /// /// Gets a single column for this project. /// /// /// See the API documentation for more information. /// /// The id of the column [ManualRoute("GET", "/projects/columns/{column_id}")] public Task Get(int columnId) { return ApiConnection.Get(ApiUrls.ProjectColumn(columnId), null); } /// /// Creates a column for this project. /// /// /// See the API documentation for more information. /// /// The Id of the project /// The column to create [ManualRoute("POST", "/projects/{project_id}/columns")] public Task Create(int projectId, NewProjectColumn newProjectColumn) { Ensure.ArgumentNotNull(newProjectColumn, nameof(newProjectColumn)); return ApiConnection.Post(ApiUrls.ProjectColumns(projectId), newProjectColumn); } /// /// Updates a column for this project. /// /// /// See the API documentation for more information. /// /// The id of the column /// New values to update the column with [ManualRoute("PATCH", "/projects/columns/{column_id}")] public Task Update(int columnId, ProjectColumnUpdate projectColumnUpdate) { Ensure.ArgumentNotNull(projectColumnUpdate, nameof(projectColumnUpdate)); return ApiConnection.Patch(ApiUrls.ProjectColumn(columnId), projectColumnUpdate); } /// /// Deletes a column. /// /// /// See the API documentation for more information. /// /// The id of the column [ManualRoute("DELETE", "/projects/columns/{column_id}")] public async Task Delete(int columnId) { var endpoint = ApiUrls.ProjectColumn(columnId); try { var httpStatusCode = await Connection.Delete(endpoint, new object()).ConfigureAwait(false); return httpStatusCode == HttpStatusCode.NoContent; } catch (NotFoundException) { return false; } } /// /// Moves a column. /// /// /// See the API documentation for more information. /// /// The id of the column /// The position to move the column [ManualRoute("POST", "/projects/columns/{column_id}/moves")] public async Task Move(int columnId, ProjectColumnMove position) { Ensure.ArgumentNotNull(position, nameof(position)); var endpoint = ApiUrls.ProjectColumnMove(columnId); try { var httpStatusCode = await Connection.Post(endpoint, position, null).ConfigureAwait(false); return httpStatusCode == HttpStatusCode.Created; } catch (NotFoundException) { return false; } } } }