using System.Collections.Generic; using System.Threading.Tasks; using Flurl; using Flurl.Http; using Newtonsoft.Json.Linq; using Trash.Config; using Trash.Radarr.CustomFormat.Models; namespace Trash.Radarr.CustomFormat.Api { internal class CustomFormatService : ICustomFormatService { private readonly IServiceConfiguration _serviceConfig; public CustomFormatService(IServiceConfiguration serviceConfig) { _serviceConfig = serviceConfig; } public async Task> GetCustomFormats() { return await BaseUrl() .AppendPathSegment("customformat") .GetJsonAsync>(); } public async Task CreateCustomFormat(ProcessedCustomFormatData cf) { var response = await BaseUrl() .AppendPathSegment("customformat") .PostJsonAsync(cf.Json) .ReceiveJson(); cf.SetCache((int) response["id"]); } public async Task UpdateCustomFormat(ProcessedCustomFormatData cf) { await BaseUrl() .AppendPathSegment($"customformat/{cf.GetCustomFormatId()}") .PutJsonAsync(cf.Json) .ReceiveJson(); } public async Task DeleteCustomFormat(int customFormatId) { await BaseUrl() .AppendPathSegment($"customformat/{customFormatId}") .DeleteAsync(); } private string BaseUrl() { return _serviceConfig.BuildUrl(); } } }