Skip to content

Commit

Permalink
Observable repo deploy keys client
Browse files Browse the repository at this point in the history
  • Loading branch information
hnrkndrssn committed Jun 14, 2014
1 parent 9543029 commit 83a85b5
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 0 deletions.
59 changes: 59 additions & 0 deletions Octokit.Reactive/Clients/IObservableRepositoryDeployKeysClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reactive;
using System.Text;
using System.Threading.Tasks;

namespace Octokit.Reactive
{
public interface IObservableRepositoryDeployKeysClient
{
/// <summary>
/// Get a single deploy key by number for a repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/keys/#get"> API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The owner of the repository.</param>
/// <param name="name">The name of the repository.</param>
/// <param name="number">The id of the deploy key.</param>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")]
IObservable<DeployKey> Get(string owner, string name, int number);

/// <summary>
/// Get all deploy keys for a repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/keys/#list"> API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The owner of the repository.</param>
/// <param name="name">The name of the repository.</param>
IObservable<DeployKey> GetAll(string owner, string name);

/// <summary>
/// Creates a new deploy key for a repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/keys/#create"> API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The owner of the repository.</param>
/// <param name="name">The name of the repository.</param>
/// <param name="newDeployKey">The deploy key to create for the repository.</param>
/// <returns></returns>
IObservable<DeployKey> Create(string owner, string name, NewDeployKey newDeployKey);

/// <summary>
/// Deletes a deploy key from a repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/keys/#delete"> API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The owner of the repository.</param>
/// <param name="name">The name of the repository.</param>
/// <param name="number">The id of the deploy key to delete.</param>
/// <returns></returns>
IObservable<Unit> Delete(string owner, string name, int number);
}
}
102 changes: 102 additions & 0 deletions Octokit.Reactive/Clients/ObservableRepositoryDeployKeysClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive;
using System.Reactive.Threading.Tasks;
using System.Text;
using System.Threading.Tasks;
using Octokit.Reactive.Internal;

namespace Octokit.Reactive
{
public class ObservableRepositoryDeployKeysClient : IObservableRepositoryDeployKeysClient
{
readonly IRepositoryDeployKeysClient _client;
readonly IConnection _connection;

public ObservableRepositoryDeployKeysClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, "client");

_client = client.Repository.DeployKeys;
_connection = client.Connection;
}

/// <summary>
/// Get a single deploy key by number for a repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/keys/#get"> API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The owner of the repository.</param>
/// <param name="name">The name of the repository.</param>
/// <param name="number">The id of the deploy key.</param>
public IObservable<DeployKey> Get(string owner, string name, int number)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");

return _client.Get(owner, name, number).ToObservable();
}

/// <summary>
/// Get all deploy keys for a repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/keys/#list"> API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The owner of the repository.</param>
/// <param name="name">The name of the repository.</param>
public IObservable<DeployKey> GetAll(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");

return _connection.GetAndFlattenAllPages<DeployKey>(ApiUrls.RepositoryDeployKeys(owner, name));
}

/// <summary>
/// Creates a new deploy key for a repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/keys/#create"> API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The owner of the repository.</param>
/// <param name="name">The name of the repository.</param>
/// <param name="newDeployKey">The deploy key to create for the repository.</param>
/// <returns></returns>
public IObservable<DeployKey> Create(string owner, string name, NewDeployKey newDeployKey)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(newDeployKey, "newDeployKey");


if (string.IsNullOrWhiteSpace(newDeployKey.Title))
throw new ArgumentException("The new deploy key's title must not be null.");

if (string.IsNullOrWhiteSpace(newDeployKey.Key))
throw new ArgumentException("The new deploy key's key must not be null.");

return _client.Create(owner, name, newDeployKey).ToObservable();
}

/// <summary>
/// Deletes a deploy key from a repository.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/keys/#delete"> API documentation</a> for more information.
/// </remarks>
/// <param name="owner">The owner of the repository.</param>
/// <param name="name">The name of the repository.</param>
/// <param name="number">The id of the deploy key to delete.</param>
/// <returns></returns>
public IObservable<Unit> Delete(string owner, string name, int number)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");

return _client.Delete(owner, name, number).ToObservable();
}
}
}
2 changes: 2 additions & 0 deletions Octokit.Reactive/Octokit.Reactive.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
</Compile>
<Compile Include="Clients\IObservableOauthClient.cs" />
<Compile Include="Clients\IObservableRepositoryCommitsClients.cs" />
<Compile Include="Clients\IObservableRepositoryDeployKeysClient.cs" />
<Compile Include="Clients\ObservableRepositoryDeployKeysClient.cs" />
<Compile Include="Clients\ObservableOauthClient.cs" />
<Compile Include="Clients\ObservableRepositoryCommentsClient.cs" />
<Compile Include="Clients\IObservableRepositoryCommentsClient.cs" />
Expand Down

0 comments on commit 83a85b5

Please sign in to comment.