using System;
using System.Reactive;
using System.Reactive.Threading.Tasks;
using Octokit.Reactive.Internal;
namespace Octokit.Reactive
{
///
/// A client for GitHub's Repository Webhooks API.
///
///
/// See the Webhooks API documentation for more information.
///
public class ObservableRepositoryHooksClient : IObservableRepositoryHooksClient
{
readonly IRepositoryHooksClient _client;
readonly IConnection _connection;
///
/// Initializes a new GitHub Webhooks API client.
///
///
public ObservableRepositoryHooksClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, "client");
_client = client.Repository.Hooks;
_connection = client.Connection;
}
///
/// Gets the list of hooks defined for a repository
///
/// The repository's owner
/// The repository's name
/// See API documentation for more information.
/// A of s representing hooks for specified repository
public IObservable GetAll(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return GetAll(owner, name, ApiOptions.None);
}
///
/// Gets the list of hooks defined for a repository
///
/// The repository's owner
/// The repository's name
/// Options for changing the API response
/// See API documentation for more information.
/// A of s representing hooks for specified repository
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.RepositoryHooks(owner, name), options);
}
///
/// Gets a single hook by Id
///
/// The repository's owner
/// The repository's name
/// The repository's hook id
/// See API documentation for more information.
/// A representing hook for specified hook id
public IObservable Get(string owner, string name, int hookId)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return _client.Get(owner, name, hookId).ToObservable();
}
///
/// Creates a hook for a repository
///
/// The repository's owner
/// The repository's name
/// The hook's parameters
/// See API documentation for more information.
/// A representing created hook for specified repository
public IObservable Create(string owner, string name, NewRepositoryHook hook)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(hook, "hook");
return _client.Create(owner, name, hook).ToObservable();
}
///
/// Edits a hook for a repository
///
/// The repository's owner
/// The repository's name
/// The repository's hook id
/// The requested changes to an edit repository hook
/// See API documentation for more information.
/// A representing modified hook for specified repository
public IObservable Edit(string owner, string name, int hookId, EditRepositoryHook hook)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(hook, "hook");
return _client.Edit(owner, name, hookId, hook).ToObservable();
}
///
/// Tests a hook for a repository
///
/// The repository's owner
/// The repository's name
/// The repository's hook id
/// See API documentation for more information.
/// This will trigger the hook with the latest push to the current repository if the hook is subscribed to push events. If the hook
/// is not subscribed to push events, the server will respond with 204 but no test POST will be generated.
///
public IObservable Test(string owner, string name, int hookId)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return _client.Test(owner, name, hookId).ToObservable();
}
///
/// This will trigger a ping event to be sent to the hook.
///
/// The repository's owner
/// The repository's name
/// The repository's hook id
/// See API documentation for more information.
///
public IObservable Ping(string owner, string name, int hookId)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return _client.Ping(owner, name, hookId).ToObservable();
}
///
/// Deletes a hook for a repository
///
/// The repository's owner
/// The repository's name
/// The repository's hook id
/// See API documentation for more information.
///
public IObservable Delete(string owner, string name, int hookId)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return _client.Delete(owner, name, hookId).ToObservable();
}
}
}