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, nameof(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, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(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(long 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, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(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(long 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, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNull(options, nameof(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(long repositoryId, ApiOptions options)
{
Ensure.ArgumentNotNull(options, nameof(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, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(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(long repositoryId)
{
return _client.GetLatest(repositoryId).ToObservable();
}
///
/// Requests your site be built from the latest revision on the default branch for a given repository
///
/// The owner of the repository
/// The name of the repository
///
/// See the API documentation for more information.
///
public IObservable RequestPageBuild(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
return _client.RequestPageBuild(owner, name).ToObservable();
}
///
/// Requests your site be built from the latest revision on the default branch for a given repository
///
/// The Id of the repository
///
/// See the API documentation for more information.
///
public IObservable RequestPageBuild(long repositoryId)
{
return _client.RequestPageBuild(repositoryId).ToObservable();
}
}
}