using Octokit.Reactive.Internal; using System; using System.Collections.Generic; using System.Reactive; using System.Reactive.Threading.Tasks; namespace Octokit.Reactive { public class ObservableRepositoryInvitationsClient : IObservableRepositoryInvitationsClient { readonly IRepositoryInvitationsClient _client; readonly IConnection _connection; public ObservableRepositoryInvitationsClient(IGitHubClient client) { Ensure.ArgumentNotNull(client, nameof(client)); _client = client.Repository.Invitation; _connection = client.Connection; } /// /// Accept a repository invitation. /// /// /// See the API documentation for more information. /// /// The id of the invitation. public IObservable Accept(long invitationId) { return _client.Accept(invitationId).ToObservable(); } /// /// Decline a repository invitation. /// /// /// See the API documentation for more information. /// /// The id of the invitation. public IObservable Decline(long invitationId) { return _client.Decline(invitationId).ToObservable(); } /// /// Deletes a repository invitation. /// /// /// See the API documentation for more information. /// /// The id of the repository. /// The id of the invitation. public IObservable Delete(long repositoryId, long invitationId) { return _client.Delete(repositoryId, invitationId).ToObservable(); } /// /// Updates a repository invitation. /// /// /// See the API documentation for more information. /// /// The id of the repository. /// The id of the invitatio.n /// The permission to set. public IObservable Edit(long repositoryId, long invitationId, InvitationUpdate permissions) { Ensure.ArgumentNotNull(permissions, nameof(permissions)); return _client.Edit(repositoryId, invitationId, permissions).ToObservable(); } /// /// Gets all invitations for the current user. /// /// /// See the API documentation for more information. /// public IObservable GetAllForCurrent() { return GetAllForCurrent(ApiOptions.None); } /// /// Gets all invitations for the current user. /// /// /// See the API documentation for more information. /// /// Options for changing the API response public IObservable GetAllForCurrent(ApiOptions options) { Ensure.ArgumentNotNull(options, nameof(options)); return _connection.GetAndFlattenAllPages(ApiUrls.UserInvitations(), null, null, options); } /// /// Gets all the invitations on a repository. /// /// /// See the API documentation for more information. /// /// The id of the repository public IObservable GetAllForRepository(long repositoryId) { return GetAllForRepository(repositoryId, ApiOptions.None); } /// /// Gets all the invitations on a repository. /// /// /// See the API documentation for more information. /// /// The id of the repository /// Options for changing the API response public IObservable GetAllForRepository(long repositoryId, ApiOptions options) { Ensure.ArgumentNotNull(options, nameof(options)); return _connection.GetAndFlattenAllPages(ApiUrls.RepositoryInvitations(repositoryId), null, null, options); } } }