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
/// A of s representing forks of specified 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
/// A of s representing forks of specified 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
/// A of s representing forks of specified repository.
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
/// A of s representing forks of specified repository.
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
/// A of s representing forks of specified repository.
public IObservable GetAll(string owner, string name, RepositoryForksListRequest request)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
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
/// A of s representing forks of specified repository.
public IObservable GetAll(int repositoryId, RepositoryForksListRequest 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
/// A of s representing forks of specified repository.
public IObservable GetAll(string owner, string name, RepositoryForksListRequest request, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(options, "options");
return request == null ? _connection.GetAndFlattenAllPages(ApiUrls.RepositoryForks(owner, name), options) :
_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
/// A of s representing forks of specified repository.
public IObservable GetAll(int repositoryId, RepositoryForksListRequest request, ApiOptions options)
{
Ensure.ArgumentNotNull(options, "options");
return request == null ? _connection.GetAndFlattenAllPages(ApiUrls.RepositoryForks(repositoryId), options) :
_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
/// A of representing the created fork of specified 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
/// A of representing the created fork of specified repository.
public IObservable Create(int repositoryId, NewRepositoryFork fork)
{
Ensure.ArgumentNotNull(fork, "fork");
return _client.Create(repositoryId, fork).ToObservable();
}
}
}