piwigodotnet/PiwigoDotnet/Piwigo.Client/CategoryApi.cs

26 lines
1.0 KiB
C#
Raw Normal View History

using System.Collections.ObjectModel;
using Flurl.Http;
using Microsoft.Extensions.Logging;
using Piwigo.Client.Contract;
namespace Piwigo.Client;
public class CategoryApi : ICategoryApi
{
private readonly IPiwigoContext _context;
private readonly ILogger<CategoryApi> _logger;
public CategoryApi(IPiwigoContext context, ILogger<CategoryApi> logger)
{
_context = context ?? throw new ArgumentNullException(nameof(context));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
public async Task<IReadOnlyCollection<PiwigoCategory>> GetAllCategoriesAsync()
{
_logger.LogInformation("Getting all existing categories from server");
var response = await _context.ConfigureRequest(_logger).PostMultipartAsync(c => c.AddMethod("pwg.categories.getList").AddString("recursive", "true"));
var typedResponse = await response.GetJsonAsync<PiwigoResponse<PiwigoCategoryList>>();
return new ReadOnlyCollection<PiwigoCategory>(typedResponse.Result.Categories);
}
}