From 7f901c47e8c28fd29639d0a65bf33e73b8ae9227 Mon Sep 17 00:00:00 2001 From: Haacked Date: Sat, 12 Sep 2015 16:14:13 -0700 Subject: [PATCH 1/2] 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 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..869a272655 --- /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 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 @@ + From a3ad7c9ea6c668911474dd4fce4934c6d3dd4157 Mon Sep 17 00:00:00 2001 From: Haacked Date: Sat, 12 Sep 2015 16:21:49 -0700 Subject: [PATCH 2/2] Make it a readonly list --- Octokit/Models/Response/Meta.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Octokit/Models/Response/Meta.cs b/Octokit/Models/Response/Meta.cs index 869a272655..6672082540 100644 --- a/Octokit/Models/Response/Meta.cs +++ b/Octokit/Models/Response/Meta.cs @@ -18,9 +18,9 @@ public Meta() public Meta( bool verifiablePasswordAuthentication, string gitHubServicesSha, - IReadOnlyCollection hooks, - IReadOnlyCollection git, - IReadOnlyCollection pages) + IReadOnlyList hooks, + IReadOnlyList git, + IReadOnlyList pages) { VerifiablePasswordAuthentication = verifiablePasswordAuthentication; GitHubServicesSha = gitHubServicesSha; @@ -46,17 +46,17 @@ public Meta( /// 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; } + public IReadOnlyList 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; } + public IReadOnlyList 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; } + public IReadOnlyList Pages { get; private set; } internal string DebuggerDisplay {