Files

27 lines
778 B
C#
Raw Permalink Normal View History

2022-02-16 17:07:30 +02:00
using Newtonsoft.Json;
2023-01-02 19:01:03 +02:00
using Telegram.Bot.Types;
2022-02-16 17:07:30 +02:00
using West.TelegramBot.ContentStore.Model;
namespace West.TelegramBot.ContentStore.Service;
public abstract class AnimalAsAService : IRandomMediaService
{
private readonly HttpClient _httpClient;
2022-02-16 18:08:02 +02:00
public abstract StoreItem StoreItem { get; }
2022-02-16 17:07:30 +02:00
protected AnimalAsAService(Uri baseAddress)
{
_httpClient = new HttpClient
{
BaseAddress = baseAddress
};
}
2022-02-16 18:08:02 +02:00
2022-02-16 17:07:30 +02:00
public async Task<RandomMedia> GetRandomMediaAsync()
{
var resp = await _httpClient.GetAsync("images/search");
2023-01-02 19:01:03 +02:00
var catImage = JsonConvert.DeserializeObject<List<AnimalImage>>(await resp.Content.ReadAsStringAsync())![0];
return new RandomMedia(new InputFileUrl(catImage.Url));
2022-02-16 17:07:30 +02:00
}
}