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.
56 lines
1.5 KiB
56 lines
1.5 KiB
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using Flurl.Http;
|
|
using Newtonsoft.Json.Linq;
|
|
using TrashLib.Config.Services;
|
|
using TrashLib.Radarr.CustomFormat.Models;
|
|
|
|
namespace TrashLib.Radarr.CustomFormat.Api;
|
|
|
|
internal class CustomFormatService : ICustomFormatService
|
|
{
|
|
private readonly IServerInfo _serverInfo;
|
|
|
|
public CustomFormatService(IServerInfo serverInfo)
|
|
{
|
|
_serverInfo = serverInfo;
|
|
}
|
|
|
|
public async Task<List<JObject>> GetCustomFormats()
|
|
{
|
|
return await BuildRequest()
|
|
.AppendPathSegment("customformat")
|
|
.GetJsonAsync<List<JObject>>();
|
|
}
|
|
|
|
public async Task CreateCustomFormat(ProcessedCustomFormatData cf)
|
|
{
|
|
var response = await BuildRequest()
|
|
.AppendPathSegment("customformat")
|
|
.PostJsonAsync(cf.Json)
|
|
.ReceiveJson<JObject>();
|
|
|
|
if (response != null)
|
|
{
|
|
cf.SetCache(response.Value<int>("id"));
|
|
}
|
|
}
|
|
|
|
public async Task UpdateCustomFormat(ProcessedCustomFormatData cf)
|
|
{
|
|
await BuildRequest()
|
|
.AppendPathSegment($"customformat/{cf.GetCustomFormatId()}")
|
|
.PutJsonAsync(cf.Json)
|
|
.ReceiveJson<JObject>();
|
|
}
|
|
|
|
public async Task DeleteCustomFormat(int customFormatId)
|
|
{
|
|
await BuildRequest()
|
|
.AppendPathSegment($"customformat/{customFormatId}")
|
|
.DeleteAsync();
|
|
}
|
|
|
|
private IFlurlRequest BuildRequest() => _serverInfo.BuildRequest();
|
|
}
|