Files
octokit.net/Octokit/Clients/AssigneesClient.cs
Haacked e1d618dcaa Implement AssigneesClient
Implement client to list and check available assignees for a repository
2013-10-23 14:51:48 -07:00

56 lines
2.2 KiB
C#

using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;
namespace Octokit
{
public class AssigneesClient : ApiClient, IAssigneesClient
{
public AssigneesClient(IApiConnection apiConnection) : base(apiConnection)
{
}
/// <summary>
/// Gets all the available assignees (owner + collaborators) to which issues may be assigned.
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <returns></returns>
public async Task<IReadOnlyList<User>> GetForRepository(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return await ApiConnection.GetAll<User>(ApiUrls.Assignees(owner, name));
}
/// <summary>
/// Checks to see if a user is an assignee for a repository.
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="assignee">Username of the prospective assignee</param>
/// <returns></returns>
public async Task<bool> CheckAssignee(string owner, string name, string assignee)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNullOrEmptyString(assignee, "assignee");
try
{
var response = await Connection.GetAsync<object>(ApiUrls.CheckAssignee(owner, name, assignee), null, null);
if (response.StatusCode != HttpStatusCode.NotFound && response.StatusCode != HttpStatusCode.NoContent)
{
throw new ApiException("Invalid Status Code returned. Expected a 204 or a 404", response.StatusCode);
}
return response.StatusCode == HttpStatusCode.NoContent;
}
catch (NotFoundException)
{
return false;
}
}
}
}