A C# Wrapper for the Booru Image Boards.
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.
Booru.Net/Booru.Net/Clients/DanbooruClient.cs

45 lines
1.3 KiB

using Newtonsoft.Json;
using RestEase;
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
namespace Booru.Net
{
public class DanbooruClient : IPostsBooruClient<DanbooruImage>, IDisposable
{
IPostsBooruClient<DanbooruImage> _api;
public DanbooruClient()
{
var httpClient = new HttpClient
{
BaseAddress = new Uri("https://danbooru.donmai.us/")
};
httpClient.DefaultRequestHeaders.Add("User-Agent", $"Booru.Net/v{Props.LibraryVersion} (https://github.com/exsersewo/Booru.Net)");
JsonSerializerSettings settings = new JsonSerializerSettings
{
Formatting = Formatting.Indented,
NullValueHandling = NullValueHandling.Ignore
};
_api = new RestClient(httpClient)
{
JsonSerializerSettings = settings
}.For<IPostsBooruClient<DanbooruImage>>();
}
public Task<IReadOnlyList<DanbooruImage>> GetImagesAsync(IEnumerable<string> tags)
=> _api.GetImagesAsync(tags);
public Task<IReadOnlyList<DanbooruImage>> GetImagesAsync(params string[] tags)
=> _api.GetImagesAsync(tags);
public void Dispose()
{
_api.Dispose();
}
}
}