Merge pull request #794 from octokit/haagenson-gists

last pieces of Gists API
This commit is contained in:
Brendan Forster
2015-05-08 17:04:29 +09:30
10 changed files with 211 additions and 2 deletions
@@ -91,6 +91,24 @@ namespace Octokit.Reactive
/// <param name="since">Only gists updated at or after this time are returned</param>
IObservable<Gist> GetAllForUser(string user, DateTimeOffset since);
/// <summary>
/// List gist commits
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/gists/#list-gists-commits
/// </remarks>
/// <param name="id">The id of the gist</param>
IObservable<GistHistory> GetAllCommits(string id);
/// <summary>
/// List gist forks
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/gists/#list-gists-forks
/// </remarks>
/// <param name="id">The id of the gist</param>
IObservable<GistFork> GetAllForks(string id);
/// <summary>
/// Creates a new gist
/// </summary>
@@ -180,6 +180,34 @@ namespace Octokit.Reactive
return _connection.GetAndFlattenAllPages<Gist>(ApiUrls.UsersGists(user), request.ToParametersDictionary());
}
/// <summary>
/// List gist commits
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/gists/#list-gists-commits
/// </remarks>
/// <param name="id">The id of the gist</param>
public IObservable<GistHistory> GetAllCommits(string id)
{
Ensure.ArgumentNotNullOrEmptyString(id, "id");
return _connection.GetAndFlattenAllPages<GistHistory>(ApiUrls.GistCommits(id));
}
/// <summary>
/// List gist forks
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/gists/#list-gists-forks
/// </remarks>
/// <param name="id">The id of the gist</param>
public IObservable<GistFork> GetAllForks(string id)
{
Ensure.ArgumentNotNullOrEmptyString(id, "id");
return _connection.GetAndFlattenAllPages<GistFork>(ApiUrls.ForkGist(id));
}
/// <summary>
/// Edits a gist
/// </summary>
@@ -117,4 +117,16 @@ public class GistsClientTests
await _fixture.Delete(createdGist.Id);
}
[IntegrationTest]
public async Task CanGetGistChildren()
{
// Test History/Commits
var commits = await _fixture.GetAllCommits(testGistId);
Assert.NotEmpty(commits);
// Test Forks
var forks = await _fixture.GetAllForks(testGistId);
Assert.NotEmpty(forks);
}
}
+38
View File
@@ -122,6 +122,44 @@ public class GistsClientTests
}
}
public class TheGetChildrenMethods
{
[Fact]
public async Task EnsureNonNullArguments()
{
var connection = Substitute.For<IApiConnection>();
var client = new GistsClient(connection);
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllCommits(null));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllCommits(""));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForks(null));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForks(""));
}
[Fact]
public void RequestsCorrectGetCommitsUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new GistsClient(connection);
client.GetAllCommits("9257657");
connection.Received().GetAll<GistHistory>(Arg.Is<Uri>(u => u.ToString() == "gists/9257657/commits"));
}
[Fact]
public void RequestsCorrectGetForksUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new GistsClient(connection);
client.GetAllForks("9257657");
connection.Received().GetAll<GistFork>(Arg.Is<Uri>(u => u.ToString() == "gists/9257657/forks"));
}
}
public class TheCreateMethod
{
[Fact]
+1
View File
@@ -179,6 +179,7 @@
<Compile Include="Reactive\ObservablePullRequestReviewCommentsClientTests.cs" />
<Compile Include="Reactive\ObservableRepositoriesClientTests.cs" />
<Compile Include="Reactive\ObservableRepositoryDeployKeysClientTests.cs" />
<Compile Include="Reactive\ObservableGistsTests.cs" />
<Compile Include="Reactive\ObservableStarredClientTests.cs" />
<Compile Include="Reactive\ObservableStatisticsClientTests.cs" />
<Compile Include="Reactive\ObservableTreesClientTests.cs" />
@@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Reactive.Linq;
using System.Threading.Tasks;
using NSubstitute;
using Octokit;
using Octokit.Internal;
using Octokit.Reactive;
using Octokit.Reactive.Internal;
using Octokit.Tests.Helpers;
using Xunit;
using Xunit.Extensions;
namespace Octokit.Tests.Reactive
{
public class ObservableGistsTests
{
public class TheGetChildrenMethods
{
[Fact]
public async Task EnsureNonNullArguments()
{
var client = new ObservableGistsClient(Substitute.For<IGitHubClient>());
await AssertEx.Throws<ArgumentNullException>(async () => await client.GetAllCommits(null));
await AssertEx.Throws<ArgumentException>(async () => await client.GetAllCommits(""));
await AssertEx.Throws<ArgumentNullException>(async () => await client.GetAllForks(null));
await AssertEx.Throws<ArgumentException>(async () => await client.GetAllForks(""));
}
[Fact]
public void RequestsCorrectGetCommitsUrl()
{
var github = Substitute.For<IGitHubClient>();
var client = new ObservableGistsClient(github);
var expected = new Uri("gists/9257657/commits", UriKind.Relative);
client.GetAllCommits("9257657");
github.Connection.Received(1).Get<List<GistHistory>>(expected, Arg.Any<IDictionary<string, string>>(), null);
}
[Fact]
public void RequestsCorrectGetForksUrl()
{
var github = Substitute.For<IGitHubClient>();
var client = new ObservableGistsClient(github);
var expected = new Uri("gists/9257657/forks", UriKind.Relative);
client.GetAllForks("9257657");
github.Connection.Received(1).Get<List<GistFork>>(expected, Arg.Any<IDictionary<string, string>>(), null);
}
}
}
}
+28
View File
@@ -196,6 +196,34 @@ namespace Octokit
return ApiConnection.GetAll<Gist>(ApiUrls.UsersGists(user), request.ToParametersDictionary());
}
/// <summary>
/// List gist commits
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/gists/#list-gists-commits
/// </remarks>
/// <param name="id">The id of the gist</param>
public Task<IReadOnlyList<GistHistory>> GetAllCommits(string id)
{
Ensure.ArgumentNotNullOrEmptyString(id, "id");
return ApiConnection.GetAll<GistHistory>(ApiUrls.GistCommits(id));
}
/// <summary>
/// List gist forks
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/gists/#list-gists-forks
/// </remarks>
/// <param name="id">The id of the gist</param>
public Task<IReadOnlyList<GistFork>> GetAllForks(string id)
{
Ensure.ArgumentNotNullOrEmptyString(id, "id");
return ApiConnection.GetAll<GistFork>(ApiUrls.ForkGist(id));
}
/// <summary>
/// Edits a gist
/// </summary>
+18
View File
@@ -98,6 +98,24 @@ namespace Octokit
/// <param name="since">Only gists updated at or after this time are returned</param>
Task<IReadOnlyList<Gist>> GetAllForUser(string user, DateTimeOffset since);
/// <summary>
/// List gist commits
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/gists/#list-gists-commits
/// </remarks>
/// <param name="id">The id of the gist</param>
Task<IReadOnlyList<GistHistory>> GetAllCommits(string id);
/// <summary>
/// List gist forks
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/gists/#list-gists-forks
/// </remarks>
/// <param name="id">The id of the gist</param>
Task<IReadOnlyList<GistFork>> GetAllForks(string id);
/// <summary>
/// Creates a new gist
/// </summary>
+10 -1
View File
@@ -723,7 +723,7 @@ namespace Octokit
}
/// <summary>
/// Returns the <see cref="Uri"/> for the forks of a given gist.
/// Returns the <see cref="Uri"/> for the forks for the specified gist.
/// </summary>
/// <param name="id">The id of the gist</param>
public static Uri ForkGist(string id)
@@ -774,6 +774,15 @@ namespace Octokit
return "gists/{0}/comments".FormatUri(gistId);
}
/// <summary>
/// Returns the <see cref="Uri"/> for the commits for the specified gist.
/// </summary>
/// <param name="id">The id of the gist</param>
public static Uri GistCommits(string id)
{
return "gists/{0}/commits".FormatUri(id);
}
/// <summary>
/// Returns the <see cref="Uri"/> that returns the specified pull request.
/// </summary>
+1 -1
View File
@@ -5,7 +5,7 @@ using System.Globalization;
namespace Octokit
{
/// <summary>
/// User by <see cref="GistHistory"/> to indicate the level of change.
/// Used by <see cref="GistHistory"/> to indicate the level of change.
/// </summary>
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class GistChangeStatus