rx client fixup

This commit is contained in:
Andy Cross
2014-01-20 17:50:18 +00:00
parent 740fd9cf53
commit 5f038b8d1f
5 changed files with 174 additions and 13 deletions
@@ -100,13 +100,9 @@ namespace Octokit.Reactive
/// </remarks>
IObservableCommitStatusClient CommitStatus { get; }
/// <summary>
/// Gets the list of hooks defined for a repository
/// Gets a client for GitHub's Repository Hooks
/// </summary>
/// <remarks>See <a href="http://developer.github.com/v3/repos/hooks/#json-http">API documentation</a> for more information.</remarks>
/// <returns></returns>
IObservable<IReadOnlyList<RepositoryHook>> GetHooks(string owner, string repositoryName);
IObservableRepositoryHooksClient Hooks { get; }
}
}
@@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Reactive;
namespace Octokit.Reactive.Clients
{
public interface IObservableRepositoryHooksClient
{
/// <summary>
/// Gets the list of hooks defined for a repository
/// </summary>
/// <remarks>See <a href="http://developer.github.com/v3/repos/hooks/#list">API documentation</a> for more information.</remarks>
/// <returns></returns>
IObservable<IReadOnlyList<RepositoryHook>> Get(string owner, string repositoryName);
/// <summary>
/// Gets a single hook defined for a repository by id
/// </summary>
/// <remarks>See <a href="http://developer.github.com/v3/repos/hooks/#get-single-hook">API documentation</a> for more information.</remarks>
/// <returns></returns>
IObservable<RepositoryHook> GetById(string owner, string repositoryName, int hookId);
/// <summary>
/// Creates a hook for a repository
/// </summary>
/// <remarks>See <a href="http://developer.github.com/v3/repos/hooks/#create-a-hook">API documentation</a> for more information.</remarks>
/// <returns></returns>
IObservable<RepositoryHook> Create(string owner, string repositoryName, NewRepositoryHook hook);
/// <summary>
/// Edits a hook for a repository
/// </summary>
/// <remarks>See <a href="http://developer.github.com/v3/repos/hooks/#edit-a-hook">API documentation</a> for more information.</remarks>
/// <returns></returns>
IObservable<RepositoryHook> Edit(string owner, string repositoryName, int hookId, EditRepositoryHook hook);
/// <summary>
/// Tests a hook for a repository
/// </summary>
/// <remarks>See <a href="http://developer.github.com/v3/repos/hooks/#test-a-hook">API documentation</a> 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.</remarks>
/// <returns></returns>
IObservable<Unit> Test(string owner, string repositoryName, int hookId);
/// <summary>
/// Deletes a hook for a repository
/// </summary>
/// <param name="owner"></param>
/// <param name="repositoryName"></param>
/// <param name="hookId"></param>
/// <remarks>See <a href="http://developer.github.com/v3/repos/hooks/#delete-a-hook">API documentation</a> for more information.</remarks>
/// <returns></returns>
IObservable<Unit> Delete(string owner, string repositoryName, int hookId);
}
}
@@ -18,6 +18,8 @@ namespace Octokit.Reactive
_client = client.Repository;
_connection = client.Connection;
CommitStatus = new ObservableCommitStatusClient(client);
var apiConnection = new ApiConnection(_connection);
_hooks = new Lazy<IRepositoryHooksClient>( () => new RepositoryHooksClient(apiConnection));
}
/// <summary>
@@ -109,15 +111,14 @@ namespace Octokit.Reactive
}
public IObservableCommitStatusClient CommitStatus { get; private set; }
Lazy<IRepositoryHooksClient> _hooks;
public IObservable<IReadOnlyList<RepositoryHook>> GetHooks(string owner, string repositoryName)
/// <summary>
/// Gets a client for GitHub's Repository Hooks
/// </summary>
public IRepositoryHooksClient Hooks
{
throw new NotImplementedException("refactor");
//Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
//Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");
//return _client.Get(owner, repositoryName).ToObservable();
get { return _hooks.Value; }
}
}
}
@@ -0,0 +1,106 @@
using System;
using System.Collections.Generic;
using System.Reactive;
using System.Reactive.Threading.Tasks;
namespace Octokit.Reactive.Clients
{
public class ObservableRepositoryHooksClient : IObservableRepositoryHooksClient
{
readonly IRepositoriesClient _client;
readonly IConnection _connection;
public ObservableRepositoryHooksClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, "client");
_client = client.Repository;
_connection = client.Connection;
}
/// <summary>
/// Gets the list of hooks defined for a repository
/// </summary>
/// <remarks>See <a href="http://developer.github.com/v3/repos/hooks/#list">API documentation</a> for more information.</remarks>
/// <returns></returns>
public IObservable<IReadOnlyList<RepositoryHook>> Get(string owner, string repositoryName)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");
return _client.Hooks.Get(owner, repositoryName).ToObservable();
}
/// <summary>
/// Gets a single hook defined for a repository by id
/// </summary>
/// <remarks>See <a href="http://developer.github.com/v3/repos/hooks/#get-single-hook">API documentation</a> for more information.</remarks>
/// <returns></returns>
public IObservable<RepositoryHook> GetById(string owner, string repositoryName, int hookId)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");
return _client.Hooks.GetById(owner, repositoryName, hookId).ToObservable();
}
/// <summary>
/// Creates a hook for a repository
/// </summary>
/// <remarks>See <a href="http://developer.github.com/v3/repos/hooks/#create-a-hook">API documentation</a> for more information.</remarks>
/// <returns></returns>
public IObservable<RepositoryHook> Create(string owner, string repositoryName, NewRepositoryHook hook)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");
Ensure.ArgumentNotNull(hook, "hook");
return _client.Hooks.Create(owner, repositoryName, hook).ToObservable();
}
/// <summary>
/// Edits a hook for a repository
/// </summary>
/// <remarks>See <a href="http://developer.github.com/v3/repos/hooks/#edit-a-hook">API documentation</a> for more information.</remarks>
/// <returns></returns>
public IObservable<RepositoryHook> Edit(string owner, string repositoryName, int hookId, EditRepositoryHook hook)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");
Ensure.ArgumentNotNull(hook, "hook");
return _client.Hooks.Edit(owner, repositoryName, hookId, hook).ToObservable();
}
/// <summary>
/// Tests a hook for a repository
/// </summary>
/// <remarks>See <a href="http://developer.github.com/v3/repos/hooks/#test-a-hook">API documentation</a> 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.</remarks>
/// <returns></returns>
public IObservable<Unit> Test(string owner, string repositoryName, int hookId)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");
return _client.Hooks.Test(owner, repositoryName, hookId).ToObservable();
}
/// <summary>
/// Deletes a hook for a repository
/// </summary>
/// <param name="owner"></param>
/// <param name="repositoryName"></param>
/// <param name="hookId"></param>
/// <remarks>See <a href="http://developer.github.com/v3/repos/hooks/#delete-a-hook">API documentation</a> for more information.</remarks>
/// <returns></returns>
public IObservable<Unit> Delete(string owner, string repositoryName, int hookId)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");
return _client.Hooks.Delete(owner, repositoryName, hookId).ToObservable();
}
}
}
+2
View File
@@ -71,6 +71,7 @@
<Compile Include="..\SolutionInfo.cs">
<Link>Properties\SolutionInfo.cs</Link>
</Compile>
<Compile Include="Clients\IObservableRepositoryHooksClient.cs" />
<Compile Include="Clients\ObservableAssigneesClient.cs" />
<Compile Include="Clients\IObservableCommitStatusClient.cs" />
<Compile Include="Clients\ObservableCommitStatusClient.cs" />
@@ -80,6 +81,7 @@
<Compile Include="Clients\ObservableOrganizationsClient.cs" />
<Compile Include="Clients\ObservableReleasesClient.cs" />
<Compile Include="Clients\ObservableRepositoriesClient.cs" />
<Compile Include="Clients\ObservableRepositoryHooksClient.cs" />
<Compile Include="Clients\ObservableSshKeysClient.cs" />
<Compile Include="Clients\ObservableUsersClient.cs" />
<Compile Include="Clients\IObservableAssigneesClient.cs" />