refactor: use Flurl's own IFlurlClientFactory

pull/231/head
Robert Dailey 1 year ago
parent aae8897250
commit 0b31352c3c

@ -3,7 +3,6 @@ using Autofac.Extras.AggregateService;
using Recyclarr.Cli.Cache; using Recyclarr.Cli.Cache;
using Recyclarr.Cli.Pipelines.CustomFormat.Models; using Recyclarr.Cli.Pipelines.CustomFormat.Models;
using Recyclarr.Cli.Pipelines.CustomFormat.PipelinePhases; using Recyclarr.Cli.Pipelines.CustomFormat.PipelinePhases;
using Recyclarr.ServarrApi.Services;
namespace Recyclarr.Cli.Pipelines.CustomFormat; namespace Recyclarr.Cli.Pipelines.CustomFormat;

@ -1,7 +1,6 @@
using Autofac; using Autofac;
using Autofac.Extras.AggregateService; using Autofac.Extras.AggregateService;
using Recyclarr.Cli.Pipelines.QualityProfile.PipelinePhases; using Recyclarr.Cli.Pipelines.QualityProfile.PipelinePhases;
using Recyclarr.ServarrApi.Services;
namespace Recyclarr.Cli.Pipelines.QualityProfile; namespace Recyclarr.Cli.Pipelines.QualityProfile;

@ -1,7 +1,6 @@
using Autofac; using Autofac;
using Autofac.Extras.AggregateService; using Autofac.Extras.AggregateService;
using Recyclarr.Cli.Pipelines.QualitySize.PipelinePhases; using Recyclarr.Cli.Pipelines.QualitySize.PipelinePhases;
using Recyclarr.ServarrApi.Services;
namespace Recyclarr.Cli.Pipelines.QualitySize; namespace Recyclarr.Cli.Pipelines.QualitySize;

@ -1,3 +1,4 @@
using Flurl;
using Flurl.Http; using Flurl.Http;
using Flurl.Http.Configuration; using Flurl.Http.Configuration;
using Recyclarr.Common.Networking; using Recyclarr.Common.Networking;
@ -7,7 +8,7 @@ using Serilog;
namespace Recyclarr.ServarrApi.Http; namespace Recyclarr.ServarrApi.Http;
public class FlurlClientFactory : IFlurlClientFactory public sealed class FlurlClientFactory : IFlurlClientFactory
{ {
private readonly ILogger _log; private readonly ILogger _log;
private readonly ISettingsProvider _settingsProvider; private readonly ISettingsProvider _settingsProvider;
@ -20,9 +21,9 @@ public class FlurlClientFactory : IFlurlClientFactory
_factory = new PerBaseUrlFlurlClientFactory(); _factory = new PerBaseUrlFlurlClientFactory();
} }
public IFlurlClient BuildClient(Uri baseUrl) public IFlurlClient Get(Url url)
{ {
var client = _factory.Get(baseUrl); var client = _factory.Get(url);
client.Settings = GetClientSettings(); client.Settings = GetClientSettings();
return client; return client;
} }
@ -47,4 +48,9 @@ public class FlurlClientFactory : IFlurlClientFactory
return settings; return settings;
} }
public void Dispose()
{
_factory.Dispose();
}
} }

@ -1,8 +0,0 @@
using Flurl.Http;
namespace Recyclarr.ServarrApi.Http;
public interface IFlurlClientFactory
{
IFlurlClient BuildClient(Uri baseUrl);
}

@ -1,4 +1,5 @@
using Flurl.Http; using Flurl.Http;
using Flurl.Http.Configuration;
using Recyclarr.Config.Models; using Recyclarr.Config.Models;
namespace Recyclarr.ServarrApi.Http; namespace Recyclarr.ServarrApi.Http;
@ -14,7 +15,7 @@ public class ServiceRequestBuilder : IServiceRequestBuilder
public IFlurlRequest Request(IServiceConfiguration config, params object[] path) public IFlurlRequest Request(IServiceConfiguration config, params object[] path)
{ {
var client = _clientFactory.BuildClient(config.BaseUrl); var client = _clientFactory.Get(config.BaseUrl);
return client.Request(new[] {"api", "v3"}.Concat(path).ToArray()) return client.Request(new[] {"api", "v3"}.Concat(path).ToArray())
.WithHeader("X-Api-Key", config.ApiKey); .WithHeader("X-Api-Key", config.ApiKey);
} }

Loading…
Cancel
Save