using System.Collections.Generic; using System.Net; using System.Threading.Tasks; namespace Octokit { /// /// A client for GitHub's Project Cards API. /// /// /// See the Repository Projects API documentation for more information. /// public class ProjectCardsClient : ApiClient, IProjectCardsClient { public ProjectCardsClient(IApiConnection apiConnection) : base(apiConnection) { } /// /// Gets all cards. /// /// /// See the API documentation for more information. /// /// The id of the column [ManualRoute("GET", "/projects/columns/{column_id}/cards")] public Task> GetAll(int columnId) { return GetAll(columnId, ApiOptions.None); } /// /// Gets all cards. /// /// /// See the API documentation for more information. /// /// The id of the column /// Options for changing the API response [ManualRoute("GET", "/projects/columns/{column_id}/cards")] public Task> 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 [ManualRoute("GET", "/projects/columns/{column_id}/cards")] public Task> 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 [Preview("inertia")] [ManualRoute("GET", "/projects/columns/{column_id}/cards")] public Task> GetAll(int columnId, ProjectCardRequest request, ApiOptions options) { Ensure.ArgumentNotNull(request, nameof(request)); Ensure.ArgumentNotNull(options, nameof(options)); return ApiConnection.GetAll(ApiUrls.ProjectCards(columnId), request.ToParametersDictionary(), AcceptHeaders.ProjectsApiPreview, options); } /// /// Gets a single card. /// /// /// See the API documentation for more information. /// /// The id of the card [Preview("inertia")] [ManualRoute("GET", "/projects/columns/cards/{card_id}")] public Task Get(int id) { return ApiConnection.Get(ApiUrls.ProjectCard(id), null, AcceptHeaders.ProjectsApiPreview); } /// /// Creates a card. /// /// /// See the API documentation for more information. /// /// The id of the column /// The card to create [Preview("inertia")] [ManualRoute("POST", "/projects/columns/{column_id}/cards")] public Task Create(int columnId, NewProjectCard newProjectCard) { Ensure.ArgumentNotNull(newProjectCard, nameof(newProjectCard)); return ApiConnection.Post(ApiUrls.ProjectCards(columnId), newProjectCard, AcceptHeaders.ProjectsApiPreview); } /// /// Updates a card. /// /// /// See the API documentation for more information. /// /// The id of the card /// New values to update the card with [Preview("inertia")] [ManualRoute("GET", "/projects/columns/cards/{card_id}")] public Task Update(int id, ProjectCardUpdate projectCardUpdate) { Ensure.ArgumentNotNull(projectCardUpdate, nameof(projectCardUpdate)); return ApiConnection.Patch(ApiUrls.ProjectCard(id), projectCardUpdate, AcceptHeaders.ProjectsApiPreview); } /// /// Deletes a card. /// /// /// See the API documentation for more information. /// /// The id of the card [Preview("inertia")] [ManualRoute("DELETE", "/projects/columns/cards/{card_id}")] public async Task Delete(int id) { var endpoint = ApiUrls.ProjectCard(id); try { var httpStatusCode = await Connection.Delete(endpoint, new object(), AcceptHeaders.ProjectsApiPreview).ConfigureAwait(false); return httpStatusCode == HttpStatusCode.NoContent; } catch (NotFoundException) { return false; } } /// /// Moves a card. /// /// /// See the API documentation for more information. /// /// The id of the card /// The position to move the card [Preview("inertia")] [ManualRoute("POST", "/projects/columns/cards/{card_id}/moves")] public async Task Move(int id, ProjectCardMove position) { Ensure.ArgumentNotNull(position, nameof(position)); var endpoint = ApiUrls.ProjectCardMove(id); try { var httpStatusCode = await Connection.Post(endpoint, position, AcceptHeaders.ProjectsApiPreview).ConfigureAwait(false); return httpStatusCode == HttpStatusCode.Created; } catch (NotFoundException) { return false; } } } }