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.
48 lines
1.5 KiB
48 lines
1.5 KiB
using Flurl.Http;
|
|
|
|
namespace Recyclarr.ServarrApi.QualityProfile;
|
|
|
|
internal class QualityProfileApiService(IServarrRequestBuilder service) : IQualityProfileApiService
|
|
{
|
|
private IFlurlRequest Request(params object[] path)
|
|
{
|
|
return service.Request(["qualityprofile", ..path]);
|
|
}
|
|
|
|
public async Task<IList<QualityProfileDto>> GetQualityProfiles(CancellationToken ct)
|
|
{
|
|
var response = await Request()
|
|
.GetJsonAsync<IList<QualityProfileDto>>(cancellationToken: ct);
|
|
|
|
return response.Select(x => x.ReverseItems()).ToList();
|
|
}
|
|
|
|
public async Task<QualityProfileDto> GetSchema(CancellationToken ct)
|
|
{
|
|
var response = await Request("schema")
|
|
.GetJsonAsync<QualityProfileDto>(cancellationToken: ct);
|
|
|
|
return response.ReverseItems();
|
|
}
|
|
|
|
public async Task UpdateQualityProfile(QualityProfileDto profile, CancellationToken ct)
|
|
{
|
|
if (profile.Id is null)
|
|
{
|
|
throw new ArgumentException($"Profile's ID property must not be null: {profile.Name}");
|
|
}
|
|
|
|
await Request(profile.Id)
|
|
.PutJsonAsync(profile.ReverseItems(), cancellationToken: ct);
|
|
}
|
|
|
|
public async Task CreateQualityProfile(QualityProfileDto profile, CancellationToken ct)
|
|
{
|
|
var response = await Request()
|
|
.PostJsonAsync(profile.ReverseItems(), cancellationToken: ct)
|
|
.ReceiveJson<QualityProfileDto>();
|
|
|
|
profile.Id = response.Id;
|
|
}
|
|
}
|