From 7f901c47e8c28fd29639d0a65bf33e73b8ae9227 Mon Sep 17 00:00:00 2001 From: Haacked Date: Sat, 12 Sep 2015 16:14:13 -0700 Subject: [PATCH] Implement the Meta endpoint See https://developer.github.com/v3/meta/ for more information about this endpoint. --- .../Clients/IObservableMiscellaneousClient.cs | 7 ++ .../Clients/ObservableMiscellaneousClient.cs | 14 +++- .../Clients/MiscellaneousClientTests.cs | 15 +++- Octokit.Tests.Integration/Helper.cs | 1 - Octokit/Clients/IMiscellaneousClient.cs | 8 ++ Octokit/Clients/MiscellaneousClient.cs | 16 +++- Octokit/Models/Response/Meta.cs | 73 +++++++++++++++++++ Octokit/Octokit-Mono.csproj | 1 + Octokit/Octokit-MonoAndroid.csproj | 1 + Octokit/Octokit-Monotouch.csproj | 1 + Octokit/Octokit-Portable.csproj | 1 + Octokit/Octokit-netcore45.csproj | 1 + Octokit/Octokit.csproj | 1 + 13 files changed, 136 insertions(+), 4 deletions(-) create mode 100644 Octokit/Models/Response/Meta.cs diff --git a/Octokit.Reactive/Clients/IObservableMiscellaneousClient.cs b/Octokit.Reactive/Clients/IObservableMiscellaneousClient.cs index 792fd294..87a9382f 100644 --- a/Octokit.Reactive/Clients/IObservableMiscellaneousClient.cs +++ b/Octokit.Reactive/Clients/IObservableMiscellaneousClient.cs @@ -59,5 +59,12 @@ namespace Octokit.Reactive [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 0675437f..8aa2f98b 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 @@ namespace Octokit.Reactive /// /// 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 149c49b2..bff700dc 100644 --- a/Octokit.Tests.Integration/Clients/MiscellaneousClientTests.cs +++ b/Octokit.Tests.Integration/Clients/MiscellaneousClientTests.cs @@ -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); + } + } +} \ No newline at end of file diff --git a/Octokit.Tests.Integration/Helper.cs b/Octokit.Tests.Integration/Helper.cs index 8e623528..d0abd3bd 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 10b92cd6..95367c3e 100644 --- a/Octokit/Clients/IMiscellaneousClient.cs +++ b/Octokit/Clients/IMiscellaneousClient.cs @@ -67,5 +67,13 @@ namespace Octokit /// 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 10011656..7510ca84 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 @@ namespace Octokit /// /// 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 00000000..869a2726 --- /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, + IReadOnlyCollection hooks, + IReadOnlyCollection git, + IReadOnlyCollection 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 IReadOnlyCollection Hooks { get; private set; } + + /// + /// An Array of IP addresses in CIDR format specifying the Git servers for GitHub.com. + /// + public IReadOnlyCollection Git { get; private set; } + + /// + /// An Array of IP addresses in CIDR format specifying the A records for GitHub Pages. + /// + public IReadOnlyCollection 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 e7f218f5..3961d74f 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 e0a3a0b7..07304a96 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 02c0ac71..caaeb90c 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 4e487ca9..b25ddd45 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 2702f109..ec20803e 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 17e33a4b..58be85ed 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -118,6 +118,7 @@ +