using System; using System.Reactive; using System.Reactive.Threading.Tasks; using Octokit.Reactive.Internal; namespace Octokit.Reactive { public class ObservableRepositoriesClient : IObservableRepositoriesClient { readonly IRepositoriesClient _client; readonly IConnection _connection; public ObservableRepositoriesClient(IGitHubClient client) { Ensure.ArgumentNotNull(client, "client"); _client = client.Repository; _connection = client.Connection; CommitStatus = new ObservableCommitStatusClient(client); } /// /// Creates a new repository for the current user. /// /// A instance describing the new repository to create /// An instance for the created repository public IObservable Create(NewRepository newRepository) { Ensure.ArgumentNotNull(newRepository, "newRepository"); if (string.IsNullOrEmpty(newRepository.Name)) throw new ArgumentException("The new repository's name must not be null."); return _client.Create(newRepository).ToObservable(); } /// /// Creates a new repository in the specified organization. /// /// The login of the organization in which to create the repostiory /// A instance describing the new repository to create /// An instance for the created repository public IObservable Create(string organizationLogin, NewRepository newRepository) { Ensure.ArgumentNotNull(organizationLogin, "organizationLogin"); Ensure.ArgumentNotNull(newRepository, "newRepository"); if (string.IsNullOrEmpty(newRepository.Name)) throw new ArgumentException("The new repository's name must not be null."); return _client.Create(organizationLogin, newRepository).ToObservable(); } /// /// Deletes a repository for the specified owner and name. /// /// The owner of the repository /// The name of the repository /// Deleting a repository requires admin access. If OAuth is used, the `delete_repo` scope is required. /// An for the operation public IObservable Delete(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); return _client.Delete(owner, name).ToObservable(); } /// /// Retrieves the for the specified owner and name. /// /// The owner of the repository /// The name of the repository /// A public IObservable Get(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); return _client.Get(owner, name).ToObservable(); } /// /// Retrieves every that belongs to the current user. /// /// /// The default page size on GitHub.com is 30. /// /// Thrown if the client is not authenticated. /// A of . public IObservable GetAllForCurrent() { return _connection.GetAndFlattenAllPages(ApiUrls.Repositories()); } /// /// Retrieves every that belongs to the specified user. /// /// /// The default page size on GitHub.com is 30. /// /// A of . public IObservable GetAllForUser(string login) { Ensure.ArgumentNotNullOrEmptyString(login, "login"); return _connection.GetAndFlattenAllPages(ApiUrls.Repositories(login)); } /// /// Retrieves every that belongs to the specified organization. /// /// /// The default page size on GitHub.com is 30. /// /// A of . public IObservable GetAllForOrg(string organization) { Ensure.ArgumentNotNullOrEmptyString(organization, "organization"); return _connection.GetAndFlattenAllPages(ApiUrls.OrganizationRepositories(organization)); } /// /// Returns the HTML rendered README. /// /// The owner of the repository /// The name of the repository /// public IObservable GetReadme(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); return _client.GetReadme(owner, name).ToObservable(); } /// /// Returns just the HTML portion of the README without the surrounding HTML document. /// /// The owner of the repository /// The name of the repository /// public IObservable GetReadmeHtml(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); return _client.GetReadmeHtml(owner, name).ToObservable(); } /// /// A client for GitHub's Commit Status API. /// /// /// See the Commit Status API documentation for more /// details. Also check out the blog post /// that announced this feature. /// public IObservableCommitStatusClient CommitStatus { get; private set; } } }