Skip to content

Commit 074dce7

Browse files
committed
Merge pull request #225 from SimonCropp/master
Add gist get support
2 parents 30cd7ad + 0440888 commit 074dce7

19 files changed

+362
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.Linq;
3+
using System.Net.Http.Headers;
4+
using System.Threading.Tasks;
5+
using Xunit;
6+
7+
namespace Octokit.Tests.Integration
8+
{
9+
public class GistsClientTests
10+
{
11+
readonly IGitHubClient _gitHubClient;
12+
readonly IGistsClient _gistsClient;
13+
14+
public GistsClientTests()
15+
{
16+
this._gitHubClient = new GitHubClient(new ProductHeaderValue("OctokitTests"))
17+
{
18+
Credentials = Helper.Credentials
19+
};
20+
21+
this._gistsClient = this._gitHubClient.Gist;
22+
}
23+
24+
[IntegrationTest]
25+
public async Task CanGetGist()
26+
{
27+
var retrieved = await this._gistsClient.Get("6305249");
28+
Assert.NotNull(retrieved);
29+
}
30+
}
31+
}

Octokit.Tests.Integration/Octokit.Tests.Integration.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
<Compile Include="AssigneesClientTests.cs" />
6161
<Compile Include="CommitsClientTests.cs" />
6262
<Compile Include="CommitStatusClientTests.cs" />
63+
<Compile Include="GistsClientTests.cs" />
6364
<Compile Include="IssuesEventsClientTests.cs" />
6465
<Compile Include="MilestonesClientTests.cs" />
6566
<Compile Include="IntegrationTestAttribute.cs" />
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using NSubstitute;
3+
using Octokit;
4+
using Xunit;
5+
6+
public class GistsClientTests
7+
{
8+
public class TheGetMethod
9+
{
10+
[Fact]
11+
public void RequestsCorrectUrl()
12+
{
13+
var connection = Substitute.For<IApiConnection>();
14+
var client = new GistsClient(connection);
15+
16+
client.Get("1");
17+
18+
connection.Received().Get<Gist>(Arg.Is<Uri>(u => u.ToString() == "gists/1"), null);
19+
}
20+
}
21+
22+
public class TheCtor
23+
{
24+
[Fact]
25+
public void EnsuresArgument()
26+
{
27+
Assert.Throws<ArgumentNullException>(() => new GistsClient(null));
28+
}
29+
}
30+
}

Octokit.Tests/Octokit.Tests.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
</ItemGroup>
6363
<ItemGroup>
6464
<Compile Include="Authentication\CredentialsTests.cs" />
65+
<Compile Include="Clients\GistsClientTests.cs" />
6566
<Compile Include="Clients\BlobClientTests.cs" />
6667
<Compile Include="Clients\RepoCollaboratorsClientTests.cs" />
6768
<Compile Include="Clients\EventsClientTests.cs" />

Octokit/Clients/GistsClient.cs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.Threading.Tasks;
2+
3+
namespace Octokit
4+
{
5+
public class GistsClient : ApiClient, IGistsClient
6+
{
7+
public GistsClient(IApiConnection apiConnection) :
8+
base(apiConnection)
9+
{
10+
}
11+
12+
/// <summary>
13+
/// Gets a gist
14+
/// </summary>
15+
/// <remarks>
16+
/// http://developer.github.com/v3/gists/#get-a-single-gist
17+
/// </remarks>
18+
/// <param name="id">The id of the gist</param>
19+
public Task<Gist> Get(string id)
20+
{
21+
return ApiConnection.Get<Gist>(ApiUrls.Gist(id));
22+
}
23+
}
24+
}

Octokit/Clients/IGistsClient.cs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
using System.Threading.Tasks;
3+
4+
namespace Octokit
5+
{
6+
public interface IGistsClient
7+
{
8+
/// <summary>
9+
/// Gets a gist
10+
/// </summary>
11+
/// <remarks>
12+
/// http://developer.github.com/v3/gists/#get-a-single-gist
13+
/// </remarks>
14+
/// <param name="id">The id of the gist</param>
15+
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get",
16+
Justification = "Method makes a network request")]
17+
Task<Gist> Get(string id);
18+
}
19+
}

Octokit/GitHubClient.cs

+2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public GitHubClient(IConnection connection)
8787
Notification = new NotificationsClient(apiConnection);
8888
Organization = new OrganizationsClient(apiConnection);
8989
Repository = new RepositoriesClient(apiConnection);
90+
Gist = new GistsClient(apiConnection);
9091
Release = new ReleasesClient(apiConnection);
9192
User = new UsersClient(apiConnection);
9293
SshKey = new SshKeysClient(apiConnection);
@@ -135,6 +136,7 @@ public Uri BaseAddress
135136
public IMiscellaneousClient Miscellaneous { get; private set; }
136137
public IOrganizationsClient Organization { get; private set; }
137138
public IRepositoriesClient Repository { get; private set; }
139+
public IGistsClient Gist { get; private set; }
138140
public IReleasesClient Release { get; private set; }
139141
public ISshKeysClient SshKey { get; private set; }
140142
public IUsersClient User { get; private set; }

Octokit/Helpers/ApiUrls.cs

+9
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,15 @@ public static Uri Events()
448448
return "events".FormatUri();
449449
}
450450

451+
/// <summary>
452+
/// Returns the <see cref="Uri"/> for the specified commit.
453+
/// </summary>
454+
/// <param name="id">The id of the gist</param>
455+
public static Uri Gist(string id)
456+
{
457+
return "gists/{0}".FormatUri(id);
458+
}
459+
451460
/// <summary>
452461
/// Returns the <see cref="Uri"/> for the specified commit.
453462
/// </summary>

Octokit/IGitHubClient.cs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public interface IGitHubClient
1313
IMiscellaneousClient Miscellaneous { get; }
1414
IOrganizationsClient Organization { get; }
1515
IRepositoriesClient Repository { get; }
16+
IGistsClient Gist { get; }
1617
IReleasesClient Release { get; }
1718
ISshKeysClient SshKey { get; }
1819
IUsersClient User { get; }

Octokit/Models/Response/Gist.cs

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics.CodeAnalysis;
4+
5+
namespace Octokit
6+
{
7+
public class Gist
8+
{
9+
/// <summary>
10+
/// The API URL for this <see cref="Gist"/>.
11+
/// </summary>
12+
public string Url { get; set; }
13+
14+
/// <summary>
15+
/// The Id of this <see cref="Gist"/>.
16+
/// </summary>
17+
/// <remarks>
18+
/// Given a gist url of https://gist.github.com/UserName/1234 the Id would be '1234'.
19+
/// </remarks>
20+
public string Id { get; set; }
21+
22+
/// <summary>
23+
/// A description of the <see cref="Gist"/>.
24+
/// </summary>
25+
public string Description { get; set; }
26+
27+
/// <summary>
28+
/// Indicates if the <see cref="Gist"/> is private or public.
29+
/// </summary>
30+
public bool Public { get; set; }
31+
32+
/// <summary>
33+
/// The <see cref="User"/> who owns this <see cref="Gist"/>.
34+
/// </summary>
35+
/// <remarks>
36+
/// Given a gist url of https://gist.github.com/UserName/1234 the Owner would be 'UserName'.
37+
/// </remarks>
38+
public User Owner { get; set; }
39+
40+
/// <summary>
41+
/// A <see cref="IDictionary{TKey,TValue}"/> containing all <see cref="GistFile"/>s in this <see cref="Gist"/>.
42+
/// </summary>
43+
[SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
44+
public IDictionary<string, GistFile> Files { get; set; }
45+
46+
/// <summary>
47+
/// The number of comments on this <see cref="Gist"/>.
48+
/// </summary>
49+
public int Comments { get; set; }
50+
51+
/// <summary>
52+
/// A url to retrieve the comments for this <see cref="Gist"/>.
53+
/// </summary>
54+
public string CommentsUrl { get; set; }
55+
56+
public string HtmlUrl { get; set; }
57+
58+
/// <summary>
59+
/// The git url to pull from to retrieve the contents for this <see cref="Gist"/>.
60+
/// </summary>
61+
public string GitPullUrl { get; set; }
62+
63+
/// <summary>
64+
/// The git url to push to when changing this <see cref="Gist"/>.
65+
/// </summary>
66+
public string GitPushUrl { get; set; }
67+
68+
/// <summary>
69+
/// The <see cref="DateTimeOffset"/> for when this <see cref="Gist"/> was created.
70+
/// </summary>
71+
public DateTimeOffset CreatedAt { get; set; }
72+
73+
/// <summary>
74+
/// The <see cref="DateTimeOffset"/> for when this <see cref="Gist"/> was last updated.
75+
/// </summary>
76+
public DateTimeOffset UpdatedAt { get; set; }
77+
78+
/// <summary>
79+
/// A <see cref="IList{T}"/> of all <see cref="GistFork"/> that exist for this <see cref="Gist"/>.
80+
/// </summary>
81+
[SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
82+
public IList<GistFork> Forks { get; set; }
83+
84+
/// <summary>
85+
/// A <see cref="IList{T}"/> of all <see cref="GistHistory"/> containing the full history for this <see cref="Gist"/>.
86+
/// </summary>
87+
[SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
88+
public IList<GistHistory> History { get; set; }
89+
}
90+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace Octokit
2+
{
3+
/// <summary>
4+
/// User by <see cref="GistHistory"/> to indicate the level of change.
5+
/// </summary>
6+
public class GistChangeStatus
7+
{
8+
/// <summary>
9+
/// The number of deletions that occurred as part of this change.
10+
/// </summary>
11+
public int Deletions { get; set; }
12+
13+
/// <summary>
14+
/// The number of additions that occurred as part of this change.
15+
/// </summary>
16+
public int Additions { get; set; }
17+
18+
/// <summary>
19+
/// The total number of changes.
20+
/// </summary>
21+
public int Total { get; set; }
22+
}
23+
}

Octokit/Models/Response/GistFile.cs

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using System.Diagnostics.CodeAnalysis;
2+
3+
namespace Octokit
4+
{
5+
public class GistFile
6+
{
7+
/// <summary>
8+
/// The size in bytes of the file.
9+
/// </summary>
10+
public int Size { get; set; }
11+
12+
/// <summary>
13+
/// The name of the file
14+
/// </summary>
15+
[SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly")]
16+
public string Filename { get; set; }
17+
18+
/// <summary>
19+
/// The mime type of the file
20+
/// </summary>
21+
[SuppressMessage("Microsoft.Naming", "CA1721:PropertyNamesShouldNotMatchGetMethods")]
22+
public string Type { get; set; }
23+
24+
/// <summary>
25+
/// The programming language of the file, if any.
26+
/// </summary>
27+
public string Language { get; set; }
28+
29+
/// <summary>
30+
/// The text content of the file.
31+
/// </summary>
32+
public string Content { get; set; }
33+
34+
/// <summary>
35+
/// The url to download the file.
36+
/// </summary>
37+
public string RawUrl { get; set; }
38+
}
39+
}

Octokit/Models/Response/GistFork.cs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
3+
namespace Octokit
4+
{
5+
public class GistFork
6+
{
7+
/// <summary>
8+
/// The <see cref="User"/> that created this <see cref="GistFork"/>
9+
/// </summary>
10+
public User User { get; set; }
11+
12+
/// <summary>
13+
/// The API URL for this <see cref="GistFork"/>.
14+
/// </summary>
15+
public string Url { get; set; }
16+
17+
/// <summary>
18+
/// The <see cref="DateTimeOffset"/> for when this <see cref="Gist"/> was created.
19+
/// </summary>
20+
public DateTimeOffset CreatedAt { get; set; }
21+
}
22+
}
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
3+
namespace Octokit
4+
{
5+
/// <summary>
6+
/// A historical version of a <see cref="Gist"/>
7+
/// </summary>
8+
public class GistHistory
9+
{
10+
/// <summary>
11+
/// The url that can be used by the API to retrieve this version of the <see cref="Gist"/>.
12+
/// </summary>
13+
public string Url { get; set; }
14+
15+
/// <summary>
16+
/// A git sha representing the version.
17+
/// </summary>
18+
public string Version { get; set; }
19+
20+
/// <summary>
21+
/// The <see cref="User"/> who create this version.
22+
/// </summary>
23+
public User User { get; set; }
24+
25+
/// <summary>
26+
/// A <see cref="GistHistory"/> that represents the level of change for this <see cref="GistHistory"/>.
27+
/// </summary>
28+
public GistChangeStatus ChangeStatus { get; set; }
29+
30+
/// <summary>
31+
/// The <see cref="DateTimeOffset"/> the version was created.
32+
/// </summary>
33+
public DateTimeOffset CommittedAt { get; set; }
34+
}
35+
}

0 commit comments

Comments
 (0)