2023-01-05 02:09:53 +02:00
|
|
|
using System.Net.Http.Json;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using Telegram.Bot.Types;
|
|
|
|
|
using West.TelegramBot.ContentStore.Model;
|
|
|
|
|
|
|
|
|
|
namespace West.TelegramBot.ContentStore.Service;
|
|
|
|
|
|
|
|
|
|
public class RedPandaService : IRandomMediaService
|
|
|
|
|
{
|
|
|
|
|
public StoreItem StoreItem { get; } = new("red_panda", "Красная панда", 40, 150);
|
|
|
|
|
|
|
|
|
|
private readonly HttpClient _httpClient;
|
|
|
|
|
|
|
|
|
|
public RedPandaService()
|
|
|
|
|
{
|
|
|
|
|
// TODO: use factory or something, cause we have a lot of http clients in use
|
|
|
|
|
_httpClient = new HttpClient();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<RandomMedia> GetRandomMediaAsync()
|
|
|
|
|
{
|
2023-05-17 22:37:40 +03:00
|
|
|
var response = await _httpClient.GetStringAsync("https://some-random-api.com/animal/red_panda");
|
2023-01-05 02:09:53 +02:00
|
|
|
|
|
|
|
|
var image = JsonConvert.DeserializeObject<RedPandaResponse>(response);
|
|
|
|
|
|
|
|
|
|
return new RandomMedia(new InputFileUrl(image.Image), image.Fact);
|
|
|
|
|
}
|
2023-05-17 22:37:40 +03:00
|
|
|
}
|