using System; #if NET_45 using System.Collections.Generic; #endif using System.Threading.Tasks; using Octokit.Http; namespace Octokit { public class RepositoriesClient : ApiClient, IRepositoriesClient { public RepositoriesClient(IApiConnection client) : base(client) { } /// /// Creates a new repository for the current user. /// /// A instance describing the new repository to create /// A instance for the created repository public async Task Create(NewRepository newRepository) { Ensure.ArgumentNotNull(newRepository, "newRepository"); if (string.IsNullOrEmpty(newRepository.Name)) throw new ArgumentException("The new repository's name must not be null."); var endpoint = new Uri("user/repos", UriKind.Relative); return await Client.Create(endpoint, newRepository); } public async Task Get(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); var endpoint = "/repos/{0}/{1}".FormatUri(owner, name); return await Client.Get(endpoint); } public async Task> GetAllForCurrent() { var endpoint = new Uri("user/repos", UriKind.Relative); return await Client.GetAll(endpoint); } public async Task> GetAllForUser(string login) { Ensure.ArgumentNotNullOrEmptyString(login, "login"); var endpoint = "/users/{0}/repos".FormatUri(login); return await Client.GetAll(endpoint); } public async Task> GetAllForOrg(string organization) { Ensure.ArgumentNotNullOrEmptyString(organization, "organization"); var endpoint = "/orgs/{0}/repos".FormatUri(organization); return await Client.GetAll(endpoint); } public async Task GetReadme(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); var endpoint = "/repos/{0}/{1}/readme".FormatUri(owner, name); var readmeInfo = await Client.GetItem(endpoint, null); return new Readme(readmeInfo, Client); } } }