using System; using System.Reactive; using System.Reactive.Threading.Tasks; using Octokit.Reactive.Internal; namespace Octokit.Reactive { public class ObservableOrganizationMembersClient : IObservableOrganizationMembersClient { readonly IOrganizationMembersClient _client; readonly IConnection _connection; /// /// Initializes a new Organization Members API client. /// /// An used to make the requests public ObservableOrganizationMembersClient(IGitHubClient client) { Ensure.ArgumentNotNull(client, nameof(client)); _client = client.Organization.Member; _connection = client.Connection; } /// /// /// List all users who are members of an organization. A member is a user that /// belongs to at least 1 team in the organization. /// /// /// If the authenticated user is also an owner of this organization then both /// concealed and public member will be returned. /// /// /// If the requester is not an owner of the organization the query will be redirected /// to the public members list. /// /// /// /// See the API documentation /// for more information. /// /// The login for the organization /// public IObservable GetAll(string org) { Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); return GetAll(org, ApiOptions.None); } /// /// /// List all users who are members of an organization. A member is a user that /// belongs to at least 1 team in the organization. /// /// /// If the authenticated user is also an owner of this organization then both /// concealed and public member will be returned. /// /// /// If the requester is not an owner of the organization the query will be redirected /// to the public members list. /// /// /// /// See the API documentation /// for more information. /// /// The login for the organization /// Options for changing the API response /// public IObservable GetAll(string org, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); Ensure.ArgumentNotNull(options, nameof(options)); return _connection.GetAndFlattenAllPages(ApiUrls.Members(org), options); } /// /// /// List all users who are members of an organization. A member is a user that /// belongs to at least 1 team in the organization. /// /// /// If the authenticated user is also an owner of this organization then both /// concealed and public member will be returned. /// /// /// If the requester is not an owner of the organization the query will be redirected /// to the public members list. /// /// /// /// See the API documentation /// for more information. /// /// The login for the organization /// The members filter, /// public IObservable GetAll(string org, OrganizationMembersFilter filter) { Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); return GetAll(org, filter, ApiOptions.None); } /// /// /// List all users who are members of an organization. A member is a user that /// belongs to at least 1 team in the organization. /// /// /// If the authenticated user is also an owner of this organization then both /// concealed and public member will be returned. /// /// /// If the requester is not an owner of the organization the query will be redirected /// to the public members list. /// /// /// /// See the API documentation /// for more information. /// /// The login for the organization /// The members filter, /// Options for changing the API response /// public IObservable GetAll(string org, OrganizationMembersFilter filter, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); Ensure.ArgumentNotNull(options, nameof(options)); return _connection.GetAndFlattenAllPages(ApiUrls.Members(org, filter), options); } /// /// /// List all users who are members of an organization. A member is a user that /// belongs to at least 1 team in the organization. /// /// /// If the authenticated user is also an owner of this organization then both /// concealed and public member will be returned. /// /// /// If the requester is not an owner of the organization the query will be redirected /// to the public members list. /// /// /// /// See the API documentation /// for more information. /// /// The login for the organization /// The role filter to use when getting the users, /// public IObservable GetAll(string org, OrganizationMembersRole role) { Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); return GetAll(org, role, ApiOptions.None); } /// /// /// List all users who are members of an organization. A member is a user that /// belongs to at least 1 team in the organization. /// /// /// If the authenticated user is also an owner of this organization then both /// concealed and public member will be returned. /// /// /// If the requester is not an owner of the organization the query will be redirected /// to the public members list. /// /// /// /// See the API documentation /// for more information. /// /// The login for the organization /// The role filter to use when getting the users, /// Options for changing the API response /// public IObservable GetAll(string org, OrganizationMembersRole role, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); Ensure.ArgumentNotNull(options, nameof(options)); return _connection.GetAndFlattenAllPages(ApiUrls.Members(org, role), options); } /// /// /// List all users who are members of an organization. A member is a user that /// belongs to at least 1 team in the organization. /// /// /// If the authenticated user is also an owner of this organization then both /// concealed and public member will be returned. /// /// /// If the requester is not an owner of the organization the query will be redirected /// to the public members list. /// /// /// /// See the API documentation /// for more information. /// /// The login for the organization /// The members filter, /// The role filter to use when getting the users, /// public IObservable GetAll(string org, OrganizationMembersFilter filter, OrganizationMembersRole role) { Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); return GetAll(org, filter, role, ApiOptions.None); } /// /// /// List all users who are members of an organization. A member is a user that /// belongs to at least 1 team in the organization. /// /// /// If the authenticated user is also an owner of this organization then both /// concealed and public member will be returned. /// /// /// If the requester is not an owner of the organization the query will be redirected /// to the public members list. /// /// /// /// See the API documentation /// for more information. /// /// The login for the organization /// The members filter, /// The role filter to use when getting the users, /// Options for changing the API response /// public IObservable GetAll(string org, OrganizationMembersFilter filter, OrganizationMembersRole role, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); Ensure.ArgumentNotNull(options, nameof(options)); return _connection.GetAndFlattenAllPages(ApiUrls.Members(org, filter, role), options); } /// /// List all users who have publicized their membership of the organization. /// /// http://developer.github.com/v3/orgs/members/#public-members-list /// The login for the organization /// public IObservable GetAllPublic(string org) { Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); return GetAllPublic(org, ApiOptions.None); } /// /// List all users who have publicized their membership of the organization. /// /// http://developer.github.com/v3/orgs/members/#public-members-list /// The login for the organization /// Options for changing the API response /// public IObservable GetAllPublic(string org, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); Ensure.ArgumentNotNull(options, nameof(options)); return _connection.GetAndFlattenAllPages(ApiUrls.PublicMembers(org), options); } /// /// Check if a user is, publicly or privately, a member of the organization. /// /// /// See the API documentation /// for more information. /// /// The login for the organization /// The login for the user /// public IObservable CheckMember(string org, string user) { Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); Ensure.ArgumentNotNullOrEmptyString(user, nameof(user)); return _client.CheckMember(org, user).ToObservable(); } /// /// Check is a user is publicly a member of the organization. /// /// /// See the API documentation /// for more information. /// /// The login for the organization /// The login for the user /// public IObservable CheckMemberPublic(string org, string user) { Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); Ensure.ArgumentNotNullOrEmptyString(user, nameof(user)); return _client.CheckMemberPublic(org, user).ToObservable(); } /// /// Removes a user from the organization, this will also remove them from all teams /// within the organization and they will no longer have any access to the organization's /// repositories. /// /// /// See the API documentation /// for more information. /// /// The login for the organization /// The login for the user /// public IObservable Delete(string org, string user) { Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); Ensure.ArgumentNotNullOrEmptyString(user, nameof(user)); return _client.Delete(org, user).ToObservable(); } /// /// Make the authenticated user's organization membership public. /// /// /// This method requires authentication. /// See the API documentation /// for more information. /// /// The login for the organization /// The login for the user /// public IObservable Publicize(string org, string user) { Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); Ensure.ArgumentNotNullOrEmptyString(user, nameof(user)); return _client.Publicize(org, user).ToObservable(); } /// /// Make the authenticated user's organization membership private. /// /// /// This method requires authentication. /// See the API documentation /// for more information. /// /// The login for the organization /// The login for the user /// public IObservable Conceal(string org, string user) { Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); Ensure.ArgumentNotNullOrEmptyString(user, nameof(user)); return _client.Conceal(org, user).ToObservable(); } /// /// Get a user's membership with an organization. /// /// /// This method requires authentication. /// The authenticated user must be an organization member. /// See the API documentation /// for more information. /// /// The login for the organization /// The login for the user /// public IObservable GetOrganizationMembership(string org, string user) { Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); Ensure.ArgumentNotNullOrEmptyString(user, nameof(user)); return _client.GetOrganizationMembership(org, user).ToObservable(); } /// /// Add a user to the organization or update the user's role withing the organization. /// /// /// This method requires authentication. /// The authenticated user must be an organization owner. /// See the API documentation /// for more information. /// /// The login for the organization /// The login for the user /// An instance describing the /// changes to make to the user's organization membership /// public IObservable AddOrUpdateOrganizationMembership(string org, string user, OrganizationMembershipUpdate addOrUpdateRequest) { Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); Ensure.ArgumentNotNullOrEmptyString(user, nameof(user)); Ensure.ArgumentNotNull(addOrUpdateRequest, nameof(addOrUpdateRequest)); return _client.AddOrUpdateOrganizationMembership(org, user, addOrUpdateRequest).ToObservable(); } /// /// Remove a user's membership with an organization. /// /// /// This method requires authentication. /// The authenticated user must be an organization owner. /// See the API documentation /// for more information. /// /// The login for the organization /// The login for the user /// public IObservable RemoveOrganizationMembership(string org, string user) { Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); Ensure.ArgumentNotNullOrEmptyString(user, nameof(user)); return _client.RemoveOrganizationMembership(org, user).ToObservable(); } /// /// List all pending invitations for the organization. /// /// /// See the API Documentation /// for more information. /// /// The login for the organization /// public IObservable GetAllPendingInvitations(string org) { Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); return GetAllPendingInvitations(org, ApiOptions.None); } /// /// List all pending invitations for the organization. /// /// /// See the API Documentation /// for more information. /// /// The login for the organization /// Options to change API behaviour /// public IObservable GetAllPendingInvitations(string org, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(org, nameof(org)); Ensure.ArgumentNotNull(options, nameof(options)); return _connection.GetAndFlattenAllPages(ApiUrls.OrganizationPendingInvititations(org), null, AcceptHeaders.OrganizationMembershipPreview, options); } } }