-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1061 from M-Zuber/IRepositoryPagesClient
Implement Repository Pages client
- Loading branch information
Showing
27 changed files
with
557 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
Octokit.Reactive/Clients/IObservableRepositoryPagesClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
Octokit.Reactive/Clients/ObservableRepositoryPagesClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.