From d04b10f9d07388f3659527b3d6280651732d6678 Mon Sep 17 00:00:00 2001 From: Robert Dailey Date: Sat, 26 Nov 2022 14:50:02 -0600 Subject: [PATCH] refactor: Utilize DI for Flurl The goal is to eliminate the need for a "global setup" step for HTTP communication. This can instead be done in the composition root as part of the factory to request FlurlClient objects. --- src/Recyclarr/Command/RadarrCommand.cs | 2 +- src/Recyclarr/Command/ServiceCommand.cs | 33 +---------- src/Recyclarr/Command/SonarrCommand.cs | 2 +- src/Recyclarr/CompositionRoot.cs | 5 +- src/TrashLib/Config/Services/IServerInfo.cs | 9 --- .../Config/Services/IServiceRequestBuilder.cs | 9 +++ src/TrashLib/Config/Services/ServerInfo.cs | 26 --------- .../Config/Services/ServiceRequestBuilder.cs | 25 +++++++++ src/TrashLib/Http/FlurlClientFactory.cs | 55 +++++++++++++++++++ .../{Extensions => Http}/FlurlExtensions.cs | 2 +- .../{Extensions => Http}/FlurlLogging.cs | 2 +- src/TrashLib/Http/IFlurlClientFactory.cs | 8 +++ .../CustomFormat/Api/CustomFormatService.cs | 21 +++---- .../CustomFormat/Api/QualityProfileService.cs | 15 ++--- .../CustomFormat/CustomFormatUpdater.cs | 12 ++-- .../Api/QualityDefinitionService.cs | 15 ++--- .../Sonarr/Api/ReleaseProfileApiService.cs | 18 +++--- src/TrashLib/Services/Sonarr/Api/SonarrApi.cs | 21 +++---- .../Services/System/SystemApiService.cs | 12 ++-- 19 files changed, 147 insertions(+), 145 deletions(-) delete mode 100644 src/TrashLib/Config/Services/IServerInfo.cs create mode 100644 src/TrashLib/Config/Services/IServiceRequestBuilder.cs delete mode 100644 src/TrashLib/Config/Services/ServerInfo.cs create mode 100644 src/TrashLib/Config/Services/ServiceRequestBuilder.cs create mode 100644 src/TrashLib/Http/FlurlClientFactory.cs rename src/TrashLib/{Extensions => Http}/FlurlExtensions.cs (93%) rename src/TrashLib/{Extensions => Http}/FlurlLogging.cs (98%) create mode 100644 src/TrashLib/Http/IFlurlClientFactory.cs diff --git a/src/Recyclarr/Command/RadarrCommand.cs b/src/Recyclarr/Command/RadarrCommand.cs index 1a1a007d..87d9ccd2 100644 --- a/src/Recyclarr/Command/RadarrCommand.cs +++ b/src/Recyclarr/Command/RadarrCommand.cs @@ -5,7 +5,7 @@ using JetBrains.Annotations; using Recyclarr.Config; using Serilog; using TrashLib.Config.Services; -using TrashLib.Extensions; +using TrashLib.Http; using TrashLib.Services.CustomFormat; using TrashLib.Services.Radarr; using TrashLib.Services.Radarr.Config; diff --git a/src/Recyclarr/Command/ServiceCommand.cs b/src/Recyclarr/Command/ServiceCommand.cs index c83286ba..c3c96e45 100644 --- a/src/Recyclarr/Command/ServiceCommand.cs +++ b/src/Recyclarr/Command/ServiceCommand.cs @@ -3,15 +3,11 @@ using Autofac; using CliFx.Attributes; using CliFx.Exceptions; using CliFx.Infrastructure; -using Common.Networking; using Flurl.Http; -using Flurl.Http.Configuration; using JetBrains.Annotations; -using Newtonsoft.Json; using Recyclarr.Migration; using Serilog; -using TrashLib.Config.Settings; -using TrashLib.Extensions; +using TrashLib.Http; using TrashLib.Repo; using TrashLib.Repo.VersionControl; using YamlDotNet.Core; @@ -76,7 +72,6 @@ public abstract class ServiceCommand : BaseCommand, IServiceCommand public override async Task Process(ILifetimeScope container) { var log = container.Resolve(); - var settingsProvider = container.Resolve(); var repoUpdater = container.Resolve(); var migration = container.Resolve(); @@ -85,32 +80,6 @@ public abstract class ServiceCommand : BaseCommand, IServiceCommand // Will throw if migration is required, otherwise just a warning is issued. migration.CheckNeededMigrations(); - SetupHttp(log, settingsProvider); await repoUpdater.UpdateRepo(); } - - private static void SetupHttp(ILogger log, ISettingsProvider settingsProvider) - { - FlurlHttp.Configure(settings => - { - var jsonSettings = new JsonSerializerSettings - { - // This makes sure that null properties, such as maxSize and preferredSize in Radarr - // Quality Definitions, do not get written out to JSON request bodies. - NullValueHandling = NullValueHandling.Ignore - }; - - settings.JsonSerializer = new NewtonsoftJsonSerializer(jsonSettings); - FlurlLogging.SetupLogging(settings, log); - - // ReSharper disable once InvertIf - if (!settingsProvider.Settings.EnableSslCertificateValidation) - { - log.Warning( - "Security Risk: Certificate validation is being DISABLED because setting " + - "`enable_ssl_certificate_validation` is set to `false`"); - settings.HttpClientFactory = new UntrustedCertClientFactory(); - } - }); - } } diff --git a/src/Recyclarr/Command/SonarrCommand.cs b/src/Recyclarr/Command/SonarrCommand.cs index b00645a5..f3599c02 100644 --- a/src/Recyclarr/Command/SonarrCommand.cs +++ b/src/Recyclarr/Command/SonarrCommand.cs @@ -5,7 +5,7 @@ using JetBrains.Annotations; using Recyclarr.Config; using Serilog; using TrashLib.Config.Services; -using TrashLib.Extensions; +using TrashLib.Http; using TrashLib.Services.CustomFormat; using TrashLib.Services.Sonarr; using TrashLib.Services.Sonarr.Config; diff --git a/src/Recyclarr/CompositionRoot.cs b/src/Recyclarr/CompositionRoot.cs index 10e2e4ff..0def5f7b 100644 --- a/src/Recyclarr/CompositionRoot.cs +++ b/src/Recyclarr/CompositionRoot.cs @@ -13,6 +13,7 @@ using Recyclarr.Migration; using TrashLib.Cache; using TrashLib.Config; using TrashLib.Config.Services; +using TrashLib.Http; using TrashLib.Repo; using TrashLib.Repo.VersionControl; using TrashLib.Services.Common; @@ -52,7 +53,7 @@ public static class CompositionRoot builder.RegisterModule(); builder.RegisterType().As(); - builder.RegisterType().As(); + builder.RegisterType().As(); builder.RegisterType(); ConfigurationRegistrations(builder); @@ -60,6 +61,8 @@ public static class CompositionRoot builder.Register(_ => AutoMapperConfig.Setup()).SingleInstance(); + builder.RegisterType().As().SingleInstance(); + extraRegistrations?.Invoke(builder); return builder.Build(); diff --git a/src/TrashLib/Config/Services/IServerInfo.cs b/src/TrashLib/Config/Services/IServerInfo.cs deleted file mode 100644 index 11e810cf..00000000 --- a/src/TrashLib/Config/Services/IServerInfo.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Flurl; - -namespace TrashLib.Config.Services; - -public interface IServerInfo -{ - Url BuildRequest(); - string SanitizedBaseUrl { get; } -} diff --git a/src/TrashLib/Config/Services/IServiceRequestBuilder.cs b/src/TrashLib/Config/Services/IServiceRequestBuilder.cs new file mode 100644 index 00000000..17d401e4 --- /dev/null +++ b/src/TrashLib/Config/Services/IServiceRequestBuilder.cs @@ -0,0 +1,9 @@ +using Flurl.Http; + +namespace TrashLib.Config.Services; + +public interface IServiceRequestBuilder +{ + string SanitizedBaseUrl { get; } + IFlurlRequest Request(params object[] path); +} diff --git a/src/TrashLib/Config/Services/ServerInfo.cs b/src/TrashLib/Config/Services/ServerInfo.cs deleted file mode 100644 index 626780f3..00000000 --- a/src/TrashLib/Config/Services/ServerInfo.cs +++ /dev/null @@ -1,26 +0,0 @@ -using Flurl; -using TrashLib.Extensions; - -namespace TrashLib.Config.Services; - -public class ServerInfo : IServerInfo -{ - private readonly IServiceConfiguration _config; - - public ServerInfo(IServiceConfiguration config) - { - _config = config; - } - - public Url BuildRequest() - { - var apiKey = _config.ApiKey; - var baseUrl = _config.BaseUrl; - - return baseUrl - .AppendPathSegment("api/v3") - .SetQueryParams(new {apikey = apiKey}); - } - - public string SanitizedBaseUrl => FlurlLogging.SanitizeUrl(_config.BaseUrl); -} diff --git a/src/TrashLib/Config/Services/ServiceRequestBuilder.cs b/src/TrashLib/Config/Services/ServiceRequestBuilder.cs new file mode 100644 index 00000000..df6996e1 --- /dev/null +++ b/src/TrashLib/Config/Services/ServiceRequestBuilder.cs @@ -0,0 +1,25 @@ +using Flurl.Http; +using TrashLib.Http; + +namespace TrashLib.Config.Services; + +public class ServiceRequestBuilder : IServiceRequestBuilder +{ + private readonly IServiceConfiguration _config; + private readonly IFlurlClientFactory _clientFactory; + + public ServiceRequestBuilder(IServiceConfiguration config, IFlurlClientFactory clientFactory) + { + _config = config; + _clientFactory = clientFactory; + } + + public IFlurlRequest Request(params object[] path) + { + var client = _clientFactory.Get(_config.BaseUrl); + return client.Request(new[] {"api", "v3"}.Concat(path).ToArray()) + .SetQueryParams(new {apikey = _config.ApiKey}); + } + + public string SanitizedBaseUrl => FlurlLogging.SanitizeUrl(_config.BaseUrl); +} diff --git a/src/TrashLib/Http/FlurlClientFactory.cs b/src/TrashLib/Http/FlurlClientFactory.cs new file mode 100644 index 00000000..8e2edf4d --- /dev/null +++ b/src/TrashLib/Http/FlurlClientFactory.cs @@ -0,0 +1,55 @@ +using Common.Networking; +using Flurl.Http; +using Flurl.Http.Configuration; +using Newtonsoft.Json; +using Serilog; +using TrashLib.Config.Settings; + +namespace TrashLib.Http; + +public class FlurlClientFactory : IFlurlClientFactory +{ + private readonly ILogger _log; + private readonly ISettingsProvider _settingsProvider; + private readonly PerBaseUrlFlurlClientFactory _factory; + + public FlurlClientFactory(ILogger log, ISettingsProvider settingsProvider) + { + _log = log; + _settingsProvider = settingsProvider; + _factory = new PerBaseUrlFlurlClientFactory(); + } + + public IFlurlClient Get(string baseUrl) + { + var client = _factory.Get(baseUrl); + client.Settings = GetClientSettings(); + return client; + } + + private ClientFlurlHttpSettings GetClientSettings() + { + var settings = new ClientFlurlHttpSettings + { + JsonSerializer = new NewtonsoftJsonSerializer(new JsonSerializerSettings + { + // This makes sure that null properties, such as maxSize and preferredSize in Radarr + // Quality Definitions, do not get written out to JSON request bodies. + NullValueHandling = NullValueHandling.Ignore + }) + }; + + FlurlLogging.SetupLogging(settings, _log); + + // ReSharper disable once InvertIf + if (!_settingsProvider.Settings.EnableSslCertificateValidation) + { + _log.Warning( + "Security Risk: Certificate validation is being DISABLED because setting " + + "`enable_ssl_certificate_validation` is set to `false`"); + settings.HttpClientFactory = new UntrustedCertClientFactory(); + } + + return settings; + } +} diff --git a/src/TrashLib/Extensions/FlurlExtensions.cs b/src/TrashLib/Http/FlurlExtensions.cs similarity index 93% rename from src/TrashLib/Extensions/FlurlExtensions.cs rename to src/TrashLib/Http/FlurlExtensions.cs index 6546c1bd..cf9b5126 100644 --- a/src/TrashLib/Extensions/FlurlExtensions.cs +++ b/src/TrashLib/Http/FlurlExtensions.cs @@ -1,7 +1,7 @@ using System.Text.RegularExpressions; using Flurl.Http; -namespace TrashLib.Extensions; +namespace TrashLib.Http; public static class FlurlExtensions { diff --git a/src/TrashLib/Extensions/FlurlLogging.cs b/src/TrashLib/Http/FlurlLogging.cs similarity index 98% rename from src/TrashLib/Extensions/FlurlLogging.cs rename to src/TrashLib/Http/FlurlLogging.cs index bdb34a52..eeb8d696 100644 --- a/src/TrashLib/Extensions/FlurlLogging.cs +++ b/src/TrashLib/Http/FlurlLogging.cs @@ -3,7 +3,7 @@ using Flurl.Http.Configuration; using Newtonsoft.Json; using Serilog; -namespace TrashLib.Extensions; +namespace TrashLib.Http; public static class FlurlLogging { diff --git a/src/TrashLib/Http/IFlurlClientFactory.cs b/src/TrashLib/Http/IFlurlClientFactory.cs new file mode 100644 index 00000000..21aebe13 --- /dev/null +++ b/src/TrashLib/Http/IFlurlClientFactory.cs @@ -0,0 +1,8 @@ +using Flurl.Http; + +namespace TrashLib.Http; + +public interface IFlurlClientFactory +{ + IFlurlClient Get(string baseUrl); +} diff --git a/src/TrashLib/Services/CustomFormat/Api/CustomFormatService.cs b/src/TrashLib/Services/CustomFormat/Api/CustomFormatService.cs index 7d619dc1..953e4d44 100644 --- a/src/TrashLib/Services/CustomFormat/Api/CustomFormatService.cs +++ b/src/TrashLib/Services/CustomFormat/Api/CustomFormatService.cs @@ -1,4 +1,3 @@ -using Flurl; using Flurl.Http; using Newtonsoft.Json.Linq; using TrashLib.Config.Services; @@ -8,24 +7,22 @@ namespace TrashLib.Services.CustomFormat.Api; internal class CustomFormatService : ICustomFormatService { - private readonly IServerInfo _serverInfo; + private readonly IServiceRequestBuilder _service; - public CustomFormatService(IServerInfo serverInfo) + public CustomFormatService(IServiceRequestBuilder service) { - _serverInfo = serverInfo; + _service = service; } public async Task> GetCustomFormats() { - return await BuildRequest() - .AppendPathSegment("customformat") + return await _service.Request("customformat") .GetJsonAsync>(); } public async Task CreateCustomFormat(ProcessedCustomFormatData cf) { - var response = await BuildRequest() - .AppendPathSegment("customformat") + var response = await _service.Request("customformat") .PostJsonAsync(cf.Json) .ReceiveJson(); @@ -37,18 +34,14 @@ internal class CustomFormatService : ICustomFormatService public async Task UpdateCustomFormat(ProcessedCustomFormatData cf) { - await BuildRequest() - .AppendPathSegment($"customformat/{cf.GetCustomFormatId()}") + await _service.Request("customformat", cf.GetCustomFormatId()) .PutJsonAsync(cf.Json) .ReceiveJson(); } public async Task DeleteCustomFormat(int customFormatId) { - await BuildRequest() - .AppendPathSegment($"customformat/{customFormatId}") + await _service.Request("customformat", customFormatId) .DeleteAsync(); } - - private Url BuildRequest() => _serverInfo.BuildRequest(); } diff --git a/src/TrashLib/Services/CustomFormat/Api/QualityProfileService.cs b/src/TrashLib/Services/CustomFormat/Api/QualityProfileService.cs index 31a4f3ff..f1cbb7d6 100644 --- a/src/TrashLib/Services/CustomFormat/Api/QualityProfileService.cs +++ b/src/TrashLib/Services/CustomFormat/Api/QualityProfileService.cs @@ -1,4 +1,3 @@ -using Flurl; using Flurl.Http; using Newtonsoft.Json.Linq; using TrashLib.Config.Services; @@ -7,27 +6,23 @@ namespace TrashLib.Services.CustomFormat.Api; internal class QualityProfileService : IQualityProfileService { - private readonly IServerInfo _serverInfo; + private readonly IServiceRequestBuilder _service; - public QualityProfileService(IServerInfo serverInfo) + public QualityProfileService(IServiceRequestBuilder service) { - _serverInfo = serverInfo; + _service = service; } public async Task> GetQualityProfiles() { - return await BuildRequest() - .AppendPathSegment("qualityprofile") + return await _service.Request("qualityprofile") .GetJsonAsync>(); } public async Task UpdateQualityProfile(JObject profileJson, int id) { - return await BuildRequest() - .AppendPathSegment($"qualityprofile/{id}") + return await _service.Request("qualityprofile", id) .PutJsonAsync(profileJson) .ReceiveJson(); } - - private Url BuildRequest() => _serverInfo.BuildRequest(); } diff --git a/src/TrashLib/Services/CustomFormat/CustomFormatUpdater.cs b/src/TrashLib/Services/CustomFormat/CustomFormatUpdater.cs index 22af038e..20c5c47f 100644 --- a/src/TrashLib/Services/CustomFormat/CustomFormatUpdater.cs +++ b/src/TrashLib/Services/CustomFormat/CustomFormatUpdater.cs @@ -14,7 +14,7 @@ internal class CustomFormatUpdater : ICustomFormatUpdater private readonly IGuideProcessor _guideProcessor; private readonly IPersistenceProcessor _persistenceProcessor; private readonly IConsole _console; - private readonly IServerInfo _serverInfo; + private readonly IServiceRequestBuilder _service; private readonly ILogger _log; public CustomFormatUpdater( @@ -23,14 +23,14 @@ internal class CustomFormatUpdater : ICustomFormatUpdater IGuideProcessor guideProcessor, IPersistenceProcessor persistenceProcessor, IConsole console, - IServerInfo serverInfo) + IServiceRequestBuilder service) { _log = log; _cache = cache; _guideProcessor = guideProcessor; _persistenceProcessor = persistenceProcessor; _console = console; - _serverInfo = serverInfo; + _service = service; } public async Task Process(bool isPreview, IEnumerable configs, IGuideService guideService) @@ -141,8 +141,8 @@ internal class CustomFormatUpdater : ICustomFormatUpdater if (_guideProcessor.CustomFormatsNotInGuide.Count > 0) { _log.Warning("The Custom Formats below do not exist in the guide and will " + - "be skipped. Trash IDs must match what is listed in the output when using the " + - "`--list-custom-formats` option"); + "be skipped. Trash IDs must match what is listed in the output when using the " + + "`--list-custom-formats` option"); _log.Warning("{CfList}", _guideProcessor.CustomFormatsNotInGuide); _console.Output.WriteLine(""); @@ -165,7 +165,7 @@ internal class CustomFormatUpdater : ICustomFormatUpdater if (_guideProcessor.ConfigData.Count == 0) { _log.Error("Guide processing yielded no custom formats for configured instance host {BaseUrl}", - _serverInfo.SanitizedBaseUrl); + _service.SanitizedBaseUrl); return false; } diff --git a/src/TrashLib/Services/Radarr/QualityDefinition/Api/QualityDefinitionService.cs b/src/TrashLib/Services/Radarr/QualityDefinition/Api/QualityDefinitionService.cs index e688090b..6a89dd0b 100644 --- a/src/TrashLib/Services/Radarr/QualityDefinition/Api/QualityDefinitionService.cs +++ b/src/TrashLib/Services/Radarr/QualityDefinition/Api/QualityDefinitionService.cs @@ -1,4 +1,3 @@ -using Flurl; using Flurl.Http; using TrashLib.Config.Services; using TrashLib.Services.Radarr.QualityDefinition.Api.Objects; @@ -7,28 +6,24 @@ namespace TrashLib.Services.Radarr.QualityDefinition.Api; internal class QualityDefinitionService : IQualityDefinitionService { - private readonly IServerInfo _serverInfo; + private readonly IServiceRequestBuilder _service; - public QualityDefinitionService(IServerInfo serverInfo) + public QualityDefinitionService(IServiceRequestBuilder service) { - _serverInfo = serverInfo; + _service = service; } public async Task> GetQualityDefinition() { - return await BuildRequest() - .AppendPathSegment("qualitydefinition") + return await _service.Request("qualitydefinition") .GetJsonAsync>(); } public async Task> UpdateQualityDefinition( IList newQuality) { - return await BuildRequest() - .AppendPathSegment("qualityDefinition/update") + return await _service.Request("qualityDefinition", "update") .PutJsonAsync(newQuality) .ReceiveJson>(); } - - private Url BuildRequest() => _serverInfo.BuildRequest(); } diff --git a/src/TrashLib/Services/Sonarr/Api/ReleaseProfileApiService.cs b/src/TrashLib/Services/Sonarr/Api/ReleaseProfileApiService.cs index d402cbf6..26a3d276 100644 --- a/src/TrashLib/Services/Sonarr/Api/ReleaseProfileApiService.cs +++ b/src/TrashLib/Services/Sonarr/Api/ReleaseProfileApiService.cs @@ -8,21 +8,20 @@ namespace TrashLib.Services.Sonarr.Api; public class ReleaseProfileApiService : IReleaseProfileApiService { private readonly ISonarrReleaseProfileCompatibilityHandler _profileHandler; - private readonly IServerInfo _serverInfo; + private readonly IServiceRequestBuilder _service; public ReleaseProfileApiService( ISonarrReleaseProfileCompatibilityHandler profileHandler, - IServerInfo serverInfo) + IServiceRequestBuilder service) { _profileHandler = profileHandler; - _serverInfo = serverInfo; + _service = service; } public async Task UpdateReleaseProfile(SonarrReleaseProfile profile) { var profileToSend = await _profileHandler.CompatibleReleaseProfileForSendingAsync(profile); - await _serverInfo.BuildRequest() - .AppendPathSegment($"releaseprofile/{profile.Id}") + await _service.Request("releaseprofile", profile.Id) .PutJsonAsync(profileToSend); } @@ -30,8 +29,7 @@ public class ReleaseProfileApiService : IReleaseProfileApiService { var profileToSend = await _profileHandler.CompatibleReleaseProfileForSendingAsync(profile); - var response = await _serverInfo.BuildRequest() - .AppendPathSegment("releaseprofile") + var response = await _service.Request("releaseprofile") .PostJsonAsync(profileToSend) .ReceiveJson(); @@ -40,8 +38,7 @@ public class ReleaseProfileApiService : IReleaseProfileApiService public async Task> GetReleaseProfiles() { - var response = await _serverInfo.BuildRequest() - .AppendPathSegment("releaseprofile") + var response = await _service.Request("releaseprofile") .GetJsonAsync>(); return response @@ -51,8 +48,7 @@ public class ReleaseProfileApiService : IReleaseProfileApiService public async Task DeleteReleaseProfile(int releaseProfileId) { - await _serverInfo.BuildRequest() - .AppendPathSegment($"releaseprofile/{releaseProfileId}") + await _service.Request("releaseprofile", releaseProfileId) .DeleteAsync(); } } diff --git a/src/TrashLib/Services/Sonarr/Api/SonarrApi.cs b/src/TrashLib/Services/Sonarr/Api/SonarrApi.cs index df1e270a..371faca5 100644 --- a/src/TrashLib/Services/Sonarr/Api/SonarrApi.cs +++ b/src/TrashLib/Services/Sonarr/Api/SonarrApi.cs @@ -1,4 +1,3 @@ -using Flurl; using Flurl.Http; using TrashLib.Config.Services; using TrashLib.Services.Sonarr.Api.Objects; @@ -7,43 +6,37 @@ namespace TrashLib.Services.Sonarr.Api; public class SonarrApi : ISonarrApi { - private readonly IServerInfo _serverInfo; + private readonly IServiceRequestBuilder _service; - public SonarrApi(IServerInfo serverInfo) + public SonarrApi(IServiceRequestBuilder service) { - _serverInfo = serverInfo; + _service = service; } public async Task> GetTags() { - return await BaseUrl() - .AppendPathSegment("tag") + return await _service.Request("tag") .GetJsonAsync>(); } public async Task CreateTag(string tag) { - return await BaseUrl() - .AppendPathSegment("tag") + return await _service.Request("tag") .PostJsonAsync(new {label = tag}) .ReceiveJson(); } public async Task> GetQualityDefinition() { - return await BaseUrl() - .AppendPathSegment("qualitydefinition") + return await _service.Request("qualitydefinition") .GetJsonAsync>(); } public async Task> UpdateQualityDefinition( IReadOnlyCollection newQuality) { - return await BaseUrl() - .AppendPathSegment("qualityDefinition/update") + return await _service.Request("qualityDefinition", "update") .PutJsonAsync(newQuality) .ReceiveJson>(); } - - private Url BaseUrl() => _serverInfo.BuildRequest(); } diff --git a/src/TrashLib/Services/System/SystemApiService.cs b/src/TrashLib/Services/System/SystemApiService.cs index 78ae3449..7d71da6e 100644 --- a/src/TrashLib/Services/System/SystemApiService.cs +++ b/src/TrashLib/Services/System/SystemApiService.cs @@ -1,4 +1,3 @@ -using Flurl; using Flurl.Http; using TrashLib.Config.Services; using TrashLib.Services.System.Dto; @@ -7,19 +6,16 @@ namespace TrashLib.Services.System; public class SystemApiService : ISystemApiService { - private readonly IServerInfo _serverInfo; + private readonly IServiceRequestBuilder _service; - public SystemApiService(IServerInfo serverInfo) + public SystemApiService(IServiceRequestBuilder service) { - _serverInfo = serverInfo; + _service = service; } public async Task GetStatus() { - return await BaseUrl() - .AppendPathSegment("system/status") + return await _service.Request("system", "status") .GetJsonAsync(); } - - private Url BaseUrl() => _serverInfo.BuildRequest(); }