Skip to content

Commit

Permalink
Merge pull request #794 from octokit/haagenson-gists
Browse files Browse the repository at this point in the history
last pieces of Gists API
  • Loading branch information
shiftkey committed May 8, 2015
2 parents 1fafe03 + 617e04d commit b3ba03f
Show file tree
Hide file tree
Showing 10 changed files with 211 additions and 2 deletions.
18 changes: 18 additions & 0 deletions Octokit.Reactive/Clients/IObservableGistsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,24 @@ public interface IObservableGistsClient
/// <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>
Expand Down
28 changes: 28 additions & 0 deletions Octokit.Reactive/Clients/ObservableGistsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,34 @@ public IObservable<Gist> GetAllForUser(string user, DateTimeOffset since)
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>
Expand Down
12 changes: 12 additions & 0 deletions Octokit.Tests.Integration/Clients/GistsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,16 @@ public async Task CanListGists()

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 changes: 38 additions & 0 deletions Octokit.Tests/Clients/GistsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,44 @@ public void RequestsCorrectGetGistsForAUserWithSinceUrl()
}
}

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]
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 @@ -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" />
Expand Down
57 changes: 57 additions & 0 deletions Octokit.Tests/Reactive/ObservableGistsTests.cs
Original file line number Diff line number Diff line change
@@ -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 changes: 28 additions & 0 deletions Octokit/Clients/GistsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,34 @@ public Task<IReadOnlyList<Gist>> GetAllForUser(string user, DateTimeOffset since
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>
Expand Down
18 changes: 18 additions & 0 deletions Octokit/Clients/IGistsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,24 @@ public interface IGistsClient
/// <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>
Expand Down
11 changes: 10 additions & 1 deletion Octokit/Helpers/ApiUrls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ public static Uri Gist(string id)
}

/// <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)
Expand Down Expand Up @@ -774,6 +774,15 @@ public static Uri GistComments(string 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>
/// Returns the <see cref="Uri"/> that returns the specified pull request.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion Octokit/Models/Response/GistChangeStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
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
Expand Down

0 comments on commit b3ba03f

Please sign in to comment.