using System;
using System.Reactive;
using System.Reactive.Linq;
using System.Reactive.Threading.Tasks;
namespace Octokit.Reactive
{
///
/// A client for GitHub's User Keys API.
///
///
/// See the User Keys API documentation for more information.
///
public class ObservableUserKeysClient : IObservableUserKeysClient
{
readonly IUserKeysClient _client;
public ObservableUserKeysClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, "client");
_client = client.User.GitSshKey;
}
///
/// Gets all verified public keys for a user.
///
///
/// https://developer.github.com/v3/users/keys/#list-public-keys-for-a-user
///
/// The @ handle of the user.
/// Lists the verified public keys for a user.
public IObservable GetAll(string userName)
{
Ensure.ArgumentNotNullOrEmptyString(userName, "userName");
return GetAll(userName, ApiOptions.None);
}
///
/// Gets all verified public keys for a user.
///
///
/// https://developer.github.com/v3/users/keys/#list-public-keys-for-a-user
///
/// The @ handle of the user.
/// Options to change API's behavior.
/// Lists the verified public keys for a user.
public IObservable GetAll(string userName, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(userName, "userName");
Ensure.ArgumentNotNull(options, "options");
return _client.GetAll(userName, options).ToObservable().SelectMany(k => k);
}
///
/// Gets all public keys for the authenticated user.
///
///
/// https://developer.github.com/v3/users/keys/#list-your-public-keys
///
/// Lists the current user's keys.
public IObservable GetAllForCurrent()
{
return GetAllForCurrent(ApiOptions.None);
}
///
/// Gets all public keys for the authenticated user.
///
///
/// https://developer.github.com/v3/users/keys/#list-your-public-keys
///
/// Options to change API's behavior.
/// Lists the current user's keys.
public IObservable GetAllForCurrent(ApiOptions options)
{
Ensure.ArgumentNotNull(options, "options");
return _client.GetAllForCurrent(options).ToObservable().SelectMany(k => k);
}
///
/// Retrieves the for the specified id.
///
///
/// https://developer.github.com/v3/users/keys/#get-a-single-public-key
///
/// The ID of the SSH key
/// View extended details for a single public key.
public IObservable Get(int id)
{
return _client.Get(id).ToObservable();
}
///
/// Create a public key .
///
///
/// https://developer.github.com/v3/users/keys/#create-a-public-key
///
/// The SSH Key contents
/// Creates a public key.
public IObservable Create(NewPublicKey newKey)
{
Ensure.ArgumentNotNull(newKey, "newKey");
return _client.Create(newKey).ToObservable();
}
///
/// Delete a public key.
///
///
/// https://developer.github.com/v3/users/keys/#delete-a-public-key
///
/// The id of the key to delete
/// Removes a public key.
public IObservable Delete(int id)
{
return _client.Delete(id).ToObservable();
}
}
}