Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Additional Enterprise methods on User Administration Client #1108

Merged
merged 3 commits into from
Feb 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 92 additions & 9 deletions Octokit.Reactive/Clients/IObservableUserAdministrationClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,134 @@
namespace Octokit.Reactive
{
/// <summary>
/// A client for GitHub's User Administration API.
/// A client for GitHub's User Administration API (GitHub Enterprise)
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/users/administration/">Administration API documentation</a> for more details.
/// </remarks>
public interface IObservableUserAdministrationClient
{
/// <summary>
/// Promotes ordinary user to a site administrator.
/// Create a new user (must be Site Admin user).
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/users/administration/#promote-an-ordinary-user-to-a-site-administrator
/// See the <a href="https://developer.github.com/enterprise/2.5/v3/users/administration/#create-a-new-user">API documentation</a>
/// for more information.
/// </remarks>
/// <param name="newUser">The <see cref="NewUser"/> object describing the user to create</param>
/// <returns>The created <see cref="User"/> object</returns>
IObservable<User> Create(NewUser newUser);

/// <summary>
/// Rename an existing user (must be Site Admin user).
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/enterprise/2.5/v3/users/administration/#rename-an-existing-user">API documentation</a>
/// for more information.
/// Note that this queues a request to rename a user, rather than execute it straight away
/// </remarks>
/// <param name="login">The username to rename</param>
/// <param name="userRename">The <see cref="UserRename"/> request, specifying the new login</param>
/// <returns>A <see cref="UserRenameResponse"/> object indicating the queued task message and Url to the user</returns>
IObservable<UserRenameResponse> Rename(string login, UserRename userRename);

/// <summary>
/// Create an impersonation OAuth token (must be Site Admin user).
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/enterprise/2.5/v3/users/administration/#create-an-impersonation-oauth-token">API documentation</a>
/// for more information.
/// </remarks>
/// <param name="login">The user to impersonate</param>
/// <param name="newImpersonationToken">The <see cref="NewImpersonationToken"/> request specifying the required scopes</param>
/// <returns>An <see cref="Authorization"/> object containing the impersonation token</returns>
IObservable<Authorization> CreateImpersonationToken(string login, NewImpersonationToken newImpersonationToken);

/// <summary>
/// Deletes an impersonation OAuth token (must be Site Admin user).
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/enterprise/2.5/v3/users/administration/#delete-an-impersonation-oauth-token">API documentation</a>
/// for more information.
/// </remarks>
/// <param name="login">The user to remove impersonation token from</param>
/// <returns></returns>
IObservable<Unit> DeleteImpersonationToken(string login);

/// <summary>
/// Promotes ordinary user to a site administrator (must be Site Admin user).
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/users/administration/#promote-an-ordinary-user-to-a-site-administrator">API documentation</a>
/// for more information.
/// </remarks>
/// <param name="login">The user to promote to administrator.</param>
/// <returns></returns>
IObservable<Unit> Promote(string login);

/// <summary>
/// Demotes a site administrator to an ordinary user.
/// Demotes a site administrator to an ordinary user (must be Site Admin user).
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/users/administration/#demote-a-site-administrator-to-an-ordinary-user
/// See the <a href="https://developer.github.com/v3/users/administration/#demote-a-site-administrator-to-an-ordinary-user">API documentation</a>
/// for more information.
/// </remarks>
/// <param name="login">The user to demote from administrator.</param>
/// <returns></returns>
IObservable<Unit> Demote(string login);

/// <summary>
/// Suspends a user.
/// Suspends a user (must be Site Admin user).
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/users/administration/#suspend-a-user
/// See the <a href="https://developer.github.com/v3/users/administration/#suspend-a-user">API documentation</a>
/// for more information.
/// </remarks>
/// <param name="login">The user to suspend.</param>
/// <returns></returns>
IObservable<Unit> Suspend(string login);

/// <summary>
/// Unsuspends a user.
/// Unsuspends a user (must be Site Admin user).
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/users/administration/#unsuspend-a-user
/// See the <a href="https://developer.github.com/v3/users/administration/#unsuspend-a-user">API documentation</a>
/// for more information.
/// </remarks>
/// <param name="login">The user to unsuspend.</param>
/// <returns></returns>
IObservable<Unit> Unsuspend(string login);

/// <summary>
/// List all public keys (must be Site Admin user).
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/enterprise/2.5/v3/users/administration/#list-all-public-keys">API documentation</a>
/// for more information.
/// </remarks>
/// <returns></returns>
IObservable<PublicKey> ListAllPublicKeys();

/// <summary>
/// Delete a user (must be Site Admin user).
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/enterprise/2.5/v3/users/administration/#delete-a-user">API documentation</a>
/// for more information.
/// </remarks>
/// <param name="login">The user to delete</param>
/// <returns></returns>
IObservable<Unit> Delete(string login);

/// <summary>
/// Delete a public key (must be Site Admin user).
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/enterprise/2.5/v3/users/administration/#delete-a-public-key">API documentation</a>
/// for more information.
/// </remarks>
/// <param name="keyId">The key to delete</param>
/// <returns></returns>
IObservable<Unit> DeletePublicKey(int keyId);
}
}
128 changes: 120 additions & 8 deletions Octokit.Reactive/Clients/ObservableUserAdministrationClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@

namespace Octokit.Reactive
{
/// <summary>
/// A client for GitHub's User Administration API (GitHub Enterprise)
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/users/administration/">Administration API documentation</a> for more details.
/// </remarks>
public class ObservableUserAdministrationClient : IObservableUserAdministrationClient
{
readonly IUserAdministrationClient _client;
readonly IConnection _connection;

/// <summary>
/// Initializes a new instance of the <see cref="ObservableUserAdministrationClient"/> class.
Expand All @@ -20,13 +27,74 @@ public ObservableUserAdministrationClient(IGitHubClient client)
Ensure.ArgumentNotNull(client, "client");

_client = client.User.Administration;
_connection = client.Connection;
}

/// <summary>
/// Promotes ordinary user to a site administrator.
/// Create a new user (must be Site Admin user).
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/users/administration/#promote-an-ordinary-user-to-a-site-administrator
/// See the <a href="https://developer.github.com/enterprise/2.5/v3/users/administration/#create-a-new-user">API documentation</a>
/// for more information.
/// </remarks>
/// <param name="newUser">The <see cref="NewUser"/> object describing the user to create</param>
/// <returns>The created <see cref="User"/> object</returns>
public IObservable<User> Create(NewUser newUser)
{
return _client.Create(newUser).ToObservable();
}

/// <summary>
/// Rename an existing user (must be Site Admin user).
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/enterprise/2.5/v3/users/administration/#rename-an-existing-user">API documentation</a>
/// for more information.
/// Note that this queues a request to rename a user, rather than execute it straight away
/// </remarks>
/// <param name="login">The username to rename</param>
/// <param name="userRename">The <see cref="UserRename"/> request, specifying the new login</param>
/// <returns>A <see cref="UserRenameResponse"/> object indicating the queued task message and Url to the user</returns>
public IObservable<UserRenameResponse> Rename(string login, UserRename userRename)
{
return _client.Rename(login, userRename).ToObservable();
}

/// <summary>
/// Create an impersonation OAuth token (must be Site Admin user).
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/enterprise/2.5/v3/users/administration/#create-an-impersonation-oauth-token">API documentation</a>
/// for more information.
/// </remarks>
/// <param name="login">The user to impersonate</param>
/// <param name="newImpersonationToken">The <see cref="NewImpersonationToken"/> request specifying the required scopes</param>
/// <returns>An <see cref="Authorization"/> object containing the impersonation token</returns>
public IObservable<Authorization> CreateImpersonationToken(string login, NewImpersonationToken newImpersonationToken)
{
return _client.CreateImpersonationToken(login, newImpersonationToken).ToObservable();
}

/// <summary>
/// Deletes an impersonation OAuth token (must be Site Admin user).
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/enterprise/2.5/v3/users/administration/#delete-an-impersonation-oauth-token">API documentation</a>
/// for more information.
/// </remarks>
/// <param name="login">The user to remove impersonation token from</param>
/// <returns></returns>
public IObservable<Unit> DeleteImpersonationToken(string login)
{
return _client.DeleteImpersonationToken(login).ToObservable();
}

/// <summary>
/// Promotes ordinary user to a site administrator (must be Site Admin user).
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/users/administration/#promote-an-ordinary-user-to-a-site-administrator">API documentation</a>
/// for more information.
/// </remarks>
/// <param name="login">The user to promote to administrator.</param>
/// <returns></returns>
Expand All @@ -36,10 +104,11 @@ public IObservable<Unit> Promote(string login)
}

/// <summary>
/// Demotes a site administrator to an ordinary user.
/// Demotes a site administrator to an ordinary user (must be Site Admin user).
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/users/administration/#demote-a-site-administrator-to-an-ordinary-user
/// See the <a href="https://developer.github.com/v3/users/administration/#demote-a-site-administrator-to-an-ordinary-user">API documentation</a>
/// for more information.
/// </remarks>
/// <param name="login">The user to demote from administrator.</param>
/// <returns></returns>
Expand All @@ -49,10 +118,11 @@ public IObservable<Unit> Demote(string login)
}

/// <summary>
/// Suspends a user.
/// Suspends a user (must be Site Admin user).
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/users/administration/#suspend-a-user
/// See the <a href="https://developer.github.com/v3/users/administration/#suspend-a-user">API documentation</a>
/// for more information.
/// </remarks>
/// <param name="login">The user to suspend.</param>
/// <returns></returns>
Expand All @@ -62,16 +132,58 @@ public IObservable<Unit> Suspend(string login)
}

/// <summary>
/// Unsuspends a user.
/// Unsuspends a user (must be Site Admin user).
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/users/administration/#unsuspend-a-user
/// See the <a href="https://developer.github.com/v3/users/administration/#unsuspend-a-user">API documentation</a>
/// for more information.
/// </remarks>
/// <param name="login">The user to unsuspend.</param>
/// <returns></returns>
public IObservable<Unit> Unsuspend(string login)
{
return _client.Unsuspend(login).ToObservable();
}

/// <summary>
/// List all public keys (must be Site Admin user).
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/enterprise/2.5/v3/users/administration/#list-all-public-keys">API documentation</a>
/// for more information.
/// </remarks>
/// <returns></returns>
public IObservable<PublicKey> ListAllPublicKeys()
{
return _connection.GetAndFlattenAllPages<PublicKey>(ApiUrls.UserAdministrationPublicKeys());
}

/// <summary>
/// Delete a user (must be Site Admin user).
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/enterprise/2.5/v3/users/administration/#delete-a-user">API documentation</a>
/// for more information.
/// </remarks>
/// <param name="login">The user to delete</param>
/// <returns></returns>
public IObservable<Unit> Delete(string login)
{
return _client.Delete(login).ToObservable();
}

/// <summary>
/// Delete a public key (must be Site Admin user).
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/enterprise/2.5/v3/users/administration/#delete-a-public-key">API documentation</a>
/// for more information.
/// </remarks>
/// <param name="keyId">The key to delete</param>
/// <returns></returns>
public IObservable<Unit> DeletePublicKey(int keyId)
{
return _client.DeletePublicKey(keyId).ToObservable();
}
}
}
Loading