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 user Administrator Client #1068

Merged
merged 8 commits into from
Feb 1, 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
1 change: 1 addition & 0 deletions CustomDictionary.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<Word>Submodule</Word>
<Word>Forkee</Word>
<Word>Tarball</Word>
<Word>Unsuspend</Word>
<Word>Zipball</Word>
</Recognized>
</Words>
Expand Down
56 changes: 56 additions & 0 deletions Octokit.Reactive/Clients/IObservableUserAdministrationClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reactive;

namespace Octokit.Reactive
{
/// <summary>
/// A client for GitHub's User Administration API.
/// </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.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/users/administration/#promote-an-ordinary-user-to-a-site-administrator
/// </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.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/users/administration/#demote-a-site-administrator-to-an-ordinary-user
/// </remarks>
/// <param name="login">The user to demote from administrator.</param>
/// <returns></returns>
IObservable<Unit> Demote(string login);

/// <summary>
/// Suspends a user.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/users/administration/#suspend-a-user
/// </remarks>
/// <param name="login">The user to suspend.</param>
/// <returns></returns>
IObservable<Unit> Suspend(string login);

/// <summary>
/// Unsuspends a user.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/users/administration/#unsuspend-a-user
/// </remarks>
/// <param name="login">The user to unsuspend.</param>
/// <returns></returns>
IObservable<Unit> Unsuspend(string login);

}
}
8 changes: 8 additions & 0 deletions Octokit.Reactive/Clients/IObservableUsersClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,13 @@ public interface IObservableUsersClient
/// See the <a href="http://developer.github.com/v3/users/keys/">Keys API documentation</a> for more information.
///</remarks>
IObservableUserKeysClient Keys { get; }

/// <summary>
/// A client for GitHub's User Administration API
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/users/administration/">User Administrator API documentation</a> for more information.
///</remarks>
IObservableUserAdministrationClient Administration { get; }
}
}
77 changes: 77 additions & 0 deletions Octokit.Reactive/Clients/ObservableUserAdministrationClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using System;
using System.Reactive;
using System.Reactive.Threading.Tasks;
using Octokit.Reactive.Internal;
using System.Reactive.Linq;


namespace Octokit.Reactive
{
public class ObservableUserAdministrationClient : IObservableUserAdministrationClient
{
readonly IUserAdministrationClient _client;

/// <summary>
/// Initializes a new instance of the <see cref="ObservableUserAdministrationClient"/> class.
/// </summary>
/// <param name="client">An <see cref="IGitHubClient" /> used to make the requests</param>
public ObservableUserAdministrationClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, "client");

_client = client.User.Administration;
}

/// <summary>
/// Promotes ordinary user to a site administrator.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/users/administration/#promote-an-ordinary-user-to-a-site-administrator
/// </remarks>
/// <param name="login">The user to promote to administrator.</param>
/// <returns></returns>
public IObservable<Unit> Promote(string login)
{
return _client.Promote(login).ToObservable();
}

/// <summary>
/// Demotes a site administrator to an ordinary user.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/users/administration/#demote-a-site-administrator-to-an-ordinary-user
/// </remarks>
/// <param name="login">The user to demote from administrator.</param>
/// <returns></returns>
public IObservable<Unit> Demote(string login)
{
return _client.Demote(login).ToObservable();
}

/// <summary>
/// Suspends a user.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/users/administration/#suspend-a-user
/// </remarks>
/// <param name="login">The user to suspend.</param>
/// <returns></returns>
public IObservable<Unit> Suspend(string login)
{
return _client.Suspend(login).ToObservable();
}

/// <summary>
/// Unsuspends a user.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/users/administration/#unsuspend-a-user
/// </remarks>
/// <param name="login">The user to unsuspend.</param>
/// <returns></returns>
public IObservable<Unit> Unsuspend(string login)
{
return _client.Unsuspend(login).ToObservable();
}
}
}
10 changes: 10 additions & 0 deletions Octokit.Reactive/Clients/ObservableUsersClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public ObservableUsersClient(IGitHubClient client)
Followers = new ObservableFollowersClient(client);
Email = new ObservableUserEmailsClient(client);
Keys = new ObservableUserKeysClient(client);
Administration = new ObservableUserAdministrationClient(client);

}

/// <summary>
Expand Down Expand Up @@ -75,5 +77,13 @@ public IObservable<User> Update(UserUpdate user)
/// See the <a href="http://developer.github.com/v3/users/keys/">Keys API documentation</a> for more information.
///</remarks>
public IObservableUserKeysClient Keys { get; private set; }

/// <summary>
/// A client for GitHub's User Administration API
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/users/administration/">User Administrator API documentation</a> for more information.
///</remarks>
public IObservableUserAdministrationClient Administration { get; private set; }
}
}
2 changes: 2 additions & 0 deletions Octokit.Reactive/Octokit.Reactive-Mono.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@
<Compile Include="Clients\Enterprise\IObservableEnterpriseClient.cs" />
<Compile Include="Clients\Enterprise\ObservableEnterpriseAdminStatsClient.cs" />
<Compile Include="Clients\Enterprise\ObservableEnterpriseClient.cs" />
<Compile Include="Clients\IObservableUserAdministrationClient.cs" />
<Compile Include="Clients\ObservableUserAdministrationClient.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@
<Compile Include="Clients\Enterprise\IObservableEnterpriseClient.cs" />
<Compile Include="Clients\Enterprise\ObservableEnterpriseAdminStatsClient.cs" />
<Compile Include="Clients\Enterprise\ObservableEnterpriseClient.cs" />
<Compile Include="Clients\IObservableUserAdministrationClient.cs" />
<Compile Include="Clients\ObservableUserAdministrationClient.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions Octokit.Reactive/Octokit.Reactive-Monotouch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@
<Compile Include="Clients\Enterprise\IObservableEnterpriseClient.cs" />
<Compile Include="Clients\Enterprise\ObservableEnterpriseAdminStatsClient.cs" />
<Compile Include="Clients\Enterprise\ObservableEnterpriseClient.cs" />
<Compile Include="Clients\IObservableUserAdministrationClient.cs" />
<Compile Include="Clients\ObservableUserAdministrationClient.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions Octokit.Reactive/Octokit.Reactive.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
<Compile Include="Clients\IObservableRepositoryCommitsClients.cs" />
<Compile Include="Clients\IObservableRepositoryDeployKeysClient.cs" />
<Compile Include="Clients\IObservableRepositoryPagesClient.cs" />
<Compile Include="Clients\IObservableUserAdministrationClient.cs" />
<Compile Include="Clients\IObservableUserKeysClient.cs" />
<Compile Include="Clients\ObservableMergingClient.cs" />
<Compile Include="Clients\ObservableRepositoryDeployKeysClient.cs" />
Expand Down Expand Up @@ -161,6 +162,7 @@
<Compile Include="Clients\ObservableTagsClient.cs" />
<Compile Include="Clients\ObservableTreesClient.cs" />
<Compile Include="Clients\ObservableFollowersClient.cs" />
<Compile Include="Clients\ObservableUserAdministrationClient.cs" />
<Compile Include="Clients\ObservableUserEmailsClient.cs" />
<Compile Include="Clients\ObservableUserKeysClient.cs" />
<Compile Include="Clients\ObservableUsersClient.cs" />
Expand Down
127 changes: 127 additions & 0 deletions Octokit.Tests/Clients/UserAdministrationClientTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using NSubstitute;
using Octokit.Tests.Helpers;
using Xunit;

namespace Octokit.Tests.Clients
{
public class UserAdministrationClientTests
{
public class ThePromoteMethod
{
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new UserAdministrationClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Promote(null));
}

[Fact]
public async Task EnsuresNonEmptyString()
{
var client = new UserAdministrationClient(Substitute.For<IApiConnection>());
var exception = await Assert.ThrowsAsync<ArgumentException>(() => client.Promote(""));
Assert.Equal("login", exception.ParamName);
}

[Fact]
public void RequestsTheCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new UserAdministrationClient(connection);

client.Promote("auser");

connection.Received().Put(Arg.Is<Uri>(u => u.ToString() == "/users/auser/site_admin"));
}
}
public class TheDemoteMethod
{
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new UserAdministrationClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Demote(null));
}

[Fact]
public async Task EnsuresNonEmptyString()
{
var client = new UserAdministrationClient(Substitute.For<IApiConnection>());
var exception = await Assert.ThrowsAsync<ArgumentException>(() => client.Demote(""));
Assert.Equal("login", exception.ParamName);
}

[Fact]
public void RequestsTheCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new UserAdministrationClient(connection);

client.Demote("auser");

connection.Received().Delete(Arg.Is<Uri>(u => u.ToString() == "/users/auser/site_admin"));
}
}

public class TheSuspendMethod
{
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new UserAdministrationClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Suspend(null));
}

[Fact]
public async Task EnsuresNonEmptyString()
{
var client = new UserAdministrationClient(Substitute.For<IApiConnection>());
var exception = await Assert.ThrowsAsync<ArgumentException>(() => client.Suspend(""));
Assert.Equal("login", exception.ParamName);
}

[Fact]
public void RequestsTheCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new UserAdministrationClient(connection);

client.Suspend("auser");

connection.Received().Put(Arg.Is<Uri>(u => u.ToString() == "/users/auser/suspended"));
}
}

public class TheUnsuspendMethod
{
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new UserAdministrationClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Unsuspend(null));
}

[Fact]
public async Task EnsuresNonEmptyString()
{
var client = new UserAdministrationClient(Substitute.For<IApiConnection>());
var exception = await Assert.ThrowsAsync<ArgumentException>(() => client.Unsuspend(""));
Assert.Equal("login", exception.ParamName);
}

[Fact]
public void RequestsTheCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new UserAdministrationClient(connection);

client.Unsuspend("auser");

connection.Received().Delete(Arg.Is<Uri>(u => u.ToString() == "/users/auser/suspended"));
}
}
}
}
1 change: 1 addition & 0 deletions Octokit.Tests/OctoKit.Tests-NetCore45.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
<Compile Include="Clients\StatisticsClientTests.cs" />
<Compile Include="Clients\TagsClientTests.cs" />
<Compile Include="Clients\TreesClientTests.cs" />
<Compile Include="Clients\UserAdministrationClientTests.cs" />
<Compile Include="Clients\UserEmailsClientTests.cs" />
<Compile Include="Clients\WatchedClientTests.cs" />
<Compile Include="Exceptions\ApiErrorTests.cs" />
Expand Down
1 change: 1 addition & 0 deletions Octokit.Tests/Octokit.Tests-Portable.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
<Compile Include="Clients\StatisticsClientTests.cs" />
<Compile Include="Clients\TagsClientTests.cs" />
<Compile Include="Clients\TreesClientTests.cs" />
<Compile Include="Clients\UserAdministrationClientTests.cs" />
<Compile Include="Clients\UserEmailsClientTests.cs" />
<Compile Include="Clients\WatchedClientTests.cs" />
<Compile Include="Exceptions\ApiErrorTests.cs" />
Expand Down
2 changes: 2 additions & 0 deletions Octokit.Tests/Octokit.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
<Compile Include="Clients\RepositoryHooksClientTest.cs" />
<Compile Include="Clients\SshKeysClientTests.cs" />
<Compile Include="Clients\TreesClientTests.cs" />
<Compile Include="Clients\UserAdministrationClientTests.cs" />
<Compile Include="Clients\UserEmailsClientTests.cs" />
<Compile Include="Clients\WatchedClientTests.cs" />
<Compile Include="Clients\FollowersClientTests.cs" />
Expand Down Expand Up @@ -207,6 +208,7 @@
<Compile Include="Reactive\ObservableStatisticsClientTests.cs" />
<Compile Include="Reactive\ObservableTreesClientTests.cs" />
<Compile Include="Reactive\ObservableFollowersTest.cs" />
<Compile Include="Reactive\ObservableUserAdministrationClientTests.cs" />
<Compile Include="Reactive\Enterprise\ObservableEnterpriseAdminStatsClientTests.cs" />
<Compile Include="Reactive\ObservableUserEmailsClientTests.cs" />
<Compile Include="SelfTests.cs" />
Expand Down
Loading