using System;
using System.Reactive.Threading.Tasks;
using Octokit.Reactive.Internal;
namespace Octokit.Reactive.Clients
{
///
/// A client for GitHub's Repository Deployments API.
/// Gets and creates Deployments.
///
///
/// See the Repository Deployments API documentation for more information.
///
public class ObservableDeploymentsClient : IObservableDeploymentsClient
{
readonly IDeploymentsClient _client;
readonly IConnection _connection;
public ObservableDeploymentsClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, "client");
_client = client.Repository.Deployment;
_connection = client.Connection;
Status = new ObservableDeploymentStatusClient(client);
}
///
/// Gets all the deployments for the specified repository. Any user with pull access
/// to a repository can view deployments.
///
///
/// http://developer.github.com/v3/repos/deployments/#list-deployments
///
/// The owner of the repository
/// The name of the repository
public IObservable GetAll(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return GetAll(owner, name, ApiOptions.None);
}
///
/// Gets all the deployments for the specified repository. Any user with pull access
/// to a repository can view deployments.
///
///
/// http://developer.github.com/v3/repos/deployments/#list-deployments
///
/// The ID of the repository
public IObservable GetAll(int repositoryId)
{
return GetAll(repositoryId, ApiOptions.None);
}
///
/// Gets all the deployments for the specified repository. Any user with pull access
/// to a repository can view deployments.
///
///
/// http://developer.github.com/v3/repos/deployments/#list-deployments
///
/// The owner of the repository
/// The name of the repository
/// Options for changing the API response
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.Deployments(owner, name), options);
}
///
/// Gets all the deployments for the specified repository. Any user with pull access
/// to a repository can view deployments.
///
///
/// http://developer.github.com/v3/repos/deployments/#list-deployments
///
/// The ID of the repository
/// Options for changing the API response
public IObservable GetAll(int repositoryId, ApiOptions options)
{
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages(
ApiUrls.Deployments(repositoryId), options);
}
///
/// Creates a new deployment for the specified repository.
/// Users with push access can create a deployment for a given ref.
///
///
/// http://developer.github.com/v3/repos/deployments/#create-a-deployment
///
/// The owner of the repository
/// The name of the repository
/// A instance describing the new deployment to create
public IObservable Create(string owner, string name, NewDeployment newDeployment)
{
Ensure.ArgumentNotNull(newDeployment, "newDeployment");
return _client.Create(owner, name, newDeployment).ToObservable();
}
///
/// Creates a new deployment for the specified repository.
/// Users with push access can create a deployment for a given ref.
///
///
/// http://developer.github.com/v3/repos/deployments/#create-a-deployment
///
/// The ID of the repository
/// A instance describing the new deployment to create
public IObservable Create(int repositoryId, NewDeployment newDeployment)
{
Ensure.ArgumentNotNull(newDeployment, "newDeployment");
return _client.Create(repositoryId, newDeployment).ToObservable();
}
///
/// Client for managing deployment status.
///
public IObservableDeploymentStatusClient Status { get; private set; }
}
}