using System;
using System.Reactive.Threading.Tasks;
using Octokit.Reactive.Internal;
namespace Octokit.Reactive
{
public class ObservableRepositoryCommitsClient : IObservableRepositoryCommitsClient
{
readonly IGitHubClient _client;
readonly IConnection _connection;
readonly IRepositoryCommitsClient _commit;
public ObservableRepositoryCommitsClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, "client");
_client = client;
_connection = client.Connection;
_commit = client.Repository.Commits;
}
///
/// Compare two references in a repository
///
/// The owner of the repository
/// The name of the repository
/// The reference to use as the base commit
/// The reference to use as the head commit
///
public IObservable Compare(string owner, string name, string @base, string head)
{
return _client.Repository.Commits.Compare(owner, name, @base, head).ToObservable();
}
///
/// Gets all commits for a given repository
///
/// The owner of the repository
/// The name of the repository
/// The reference for the commit
///
public IObservable Get(string owner, string name, string reference)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNullOrEmptyString(reference, "reference");
return _commit.Get(owner, name, reference).ToObservable();
}
///
/// Gets all commits for a given repository
///
/// The owner of the repository
/// The name of the repository
///
public IObservable GetAll(string owner, string name)
{
return GetAll(owner, name, new CommitRequest());
}
///
/// Gets all commits for a given repository
///
/// The owner of the repository
/// The name of the repository
/// Used to filter list of commits returned
///
public IObservable GetAll(string owner, string name, CommitRequest request)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(request, "request");
return _connection.GetAndFlattenAllPages(ApiUrls.RepositoryCommits(owner, name),
request.ToParametersDictionary());
}
}
}