Skip to content

Commit

Permalink
Merge pull request #1061 from M-Zuber/IRepositoryPagesClient
Browse files Browse the repository at this point in the history
Implement Repository Pages client
  • Loading branch information
shiftkey committed Jan 26, 2016
2 parents 0df47c2 + ef06aa4 commit 0c4fff0
Show file tree
Hide file tree
Showing 27 changed files with 557 additions and 4 deletions.
7 changes: 7 additions & 0 deletions Octokit.Reactive/Clients/IObservableRepositoriesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,5 +347,12 @@ public interface IObservableRepositoriesClient
/// See the <a href="https://developer.github.com/v3/repos/keys/">Repository Deploy Keys API documentation</a> for more information.
/// </remarks>
IObservableRepositoryDeployKeysClient DeployKeys { get; }
/// <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>
IObservableRepositoryPagesClient Page { get; }
}
}
40 changes: 40 additions & 0 deletions Octokit.Reactive/Clients/IObservableRepositoryPagesClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Diagnostics.CodeAnalysis;

namespace Octokit.Reactive
{
public interface IObservableRepositoryPagesClient
{
/// <summary>
/// Gets the page metadata for a given repository
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="repositoryName">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>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")]
IObservable<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="repositoryName">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>
IObservable<PagesBuild> GetAll(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="repositoryName">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>
IObservable<PagesBuild> GetLatest(string owner, string repositoryName);
}
}
8 changes: 8 additions & 0 deletions Octokit.Reactive/Clients/ObservableRepositoriesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public ObservableRepositoriesClient(IGitHubClient client)
DeployKeys = new ObservableRepositoryDeployKeysClient(client);
Content = new ObservableRepositoryContentsClient(client);
Merging = new ObservableMergingClient(client);
Page = new ObservableRepositoryPagesClient(client);
}

/// <summary>
Expand Down Expand Up @@ -493,5 +494,12 @@ public IObservable<CompareResult> Compare(string owner, string name, string @bas
/// See the <a href="https://developer.github.com/v3/repos/keys/">Repository Deploy Keys API documentation</a> for more information.
/// </remarks>
public IObservableRepositoryDeployKeysClient DeployKeys { get; private set; }
/// <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 IObservableRepositoryPagesClient Page { get; private set; }
}
}
73 changes: 73 additions & 0 deletions Octokit.Reactive/Clients/ObservableRepositoryPagesClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using Octokit.Reactive.Internal;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reactive.Threading.Tasks;

namespace Octokit.Reactive
{
public class ObservableRepositoryPagesClient : IObservableRepositoryPagesClient
{
readonly IRepositoryPagesClient _client;
readonly IConnection _connection;

public ObservableRepositoryPagesClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, "client");

_client = client.Repository.Page;
_connection = client.Connection;
}

/// <summary>
/// Gets the page metadata for a given repository
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="repositoryName">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>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")]
public IObservable<Page> Get(string owner, string repositoryName)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");

return _client.Get(owner, repositoryName).ToObservable();
}

/// <summary>
/// Gets all build metadata for a given repository
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="repositoryName">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 IObservable<PagesBuild> GetAll(string owner, string repositoryName)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");

return _connection.GetAndFlattenAllPages<PagesBuild>(ApiUrls.RepositoryPageBuilds(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="repositoryName">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 IObservable<PagesBuild> GetLatest(string owner, string repositoryName)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(repositoryName, "repositoryName");

return _client.GetLatest(owner, repositoryName).ToObservable();
}
}
}
4 changes: 3 additions & 1 deletion Octokit.Reactive/Octokit.Reactive-Mono.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@
<Compile Include="Clients\ObservableRepositoryContentsClient.cs" />
<Compile Include="Clients\IObservableMergingClient.cs" />
<Compile Include="Clients\ObservableMergingClient.cs" />
<Compile Include="Clients\IObservableRepositoryPagesClient.cs" />
<Compile Include="Clients\ObservableRepositoryPagesClient.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
Expand All @@ -165,4 +167,4 @@
<Name>Octokit-Mono</Name>
</ProjectReference>
</ItemGroup>
</Project>
</Project>
4 changes: 3 additions & 1 deletion Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@
<Compile Include="Clients\ObservableRepositoryContentsClient.cs" />
<Compile Include="Clients\IObservableMergingClient.cs" />
<Compile Include="Clients\ObservableMergingClient.cs" />
<Compile Include="Clients\IObservableRepositoryPagesClient.cs" />
<Compile Include="Clients\ObservableRepositoryPagesClient.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
<ItemGroup>
Expand All @@ -173,4 +175,4 @@
<Name>Octokit-MonoAndroid</Name>
</ProjectReference>
</ItemGroup>
</Project>
</Project>
4 changes: 3 additions & 1 deletion Octokit.Reactive/Octokit.Reactive-Monotouch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@
<Compile Include="Clients\ObservableRepositoryContentsClient.cs" />
<Compile Include="Clients\IObservableMergingClient.cs" />
<Compile Include="Clients\ObservableMergingClient.cs" />
<Compile Include="Clients\IObservableRepositoryPagesClient.cs" />
<Compile Include="Clients\ObservableRepositoryPagesClient.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
Expand All @@ -169,4 +171,4 @@
<Name>Octokit-Monotouch</Name>
</ProjectReference>
</ItemGroup>
</Project>
</Project>
2 changes: 2 additions & 0 deletions Octokit.Reactive/Octokit.Reactive.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
<Compile Include="Clients\IObservableOauthClient.cs" />
<Compile Include="Clients\IObservableRepositoryCommitsClients.cs" />
<Compile Include="Clients\IObservableRepositoryDeployKeysClient.cs" />
<Compile Include="Clients\IObservableRepositoryPagesClient.cs" />
<Compile Include="Clients\IObservableUserKeysClient.cs" />
<Compile Include="Clients\ObservableMergingClient.cs" />
<Compile Include="Clients\ObservableRepositoryDeployKeysClient.cs" />
Expand All @@ -102,6 +103,7 @@
<Compile Include="Clients\ObservableIssuesLabelsClient.cs" />
<Compile Include="Clients\ObservableRepositoryCommitsClients.cs" />
<Compile Include="Clients\ObservableRepositoryContentsClient.cs" />
<Compile Include="Clients\ObservableRepositoryPagesClient.cs" />
<Compile Include="Clients\ObservableSearchClient.cs" />
<Compile Include="Clients\IObservableBlobsClient.cs" />
<Compile Include="Clients\IObservableGistCommentsClient.cs" />
Expand Down
82 changes: 82 additions & 0 deletions Octokit.Tests/Clients/RepositoryPagesClientTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using NSubstitute;
using System;
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"), null);
}

[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));
}
}

public class TheGetBuildsMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoryPagesClient(connection);

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

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

[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));
}
}

public class TheGetLatestBuildMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoryPagesClient(connection);

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

connection.Received().Get<PagesBuild>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/pages/builds/latest"), null);
}

[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-NetCore45.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
<Compile Include="Clients\RepositoryForksClientTests.cs" />
<Compile Include="Clients\RepositoryHooksClientTest.cs" />
<Compile Include="Clients\RepositoryDeployKeysClientTests.cs" />
<Compile Include="Clients\RepositoryPagesClientTests.cs" />
<Compile Include="Clients\SshKeysClientTests.cs" />
<Compile Include="Clients\StarredClientTests.cs" />
<Compile Include="Clients\StatisticsClientTests.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 @@ -104,6 +104,7 @@
<Compile Include="Clients\RepositoryCommentsClientTests.cs" />
<Compile Include="Clients\RepositoryContentsClientTests.cs" />
<Compile Include="Clients\RepositoryDeployKeysClientTests.cs" />
<Compile Include="Clients\RepositoryPagesClientTests.cs" />
<Compile Include="Clients\SshKeysClientTests.cs" />
<Compile Include="Clients\StarredClientTests.cs" />
<Compile Include="Clients\StatisticsClientTests.cs" />
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 @@ -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; }
}
}
47 changes: 47 additions & 0 deletions Octokit/Clients/IRepositoryPagesClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
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 interface IRepositoryPagesClient
{
/// <summary>
/// Gets the page metadata for a given repository
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="repositoryName">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>
[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="repositoryName">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>> GetAll(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="repositoryName">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> GetLatest(string owner, string repositoryName);
}
}
Loading

0 comments on commit 0c4fff0

Please sign in to comment.