using Octokit.Reactive.Internal;
using System;
using System.Collections.Generic;
using System.Reactive;
using System.Reactive.Threading.Tasks;
using System.Text;
namespace Octokit.Reactive
{
///
/// A client for GitHub's Repository Variables API.
///
///
/// See the Repository Variables API documentation for more details.
///
public class ObservableRepositoryVariablesClient : IObservableRepositoryVariablesClient
{
readonly IRepositoryVariablesClient _client;
readonly IConnection _connection;
public ObservableRepositoryVariablesClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, nameof(client));
_client = client.Repository.Actions.Variables;
_connection = client.Connection;
}
///
/// List the organization variables for a repository.
///
///
/// See the API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// Thrown when a general API error occurs.
/// A instance for the list of repository variables.
public IObservable GetAllOrganization(string owner, string repoName)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(repoName, nameof(repoName));
return _client.GetAll(owner, repoName).ToObservable();
}
///
/// List the variables for a repository.
///
///
/// See the API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// Thrown when a general API error occurs.
/// A instance for the list of repository variables.
public IObservable GetAll(string owner, string repoName)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(repoName, nameof(repoName));
return _client.GetAll(owner, repoName).ToObservable();
}
///
/// Get a variable from a repository.
///
///
/// See the API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// The name of the variable
/// Thrown when a general API error occurs.
/// A instance for the repository secret.
public IObservable Get(string owner, string repoName, string variableName)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(repoName, nameof(repoName));
Ensure.ArgumentNotNullOrEmptyString(variableName, nameof(variableName));
return _client.Get(owner, repoName, variableName).ToObservable();
}
///
/// Create a variable in a repository.
///
///
/// See the API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// The variable to create
/// Thrown when a general API error occurs.
/// A instance for the repository variable that was created.
public IObservable Create(string owner, string repoName, Variable newVariable)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(repoName, nameof(repoName));
Ensure.ArgumentNotNullOrDefault(newVariable, nameof(newVariable));
Ensure.ArgumentNotNullOrEmptyString(newVariable.Name, nameof(newVariable.Name));
Ensure.ArgumentNotNullOrEmptyString(newVariable.Value, nameof(newVariable.Value));
return _client.Create(owner, repoName, newVariable).ToObservable();
}
///
/// Update a variable in a repository.
///
///
/// See the API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// The variable to update
/// Thrown when a general API error occurs.
/// A instance for the repository variable that was updated.
public IObservable Update(string owner, string repoName, Variable variable)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(repoName, nameof(repoName));
Ensure.ArgumentNotNullOrDefault(variable, nameof(variable));
Ensure.ArgumentNotNullOrEmptyString(variable.Name, nameof(variable.Name));
Ensure.ArgumentNotNullOrEmptyString(variable.Value, nameof(variable.Value));
return _client.Update(owner, repoName, variable).ToObservable();
}
///
/// Delete a variable in a repository.
///
///
/// See the API documentation for more information.
///
/// The owner of the repository
/// The name of the repository
/// The name of the variable
/// Thrown when a general API error occurs.
public IObservable Delete(string owner, string repoName, string variableName)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(repoName, nameof(repoName));
Ensure.ArgumentNotNullOrEmptyString(variableName, nameof(variableName));
return _client.Delete(owner, repoName, variableName).ToObservable();
}
}
}