Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gist get support #225

Merged
merged 8 commits into from
Nov 21, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions Octokit.Tests.Integration/GistsClientTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Linq;
using System.Net.Http.Headers;
using System.Threading.Tasks;
using Xunit;

namespace Octokit.Tests.Integration
{
public class GistsClientTests
{
readonly IGitHubClient _gitHubClient;
readonly IGistsClient _gistsClient;

public GistsClientTests()
{
this._gitHubClient = new GitHubClient(new ProductHeaderValue("OctokitTests"))
{
Credentials = Helper.Credentials
};

this._gistsClient = this._gitHubClient.Gist;
}

[IntegrationTest]
public async Task CanGetGist()
{
var retrieved = await this._gistsClient.Get("6305249");
Assert.NotNull(retrieved);
}
}
}
1 change: 1 addition & 0 deletions Octokit.Tests.Integration/Octokit.Tests.Integration.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<Compile Include="AssigneesClientTests.cs" />
<Compile Include="CommitsClientTests.cs" />
<Compile Include="CommitStatusClientTests.cs" />
<Compile Include="GistsClientTests.cs" />
<Compile Include="IssuesEventsClientTests.cs" />
<Compile Include="MilestonesClientTests.cs" />
<Compile Include="IntegrationTestAttribute.cs" />
Expand Down
30 changes: 30 additions & 0 deletions Octokit.Tests/Clients/GistsClientTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using NSubstitute;
using Octokit;
using Xunit;

public class GistsClientTests
{
public class TheGetMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new GistsClient(connection);

client.Get("1");

connection.Received().Get<Gist>(Arg.Is<Uri>(u => u.ToString() == "gists/1"), null);
}
}

public class TheCtor
{
[Fact]
public void EnsuresArgument()
{
Assert.Throws<ArgumentNullException>(() => new GistsClient(null));
}
}
}
1 change: 1 addition & 0 deletions Octokit.Tests/Octokit.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Authentication\CredentialsTests.cs" />
<Compile Include="Clients\GistsClientTests.cs" />
<Compile Include="Clients\BlobClientTests.cs" />
<Compile Include="Clients\RepoCollaboratorsClientTests.cs" />
<Compile Include="Clients\EventsClientTests.cs" />
Expand Down
24 changes: 24 additions & 0 deletions Octokit/Clients/GistsClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Threading.Tasks;

namespace Octokit
{
public class GistsClient : ApiClient, IGistsClient
{
public GistsClient(IApiConnection apiConnection) :
base(apiConnection)
{
}

/// <summary>
/// Gets a gist
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/gists/#get-a-single-gist
/// </remarks>
/// <param name="id">The id of the gist</param>
public Task<Gist> Get(string id)
{
return ApiConnection.Get<Gist>(ApiUrls.Gist(id));
}
}
}
19 changes: 19 additions & 0 deletions Octokit/Clients/IGistsClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;

namespace Octokit
{
public interface IGistsClient
{
/// <summary>
/// Gets a gist
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/gists/#get-a-single-gist
/// </remarks>
/// <param name="id">The id of the gist</param>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get",
Justification = "Method makes a network request")]
Task<Gist> Get(string id);
}
}
2 changes: 2 additions & 0 deletions Octokit/GitHubClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public GitHubClient(IConnection connection)
Notification = new NotificationsClient(apiConnection);
Organization = new OrganizationsClient(apiConnection);
Repository = new RepositoriesClient(apiConnection);
Gist = new GistsClient(apiConnection);
Release = new ReleasesClient(apiConnection);
User = new UsersClient(apiConnection);
SshKey = new SshKeysClient(apiConnection);
Expand Down Expand Up @@ -135,6 +136,7 @@ public Uri BaseAddress
public IMiscellaneousClient Miscellaneous { get; private set; }
public IOrganizationsClient Organization { get; private set; }
public IRepositoriesClient Repository { get; private set; }
public IGistsClient Gist { get; private set; }
public IReleasesClient Release { get; private set; }
public ISshKeysClient SshKey { get; private set; }
public IUsersClient User { get; private set; }
Expand Down
9 changes: 9 additions & 0 deletions Octokit/Helpers/ApiUrls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,15 @@ public static Uri Events()
return "events".FormatUri();
}

/// <summary>
/// Returns the <see cref="Uri"/> for the specified commit.
/// </summary>
/// <param name="id">The id of the gist</param>
public static Uri Gist(string id)
{
return "gists/{0}".FormatUri(id);
}

/// <summary>
/// Returns the <see cref="Uri"/> for the specified commit.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions Octokit/IGitHubClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public interface IGitHubClient
IMiscellaneousClient Miscellaneous { get; }
IOrganizationsClient Organization { get; }
IRepositoriesClient Repository { get; }
IGistsClient Gist { get; }
IReleasesClient Release { get; }
ISshKeysClient SshKey { get; }
IUsersClient User { get; }
Expand Down
90 changes: 90 additions & 0 deletions Octokit/Models/Response/Gist.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

namespace Octokit
{
public class Gist
{
/// <summary>
/// The API URL for this <see cref="Gist"/>.
/// </summary>
public string Url { get; set; }

/// <summary>
/// The Id of this <see cref="Gist"/>.
/// </summary>
/// <remarks>
/// Given a gist url of https://gist.github.com/UserName/1234 the Id would be '1234'.
/// </remarks>
public string Id { get; set; }

/// <summary>
/// A description of the <see cref="Gist"/>.
/// </summary>
public string Description { get; set; }

/// <summary>
/// Indicates if the <see cref="Gist"/> is private or public.
/// </summary>
public bool Public { get; set; }

/// <summary>
/// The <see cref="User"/> who owns this <see cref="Gist"/>.
/// </summary>
/// <remarks>
/// Given a gist url of https://gist.github.com/UserName/1234 the Owner would be 'UserName'.
/// </remarks>
public User Owner { get; set; }

/// <summary>
/// A <see cref="IDictionary{TKey,TValue}"/> containing all <see cref="GistFile"/>s in this <see cref="Gist"/>.
/// </summary>
[SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public IDictionary<string, GistFile> Files { get; set; }

/// <summary>
/// The number of comments on this <see cref="Gist"/>.
/// </summary>
public int Comments { get; set; }

/// <summary>
/// A url to retrieve the comments for this <see cref="Gist"/>.
/// </summary>
public string CommentsUrl { get; set; }

public string HtmlUrl { get; set; }

/// <summary>
/// The git url to pull from to retrieve the contents for this <see cref="Gist"/>.
/// </summary>
public string GitPullUrl { get; set; }

/// <summary>
/// The git url to push to when changing this <see cref="Gist"/>.
/// </summary>
public string GitPushUrl { get; set; }

/// <summary>
/// The <see cref="DateTimeOffset"/> for when this <see cref="Gist"/> was created.
/// </summary>
public DateTimeOffset CreatedAt { get; set; }

/// <summary>
/// The <see cref="DateTimeOffset"/> for when this <see cref="Gist"/> was last updated.
/// </summary>
public DateTimeOffset UpdatedAt { get; set; }

/// <summary>
/// A <see cref="IList{T}"/> of all <see cref="GistFork"/> that exist for this <see cref="Gist"/>.
/// </summary>
[SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public IList<GistFork> Forks { get; set; }

/// <summary>
/// A <see cref="IList{T}"/> of all <see cref="GistHistory"/> containing the full history for this <see cref="Gist"/>.
/// </summary>
[SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public IList<GistHistory> History { get; set; }
}
}
23 changes: 23 additions & 0 deletions Octokit/Models/Response/GistChangeStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace Octokit
{
/// <summary>
/// User by <see cref="GistHistory"/> to indicate the level of change.
/// </summary>
public class GistChangeStatus
{
/// <summary>
/// The number of deletions that occurred as part of this change.
/// </summary>
public int Deletions { get; set; }

/// <summary>
/// The number of additions that occurred as part of this change.
/// </summary>
public int Additions { get; set; }

/// <summary>
/// The total number of changes.
/// </summary>
public int Total { get; set; }
}
}
39 changes: 39 additions & 0 deletions Octokit/Models/Response/GistFile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System.Diagnostics.CodeAnalysis;

namespace Octokit
{
public class GistFile
{
/// <summary>
/// The size in bytes of the file.
/// </summary>
public int Size { get; set; }

/// <summary>
/// The name of the file
/// </summary>
[SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly")]
public string Filename { get; set; }

/// <summary>
/// The mime type of the file
/// </summary>
[SuppressMessage("Microsoft.Naming", "CA1721:PropertyNamesShouldNotMatchGetMethods")]
public string Type { get; set; }

/// <summary>
/// The programming language of the file, if any.
/// </summary>
public string Language { get; set; }

/// <summary>
/// The text content of the file.
/// </summary>
public string Content { get; set; }

/// <summary>
/// The url to download the file.
/// </summary>
public string RawUrl { get; set; }
}
}
22 changes: 22 additions & 0 deletions Octokit/Models/Response/GistFork.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;

namespace Octokit
{
public class GistFork
{
/// <summary>
/// The <see cref="User"/> that created this <see cref="GistFork"/>
/// </summary>
public User User { get; set; }

/// <summary>
/// The API URL for this <see cref="GistFork"/>.
/// </summary>
public string Url { get; set; }

/// <summary>
/// The <see cref="DateTimeOffset"/> for when this <see cref="Gist"/> was created.
/// </summary>
public DateTimeOffset CreatedAt { get; set; }
}
}
35 changes: 35 additions & 0 deletions Octokit/Models/Response/GistHistory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using System;

namespace Octokit
{
/// <summary>
/// A historical version of a <see cref="Gist"/>
/// </summary>
public class GistHistory
{
/// <summary>
/// The url that can be used by the API to retrieve this version of the <see cref="Gist"/>.
/// </summary>
public string Url { get; set; }

/// <summary>
/// A git sha representing the version.
/// </summary>
public string Version { get; set; }

/// <summary>
/// The <see cref="User"/> who create this version.
/// </summary>
public User User { get; set; }

/// <summary>
/// A <see cref="GistHistory"/> that represents the level of change for this <see cref="GistHistory"/>.
/// </summary>
public GistChangeStatus ChangeStatus { get; set; }

/// <summary>
/// The <see cref="DateTimeOffset"/> the version was created.
/// </summary>
public DateTimeOffset CommittedAt { get; set; }
}
}
Loading