Skip to content

Commit

Permalink
Merge pull request #1211 from devkhan/pagination-1181
Browse files Browse the repository at this point in the history
Add ApiOptions overloads to ITeamsClient
  • Loading branch information
shiftkey committed Apr 5, 2016
2 parents 4ed32bc + a1aa51a commit 5ec98b0
Show file tree
Hide file tree
Showing 9 changed files with 295 additions and 20 deletions.
43 changes: 42 additions & 1 deletion Octokit.Reactive/Clients/IObservableTeamsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,20 @@ public interface IObservableTeamsClient
/// <summary>
/// Returns all <see cref="Team" />s for the current org.
/// </summary>
/// <param name="org">Organization to list all teams of.</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>A list of the orgs's teams <see cref="Team"/>s.</returns>
IObservable<Team> GetAll(string org);

/// <summary>
/// Returns all <see cref="Team" />s for the current org.
/// </summary>
/// <param name="org">Organization to list all teams of.</param>
/// <param name="options">Options to change API behaviour.</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>A list of the orgs's teams <see cref="Team"/>s.</returns>
IObservable<Team> GetAll(string org, ApiOptions options);

/// <summary>
/// Returns all <see cref="Team" />s for the current user.
/// </summary>
Expand All @@ -39,17 +49,38 @@ public interface IObservableTeamsClient
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
IObservable<Team> GetAllForCurrent();

/// <summary>
/// Returns all <see cref="Team" />s for the current user.
/// </summary>
/// <param name="options">Options to change API behaviour.</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>A list of the user's <see cref="Team"/>s.</returns>
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
IObservable<Team> GetAllForCurrent(ApiOptions options);

/// <summary>
/// Returns all members of the given team.
/// </summary>
/// <param name="id">The team identifier</param>
/// <remarks>
/// https://developer.github.com/v3/orgs/teams/#list-team-members
/// </remarks>
/// <param name="id">The team identifier</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>A list of the team's member <see cref="User"/>s.</returns>
IObservable<User> GetAllMembers(int id);

/// <summary>
/// Returns all members of the given team.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/orgs/teams/#list-team-members
/// </remarks>
/// <param name="id">The team identifier</param>
/// <param name="options">Options to change API behaviour.</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>A list of the team's member <see cref="User"/>s.</returns>
IObservable<User> GetAllMembers(int id, ApiOptions options);

/// <summary>
/// Returns newly created <see cref="Team" /> for the current org.
/// </summary>
Expand Down Expand Up @@ -116,10 +147,20 @@ public interface IObservableTeamsClient
/// <summary>
/// Returns all team's repositories.
/// </summary>
/// <param name="id">Team Id.</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>The team's repositories</returns>
IObservable<Repository> GetAllRepositories(int id);

/// <summary>
/// Returns all team's repositories.
/// </summary>
/// <param name="id">Team Id.</param>
/// <param name="options">Options to change API behaviour.</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>The team's repositories</returns>
IObservable<Repository> GetAllRepositories(int id, ApiOptions options);

/// <summary>
/// Remove a repository from the team
/// </summary>
Expand Down
89 changes: 85 additions & 4 deletions Octokit.Reactive/Clients/ObservableTeamsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,23 @@ public IObservable<Team> Get(int id)
public IObservable<Team> GetAll(string org)
{
Ensure.ArgumentNotNullOrEmptyString(org, "org");
return _connection.GetAndFlattenAllPages<Team>(ApiUrls.OrganizationTeams(org));

return GetAll(org, ApiOptions.None);
}

/// <summary>
/// Returns all <see cref="Team" />s for the current org.
/// </summary>
/// <param name="org">Organization to list all teams of.</param>
/// <param name="options">Options to change API behaviour.</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>A list of the orgs's teams <see cref="Team"/>s.</returns>
public IObservable<Team> GetAll(string org, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(org, "org");
Ensure.ArgumentNotNull(options, "options");

return _connection.GetAndFlattenAllPages<Team>(ApiUrls.OrganizationTeams(org), options);
}

/// <summary>
Expand All @@ -58,7 +74,20 @@ public IObservable<Team> GetAll(string org)
/// <returns>A list of the user's <see cref="Team"/>s.</returns>
public IObservable<Team> GetAllForCurrent()
{
return _connection.GetAndFlattenAllPages<Team>(ApiUrls.UserTeams());
return GetAllForCurrent(ApiOptions.None);
}

/// <summary>
/// Returns all <see cref="Team" />s for the current user.
/// </summary>
/// <param name="options">Options to change API behaviour.</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>A list of the user's <see cref="Team"/>s.</returns>
public IObservable<Team> GetAllForCurrent(ApiOptions options)
{
Ensure.ArgumentNotNull(options, "options");

return _connection.GetAndFlattenAllPages<Team>(ApiUrls.UserTeams(), options);
}

/// <summary>
Expand All @@ -72,7 +101,24 @@ public IObservable<Team> GetAllForCurrent()
/// <returns>A list of the team's member <see cref="User"/>s.</returns>
public IObservable<User> GetAllMembers(int id)
{
return _connection.GetAndFlattenAllPages<User>(ApiUrls.TeamMembers(id));
return GetAllMembers(id, ApiOptions.None);
}

/// <summary>
/// Returns all members of the given team.
/// </summary>
/// <remarks>
/// https://developer.github.com/v3/orgs/teams/#list-team-members
/// </remarks>
/// <param name="id">The team identifier</param>
/// <param name="options">Options to change API behaviour.</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>A list of the team's member <see cref="User"/>s.</returns>
public IObservable<User> GetAllMembers(int id, ApiOptions options)
{
Ensure.ArgumentNotNull(options, "options");

return _connection.GetAndFlattenAllPages<User>(ApiUrls.TeamMembers(id), options);
}

/// <summary>
Expand All @@ -82,6 +128,9 @@ public IObservable<User> GetAllMembers(int id)
/// <returns>Newly created <see cref="Team"/></returns>
public IObservable<Team> Create(string org, NewTeam team)
{
Ensure.ArgumentNotNullOrEmptyString(org, "org");
Ensure.ArgumentNotNull(team, "team");

return _client.Create(org, team).ToObservable();
}

Expand All @@ -92,6 +141,8 @@ public IObservable<Team> Create(string org, NewTeam team)
/// <returns>Updated <see cref="Team"/></returns>
public IObservable<Team> Update(int id, UpdateTeam team)
{
Ensure.ArgumentNotNull(team, "team");

return _client.Update(id, team).ToObservable();
}

Expand All @@ -117,6 +168,8 @@ public IObservable<Unit> Delete(int id)
/// <returns>A <see cref="TeamMembership"/> result indicating the membership status</returns>
public IObservable<TeamMembership> AddMembership(int id, string login)
{
Ensure.ArgumentNotNullOrEmptyString(login, "login");

return _client.AddMembership(id, login).ToObservable();
}

Expand All @@ -131,6 +184,8 @@ public IObservable<TeamMembership> AddMembership(int id, string login)
/// <returns><see langword="true"/> if the user was removed from the team; <see langword="false"/> otherwise.</returns>
public IObservable<bool> RemoveMembership(int id, string login)
{
Ensure.ArgumentNotNullOrEmptyString(login, "login");

return _client.RemoveMembership(id, login).ToObservable();
}

Expand All @@ -144,6 +199,8 @@ public IObservable<bool> RemoveMembership(int id, string login)
[Obsolete("Use GetMembership(id, login) to detect pending memberships")]
public IObservable<bool> IsMember(int id, string login)
{
Ensure.ArgumentNotNullOrEmptyString(login, "login");

return _client.IsMember(id, login).ToObservable();
}

Expand All @@ -156,6 +213,8 @@ public IObservable<bool> IsMember(int id, string login)
/// <returns>A <see cref="TeamMembership"/> result indicating the membership status</returns>
public IObservable<TeamMembership> GetMembership(int id, string login)
{
Ensure.ArgumentNotNullOrEmptyString(login, "login");

return _client.GetMembership(id, login).ToObservable();
}

Expand All @@ -166,7 +225,21 @@ public IObservable<TeamMembership> GetMembership(int id, string login)
/// <returns>The team's repositories</returns>
public IObservable<Repository> GetAllRepositories(int id)
{
return _connection.GetAndFlattenAllPages<Repository>(ApiUrls.TeamRepositories(id));
return GetAllRepositories(id, ApiOptions.None);
}

/// <summary>
/// Returns all team's repositories.
/// </summary>
/// <param name="id">Team Id.</param>
/// <param name="options">Options to change API behaviour.</param>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>The team's repositories</returns>
public IObservable<Repository> GetAllRepositories(int id, ApiOptions options)
{
Ensure.ArgumentNotNull(options, "options");

return _connection.GetAndFlattenAllPages<Repository>(ApiUrls.TeamRepositories(id), options);
}

/// <summary>
Expand All @@ -182,6 +255,9 @@ public IObservable<Repository> GetAllRepositories(int id)
/// <returns><see langword="true"/> if the repository was added to the team; <see langword="false"/> otherwise.</returns>
public IObservable<bool> AddRepository(int id, string organization, string repoName)
{
Ensure.ArgumentNotNullOrEmptyString(organization, "organization");
Ensure.ArgumentNotNullOrEmptyString(repoName, "repoName");

return _client.AddRepository(id, organization, repoName).ToObservable();
}

Expand All @@ -193,6 +269,9 @@ public IObservable<bool> AddRepository(int id, string organization, string repoN
/// <returns></returns>
public IObservable<bool> RemoveRepository(int id, string organization, string repoName)
{
Ensure.ArgumentNotNullOrEmptyString(organization, "organization");
Ensure.ArgumentNotNullOrEmptyString(repoName, "repoName");

return _client.RemoveRepository(id, organization, repoName).ToObservable();
}

Expand All @@ -208,6 +287,8 @@ public IObservable<bool> RemoveRepository(int id, string organization, string re
/// <returns><see langword="true"/> if the repository is managed by the given team; <see langword="false"/> otherwise.</returns>
public IObservable<bool> IsRepositoryManagedByTeam(int id, string owner, string repo)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repo, "repo");
return _client.IsRepositoryManagedByTeam(id, owner, repo).ToObservable();
}
}
Expand Down
2 changes: 1 addition & 1 deletion Octokit.Tests.Integration/Clients/TeamsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public async Task SucceedsWhenAuthenticated()
public class TheGetAllForCurrentMethod
{
[IntegrationTest]
public async Task GetsIsMemberWhenAuthenticated()
public async Task GetsAllForCurrentWhenAuthenticated()
{
var github = Helper.GetAuthenticatedClient();
var teams = await github.Organization.Team.GetAllForCurrent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ public class ObservableTeamsClientTests
{
public class TheGetMembersMethod
{
readonly Team team;
readonly Team _team;

public TheGetMembersMethod()
{
var github = Helper.GetAuthenticatedClient();

team = github.Organization.Team.GetAll(Helper.Organization).Result.First();
_team = github.Organization.Team.GetAll(Helper.Organization).Result.First();
}

[OrganizationTest]
Expand All @@ -26,7 +26,7 @@ public async Task GetsAllMembersWhenAuthenticated()

var client = new ObservableTeamsClient(github);

var member = await client.GetAllMembers(team.Id);
var member = await client.GetAllMembers(_team.Id, ApiOptions.None);

Assert.Equal(Helper.UserName, member.Login);
}
Expand Down
20 changes: 13 additions & 7 deletions Octokit.Tests/Clients/TeamsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ public void RequestsTheCorrectUrl()

client.GetAll("orgName");

connection.Received().GetAll<Team>(Arg.Is<Uri>(u => u.ToString() == "orgs/orgName/teams"));
connection.Received().GetAll<Team>(
Arg.Is<Uri>(u => u.ToString() == "orgs/orgName/teams"),
Args.ApiOptions);
}

[Fact]
Expand All @@ -54,6 +56,7 @@ public async Task EnsuresNonNullArguments()
var teams = new TeamsClient(Substitute.For<IApiConnection>());

await Assert.ThrowsAsync<ArgumentNullException>(() => teams.GetAll(null));
await Assert.ThrowsAsync<ArgumentNullException>(() => teams.GetAll("orgName", null));
}
}

Expand All @@ -67,7 +70,9 @@ public void RequestsTheCorrectUrl()

client.GetAllMembers(1);

connection.Received().GetAll<User>(Arg.Is<Uri>(u => u.ToString() == "teams/1/members"));
connection.Received().GetAll<User>(
Arg.Is<Uri>(u => u.ToString() == "teams/1/members"),
Args.ApiOptions);
}
}

Expand Down Expand Up @@ -188,7 +193,9 @@ public void RequestsTheCorrectUrl()

client.GetAllForCurrent();

connection.Received().GetAll<Team>(Arg.Is<Uri>(u => u.ToString() == "user/teams"));
connection.Received().GetAll<Team>(
Arg.Is<Uri>(u => u.ToString() == "user/teams"),
Args.ApiOptions);
}
}

Expand Down Expand Up @@ -243,13 +250,12 @@ public void RequestsTheCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new TeamsClient(connection);
client.GetAllRepositories(1);

connection.Received().GetAll<Repository>(Arg.Is<Uri>(u => u.ToString() == "teams/1/repos"));

client.GetAllRepositories(1);

connection.Received().GetAll<Repository>(Arg.Is<Uri>(u => u.ToString() == "teams/1/repos"));
connection.Received().GetAll<Repository>(
Arg.Is<Uri>(u => u.ToString() == "teams/1/repos"),
Args.ApiOptions);
}
}

Expand Down
1 change: 1 addition & 0 deletions Octokit.Tests/Octokit.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@
<Compile Include="Reactive\ObservableGistsTests.cs" />
<Compile Include="Reactive\ObservableStarredClientTests.cs" />
<Compile Include="Reactive\ObservableStatisticsClientTests.cs" />
<Compile Include="Reactive\ObservableTeamsClientTests.cs" />
<Compile Include="Reactive\ObservableTreesClientTests.cs" />
<Compile Include="Reactive\ObservableFollowersTest.cs" />
<Compile Include="Reactive\ObservableUserKeysClientTests.cs" />
Expand Down
Loading

0 comments on commit 5ec98b0

Please sign in to comment.