Skip to content

Commit

Permalink
Merge pull request #892 from octokit/haacked/meta-endpoint
Browse files Browse the repository at this point in the history
Implement the Meta endpoint
  • Loading branch information
haacked committed Sep 17, 2015
2 parents 32c154f + a3ad7c9 commit 0925580
Show file tree
Hide file tree
Showing 13 changed files with 136 additions and 4 deletions.
7 changes: 7 additions & 0 deletions Octokit.Reactive/Clients/IObservableMiscellaneousClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,12 @@ public interface IObservableMiscellaneousClient
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
IObservable<MiscellaneousRateLimit> GetRateLimits();

/// <summary>
/// Retrieves information about GitHub.com, the service or a GitHub Enterprise installation.
/// </summary>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>An <see cref="Meta"/> containing metadata about the GitHub instance.</returns>
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
IObservable<Meta> GetMetadata();
}
}
14 changes: 13 additions & 1 deletion Octokit.Reactive/Clients/ObservableMiscellaneousClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reactive.Linq;
using System.Reactive.Threading.Tasks;

Expand Down Expand Up @@ -80,10 +81,21 @@ public IObservable<License> GetLicense(string key)
/// </summary>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>An <see cref="MiscellaneousRateLimit"/> of Rate Limits.</returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
public IObservable<MiscellaneousRateLimit> GetRateLimits()
{
return _client.GetRateLimits().ToObservable();
}

/// <summary>
/// Retrieves information about GitHub.com, the service or a GitHub Enterprise installation.
/// </summary>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>An <see cref="Meta"/> containing metadata about the GitHub instance.</returns>
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
public IObservable<Meta> GetMetadata()
{
return _client.GetMetadata().ToObservable();
}
}
}
15 changes: 14 additions & 1 deletion Octokit.Tests.Integration/Clients/MiscellaneousClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,17 @@ public async Task CanRetrieveResourceRateLimits()

}
}
}

public class TheGetMetadataMethod
{
[IntegrationTest]
public async Task CanRetrieveMetadata()
{
var github = Helper.GetAnonymousClient();

var result = await github.Miscellaneous.GetMetadata();

Assert.True(result.VerifiablePasswordAuthentication);
}
}
}
1 change: 0 additions & 1 deletion Octokit.Tests.Integration/Helper.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Security.Policy;

namespace Octokit.Tests.Integration
{
Expand Down
8 changes: 8 additions & 0 deletions Octokit/Clients/IMiscellaneousClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,13 @@ public interface IMiscellaneousClient
/// <returns>An <see cref="MiscellaneousRateLimit"/> of Rate Limits.</returns>
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
Task<MiscellaneousRateLimit> GetRateLimits();

/// <summary>
/// Retrieves information about GitHub.com, the service or a GitHub Enterprise installation.
/// </summary>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>An <see cref="Meta"/> containing metadata about the GitHub instance.</returns>
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
Task<Meta> GetMetadata();
}
}
16 changes: 15 additions & 1 deletion Octokit/Clients/MiscellaneousClient.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading.Tasks;
#if NET_45
Expand Down Expand Up @@ -122,12 +123,25 @@ public async Task<License> GetLicense(string key)
/// </summary>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>An <see cref="MiscellaneousRateLimit"/> of Rate Limits.</returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
public async Task<MiscellaneousRateLimit> GetRateLimits()
{
var endpoint = new Uri("rate_limit", UriKind.Relative);
var response = await _connection.Get<MiscellaneousRateLimit>(endpoint, null, null).ConfigureAwait(false);
return response.Body;
}

/// <summary>
/// Retrieves information about GitHub.com, the service or a GitHub Enterprise installation.
/// </summary>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>An <see cref="Meta"/> containing metadata about the GitHub instance.</returns>
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
public async Task<Meta> GetMetadata()
{
var endpoint = new Uri("meta", UriKind.Relative);
var response = await _connection.Get<Meta>(endpoint, null, null).ConfigureAwait(false);
return response.Body;
}
}
}
73 changes: 73 additions & 0 deletions Octokit/Models/Response/Meta.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;

namespace Octokit
{
/// <summary>
/// Response from the /meta endpoint that provides information about GitHub.com or a GitHub Enterprise instance.
/// </summary>
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class Meta
{
public Meta()
{
}

public Meta(
bool verifiablePasswordAuthentication,
string gitHubServicesSha,
IReadOnlyList<string> hooks,
IReadOnlyList<string> git,
IReadOnlyList<string> pages)
{
VerifiablePasswordAuthentication = verifiablePasswordAuthentication;
GitHubServicesSha = gitHubServicesSha;
Hooks = hooks;
Git = git;
Pages = pages;
}

/// <summary>
/// Whether authentication with username and password is supported. (GitHub Enterprise instances using CAS or
/// OAuth for authentication will return false. Features like Basic Authentication with a username and
/// password, sudo mode, and two-factor authentication are not supported on these servers.)
/// </summary>
public bool VerifiablePasswordAuthentication { get; private set; }

/// <summary>
/// The currently-deployed SHA of github-services.
/// </summary>
public string GitHubServicesSha { get; private set; }

/// <summary>
/// An Array of IP addresses in CIDR format specifying the addresses that incoming service hooks will
/// originate from on GitHub.com. Subscribe to the API Changes blog or follow @GitHubAPI on Twitter to get
/// updated when this list changes.
/// </summary>
public IReadOnlyList<string> Hooks { get; private set; }

/// <summary>
/// An Array of IP addresses in CIDR format specifying the Git servers for GitHub.com.
/// </summary>
public IReadOnlyList<string> Git { get; private set; }

/// <summary>
/// An Array of IP addresses in CIDR format specifying the A records for GitHub Pages.
/// </summary>
public IReadOnlyList<string> Pages { get; private set; }

internal string DebuggerDisplay
{
get
{
return String.Format(
CultureInfo.InvariantCulture,
"GitHubServicesSha: {0}, VerifiablePasswordAuthentication: {1} ",
GitHubServicesSha,
VerifiablePasswordAuthentication);
}
}
}
}
1 change: 1 addition & 0 deletions Octokit/Octokit-Mono.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@
<Compile Include="Exceptions\RepositoryFormatException.cs" />
<Compile Include="Http\RequestBody.cs" />
<Compile Include="Http\IApiInfoProvider.cs" />
<Compile Include="Models\Response\Meta.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
1 change: 1 addition & 0 deletions Octokit/Octokit-MonoAndroid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@
<Compile Include="Exceptions\RepositoryFormatException.cs" />
<Compile Include="Http\RequestBody.cs" />
<Compile Include="Http\IApiInfoProvider.cs" />
<Compile Include="Models\Response\Meta.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
</Project>
1 change: 1 addition & 0 deletions Octokit/Octokit-Monotouch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@
<Compile Include="Exceptions\RepositoryFormatException.cs" />
<Compile Include="Http\RequestBody.cs" />
<Compile Include="Http\IApiInfoProvider.cs" />
<Compile Include="Models\Response\Meta.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.MonoTouch.CSharp.targets" />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
Expand Down
1 change: 1 addition & 0 deletions Octokit/Octokit-Portable.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@
<Compile Include="Exceptions\RepositoryFormatException.cs" />
<Compile Include="Http\RequestBody.cs" />
<Compile Include="Http\IApiInfoProvider.cs" />
<Compile Include="Models\Response\Meta.cs" />
</ItemGroup>
<ItemGroup>
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">
Expand Down
1 change: 1 addition & 0 deletions Octokit/Octokit-netcore45.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@
<Compile Include="Exceptions\RepositoryFormatException.cs" />
<Compile Include="Http\RequestBody.cs" />
<Compile Include="Http\IApiInfoProvider.cs" />
<Compile Include="Models\Response\Meta.cs" />
</ItemGroup>
<ItemGroup>
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">
Expand Down
1 change: 1 addition & 0 deletions Octokit/Octokit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
<Compile Include="Models\Response\ContentType.cs" />
<Compile Include="Models\Response\ApplicationAuthorization.cs" />
<Compile Include="Models\Response\GitHubCommitFile.cs" />
<Compile Include="Models\Response\Meta.cs" />
<Compile Include="Models\Response\MiscellaneousRateLimit.cs" />
<Compile Include="Models\Response\PublicKey.cs" />
<Compile Include="Models\Response\PullRequestFile.cs" />
Expand Down

0 comments on commit 0925580

Please sign in to comment.