You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
recyclarr/src/Recyclarr.TrashLib/Services/CustomFormat/Api/CustomFormatService.cs

48 lines
1.3 KiB

using Flurl.Http;
using Newtonsoft.Json.Linq;
using Recyclarr.TrashLib.Config.Services;
using Recyclarr.TrashLib.Services.CustomFormat.Models;
namespace Recyclarr.TrashLib.Services.CustomFormat.Api;
internal class CustomFormatService : ICustomFormatService
{
private readonly IServiceRequestBuilder _service;
public CustomFormatService(IServiceRequestBuilder service)
{
_service = service;
}
public async Task<List<JObject>> GetCustomFormats()
{
return await _service.Request("customformat")
.GetJsonAsync<List<JObject>>();
}
public async Task CreateCustomFormat(ProcessedCustomFormatData cf)
{
var response = await _service.Request("customformat")
.PostJsonAsync(cf.Json)
.ReceiveJson<JObject>();
if (response != null)
{
cf.FormatId = response.Value<int>("id");
}
}
public async Task UpdateCustomFormat(ProcessedCustomFormatData cf)
{
await _service.Request("customformat", cf.FormatId)
.PutJsonAsync(cf.Json)
.ReceiveJson<JObject>();
}
public async Task DeleteCustomFormat(int customFormatId)
{
await _service.Request("customformat", customFormatId)
.DeleteAsync();
}
}