Implement the Meta endpoint

See https://developer.github.com/v3/meta/ for more information about
this endpoint.
This commit is contained in:
Haacked
2015-09-12 16:14:13 -07:00
parent c6c332f5de
commit 7f901c47e8
13 changed files with 136 additions and 4 deletions
@@ -59,5 +59,12 @@ namespace Octokit.Reactive
[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();
}
}
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reactive.Linq;
using System.Reactive.Threading.Tasks;
@@ -80,10 +81,21 @@ namespace Octokit.Reactive
/// </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();
}
}
}
@@ -103,4 +103,17 @@ public class MiscellaneousClientTests
}
}
}
public class TheGetMetadataMethod
{
[IntegrationTest]
public async Task CanRetrieveMetadata()
{
var github = Helper.GetAnonymousClient();
var result = await github.Miscellaneous.GetMetadata();
Assert.True(result.VerifiablePasswordAuthentication);
}
}
}
-1
View File
@@ -1,7 +1,6 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Security.Policy;
namespace Octokit.Tests.Integration
{
+8
View File
@@ -67,5 +67,13 @@ namespace Octokit
/// <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();
}
}
+15 -1
View File
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading.Tasks;
#if NET_45
@@ -122,12 +123,25 @@ namespace Octokit
/// </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
View File
@@ -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,
IReadOnlyCollection<string> hooks,
IReadOnlyCollection<string> git,
IReadOnlyCollection<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 IReadOnlyCollection<string> Hooks { get; private set; }
/// <summary>
/// An Array of IP addresses in CIDR format specifying the Git servers for GitHub.com.
/// </summary>
public IReadOnlyCollection<string> Git { get; private set; }
/// <summary>
/// An Array of IP addresses in CIDR format specifying the A records for GitHub Pages.
/// </summary>
public IReadOnlyCollection<string> Pages { get; private set; }
internal string DebuggerDisplay
{
get
{
return String.Format(
CultureInfo.InvariantCulture,
"GitHubServicesSha: {0}, VerifiablePasswordAuthentication: {1} ",
GitHubServicesSha,
VerifiablePasswordAuthentication);
}
}
}
}
+1
View File
@@ -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
View File
@@ -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
View File
@@ -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" />
+1
View File
@@ -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">
+1
View File
@@ -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">
+1
View File
@@ -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" />