Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "importers" field to MiscellaneousClient.Meta response #1235

Merged
merged 6 commits into from
Apr 4, 2016
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Octokit.Reactive/Clients/ObservableMiscellaneousClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,21 @@ public class ObservableMiscellaneousClient : IObservableMiscellaneousClient
{
readonly IMiscellaneousClient _client;

[Obsolete("Please use another constructor")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's make this really specific - what about something like: [Obsolete("Please use the IGitHubClient overload constructor")]

public ObservableMiscellaneousClient(IMiscellaneousClient client)
{
Ensure.ArgumentNotNull(client, "client");

_client = client;
}

public ObservableMiscellaneousClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, "client");

_client = client.Miscellaneous;
}

/// <summary>
/// Gets all the emojis available to use on GitHub.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion Octokit.Reactive/ObservableGitHubClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public ObservableGitHubClient(IGitHubClient gitHubClient)
Authorization = new ObservableAuthorizationsClient(gitHubClient);
Activity = new ObservableActivitiesClient(gitHubClient);
Issue = new ObservableIssuesClient(gitHubClient);
Miscellaneous = new ObservableMiscellaneousClient(gitHubClient.Miscellaneous);
Miscellaneous = new ObservableMiscellaneousClient(gitHubClient);
Notification = new ObservableNotificationsClient(gitHubClient);
Oauth = new ObservableOauthClient(gitHubClient);
Organization = new ObservableOrganizationsClient(gitHubClient);
Expand Down
5 changes: 5 additions & 0 deletions Octokit.Tests.Integration/Clients/MiscellaneousClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ public async Task CanRetrieveMetadata()
var result = await github.Miscellaneous.GetMetadata();

Assert.True(result.VerifiablePasswordAuthentication);
Assert.NotEmpty(result.GitHubServicesSha);
Assert.True(result.Hooks.Count > 0);
Assert.True(result.Git.Count > 0);
Assert.True(result.Pages.Count > 0);
Assert.True(result.Importer.Count > 0);
}
}
}
36 changes: 36 additions & 0 deletions Octokit.Tests/Clients/MiscellaneousClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,42 @@ public async Task RequestsTheRecourceRateLimitEndpoint()
}
}

public class TheGetMetadataMethod
{
[Fact]
public async Task RequestsTheMetadataEndpoint()
{
IApiResponse<Meta> response = new ApiResponse<Meta>
(
new Response(),
new Meta(
false,
"12345ABCDE",
new[] { "1.1.1.1/24", "1.1.1.2/24" },
new[] { "1.1.2.1/24", "1.1.2.2/24" },
new[] { "1.1.3.1/24", "1.1.3.2/24" },
new[] { "1.1.4.1", "1.1.4.2" }
)
);
var connection = Substitute.For<IConnection>();
connection.Get<Meta>(Args.Uri, null, null)
.Returns(Task.FromResult(response));
var client = new MiscellaneousClient(connection);

var result = await client.GetMetadata();

Assert.Equal(result.VerifiablePasswordAuthentication, false);
Assert.Equal(result.GitHubServicesSha, "12345ABCDE");
Assert.Equal(result.Hooks, new[] { "1.1.1.1/24", "1.1.1.2/24" });
Assert.Equal(result.Git, new[] { "1.1.2.1/24", "1.1.2.2/24" });
Assert.Equal(result.Pages, new[] { "1.1.3.1/24", "1.1.3.2/24" });
Assert.Equal(result.Importer, new[] { "1.1.4.1", "1.1.4.2" });

connection.Received()
.Get<Meta>(Arg.Is<Uri>(u => u.ToString() == "meta"), null, null);
}
}

public class TheCtor
{
[Fact]
Expand Down
1 change: 1 addition & 0 deletions Octokit.Tests/Octokit.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@
<Compile Include="Reactive\ObservableIssueCommentsClientTests.cs" />
<Compile Include="Reactive\ObservableIssuesClientTests.cs" />
<Compile Include="Reactive\ObservableMilestonesClientTests.cs" />
<Compile Include="Reactive\ObservableMiscellaneousClientTests.cs" />
<Compile Include="Reactive\ObservableOrganizationMembersClientTests.cs" />
<Compile Include="Reactive\ObservablePullRequestsClientTests.cs" />
<Compile Include="Reactive\ObservableReleasesClientTests.cs" />
Expand Down
145 changes: 145 additions & 0 deletions Octokit.Tests/Reactive/ObservableMiscellaneousClientTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
using System;
using NSubstitute;
using Octokit.Reactive;
using Xunit;

namespace Octokit.Tests.Reactive
{
public class ObservableMiscellaneousClientTests
{
public class TheGetAllEmojisMethod
{
[Fact]
public void CallsIntoClient()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableMiscellaneousClient(gitHubClient);

client.GetAllEmojis();

gitHubClient.Miscellaneous.Received(1).GetAllEmojis();
}
}

public class TheRenderArbitraryMarkdownMethod
{
[Fact]
public void CallsIntoClient()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableMiscellaneousClient(gitHubClient);

client.RenderArbitraryMarkdown(new NewArbitraryMarkdown("# test"));

gitHubClient.Miscellaneous.Received(1).RenderArbitraryMarkdown(Arg.Is<NewArbitraryMarkdown>(a => a.Text == "# test"));
}
}

public class TheRenderRawMarkdownMethod
{
[Fact]
public void CallsIntoClient()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableMiscellaneousClient(gitHubClient);

client.RenderRawMarkdown("# test");

gitHubClient.Miscellaneous.Received(1).RenderRawMarkdown("# test");
}
}

public class TheGetAllGitIgnoreTemplatesMethod
{
[Fact]
public void CallsIntoClient()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableMiscellaneousClient(gitHubClient);

client.GetAllGitIgnoreTemplates();

gitHubClient.Miscellaneous.Received(1).GetAllGitIgnoreTemplates();
}
}

public class TheGetGitIgnoreTemplate
{
[Fact]
public void CallsIntoClient()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableMiscellaneousClient(gitHubClient);

client.GetGitIgnoreTemplate("template");

gitHubClient.Miscellaneous.Received(1).GetGitIgnoreTemplate("template");
}
}

public class TheGetAllLicensesMethod
{
[Fact]
public void CallsIntoClient()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableMiscellaneousClient(gitHubClient);

client.GetAllLicenses();

gitHubClient.Miscellaneous.Received(1).GetAllLicenses();
}
}

public class TheGetLicenseMethod
{
[Fact]
public void CallsIntoClient()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableMiscellaneousClient(gitHubClient);

client.GetLicense("key");

gitHubClient.Miscellaneous.Received(1).GetLicense("key");
}
}

public class TheGetRateLimitsMethod
{
[Fact]
public void CallsIntoClient()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableMiscellaneousClient(gitHubClient);

client.GetRateLimits();

gitHubClient.Miscellaneous.Received(1).GetRateLimits();
}
}

public class TheGetMetadataMethod
{
[Fact]
public void CallsIntoClient()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableMiscellaneousClient(gitHubClient);

client.GetMetadata();

gitHubClient.Miscellaneous.Received(1).GetMetadata();
}
}

public class TheCtor
{
[Fact]
public void EnsuresArgument()
{
Assert.Throws<ArgumentNullException>(() => new ObservableMiscellaneousClient((IGitHubClient)null));
}
}
}
}
12 changes: 11 additions & 1 deletion Octokit/Models/Response/Meta.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using Octokit.Internal;

namespace Octokit
{
Expand All @@ -25,18 +26,21 @@ public Meta()
/// <param name="hooks">An array of IP addresses in CIDR format specifying the addresses that incoming service hooks will originate from on GitHub.com.</param>
/// <param name="git">An array of IP addresses in CIDR format specifying the Git servers for the GitHub server</param>
/// <param name="pages">An array of IP addresses in CIDR format specifying the A records for GitHub Pages.</param>
/// <param name="importer">An Array of IP addresses specifying the addresses that source imports will originate from on GitHub.com.</param>
public Meta(
bool verifiablePasswordAuthentication,
string gitHubServicesSha,
IReadOnlyList<string> hooks,
IReadOnlyList<string> git,
IReadOnlyList<string> pages)
IReadOnlyList<string> pages,
IReadOnlyList<string> importer)
{
VerifiablePasswordAuthentication = verifiablePasswordAuthentication;
GitHubServicesSha = gitHubServicesSha;
Hooks = hooks;
Git = git;
Pages = pages;
Importer = importer;
}

/// <summary>
Expand All @@ -49,6 +53,7 @@ public Meta(
/// <summary>
/// The currently-deployed SHA of github-services.
/// </summary>
[Parameter(Key = "github_services_sha")]
public string GitHubServicesSha { get; private set; }

/// <summary>
Expand All @@ -68,6 +73,11 @@ public Meta(
/// </summary>
public IReadOnlyList<string> Pages { get; private set; }

/// <summary>
/// An Array of IP addresses specifying the addresses that source imports will originate from on GitHub.com.
/// </summary>
public IReadOnlyList<string> Importer { get; private set; }

internal string DebuggerDisplay
{
get
Expand Down