Skip to content

Commit

Permalink
Add implementation and basic test
Browse files Browse the repository at this point in the history
The test is failing for some reason :(
  • Loading branch information
M-Zuber committed Jan 17, 2016
1 parent 1a5e3d1 commit 912f3ad
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 9 deletions.
37 changes: 37 additions & 0 deletions Octokit.Tests/Clients/RepositoryPagesClientTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using NSubstitute;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;

namespace Octokit.Tests.Clients
{
public class RepositoryPagesClientTests
{
public class TheGetMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoryPagesClient(connection);

client.Get("fake", "repo");

connection.Received().Get<Page>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/pages"));
}

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

await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get(null, "name"));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get("owner", null));
}
}
}
}
1 change: 1 addition & 0 deletions Octokit.Tests/Octokit.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
<Compile Include="Clients\FeedsClientTests.cs" />
<Compile Include="Clients\RepositoryDeployKeysClientTests.cs" />
<Compile Include="Clients\RepositoryContentsClientTests.cs" />
<Compile Include="Clients\RepositoryPagesClientTests.cs" />
<Compile Include="Clients\SearchClientTests.cs" />
<Compile Include="Clients\GistCommentsClientTests.cs" />
<Compile Include="Clients\GistsClientTests.cs" />
Expand Down
10 changes: 9 additions & 1 deletion Octokit/Clients/IRepositoriesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public interface IRepositoriesClient
/// See the <a href="http://developer.github.com/v3/repos/commits/">Commits API documentation</a> for more details
///</remarks>
IRepositoryCommitsClient Commit { get; }

/// <summary>
/// Access GitHub's Releases API.
/// </summary>
Expand Down Expand Up @@ -384,5 +384,13 @@ public interface IRepositoriesClient
/// <param name="update">New values to update the branch with</param>
/// <returns>The updated <see cref="T:Octokit.Branch"/></returns>
Task<Branch> EditBranch(string owner, string name, string branch, BranchUpdate update);

/// <summary>
/// A client for GitHub's Repository Pages API.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/pages/">Repository Pages API documentation</a> for more information.
/// </remarks>
IRepositoryPagesClient Page { get; }
}
}
22 changes: 16 additions & 6 deletions Octokit/Clients/IRepositoryPagesClient.cs
Original file line number Diff line number Diff line change
@@ -1,39 +1,49 @@
using Octokit.Models.Response;
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Octokit.Clients
namespace Octokit
{
/// <summary>
/// A client for GitHub's Repository Pages API.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/pages//">Repository Pages API documentation</a> for more information.
/// See the <a href="https://developer.github.com/v3/repos/pages/">Repository Pages API documentation</a> for more information.
/// </remarks>
interface IRepositoryPagesClient
public interface IRepositoryPagesClient
{
/// <summary>
/// Gets the page metadata for a given repository
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/pages/#get-information-about-a-pages-site">API documentation</a> for more information.
/// </remarks>
/// <returns></returns>
Task<IReadOnlyList<Page>> Get(string owner, string repositoryName);
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")]
Task<Page> Get(string owner, string repositoryName);
/// <summary>
/// Gets all build metadata for a given repository
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/pages/#list-pages-builds">API documentation</a> for more information.
/// </remarks>
/// <returns></returns>
Task<IReadOnlyList<PagesBuild>> GetBuilds(string owner, string repositoryName);
/// <summary>
/// Gets the build metadata for the last build for a given repository
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/pages/#list-latest-pages-build">API documentation</a> for more information.
/// </remarks>
/// <returns></returns>
Task<PagesBuild> GetLatestBuild(string owner, string repositoryName);
}
Expand Down
9 changes: 9 additions & 0 deletions Octokit/Clients/RepositoriesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public RepositoriesClient(IApiConnection apiConnection) : base(apiConnection)
DeployKeys = new RepositoryDeployKeysClient(apiConnection);
Merging = new MergingClient(apiConnection);
Content = new RepositoryContentsClient(apiConnection);
Page = new RepositoryPagesClient(apiConnection);
}

/// <summary>
Expand Down Expand Up @@ -577,5 +578,13 @@ public Task<Branch> GetBranch(string owner, string repositoryName, string branch

return ApiConnection.Get<Branch>(ApiUrls.RepoBranch(owner, repositoryName, branchName), null, AcceptHeaders.ProtectedBranchesApiPreview);
}

/// <summary>
/// A client for GitHub's Repository Pages API.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/pages/">Repository Pages API documentation</a> for more information.
/// </remarks>
public IRepositoryPagesClient Page { get; private set; }
}
}
77 changes: 77 additions & 0 deletions Octokit/Clients/RepositoryPagesClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Octokit
{
/// <summary>
/// A client for GitHub's Repository Pages API.
/// </summary>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/pages/">Repository Pages API documentation</a> for more information.
/// </remarks>
public class RepositoryPagesClient : ApiClient, IRepositoryPagesClient
{
/// <summary>
/// Initializes a new GitHub Repository Pages API client.
/// </summary>
/// <param name="apiConnection">An API connection.</param>
public RepositoryPagesClient(IApiConnection apiConnection) : base(apiConnection)
{

}

/// <summary>
/// Gets the page metadata for a given repository
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/pages/#get-information-about-a-pages-site">API documentation</a> for more information.
/// </remarks>
/// <returns></returns>
public Task<Page> Get(string owner, string repositoryName)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");

return ApiConnection.Get<Page>(ApiUrls.RepositoryPage(owner, repositoryName));
}

/// <summary>
/// Gets all build metadata for a given repository
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/pages/#list-pages-builds">API documentation</a> for more information.
/// </remarks>
/// <returns></returns>
public Task<IReadOnlyList<PagesBuild>> GetBuilds(string owner, string repositoryName)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");

return ApiConnection.GetAll<PagesBuild>(ApiUrls.RepositoryBuilds(owner, repositoryName));
}

/// <summary>
/// Gets the build metadata for the last build for a given repository
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <remarks>
/// See the <a href="https://developer.github.com/v3/repos/pages/#list-latest-pages-build">API documentation</a> for more information.
/// </remarks>
/// <returns></returns>
public Task<PagesBuild> GetLatestBuild(string owner, string repositoryName)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");

return ApiConnection.Get<PagesBuild>(ApiUrls.RepositoryBuildsLatest(owner, repositoryName));
}
}
}
15 changes: 15 additions & 0 deletions Octokit/Helpers/ApiUrls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1554,5 +1554,20 @@ public static Uri RepositoryContent(string owner, string name, string path, stri
{
return "repos/{0}/{1}/contents/{2}?ref={3}".FormatUri(owner, name, path, reference);
}

public static Uri RepositoryPage(string owner, string name)
{
return "repos/{0}/{1}/pages".FormatUri(owner, name);
}

public static Uri RepositoryBuilds(string owner, string name)
{
return "repos/{0}/{1}/pages/builds".FormatUri(owner, name);
}

public static Uri RepositoryBuildsLatest(string owner, string name)
{
return "repos/{0}/{1}/pages/builds/latest".FormatUri(owner, name);
}
}
}
2 changes: 1 addition & 1 deletion Octokit/Models/Response/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using System.Text;
using System.Threading.Tasks;

namespace Octokit.Models.Response
namespace Octokit
{
public enum PagesBuildStatus
{
Expand Down
2 changes: 1 addition & 1 deletion Octokit/Models/Response/PagesBuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Text;
using System.Threading.Tasks;

namespace Octokit.Models.Response
namespace Octokit
{
/// <summary>
/// Metadata of a Github Pages build.
Expand Down
1 change: 1 addition & 0 deletions Octokit/Octokit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<Compile Include="Clients\IFeedsClient.cs" />
<Compile Include="Clients\RepositoryCommitsClient.cs" />
<Compile Include="Clients\RepositoryDeployKeysClient.cs" />
<Compile Include="Clients\RepositoryPagesClient.cs" />
<Compile Include="Clients\UserKeysClient.cs" />
<Compile Include="Clients\RepositoryContentsClient.cs" />
<Compile Include="Exceptions\InvalidGitIgnoreTemplateException.cs" />
Expand Down

0 comments on commit 912f3ad

Please sign in to comment.