Skip to content

Commit

Permalink
prepping teams api client
Browse files Browse the repository at this point in the history
  • Loading branch information
hahmed committed Nov 5, 2013
1 parent 1e96fde commit c44b18e
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 4 deletions.
46 changes: 46 additions & 0 deletions Octokit.Tests/Clients/TeamsClientTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Threading.Tasks;
using NSubstitute;
using Octokit.Tests.Helpers;
using Xunit;

namespace Octokit.Tests.Clients
{
/// <summary>
/// Client tests mostly just need to make sure they call the IApiConnection with the correct
/// relative Uri. No need to fake up the response. All *those* tests are in ApiConnectionTests.cs.
/// </summary>
public class TeamsClientTests
{
public class TheConstructor
{
[Fact]
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new TeamsClient(null));
}
}

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

orgs.GetAllTeams("username");

client.Received().GetAll<Team>(Arg.Is<Uri>(u => u.ToString() == "users/username/orgs"));
}

[Fact]
public async Task EnsuresNonNullArguments()
{
var teams = new TeamsClient(Substitute.For<IApiConnection>());

AssertEx.Throws<ArgumentNullException>(async () => await teams.GetAllTeams(null));
}
}
}
}
1 change: 1 addition & 0 deletions Octokit.Tests/Octokit.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
<Compile Include="Authentication\CredentialsTests.cs" />
<Compile Include="Clients\AssigneesClientTests.cs" />
<Compile Include="Clients\CommitStatusClientTests.cs" />
<Compile Include="Clients\TeamsClientTests.cs" />
<Compile Include="Clients\MilestonesClientTests.cs" />
<Compile Include="Clients\IssuesClientTests.cs" />
<Compile Include="Clients\NotificationsClientTests.cs" />
Expand Down
24 changes: 24 additions & 0 deletions Octokit/Clients/ITeamsClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#if NET_45
using System.Collections.Generic;
#endif
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;

namespace Octokit
{
/// <summary>
/// A client for GitHub's Org Teams API.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/orgs/teams/">Orgs API documentation</a> for more information.
/// </remarks>
public interface ITeamsClient
{
/// <summary>
/// Returns all <see cref="Team" />s for the current org.
/// </summary>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>A list of the orgs's teams <see cref="Team"/>s.</returns>
Task<IReadOnlyList<Team>> GetAllTeams(string org);
}
}
41 changes: 41 additions & 0 deletions Octokit/Clients/TeamsClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#if NET_45
using System.Collections.Generic;
#endif
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;

namespace Octokit
{

/// <summary>
/// A client for GitHub's Org Teams API.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/orgs/teams/">Orgs API documentation</a> for more information.
/// </remarks>
public class TeamsClient : ApiClient, ITeamsClient
{
/// <summary>
/// Initializes a new GitHub Orgs Team API client.
/// </summary>
/// <param name="apiConnection">An API connection.</param>
public TeamsClient(IApiConnection apiConnection)
: base(apiConnection)
{
}

/// <summary>
/// Returns all <see cref="Team" />s for the current org.
/// </summary>
/// <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 Task<IReadOnlyList<Team>> GetAllTeams(string org)
{
Ensure.ArgumentNotNullOrEmptyString(org, "org");

var endpoint = "orgs/{0}/teams".FormatUri(org);

return ApiConnection.GetAll<Team>(endpoint);
}
}
}
25 changes: 25 additions & 0 deletions Octokit/Models/Request/Permission.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;

namespace Octokit
{
public enum Permission
{
/// <summary>
/// team members can pull, push and administer these repositories.
/// </summary>
Admin,

/// <summary>
/// team members can pull and push, but not administer these repositories
/// </summary>
Push,

/// <summary>
/// team members can pull, but not push to or administer these repositories
/// </summary>
Pull
}
}
23 changes: 23 additions & 0 deletions Octokit/Models/Response/Team.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;

namespace Octokit
{
/// <summary>
/// organization teams
/// </summary>
public class Team
{
/// <summary>
/// team id
/// </summary>
public int Id { get; set; }

/// <summary>
/// team name
/// </summary>
public string Name { get; set; }
}
}
6 changes: 5 additions & 1 deletion Octokit/Octokit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
</Compile>
<Compile Include="Clients\AssigneesClient.cs" />
<Compile Include="Clients\CommitStatusClient.cs" />
<Compile Include="Clients\TeamsClient.cs" />
<Compile Include="Clients\ITeamsClient.cs" />
<Compile Include="Clients\ICommitStatusClient.cs" />
<Compile Include="Clients\IssuesClient.cs" />
<Compile Include="Clients\MilestonesClient.cs" />
Expand All @@ -66,6 +68,8 @@
<Compile Include="Models\Request\NewMilestone.cs" />
<Compile Include="Models\Request\RequestParameters.cs" />
<Compile Include="Models\Response\CommitStatus.cs" />
<Compile Include="Models\Request\Permission.cs" />
<Compile Include="Models\Response\Team.cs" />
<Compile Include="Models\Response\Issue.cs" />
<Compile Include="Models\Request\IssueRequest.cs" />
<Compile Include="Models\Request\IssueUpdate.cs" />
Expand Down Expand Up @@ -198,4 +202,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
7 changes: 4 additions & 3 deletions SolutionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[assembly: AssemblyProductAttribute("Octokit")]
[assembly: AssemblyVersionAttribute("0.1.2")]
[assembly: AssemblyFileVersionAttribute("0.1.2")]

class AssemblyVersionInformation { public const string Version = "0.1.2"; }

class AssemblyVersionInformation {
AssemblyVersionInformation() { }
public const string Version = "0.1.2";
}

0 comments on commit c44b18e

Please sign in to comment.