using Octokit.Reactive.Internal;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reactive.Threading.Tasks;
namespace Octokit.Reactive
{
///
/// A client for GitHub's Repository Pages API.
///
///
/// See the Repository Pages API documentation for more information.
///
public class ObservableRepositoryPagesClient : IObservableRepositoryPagesClient
{
readonly IRepositoryPagesClient _client;
readonly IConnection _connection;
public ObservableRepositoryPagesClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, "client");
_client = client.Repository.Page;
_connection = client.Connection;
}
///
/// Gets the page metadata for a given repository
///
/// The owner of the repository
/// The name of the repository
///
/// See the API documentation for more information.
///
///
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")]
public IObservable Get(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return _client.Get(owner, name).ToObservable();
}
///
/// Gets the page metadata for a given repository
///
/// The ID of the repository
///
/// See the API documentation for more information.
///
///
public IObservable Get(int repositoryId)
{
return _client.Get(repositoryId).ToObservable();
}
///
/// Gets all build metadata for a given repository
///
/// The owner of the repository
/// The name of the repository
///
/// See the API documentation for more information.
///
///
public IObservable GetAll(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return GetAll(owner, name, ApiOptions.None);
}
///
/// Gets all build metadata for a given repository
///
/// The ID of the repository
///
/// See the API documentation for more information.
///
///
public IObservable GetAll(int repositoryId)
{
return GetAll(repositoryId, ApiOptions.None);
}
///
/// Gets all build metadata for a given repository
///
/// The owner of the repository
/// The name of the repository
/// Options to change the API response
///
/// See the API documentation for more information.
///
///
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.RepositoryPageBuilds(owner, name), options);
}
///
/// Gets all build metadata for a given repository
///
/// The ID of the repository
/// Options to change the API response
///
/// See the API documentation for more information.
///
///
public IObservable GetAll(int repositoryId, ApiOptions options)
{
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages(ApiUrls.RepositoryPageBuilds(repositoryId), options);
}
///
/// Gets the build metadata for the last build for a given repository
///
/// The owner of the repository
/// The name of the repository
///
/// See the API documentation for more information.
///
///
public IObservable GetLatest(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return _client.GetLatest(owner, name).ToObservable();
}
///
/// Gets the build metadata for the last build for a given repository
///
/// The ID of the repository
///
/// See the API documentation for more information.
///
///
public IObservable GetLatest(int repositoryId)
{
return _client.GetLatest(repositoryId).ToObservable();
}
}
}