using System; using System.Reactive.Threading.Tasks; using Octokit.Reactive.Internal; namespace Octokit.Reactive { /// /// A client for GitHub's Repository Forks API. /// /// /// See the Forks API documentation for more information. /// public class ObservableRepositoryForksClient : IObservableRepositoryForksClient { readonly IRepositoryForksClient _client; readonly IConnection _connection; /// /// Initializes a new GitHub Repos Fork API client. /// /// public ObservableRepositoryForksClient(IGitHubClient client) { Ensure.ArgumentNotNull(client, "client"); _client = client.Repository.Forks; _connection = client.Connection; } /// /// Gets the list of forks defined for a repository /// /// /// See API documentation for more information. /// /// The owner of the repository /// The name of the repository public IObservable GetAll(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); return GetAll(owner, name, ApiOptions.None); } /// /// Gets the list of forks defined for a repository /// /// /// See API documentation for more information. /// /// The Id of the repository public IObservable GetAll(int repositoryId) { return GetAll(repositoryId, ApiOptions.None); } /// /// Gets the list of forks defined for a repository /// /// /// See API documentation for more information. /// /// The owner of the repository /// The name of the repository /// Options for changing the API response public IObservable GetAll(string owner, string name, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(options, "options"); return _connection.GetAndFlattenAllPages(ApiUrls.RepositoryForks(owner, name), options); } /// /// Gets the list of forks defined for a repository /// /// /// See API documentation for more information. /// /// The Id of the repository /// Options for changing the API response public IObservable GetAll(int repositoryId, ApiOptions options) { Ensure.ArgumentNotNull(options, "options"); return _connection.GetAndFlattenAllPages(ApiUrls.RepositoryForks(repositoryId), options); } /// /// Gets the list of forks defined for a repository /// /// /// See API documentation for more information. /// /// The owner of the repository /// The name of the repository /// Used to request and filter a list of repository forks public IObservable GetAll(string owner, string name, RepositoryForksListRequest request) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(request, "request"); return GetAll(owner, name, request, ApiOptions.None); } /// /// Gets the list of forks defined for a repository /// /// /// See API documentation for more information. /// /// The Id of the repository /// Used to request and filter a list of repository forks public IObservable GetAll(int repositoryId, RepositoryForksListRequest request) { Ensure.ArgumentNotNull(request, "request"); return GetAll(repositoryId, request, ApiOptions.None); } /// /// Gets the list of forks defined for a repository /// /// /// See API documentation for more information. /// /// The owner of the repository /// The name of the repository /// Used to request and filter a list of repository forks /// Options for changing the API response public IObservable GetAll(string owner, string name, RepositoryForksListRequest request, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(request, "request"); Ensure.ArgumentNotNull(options, "options"); return _connection.GetAndFlattenAllPages(ApiUrls.RepositoryForks(owner, name), request.ToParametersDictionary(), options); } /// /// Gets the list of forks defined for a repository /// /// /// See API documentation for more information. /// /// The Id of the repository /// Used to request and filter a list of repository forks /// Options for changing the API response public IObservable GetAll(int repositoryId, RepositoryForksListRequest request, ApiOptions options) { Ensure.ArgumentNotNull(request, "request"); Ensure.ArgumentNotNull(options, "options"); return _connection.GetAndFlattenAllPages(ApiUrls.RepositoryForks(repositoryId), request.ToParametersDictionary(), options); } /// /// Creates a fork for a repository. Specify organization in the fork parameter to create for an organization. /// /// /// See API documentation for more information. /// /// The owner of the repository /// The name of the repository /// Used to fork a repository public IObservable Create(string owner, string name, NewRepositoryFork fork) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(fork, "fork"); return _client.Create(owner, name, fork).ToObservable(); } /// /// Creates a fork for a repository. Specify organization in the fork parameter to create for an organization. /// /// /// See API documentation for more information. /// /// The Id of the repository /// Used to fork a repository public IObservable Create(int repositoryId, NewRepositoryFork fork) { Ensure.ArgumentNotNull(fork, "fork"); return _client.Create(repositoryId, fork).ToObservable(); } } }