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
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
public Task> GetAll(int projectId, ApiOptions options)
{
Ensure.ArgumentNotNull(options, "options");
return ApiConnection.GetAll(ApiUrls.ProjectColumns(projectId), new Dictionary(), AcceptHeaders.ProjectsApiPreview, options);
}
///
/// Gets a single column for this project.
///
///
/// See the API documentation for more information.
///
/// The id of the column
public Task Get(int id)
{
return ApiConnection.Get(ApiUrls.ProjectColumn(id), null, AcceptHeaders.ProjectsApiPreview);
}
///
/// Creates a column for this project.
///
///
/// See the API documentation for more information.
///
/// The Id of the project
/// The column to create
public Task Create(int projectId, NewProjectColumn newProjectColumn)
{
Ensure.ArgumentNotNull(newProjectColumn, "newProjectColumn");
return ApiConnection.Post(ApiUrls.ProjectColumns(projectId), newProjectColumn, AcceptHeaders.ProjectsApiPreview);
}
///
/// 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
public Task Update(int id, ProjectColumnUpdate projectColumnUpdate)
{
Ensure.ArgumentNotNull(projectColumnUpdate, "projectColumnUpdate");
return ApiConnection.Patch(ApiUrls.ProjectColumn(id), projectColumnUpdate, AcceptHeaders.ProjectsApiPreview);
}
///
/// Deletes a column.
///
///
/// See the API documentation for more information.
///
/// The id of the column
public async Task Delete(int id)
{
var endpoint = ApiUrls.ProjectColumn(id);
try
{
var httpStatusCode = await Connection.Delete(endpoint, new object(), AcceptHeaders.ProjectsApiPreview).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
public async Task Move(int id, ProjectColumnMove position)
{
Ensure.ArgumentNotNull(position, "position");
var endpoint = ApiUrls.ProjectColumnMove(id);
try
{
var httpStatusCode = await Connection.Post(endpoint, position, AcceptHeaders.ProjectsApiPreview).ConfigureAwait(false);
return httpStatusCode == HttpStatusCode.Created;
}
catch (NotFoundException)
{
return false;
}
}
}
}