[WIP] Gists get Commits and Forks

- [ ] Finish Gists API Implementation
- [ ] [Add method to get gist
commits](https://developer.github.com/v3/gists/#list-gist-commits)
- [ ] [Add method to get gist
forks](https://developer.github.com/v3/gists/#list-gist-forks)

Fixes #328, Fixes #216

Added implementation for the remaining pieces of the Gists API.  The
others mentioned in #328 and #216 were completed through other PRs.
This commit is contained in:
Timothy Haagenson
2014-07-21 13:41:34 -05:00
parent 66677fdb3c
commit f172edef5b
9 changed files with 213 additions and 0 deletions

View File

@@ -91,6 +91,24 @@ namespace Octokit.Reactive
/// <param name="since">Only gists updated at or after this time are returned</param> /// <param name="since">Only gists updated at or after this time are returned</param>
IObservable<Gist> GetAllForUser(string user, DateTimeOffset since); 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> GetCommits(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> GetForks(string id);
/// <summary> /// <summary>
/// Creates a new gist /// Creates a new gist
/// </summary> /// </summary>

View File

@@ -180,6 +180,34 @@ namespace Octokit.Reactive
return _connection.GetAndFlattenAllPages<Gist>(ApiUrls.UsersGists(user), request.ToParametersDictionary()); 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> GetCommits(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> GetForks(string id)
{
Ensure.ArgumentNotNullOrEmptyString(id, "id");
return _connection.GetAndFlattenAllPages<GistFork>(ApiUrls.ForkGist(id));
}
/// <summary> /// <summary>
/// Edits a gist /// Edits a gist
/// </summary> /// </summary>

View File

@@ -126,4 +126,16 @@ public class GistsClientTests
await _fixture.Delete(createdGist.Id); await _fixture.Delete(createdGist.Id);
} }
[IntegrationTest]
public async Task CanGetGistChildren()
{
// Test History/Commits
var commits = await _fixture.GetCommits(testGistId);
Assert.NotNull(commits);
// Test Forks
var forks = await _fixture.GetForks(testGistId);
Assert.NotNull(forks);
}
} }

View File

@@ -124,6 +124,44 @@ public class GistsClientTests
} }
} }
public class TheGetChildrenMethods
{
[Fact]
public void EnsureNonNullArguments()
{
var connection = Substitute.For<IApiConnection>();
var client = new GistsClient(connection);
Assert.Throws<ArgumentNullException>(() => client.GetCommits(null));
Assert.Throws<ArgumentException>(() => client.GetCommits(""));
Assert.Throws<ArgumentNullException>(() => client.GetForks(null));
Assert.Throws<ArgumentException>(() => client.GetForks(""));
}
[Fact]
public void RequestsCorrectGetCommitsUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new GistsClient(connection);
client.GetCommits("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.GetForks("9257657");
connection.Received().GetAll<GistFork>(Arg.Is<Uri>(u => u.ToString() == "gists/9257657/forks"));
}
}
public class TheCreateMethod public class TheCreateMethod
{ {
[Fact] [Fact]

View File

@@ -162,6 +162,7 @@
<Compile Include="Reactive\ObservablePullRequestReviewCommentsClientTests.cs" /> <Compile Include="Reactive\ObservablePullRequestReviewCommentsClientTests.cs" />
<Compile Include="Reactive\ObservableRepositoriesClientTests.cs" /> <Compile Include="Reactive\ObservableRepositoriesClientTests.cs" />
<Compile Include="Reactive\ObservableRepositoryDeployKeysClientTests.cs" /> <Compile Include="Reactive\ObservableRepositoryDeployKeysClientTests.cs" />
<Compile Include="Reactive\ObservableGistsTests.cs" />
<Compile Include="Reactive\ObservableStarredClientTests.cs" /> <Compile Include="Reactive\ObservableStarredClientTests.cs" />
<Compile Include="Reactive\ObservableStatisticsClientTests.cs" /> <Compile Include="Reactive\ObservableStatisticsClientTests.cs" />
<Compile Include="Reactive\ObservableTreesClientTests.cs" /> <Compile Include="Reactive\ObservableTreesClientTests.cs" />

View File

@@ -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.GetCommits(null));
await AssertEx.Throws<ArgumentException>(async () => await client.GetCommits(""));
await AssertEx.Throws<ArgumentNullException>(async () => await client.GetForks(null));
await AssertEx.Throws<ArgumentException>(async () => await client.GetForks(""));
}
[Fact]
public void RequestsCorrectGetCommitsUrl()
{
var github = Substitute.For<IGitHubClient>();
var client = new ObservableGistsClient(github);
var expected = new Uri("gists/9257657/commits", UriKind.Relative);
client.GetCommits("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.GetForks("9257657");
github.Connection.Received(1).Get<List<GistFork>>(expected, Arg.Any<IDictionary<string, string>>(), null);
}
}
}
}

View File

@@ -196,6 +196,34 @@ namespace Octokit
return ApiConnection.GetAll<Gist>(ApiUrls.UsersGists(user), request.ToParametersDictionary()); 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>> GetCommits(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>> GetForks(string id)
{
Ensure.ArgumentNotNullOrEmptyString(id, "id");
return ApiConnection.GetAll<GistFork>(ApiUrls.ForkGist(id));
}
/// <summary> /// <summary>
/// Edits a gist /// Edits a gist
/// </summary> /// </summary>

View File

@@ -98,6 +98,24 @@ namespace Octokit
/// <param name="since">Only gists updated at or after this time are returned</param> /// <param name="since">Only gists updated at or after this time are returned</param>
Task<IReadOnlyList<Gist>> GetAllForUser(string user, DateTimeOffset since); 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>> GetCommits(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>> GetForks(string id);
/// <summary> /// <summary>
/// Creates a new gist /// Creates a new gist
/// </summary> /// </summary>

View File

@@ -646,6 +646,10 @@ namespace Octokit
return "gists/{0}".FormatUri(id); return "gists/{0}".FormatUri(id);
} }
/// <summary>
/// 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) public static Uri ForkGist(string id)
{ {
return "gists/{0}/forks".FormatUri(id); return "gists/{0}/forks".FormatUri(id);
@@ -680,6 +684,15 @@ namespace Octokit
return "gists/{0}/comments".FormatUri(gistId); 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> /// <summary>
/// Returns the <see cref="Uri"/> that returns the specified pull request. /// Returns the <see cref="Uri"/> that returns the specified pull request.
/// </summary> /// </summary>