diff --git a/Octokit.Reactive/Clients/IObservableMiscellaneousClient.cs b/Octokit.Reactive/Clients/IObservableMiscellaneousClient.cs index 792fd294ac..87a9382f3f 100644 --- a/Octokit.Reactive/Clients/IObservableMiscellaneousClient.cs +++ b/Octokit.Reactive/Clients/IObservableMiscellaneousClient.cs @@ -59,5 +59,12 @@ public interface IObservableMiscellaneousClient [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] IObservable GetRateLimits(); + /// + /// Retrieves information about GitHub.com, the service or a GitHub Enterprise installation. + /// + /// Thrown when a general API error occurs. + /// An containing metadata about the GitHub instance. + [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] + IObservable GetMetadata(); } } diff --git a/Octokit.Reactive/Clients/ObservableMiscellaneousClient.cs b/Octokit.Reactive/Clients/ObservableMiscellaneousClient.cs index 0675437f56..8aa2f98b4c 100644 --- a/Octokit.Reactive/Clients/ObservableMiscellaneousClient.cs +++ b/Octokit.Reactive/Clients/ObservableMiscellaneousClient.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.Reactive.Linq; using System.Reactive.Threading.Tasks; @@ -80,10 +81,21 @@ public IObservable GetLicense(string key) /// /// Thrown when a general API error occurs. /// An of Rate Limits. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] + [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] public IObservable GetRateLimits() { return _client.GetRateLimits().ToObservable(); } + + /// + /// Retrieves information about GitHub.com, the service or a GitHub Enterprise installation. + /// + /// Thrown when a general API error occurs. + /// An containing metadata about the GitHub instance. + [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] + public IObservable GetMetadata() + { + return _client.GetMetadata().ToObservable(); + } } } diff --git a/Octokit.Tests.Integration/Clients/MiscellaneousClientTests.cs b/Octokit.Tests.Integration/Clients/MiscellaneousClientTests.cs index 149c49b262..bff700dc03 100644 --- a/Octokit.Tests.Integration/Clients/MiscellaneousClientTests.cs +++ b/Octokit.Tests.Integration/Clients/MiscellaneousClientTests.cs @@ -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); + } + } +} \ No newline at end of file diff --git a/Octokit.Tests.Integration/Helper.cs b/Octokit.Tests.Integration/Helper.cs index 8e623528d8..d0abd3bd41 100644 --- a/Octokit.Tests.Integration/Helper.cs +++ b/Octokit.Tests.Integration/Helper.cs @@ -1,7 +1,6 @@ using System; using System.Diagnostics; using System.IO; -using System.Security.Policy; namespace Octokit.Tests.Integration { diff --git a/Octokit/Clients/IMiscellaneousClient.cs b/Octokit/Clients/IMiscellaneousClient.cs index 10b92cd6e8..95367c3ed1 100644 --- a/Octokit/Clients/IMiscellaneousClient.cs +++ b/Octokit/Clients/IMiscellaneousClient.cs @@ -67,5 +67,13 @@ public interface IMiscellaneousClient /// An of Rate Limits. [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] Task GetRateLimits(); + + /// + /// Retrieves information about GitHub.com, the service or a GitHub Enterprise installation. + /// + /// Thrown when a general API error occurs. + /// An containing metadata about the GitHub instance. + [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] + Task GetMetadata(); } } diff --git a/Octokit/Clients/MiscellaneousClient.cs b/Octokit/Clients/MiscellaneousClient.cs index 100116563d..7510ca842c 100644 --- a/Octokit/Clients/MiscellaneousClient.cs +++ b/Octokit/Clients/MiscellaneousClient.cs @@ -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 @@ public async Task GetLicense(string key) /// /// Thrown when a general API error occurs. /// An of Rate Limits. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] + [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] public async Task GetRateLimits() { var endpoint = new Uri("rate_limit", UriKind.Relative); var response = await _connection.Get(endpoint, null, null).ConfigureAwait(false); return response.Body; } + + /// + /// Retrieves information about GitHub.com, the service or a GitHub Enterprise installation. + /// + /// Thrown when a general API error occurs. + /// An containing metadata about the GitHub instance. + [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")] + public async Task GetMetadata() + { + var endpoint = new Uri("meta", UriKind.Relative); + var response = await _connection.Get(endpoint, null, null).ConfigureAwait(false); + return response.Body; + } } } \ No newline at end of file diff --git a/Octokit/Models/Response/Meta.cs b/Octokit/Models/Response/Meta.cs new file mode 100644 index 0000000000..6672082540 --- /dev/null +++ b/Octokit/Models/Response/Meta.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; + +namespace Octokit +{ + /// + /// Response from the /meta endpoint that provides information about GitHub.com or a GitHub Enterprise instance. + /// + [DebuggerDisplay("{DebuggerDisplay,nq}")] + public class Meta + { + public Meta() + { + } + + public Meta( + bool verifiablePasswordAuthentication, + string gitHubServicesSha, + IReadOnlyList hooks, + IReadOnlyList git, + IReadOnlyList pages) + { + VerifiablePasswordAuthentication = verifiablePasswordAuthentication; + GitHubServicesSha = gitHubServicesSha; + Hooks = hooks; + Git = git; + Pages = pages; + } + + /// + /// 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.) + /// + public bool VerifiablePasswordAuthentication { get; private set; } + + /// + /// The currently-deployed SHA of github-services. + /// + public string GitHubServicesSha { get; private set; } + + /// + /// 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. + /// + public IReadOnlyList Hooks { get; private set; } + + /// + /// An Array of IP addresses in CIDR format specifying the Git servers for GitHub.com. + /// + public IReadOnlyList Git { get; private set; } + + /// + /// An Array of IP addresses in CIDR format specifying the A records for GitHub Pages. + /// + public IReadOnlyList Pages { get; private set; } + + internal string DebuggerDisplay + { + get + { + return String.Format( + CultureInfo.InvariantCulture, + "GitHubServicesSha: {0}, VerifiablePasswordAuthentication: {1} ", + GitHubServicesSha, + VerifiablePasswordAuthentication); + } + } + } +} diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index e7f218f545..3961d74f15 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -402,6 +402,7 @@ + \ No newline at end of file diff --git a/Octokit/Octokit-MonoAndroid.csproj b/Octokit/Octokit-MonoAndroid.csproj index e0a3a0b7fd..07304a9657 100644 --- a/Octokit/Octokit-MonoAndroid.csproj +++ b/Octokit/Octokit-MonoAndroid.csproj @@ -410,6 +410,7 @@ + \ No newline at end of file diff --git a/Octokit/Octokit-Monotouch.csproj b/Octokit/Octokit-Monotouch.csproj index 02c0ac71a8..caaeb90c55 100644 --- a/Octokit/Octokit-Monotouch.csproj +++ b/Octokit/Octokit-Monotouch.csproj @@ -406,6 +406,7 @@ + diff --git a/Octokit/Octokit-Portable.csproj b/Octokit/Octokit-Portable.csproj index 4e487ca9c1..b25ddd45f6 100644 --- a/Octokit/Octokit-Portable.csproj +++ b/Octokit/Octokit-Portable.csproj @@ -399,6 +399,7 @@ + diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index 2702f10920..ec20803e16 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -403,6 +403,7 @@ + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 17e33a4b49..58be85ed18 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -118,6 +118,7 @@ +