Files
octokit.net/Octokit.Reactive/Clients/ObservableRepositoryPagesClient.cs
2016-06-17 05:25:18 +07:00

154 lines
6.4 KiB
C#

using Octokit.Reactive.Internal;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reactive.Threading.Tasks;
namespace Octokit.Reactive
{
/// <summary>
/// A client for GitHub's Repository Pages API.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/pages/">Repository Pages API documentation</a> for more information.
/// </remarks>
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;
}
/// <summary>
/// Gets the page metadata for a given repository
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/pages/#get-information-about-a-pages-site">API documentation</a> for more information.
/// </remarks>
/// <returns></returns>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")]
public IObservable<Page> Get(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return _client.Get(owner, name).ToObservable();
}
/// <summary>
/// Gets the page metadata for a given repository
/// </summary>
/// <param name="repositoryId">The ID of the repository</param>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/pages/#get-information-about-a-pages-site">API documentation</a> for more information.
/// </remarks>
/// <returns></returns>
public IObservable<Page> Get(int repositoryId)
{
return _client.Get(repositoryId).ToObservable();
}
/// <summary>
/// Gets all build metadata for a given repository
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/pages/#list-pages-builds">API documentation</a> for more information.
/// </remarks>
/// <returns></returns>
public IObservable<PagesBuild> GetAll(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return GetAll(owner, name, ApiOptions.None);
}
/// <summary>
/// Gets all build metadata for a given repository
/// </summary>
/// <param name="repositoryId">The ID of the repository</param>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/pages/#list-pages-builds">API documentation</a> for more information.
/// </remarks>
/// <returns></returns>
public IObservable<PagesBuild> GetAll(int repositoryId)
{
return GetAll(repositoryId, ApiOptions.None);
}
/// <summary>
/// Gets all build metadata for a given repository
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="options">Options to change the API response</param>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/pages/#list-pages-builds">API documentation</a> for more information.
/// </remarks>
/// <returns></returns>
public IObservable<PagesBuild> GetAll(string owner, string name, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages<PagesBuild>(ApiUrls.RepositoryPageBuilds(owner, name), options);
}
/// <summary>
/// Gets all build metadata for a given repository
/// </summary>
/// <param name="repositoryId">The ID of the repository</param>
/// <param name="options">Options to change the API response</param>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/pages/#list-pages-builds">API documentation</a> for more information.
/// </remarks>
/// <returns></returns>
public IObservable<PagesBuild> GetAll(int repositoryId, ApiOptions options)
{
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages<PagesBuild>(ApiUrls.RepositoryPageBuilds(repositoryId), options);
}
/// <summary>
/// Gets the build metadata for the last build for a given repository
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/pages/#list-latest-pages-build">API documentation</a> for more information.
/// </remarks>
/// <returns></returns>
public IObservable<PagesBuild> GetLatest(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return _client.GetLatest(owner, name).ToObservable();
}
/// <summary>
/// Gets the build metadata for the last build for a given repository
/// </summary>
/// <param name="repositoryId">The ID of the repository</param>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/pages/#list-latest-pages-build">API documentation</a> for more information.
/// </remarks>
/// <returns></returns>
public IObservable<PagesBuild> GetLatest(int repositoryId)
{
return _client.GetLatest(repositoryId).ToObservable();
}
}
}