using System; using System.Collections.Generic; using System.Threading.Tasks; using Flurl; using Flurl.Http; using Trash.Config; using Trash.Sonarr.Api.Objects; namespace Trash.Sonarr.Api { public class SonarrApi : ISonarrApi { private readonly IConfigurationProvider _configProvider; public SonarrApi(IConfigurationProvider configProvider) { _configProvider = configProvider; } public async Task GetVersion() { dynamic data = await BaseUrl() .AppendPathSegment("system/status") .GetJsonAsync(); return new Version(data.version); } public async Task> GetTags() { return await BaseUrl() .AppendPathSegment("tag") .GetJsonAsync>(); } public async Task CreateTag(string tag) { return await BaseUrl() .AppendPathSegment("tag") .PostJsonAsync(new {label = tag}) .ReceiveJson(); } public async Task> GetReleaseProfiles() { return await BaseUrl() .AppendPathSegment("releaseprofile") .GetJsonAsync>(); } public async Task UpdateReleaseProfile(SonarrReleaseProfile profileToUpdate) { await BaseUrl() .AppendPathSegment($"releaseprofile/{profileToUpdate.Id}") .PutJsonAsync(profileToUpdate); } public async Task CreateReleaseProfile(SonarrReleaseProfile newProfile) { return await BaseUrl() .AppendPathSegment("releaseprofile") .PostJsonAsync(newProfile) .ReceiveJson(); } public async Task> GetQualityDefinition() { return await BaseUrl() .AppendPathSegment("qualitydefinition") .GetJsonAsync>(); } public async Task> UpdateQualityDefinition( IReadOnlyCollection newQuality) { return await BaseUrl() .AppendPathSegment("qualityDefinition/update") .PutJsonAsync(newQuality) .ReceiveJson>(); } private string BaseUrl() => _configProvider.ActiveConfiguration.BuildUrl(); } }