diff --git a/src/NzbDrone.Core.Test/Framework/CoreTest.cs b/src/NzbDrone.Core.Test/Framework/CoreTest.cs index 789e40e22..420541731 100644 --- a/src/NzbDrone.Core.Test/Framework/CoreTest.cs +++ b/src/NzbDrone.Core.Test/Framework/CoreTest.cs @@ -1,4 +1,4 @@ -using System; +using System; using Moq; using NUnit.Framework; using NzbDrone.Common.Cache; @@ -33,7 +33,7 @@ protected void UseRealHttp() var httpClient = Mocker.Resolve(); Mocker.GetMock() .Setup(x => x.Get(It.IsAny(), It.IsAny(), It.IsAny())) - .Returns((HttpRequest request, bool useCavhe, TimeSpan ttl) => httpClient.Get(request)); + .Returns((HttpRequest request, bool useCache, TimeSpan ttl) => httpClient.Get(request)); } } diff --git a/src/NzbDrone.Core.Test/MetadataSource/Goodreads/GoodreadsProxySearchFixture.cs b/src/NzbDrone.Core.Test/MetadataSource/Goodreads/GoodreadsProxySearchFixture.cs index bddf9e80a..f63d1f992 100644 --- a/src/NzbDrone.Core.Test/MetadataSource/Goodreads/GoodreadsProxySearchFixture.cs +++ b/src/NzbDrone.Core.Test/MetadataSource/Goodreads/GoodreadsProxySearchFixture.cs @@ -3,7 +3,9 @@ using FluentAssertions; using Moq; using NUnit.Framework; +using NzbDrone.Common.Http; using NzbDrone.Core.Books; +using NzbDrone.Core.Http; using NzbDrone.Core.MetadataSource.Goodreads; using NzbDrone.Core.Profiles.Metadata; using NzbDrone.Core.Test.Framework; @@ -19,6 +21,11 @@ public void Setup() { UseRealHttp(); + var httpClient = Mocker.Resolve(); + Mocker.GetMock() + .Setup(x => x.Get>(It.IsAny(), It.IsAny(), It.IsAny())) + .Returns((HttpRequest request, bool useCache, TimeSpan ttl) => httpClient.Get>(request)); + var metadataProfile = new MetadataProfile(); Mocker.GetMock() diff --git a/src/NzbDrone.Core/Http/CachedHttpResponseService.cs b/src/NzbDrone.Core/Http/CachedHttpResponseService.cs index 6672fd80c..d43340a08 100644 --- a/src/NzbDrone.Core/Http/CachedHttpResponseService.cs +++ b/src/NzbDrone.Core/Http/CachedHttpResponseService.cs @@ -7,6 +7,8 @@ namespace NzbDrone.Core.Http public interface ICachedHttpResponseService { HttpResponse Get(HttpRequest request, bool useCache, TimeSpan ttl); + HttpResponse Get(HttpRequest request, bool useCache, TimeSpan ttl) + where T : new(); } public class CachedHttpResponseService : ICachedHttpResponseService @@ -54,5 +56,12 @@ public HttpResponse Get(HttpRequest request, bool useCache, TimeSpan ttl) return result; } + + public HttpResponse Get(HttpRequest request, bool useCache, TimeSpan ttl) + where T : new() + { + var response = Get(request, useCache, ttl); + return new HttpResponse(response); + } } } diff --git a/src/NzbDrone.Core/MetadataSource/Goodreads/GoodreadsProxy.cs b/src/NzbDrone.Core/MetadataSource/Goodreads/GoodreadsProxy.cs index a234c6a5a..5e1941abe 100644 --- a/src/NzbDrone.Core/MetadataSource/Goodreads/GoodreadsProxy.cs +++ b/src/NzbDrone.Core/MetadataSource/Goodreads/GoodreadsProxy.cs @@ -28,7 +28,6 @@ public class GoodreadsProxy : IProvideAuthorInfo, ISearchForNewAuthor, IProvideB private static readonly Regex NoPhotoRegex = new Regex(@"/nophoto/(book|user)/", RegexOptions.IgnoreCase | RegexOptions.Compiled); - private readonly IHttpClient _httpClient; private readonly ICachedHttpResponseService _cachedHttpClient; private readonly Logger _logger; private readonly IAuthorService _authorService; @@ -38,15 +37,13 @@ public class GoodreadsProxy : IProvideAuthorInfo, ISearchForNewAuthor, IProvideB private readonly IHttpRequestBuilderFactory _searchBuilder; private readonly ICached> _cache; - public GoodreadsProxy(IHttpClient httpClient, - ICachedHttpResponseService cachedHttpClient, + public GoodreadsProxy(ICachedHttpResponseService cachedHttpClient, IAuthorService authorService, IBookService bookService, IEditionService editionService, Logger logger, ICacheManager cacheManager) { - _httpClient = httpClient; _cachedHttpClient = cachedHttpClient; _authorService = authorService; _bookService = bookService; @@ -482,7 +479,7 @@ public List SearchByField(string field, string query) .AddQueryParam("q", query) .Build(); - var result = _httpClient.Get>(httpRequest); + var result = _cachedHttpClient.Get>(httpRequest, true, TimeSpan.FromDays(5)); return result.Resource.SelectList(MapJsonSearchResult); }