Files
telegram-bot/modules/ContentStore/Service/AnimalAsAService.cs
T

26 lines
733 B
C#
Raw Normal View History

2022-02-16 17:07:30 +02:00
using Newtonsoft.Json;
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");
var catImage = JsonConvert.DeserializeObject<List<AnimalImage>>(await resp.Content.ReadAsStringAsync())[0];
return new RandomMedia(catImage.Url);
}
}