using System; using System.Reactive; using System.Reactive.Threading.Tasks; using Octokit.Reactive.Internal; using System.Reactive.Linq; namespace Octokit.Reactive { /// /// A client for GitHub's User Administration API (GitHub Enterprise) /// /// /// See the Administration API documentation for more details. /// public class ObservableUserAdministrationClient : IObservableUserAdministrationClient { readonly IUserAdministrationClient _client; readonly IConnection _connection; /// /// Initializes a new instance of the class. /// /// An used to make the requests public ObservableUserAdministrationClient(IGitHubClient client) { Ensure.ArgumentNotNull(client, nameof(client)); _client = client.User.Administration; _connection = client.Connection; } /// /// Create a new user (must be Site Admin user). /// /// /// See the API documentation /// for more information. /// /// The object describing the user to create /// The created object public IObservable Create(NewUser newUser) { return _client.Create(newUser).ToObservable(); } /// /// Rename an existing user (must be Site Admin user). /// /// /// See the API documentation /// for more information. /// Note that this queues a request to rename a user, rather than execute it straight away /// /// The username to rename /// The request, specifying the new login /// A object indicating the queued task message and Url to the user public IObservable Rename(string login, UserRename userRename) { return _client.Rename(login, userRename).ToObservable(); } /// /// Create an impersonation OAuth token (must be Site Admin user). /// /// /// See the API documentation /// for more information. /// /// The user to impersonate /// The request specifying the required scopes /// An object containing the impersonation token public IObservable CreateImpersonationToken(string login, NewImpersonationToken newImpersonationToken) { return _client.CreateImpersonationToken(login, newImpersonationToken).ToObservable(); } /// /// Deletes an impersonation OAuth token (must be Site Admin user). /// /// /// See the API documentation /// for more information. /// /// The user to remove impersonation token from /// public IObservable DeleteImpersonationToken(string login) { return _client.DeleteImpersonationToken(login).ToObservable(); } /// /// Promotes ordinary user to a site administrator (must be Site Admin user). /// /// /// See the API documentation /// for more information. /// /// The user to promote to administrator. /// public IObservable Promote(string login) { return _client.Promote(login).ToObservable(); } /// /// Demotes a site administrator to an ordinary user (must be Site Admin user). /// /// /// See the API documentation /// for more information. /// /// The user to demote from administrator. /// public IObservable Demote(string login) { return _client.Demote(login).ToObservable(); } /// /// Suspends a user (must be Site Admin user). /// /// /// See the API documentation /// for more information. /// /// The user to suspend. /// public IObservable Suspend(string login) { return _client.Suspend(login).ToObservable(); } /// /// Unsuspends a user (must be Site Admin user). /// /// /// See the API documentation /// for more information. /// /// The user to unsuspend. /// public IObservable Unsuspend(string login) { return _client.Unsuspend(login).ToObservable(); } /// /// List all public keys (must be Site Admin user). /// /// /// See the API documentation /// for more information. /// /// public IObservable ListAllPublicKeys() { return _connection.GetAndFlattenAllPages(ApiUrls.UserAdministrationPublicKeys()); } /// /// Delete a user (must be Site Admin user). /// /// /// See the API documentation /// for more information. /// /// The user to delete /// public IObservable Delete(string login) { return _client.Delete(login).ToObservable(); } /// /// Delete a public key (must be Site Admin user). /// /// /// See the API documentation /// for more information. /// /// The key to delete /// public IObservable DeletePublicKey(int keyId) { return _client.DeletePublicKey(keyId).ToObservable(); } } }