Merge pull request #1 from khellang/api-info

API Info Proposal
This commit is contained in:
Mark Taylor
2015-08-02 16:26:00 +01:00
15 changed files with 30 additions and 37 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
namespace Octokit.Reactive
{
public interface IObservableGitHubClient : IApiInfo
public interface IObservableGitHubClient : IApiInfoProvider
{
IConnection Connection { get; }
+14 -6
View File
@@ -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<IHttpClient>();
httpClient.LastApiInfo.Returns((ApiInfo)null);
var connection = new Connection(new ProductHeaderValue("OctokitTests"),
_exampleUri,
Substitute.For<ICredentialStore>(),
@@ -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<IHttpClient>();
httpClient.LastApiInfo.Returns(apiInfo);
// We really only care about the ApiInfo property...
var expectedResponse = new Response(HttpStatusCode.OK, null, new Dictionary<string, string>(), "application/json")
{
ApiInfo = apiInfo
};
httpClient.Send(Arg.Any<IRequest>(), Arg.Any<CancellationToken>())
.Returns(Task.FromResult<IResponse>(expectedResponse));
var connection = new Connection(new ProductHeaderValue("OctokitTests"),
_exampleUri,
Substitute.For<ICredentialStore>(),
httpClient,
Substitute.For<IJsonSerializer>());
connection.Get<PullRequest>(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;
}
}
}
+2 -1
View File
@@ -140,7 +140,7 @@ namespace Octokit
/// Gets the latest API Info - this will be null if no API calls have been made
/// </summary>
/// <returns><seealso cref="ApiInfo"/> representing the information returned as part of an Api call</returns>
public ApiInfo LastApiInfo { get { return _httpClient.LastApiInfo; } }
public ApiInfo LastApiInfo { get; private set; }
public Task<IApiResponse<T>> Get<T>(Uri uri, IDictionary<string, string> 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;
}
+1 -11
View File
@@ -28,12 +28,6 @@ namespace Octokit.Internal
_http = new HttpClient(new RedirectHandler { InnerHandler = getHandler() });
}
/// <summary>
/// Gets the latest API Info - this will be null if no API calls have been made
/// </summary>
/// <returns><seealso cref="ApiInfo"/> representing the information returned as part of an Api call</returns>
public ApiInfo LastApiInfo { get; private set; }
/// <summary>
/// Sends the specified request and returns a response.
/// </summary>
@@ -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);
}
}
@@ -1,15 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Octokit
namespace Octokit
{
/// <summary>
/// Provides a property for the Last recorded API infomation
/// </summary>
public interface IApiInfo
public interface IApiInfoProvider
{
/// <summary>
/// Gets the latest API Info - this will be null if no API calls have been made
+1 -1
View File
@@ -10,7 +10,7 @@ namespace Octokit
/// <summary>
/// A connection for making HTTP requests against URI endpoints.
/// </summary>
public interface IConnection : IApiInfo
public interface IConnection : IApiInfoProvider
{
/// <summary>
/// Performs an asynchronous HTTP GET request that expects a <seealso cref="IResponse"/> containing HTML.
+1 -1
View File
@@ -10,7 +10,7 @@ namespace Octokit.Internal
/// <remarks>
/// Most folks won't ever need to swap this out. But if you're trying to run this on Windows Phone, you might.
/// </remarks>
public interface IHttpClient : IDisposable, IApiInfo
public interface IHttpClient : IDisposable
{
/// <summary>
/// Sends the specified request and returns a response.
+1 -1
View File
@@ -43,7 +43,7 @@ namespace Octokit.Internal
/// <summary>
/// Information about the API response parsed from the response headers.
/// </summary>
public ApiInfo ApiInfo { get; private set; }
public ApiInfo ApiInfo { get; internal set; } // This setter is internal for use in tests.
/// <summary>
/// The response status code.
/// </summary>
+1 -1
View File
@@ -5,7 +5,7 @@ namespace Octokit
/// <summary>
/// A Client for the GitHub API v3. You can read more about the api here: http://developer.github.com.
/// </summary>
public interface IGitHubClient : IApiInfo
public interface IGitHubClient : IApiInfoProvider
{
/// <summary>
/// Provides a client connection to make rest requests to HTTP endpoints.
+1 -1
View File
@@ -399,7 +399,7 @@
<Compile Include="Models\Response\ResourceRateLimit.cs" />
<Compile Include="Models\Response\MiscellaneousRateLimit.cs" />
<Compile Include="Exceptions\RepositoryFormatException.cs" />
<Compile Include="Http\IApiInfo.cs" />
<Compile Include="Http\IApiInfoProvider.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>
+1 -1
View File
@@ -415,7 +415,7 @@
<Compile Include="Models\Response\ResourceRateLimit.cs" />
<Compile Include="Models\Response\MiscellaneousRateLimit.cs" />
<Compile Include="Exceptions\RepositoryFormatException.cs" />
<Compile Include="Http\IApiInfo.cs" />
<Compile Include="Http\IApiInfoProvider.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
</Project>
+1 -1
View File
@@ -408,7 +408,7 @@
<Compile Include="Models\Response\ResourceRateLimit.cs" />
<Compile Include="Models\Response\MiscellaneousRateLimit.cs" />
<Compile Include="Exceptions\RepositoryFormatException.cs" />
<Compile Include="Http\IApiInfo.cs" />
<Compile Include="Http\IApiInfoProvider.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.MonoTouch.CSharp.targets" />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
+1 -1
View File
@@ -398,7 +398,7 @@
<Compile Include="Models\Response\ResourceRateLimit.cs" />
<Compile Include="Models\Response\MiscellaneousRateLimit.cs" />
<Compile Include="Exceptions\RepositoryFormatException.cs" />
<Compile Include="Http\IApiInfo.cs" />
<Compile Include="Http\IApiInfoProvider.cs" />
</ItemGroup>
<ItemGroup>
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">
+1 -1
View File
@@ -402,7 +402,7 @@
<Compile Include="Models\Response\ResourceRateLimit.cs" />
<Compile Include="Models\Response\MiscellaneousRateLimit.cs" />
<Compile Include="Exceptions\RepositoryFormatException.cs" />
<Compile Include="Http\IApiInfo.cs" />
<Compile Include="Http\IApiInfoProvider.cs" />
</ItemGroup>
<ItemGroup>
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">
+1 -1
View File
@@ -84,7 +84,7 @@
<Compile Include="Helpers\PropertyOrField.cs" />
<Compile Include="Helpers\SerializeNullAttribute.cs" />
<Compile Include="Http\HttpMessageHandlerFactory.cs" />
<Compile Include="Http\IApiInfo.cs" />
<Compile Include="Http\IApiInfoProvider.cs" />
<Compile Include="Http\ProductHeaderValue.cs" />
<Compile Include="Models\Request\GistFileUpdate.cs" />
<Compile Include="Models\Request\NewMerge.cs" />