mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-07 12:26:18 +00:00
Merge pull request #191 from alfhenrik/observable-org-members-api
Implement Observable Orgs Members API
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reactive;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Octokit.Reactive
|
||||
{
|
||||
public interface IObservableOrganizationMembersClient
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>
|
||||
/// List all users who are members of an organization. A member is a user that
|
||||
/// belongs to at least 1 team in the organization.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// If the authenticated user is also an owner of this organization then both
|
||||
/// concealed and public member will be returned.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// If the requester is not an owner of the organization the query will be redirected
|
||||
/// to the public members list.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/orgs/members/#members-list">API documentation</a>
|
||||
/// for more information.
|
||||
/// </remarks>
|
||||
/// <param name="org"></param>
|
||||
/// <returns></returns>
|
||||
IObservable<User> GetAll(string org);
|
||||
|
||||
/// <summary>
|
||||
/// List all users who have publicized their membership of the organization.
|
||||
/// </summary>
|
||||
/// <remarks>http://developer.github.com/v3/orgs/members/#public-members-list</remarks>
|
||||
/// <param name="org"></param>
|
||||
/// <returns></returns>
|
||||
IObservable<User> GetPublic(string org);
|
||||
|
||||
/// <summary>
|
||||
/// Check if a user is, publicly or privately, a member of the organization.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/orgs/members/#check-membership">API documentation</a>
|
||||
/// for more information.
|
||||
/// </remarks>
|
||||
/// <param name="org"></param>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
IObservable<bool> CheckMember(string org, string user);
|
||||
|
||||
/// <summary>
|
||||
/// Check is a user is publicly a member of the organization.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/orgs/members/#check-public-membership">API documentation</a>
|
||||
/// for more information.
|
||||
/// </remarks>
|
||||
/// <param name="org"></param>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
IObservable<bool> CheckMemberPublic(string org, string user);
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/orgs/members/#remove-a-member">API documentation</a>
|
||||
/// for more information.
|
||||
/// </remarks>
|
||||
/// <param name="org"></param>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
IObservable<Unit> Delete(string org, string user);
|
||||
|
||||
/// <summary>
|
||||
/// Make the authenticated user's organization membership public.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method requires authentication.
|
||||
/// See the <a href="http://developer.github.com/v3/orgs/members/#publicize-a-users-membership">API documentation</a>
|
||||
/// for more information.
|
||||
/// </remarks>
|
||||
/// <param name="org"></param>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
IObservable<bool> Publicize(string org, string user);
|
||||
|
||||
/// <summary>
|
||||
/// Make the authenticated user's organization membership private.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method requries authentication.
|
||||
/// See the <a href="http://developer.github.com/v3/orgs/members/#conceal-a-users-membership">API documentation</a>
|
||||
/// for more information.
|
||||
/// </remarks>
|
||||
/// <param name="org"></param>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
IObservable<Unit> Conceal(string org, string user);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
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;
|
||||
|
||||
public ObservableOrganizationMembersClient(IGitHubClient client)
|
||||
{
|
||||
Ensure.ArgumentNotNull(client, "client");
|
||||
|
||||
_client = client.Organization.Member;
|
||||
_connection = client.Connection;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>
|
||||
/// List all users who are members of an organization. A member is a user that
|
||||
/// belongs to at least 1 team in the organization.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// If the authenticated user is also an owner of this organization then both
|
||||
/// concealed and public member will be returned.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// If the requester is not an owner of the organization the query will be redirected
|
||||
/// to the public members list.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/orgs/members/#members-list">API documentation</a>
|
||||
/// for more information.
|
||||
/// </remarks>
|
||||
/// <param name="org"></param>
|
||||
/// <returns></returns>
|
||||
public IObservable<User> GetAll(string org)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(org, "org");
|
||||
|
||||
return _connection.GetAndFlattenAllPages<User>(ApiUrls.Members(org));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List all users who have publicized their membership of the organization.
|
||||
/// </summary>
|
||||
/// <remarks>http://developer.github.com/v3/orgs/members/#public-members-list</remarks>
|
||||
/// <param name="org"></param>
|
||||
/// <returns></returns>
|
||||
public IObservable<User> GetPublic(string org)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(org, "org");
|
||||
|
||||
return _connection.GetAndFlattenAllPages<User>(ApiUrls.PublicMembers(org));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if a user is, publicly or privately, a member of the organization.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/orgs/members/#check-membership">API documentation</a>
|
||||
/// for more information.
|
||||
/// </remarks>
|
||||
/// <param name="org"></param>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
public IObservable<bool> CheckMember(string org, string user)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(org, "org");
|
||||
Ensure.ArgumentNotNullOrEmptyString(user, "user");
|
||||
|
||||
return _client.CheckMember(org, user).ToObservable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check is a user is publicly a member of the organization.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/orgs/members/#check-public-membership">API documentation</a>
|
||||
/// for more information.
|
||||
/// </remarks>
|
||||
/// <param name="org"></param>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
public IObservable<bool> CheckMemberPublic(string org, string user)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(org, "org");
|
||||
Ensure.ArgumentNotNullOrEmptyString(user, "user");
|
||||
|
||||
return _client.CheckMemberPublic(org, user).ToObservable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/orgs/members/#remove-a-member">API documentation</a>
|
||||
/// for more information.
|
||||
/// </remarks>
|
||||
/// <param name="org"></param>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
public IObservable<Unit> Delete(string org, string user)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(org, "org");
|
||||
Ensure.ArgumentNotNullOrEmptyString(user, "user");
|
||||
|
||||
return _client.Delete(org, user).ToObservable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Make the authenticated user's organization membership public.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method requires authentication.
|
||||
/// See the <a href="http://developer.github.com/v3/orgs/members/#publicize-a-users-membership">API documentation</a>
|
||||
/// for more information.
|
||||
/// </remarks>
|
||||
/// <param name="org"></param>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
public IObservable<bool> Publicize(string org, string user)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(org, "org");
|
||||
Ensure.ArgumentNotNullOrEmptyString(user, "user");
|
||||
|
||||
return _client.Publicize(org, user).ToObservable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Make the authenticated user's organization membership private.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This method requries authentication.
|
||||
/// See the <a href="http://developer.github.com/v3/orgs/members/#conceal-a-users-membership">API documentation</a>
|
||||
/// for more information.
|
||||
/// </remarks>
|
||||
/// <param name="org"></param>
|
||||
/// <param name="user"></param>
|
||||
/// <returns></returns>
|
||||
public IObservable<Unit> Conceal(string org, string user)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(org, "org");
|
||||
Ensure.ArgumentNotNullOrEmptyString(user, "user");
|
||||
|
||||
return _client.Conceal(org, user).ToObservable();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -75,6 +75,7 @@
|
||||
</Compile>
|
||||
<Compile Include="Clients\IObservableEventsClient.cs" />
|
||||
<Compile Include="Clients\ObservableEventsClient.cs" />
|
||||
<Compile Include="Clients\IObservableOrganizationMembersClient.cs" />
|
||||
<Compile Include="Clients\ObservableGitDatabaseClient.cs" />
|
||||
<Compile Include="Clients\IObservableGitDatabaseClient.cs" />
|
||||
<Compile Include="Clients\IObservableTagsClient.cs" />
|
||||
@@ -92,6 +93,7 @@
|
||||
<Compile Include="Clients\ObservableNotificationsClient.cs" />
|
||||
<Compile Include="Clients\ObservableAuthorizationsClient.cs" />
|
||||
<Compile Include="Clients\ObservableMiscellaneousClient.cs" />
|
||||
<Compile Include="Clients\ObservableOrganizationMembersClient.cs" />
|
||||
<Compile Include="Clients\ObservableOrganizationsClient.cs" />
|
||||
<Compile Include="Clients\ObservableReleasesClient.cs" />
|
||||
<Compile Include="Clients\ObservableRepositoriesClient.cs" />
|
||||
|
||||
@@ -116,6 +116,7 @@
|
||||
<Compile Include="Reactive\ObservableIssueCommentsClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableIssuesClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableMilestonesClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableOrganizationMembersClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableRepositoriesClientTests.cs" />
|
||||
<Compile Include="SimpleJsonSerializerTests.cs" />
|
||||
<Compile Include="Clients\UsersClientTests.cs" />
|
||||
|
||||
@@ -0,0 +1,189 @@
|
||||
using NSubstitute;
|
||||
using Octokit;
|
||||
using Octokit.Internal;
|
||||
using Octokit.Reactive;
|
||||
using Octokit.Tests.Helpers;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace Octokit.Tests.Reactive
|
||||
{
|
||||
public class ObservableOrganizationMembersClientTests
|
||||
{
|
||||
public class TheGetAllMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableOrganizationMembersClient(gitHubClient);
|
||||
|
||||
client.GetAll("org");
|
||||
|
||||
gitHubClient.Connection.GetAsync<IReadOnlyList<User>>(
|
||||
new Uri("orgs/org/members", UriKind.Relative), null, null);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new ObservableOrganizationMembersClient(Substitute.For<IGitHubClient>());
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.GetAll(null));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.GetAll(""));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetPublicMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsTheCorrectUrl()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableOrganizationMembersClient(gitHubClient);
|
||||
|
||||
client.GetPublic("org");
|
||||
|
||||
gitHubClient.Connection.GetAsync<IReadOnlyList<User>>(
|
||||
new Uri("orgs/org/public_members", UriKind.Relative), null, null);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new ObservableOrganizationMembersClient(Substitute.For<IGitHubClient>());
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.GetPublic(null));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.GetPublic(""));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCheckMemberMethod
|
||||
{
|
||||
[Fact]
|
||||
public void ChecksMemberFromClientOrganizationMember()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableOrganizationMembersClient(gitHubClient);
|
||||
|
||||
client.CheckMember("org", "user");
|
||||
|
||||
gitHubClient.Organization.Member.Received().CheckMember("org", "user");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new ObservableOrganizationMembersClient(Substitute.For<IGitHubClient>());
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.CheckMember(null, "username"));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.CheckMember("", "username"));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.CheckMember("org", null));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.CheckMember("org", ""));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCheckMemberPublicMethod
|
||||
{
|
||||
[Fact]
|
||||
public void ChecksMemberPublicFromClientOrganizationMember()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableOrganizationMembersClient(gitHubClient);
|
||||
|
||||
client.CheckMemberPublic("org", "user");
|
||||
|
||||
gitHubClient.Organization.Member.Received().CheckMemberPublic("org", "user");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new ObservableOrganizationMembersClient(Substitute.For<IGitHubClient>());
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.CheckMemberPublic(null, "username"));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.CheckMemberPublic("", "username"));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.CheckMemberPublic("org", null));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.CheckMemberPublic("org", ""));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheDeleteMethod
|
||||
{
|
||||
[Fact]
|
||||
public void DeletesFromClientOrganizationMember()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableOrganizationMembersClient(gitHubClient);
|
||||
|
||||
client.Delete("org", "user");
|
||||
|
||||
gitHubClient.Organization.Member.Received().Delete("org", "user");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new ObservableOrganizationMembersClient(Substitute.For<IGitHubClient>());
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Delete(null, "username"));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.Delete("", "username"));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Delete("org", null));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.Delete("org", ""));
|
||||
}
|
||||
}
|
||||
|
||||
public class ThePublicizeMethod
|
||||
{
|
||||
[Fact]
|
||||
public void PublicizeFromClientOrganizationMember()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableOrganizationMembersClient(gitHubClient);
|
||||
|
||||
client.Publicize("org", "user");
|
||||
|
||||
gitHubClient.Organization.Member.Received().Publicize("org", "user");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new ObservableOrganizationMembersClient(Substitute.For<IGitHubClient>());
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Publicize(null, "username"));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.Publicize("", "username"));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Publicize("org", null));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.Publicize("org", ""));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheConcealMethod
|
||||
{
|
||||
[Fact]
|
||||
public void ConcealFromClientOrganizationMember()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableOrganizationMembersClient(gitHubClient);
|
||||
|
||||
client.Conceal("org", "user");
|
||||
|
||||
gitHubClient.Organization.Member.Received().Conceal("org", "user");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new ObservableOrganizationMembersClient(Substitute.For<IGitHubClient>());
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Conceal(null, "username"));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.Conceal("", "username"));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Conceal("org", null));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.Conceal("org", ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,7 @@ namespace Octokit
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(org, "org");
|
||||
|
||||
return ApiConnection.GetAll<User>("orgs/{0}/members".FormatUri(org));
|
||||
return ApiConnection.GetAll<User>(ApiUrls.Members(org));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -51,7 +51,7 @@ namespace Octokit
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(org, "org");
|
||||
|
||||
return ApiConnection.GetAll<User>("orgs/{0}/public_members".FormatUri(org));
|
||||
return ApiConnection.GetAll<User>(ApiUrls.PublicMembers(org));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -247,6 +247,26 @@ namespace Octokit
|
||||
return "repos/{0}/{1}/assignees/{2}".FormatUri(owner, name, login);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the <see cref="Uri"/> that returns all of the members of the organization
|
||||
/// </summary>
|
||||
/// <param name="org">The organization</param>
|
||||
/// <returns></returns>
|
||||
public static Uri Members(string org)
|
||||
{
|
||||
return "orgs/{0}/members".FormatUri(org);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the <see cref="Uri"/> that returns all of the public members of the organization
|
||||
/// </summary>
|
||||
/// <param name="org">Organization</param>
|
||||
/// <returns></returns>
|
||||
public static Uri PublicMembers(string org)
|
||||
{
|
||||
return "orgs/{0}/public_members".FormatUri(org);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the <see cref="Uri"/> that returns a 204 if requester is an organization member and
|
||||
/// the user is, publicly or privately a member of the organization.
|
||||
|
||||
Reference in New Issue
Block a user