Files
telegram-bot/modules/ContentStore/Service/AnimalAsAService.cs
2023-01-02 20:13:41 +02:00

27 lines
778 B
C#

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