using System.Collections.Generic; using System.Net; using System.Threading.Tasks; namespace Octokit { public class AssigneesClient : ApiClient, IAssigneesClient { /// /// Instatiates a new GitHub Issue Assignees API client. /// /// An API connection public AssigneesClient(IApiConnection apiConnection) : base(apiConnection) { } /// /// Gets all the available assignees (owner + collaborators) to which issues may be assigned. /// /// The owner of the repository /// The name of the repository /// public Task> GetForRepository(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); return ApiConnection.GetAll(ApiUrls.Assignees(owner, name)); } /// /// Checks to see if a user is an assignee for a repository. /// /// The owner of the repository /// The name of the repository /// Username of the prospective assignee /// public async Task 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(ApiUrls.CheckAssignee(owner, name, assignee), null, null) .ConfigureAwait(false); 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; } } } }