diff --git a/Octokit.Reactive/IObservableGitHubClient.cs b/Octokit.Reactive/IObservableGitHubClient.cs index 1dc1bb3c..be317491 100644 --- a/Octokit.Reactive/IObservableGitHubClient.cs +++ b/Octokit.Reactive/IObservableGitHubClient.cs @@ -1,6 +1,6 @@ namespace Octokit.Reactive { - public interface IObservableGitHubClient : IApiInfo + public interface IObservableGitHubClient : IApiInfoProvider { IConnection Connection { get; } diff --git a/Octokit.Tests/Http/ConnectionTests.cs b/Octokit.Tests/Http/ConnectionTests.cs index ad335e44..254c598d 100644 --- a/Octokit.Tests/Http/ConnectionTests.cs +++ b/Octokit.Tests/Http/ConnectionTests.cs @@ -4,8 +4,10 @@ using System.IO; using System.Linq; using System.Net; using System.Net.Http; +using System.Threading; using System.Threading.Tasks; using NSubstitute; +using NSubstitute.Core.Arguments; using Octokit.Internal; using Octokit.Tests.Helpers; using Xunit; @@ -571,7 +573,6 @@ namespace Octokit.Tests.Http public async Task ReturnsNullIfNew() { var httpClient = Substitute.For(); - httpClient.LastApiInfo.Returns((ApiInfo)null); var connection = new Connection(new ProductHeaderValue("OctokitTests"), _exampleUri, Substitute.For(), @@ -581,8 +582,6 @@ namespace Octokit.Tests.Http var result = connection.LastApiInfo; Assert.Null(result); - - var temp = httpClient.Received(1).LastApiInfo; } [Fact] @@ -624,13 +623,24 @@ namespace Octokit.Tests.Http ); var httpClient = Substitute.For(); - httpClient.LastApiInfo.Returns(apiInfo); + + // We really only care about the ApiInfo property... + var expectedResponse = new Response(HttpStatusCode.OK, null, new Dictionary(), "application/json") + { + ApiInfo = apiInfo + }; + + httpClient.Send(Arg.Any(), Arg.Any()) + .Returns(Task.FromResult(expectedResponse)); + var connection = new Connection(new ProductHeaderValue("OctokitTests"), _exampleUri, Substitute.For(), httpClient, Substitute.For()); + connection.Get(new Uri("https://example.com"), TimeSpan.MaxValue); + var result = connection.LastApiInfo; // No point checking all of the values as they are tested elsewhere @@ -640,8 +650,6 @@ namespace Octokit.Tests.Http Assert.Equal(4, result.AcceptedOauthScopes.Count); Assert.Equal("5634b0b187fd2e91e3126a75006cc4fa", result.Etag); Assert.Equal(100, result.RateLimit.Limit); - - var temp = httpClient.Received(1).LastApiInfo; } } } diff --git a/Octokit/Http/Connection.cs b/Octokit/Http/Connection.cs index 532c9e71..e3730915 100644 --- a/Octokit/Http/Connection.cs +++ b/Octokit/Http/Connection.cs @@ -140,7 +140,7 @@ namespace Octokit /// Gets the latest API Info - this will be null if no API calls have been made /// /// representing the information returned as part of an Api call - public ApiInfo LastApiInfo { get { return _httpClient.LastApiInfo; } } + public ApiInfo LastApiInfo { get; private set; } public Task> Get(Uri uri, IDictionary parameters, string accepts) { @@ -531,6 +531,7 @@ namespace Octokit await _authenticator.Apply(request).ConfigureAwait(false); var response = await _httpClient.Send(request, cancellationToken).ConfigureAwait(false); HandleErrors(response); + LastApiInfo = response.ApiInfo; return response; } diff --git a/Octokit/Http/HttpClientAdapter.cs b/Octokit/Http/HttpClientAdapter.cs index bf33df39..59dd87c0 100644 --- a/Octokit/Http/HttpClientAdapter.cs +++ b/Octokit/Http/HttpClientAdapter.cs @@ -28,12 +28,6 @@ namespace Octokit.Internal _http = new HttpClient(new RedirectHandler { InnerHandler = getHandler() }); } - /// - /// Gets the latest API Info - this will be null if no API calls have been made - /// - /// representing the information returned as part of an Api call - public ApiInfo LastApiInfo { get; private set; } - /// /// Sends the specified request and returns a response. /// @@ -51,11 +45,7 @@ namespace Octokit.Internal // Make the request var responseMessage = await _http.SendAsync(requestMessage, HttpCompletionOption.ResponseContentRead, cancellationTokenForRequest) .ConfigureAwait(false); - var response = await BuildResponse(responseMessage).ConfigureAwait(false); - - LastApiInfo = response.ApiInfo; - - return response; + return await BuildResponse(responseMessage).ConfigureAwait(false); } } diff --git a/Octokit/Http/IApiInfo.cs b/Octokit/Http/IApiInfoProvider.cs similarity index 70% rename from Octokit/Http/IApiInfo.cs rename to Octokit/Http/IApiInfoProvider.cs index 04a2cf89..eba8439a 100644 --- a/Octokit/Http/IApiInfo.cs +++ b/Octokit/Http/IApiInfoProvider.cs @@ -1,15 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Octokit +namespace Octokit { /// /// Provides a property for the Last recorded API infomation /// - public interface IApiInfo + public interface IApiInfoProvider { /// /// Gets the latest API Info - this will be null if no API calls have been made diff --git a/Octokit/Http/IConnection.cs b/Octokit/Http/IConnection.cs index dd756b10..bde7885a 100644 --- a/Octokit/Http/IConnection.cs +++ b/Octokit/Http/IConnection.cs @@ -10,7 +10,7 @@ namespace Octokit /// /// A connection for making HTTP requests against URI endpoints. /// - public interface IConnection : IApiInfo + public interface IConnection : IApiInfoProvider { /// /// Performs an asynchronous HTTP GET request that expects a containing HTML. diff --git a/Octokit/Http/IHttpClient.cs b/Octokit/Http/IHttpClient.cs index db9de47a..f554d750 100644 --- a/Octokit/Http/IHttpClient.cs +++ b/Octokit/Http/IHttpClient.cs @@ -10,7 +10,7 @@ namespace Octokit.Internal /// /// Most folks won't ever need to swap this out. But if you're trying to run this on Windows Phone, you might. /// - public interface IHttpClient : IDisposable, IApiInfo + public interface IHttpClient : IDisposable { /// /// Sends the specified request and returns a response. diff --git a/Octokit/Http/Response.cs b/Octokit/Http/Response.cs index 89b2750b..c143cddd 100644 --- a/Octokit/Http/Response.cs +++ b/Octokit/Http/Response.cs @@ -43,7 +43,7 @@ namespace Octokit.Internal /// /// Information about the API response parsed from the response headers. /// - public ApiInfo ApiInfo { get; private set; } + public ApiInfo ApiInfo { get; internal set; } // This setter is internal for use in tests. /// /// The response status code. /// diff --git a/Octokit/IGitHubClient.cs b/Octokit/IGitHubClient.cs index 1ae593cc..7db4a555 100644 --- a/Octokit/IGitHubClient.cs +++ b/Octokit/IGitHubClient.cs @@ -5,7 +5,7 @@ namespace Octokit /// /// A Client for the GitHub API v3. You can read more about the api here: http://developer.github.com. /// - public interface IGitHubClient : IApiInfo + public interface IGitHubClient : IApiInfoProvider { /// /// Provides a client connection to make rest requests to HTTP endpoints. diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index 4db1ff4c..51aebfb9 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -399,7 +399,7 @@ - + \ No newline at end of file diff --git a/Octokit/Octokit-MonoAndroid.csproj b/Octokit/Octokit-MonoAndroid.csproj index 66103c57..c84937fe 100644 --- a/Octokit/Octokit-MonoAndroid.csproj +++ b/Octokit/Octokit-MonoAndroid.csproj @@ -415,7 +415,7 @@ - + \ No newline at end of file diff --git a/Octokit/Octokit-Monotouch.csproj b/Octokit/Octokit-Monotouch.csproj index bde1203d..8cdea025 100644 --- a/Octokit/Octokit-Monotouch.csproj +++ b/Octokit/Octokit-Monotouch.csproj @@ -408,7 +408,7 @@ - + diff --git a/Octokit/Octokit-Portable.csproj b/Octokit/Octokit-Portable.csproj index 4080a485..5d043c79 100644 --- a/Octokit/Octokit-Portable.csproj +++ b/Octokit/Octokit-Portable.csproj @@ -398,7 +398,7 @@ - + diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index 65c2b6f0..623dbd10 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -402,7 +402,7 @@ - + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 943d7bca..ff9bcee3 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -84,7 +84,7 @@ - +