Skip to content

Commit

Permalink
Added GetMembers to retrieve all team members.
Browse files Browse the repository at this point in the history
  • Loading branch information
kzu committed Apr 22, 2014
1 parent 0e54ca8 commit 6660f1b
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 1 deletion.
11 changes: 11 additions & 0 deletions Octokit.Reactive/Clients/IObservableTeamsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ public interface IObservableTeamsClient
/// <returns>A list of the orgs's teams <see cref="Team"/>s.</returns>
IObservable<Team> GetAll(string org);

/// <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>
/// <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> GetMembers(int id);

/// <summary>
/// Returns newly created <see cref="Team" /> for the current org.
/// </summary>
Expand Down
14 changes: 14 additions & 0 deletions Octokit.Reactive/Clients/ObservableTeamsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ public IObservable<Team> GetAll(string org)
return _connection.GetAndFlattenAllPages<Team>(ApiUrls.OrganizationTeams(org));
}

/// <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>
/// <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> GetMembers(int id)
{
return _connection.GetAndFlattenAllPages<User>(ApiUrls.TeamMembers(id));
}

/// <summary>
/// Returns newly created <see cref="Team" /> for the current org.
/// </summary>
Expand Down
25 changes: 25 additions & 0 deletions Octokit.Tests.Integration/Clients/TeamsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,29 @@ public async Task GetsIsMemberFalseForNonMemberWhenAuthenticated()
Assert.False(isMember);
}
}

public class TheGetMembersMethod
{
readonly Team team;

public TheGetMembersMethod()
{
var github = new GitHubClient(new ProductHeaderValue("OctokitTests")) { Credentials = Helper.Credentials };

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

[OrganizationTest]
public async Task GetsAllMembersWhenAuthenticated()
{
var github = new GitHubClient(new ProductHeaderValue("OctokitTests"))
{
Credentials = Helper.Credentials
};

var members = await github.Organization.Team.GetMembers(team.Id);

Assert.Contains(Helper.UserName, members.Select(u => u.Login));
}
}
}
14 changes: 14 additions & 0 deletions Octokit.Tests/Clients/TeamsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ public void EnsuresNonNullArguments()
}
}

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

client.GetMembers(1);

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

public class TheCreateTeamMethod
{
[Fact]
Expand Down
10 changes: 10 additions & 0 deletions Octokit/Clients/ITeamsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ public interface ITeamsClient
/// <returns>A list of the orgs's teams <see cref="Team"/>s.</returns>
Task<IReadOnlyList<Team>> GetAll(string org);

/// <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>
/// <returns>A list of the team's member <see cref="User"/>s.</returns>
Task<IReadOnlyList<User>> GetMembers(int id);

/// <summary>
/// Returns newly created <see cref="Team" /> for the current org.
/// </summary>
Expand Down
14 changes: 14 additions & 0 deletions Octokit/Clients/TeamsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ public Task<IReadOnlyList<Team>> GetAll(string org)
return ApiConnection.GetAll<Team>(endpoint);
}

/// <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>
/// <returns>A list of the team's member <see cref="User"/>s.</returns>
public Task<IReadOnlyList<User>> GetMembers(int id)
{
var endpoint = ApiUrls.TeamMembers(id);

return ApiConnection.GetAll<User>(endpoint);
}

/// <summary>
/// Returns newly created <see cref="Team" /> for the current org.
Expand Down
11 changes: 10 additions & 1 deletion Octokit/Helpers/ApiUrls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ public static Uri Teams(int id)
}

/// <summary>
/// returns the <see cref="Uri"/> for team members
/// returns the <see cref="Uri"/> for team member
/// </summary>
/// <param name="id">The team id</param>
/// <param name="login">The user login.</param>
Expand All @@ -955,6 +955,15 @@ public static Uri TeamMember(int id, string login)
return "teams/{0}/members/{1}".FormatUri(id, login);
}

/// <summary>
/// returns the <see cref="Uri"/> for team members list
/// </summary>
/// <param name="id">The team id</param>
public static Uri TeamMembers(int id)
{
return "teams/{0}/members".FormatUri(id);
}

/// <summary>
/// returns the <see cref="Uri"/> for teams
/// use for update or deleting a team
Expand Down

0 comments on commit 6660f1b

Please sign in to comment.