mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
29 lines
964 B
C#
29 lines
964 B
C#
using Newtonsoft.Json;
|
|
using Telegram.Bot.Types;
|
|
using West.TelegramBot.ContentStore.Model;
|
|
|
|
namespace West.TelegramBot.ContentStore.Service;
|
|
|
|
public abstract class SomeRandomApiAbstractService : IRandomMediaService
|
|
{
|
|
public StoreItem StoreItem { get; }
|
|
public string ApiId => StoreItem.Id;
|
|
|
|
private readonly HttpClient _httpClient;
|
|
|
|
public SomeRandomApiAbstractService(string id, string name, double price, int order)
|
|
{
|
|
StoreItem = new(id, name, price, order);
|
|
|
|
// TODO: use factory or something, cause we have a lot of http clients in use
|
|
_httpClient = new HttpClient();
|
|
}
|
|
|
|
public async Task<RandomMedia> GetRandomMediaAsync()
|
|
{
|
|
var response = await _httpClient.GetStringAsync($"https://some-random-api.com/animal/{ApiId}");
|
|
var image = JsonConvert.DeserializeObject<SomeRandomApiAnimalResponse>(response);
|
|
|
|
return new RandomMedia(new InputFileUrl(image.Image), image.Fact);
|
|
}
|
|
} |