diff --git a/modules/ContentStore/ContentStore.csproj b/modules/ContentStore/ContentStore.csproj index c76005f..d2e1a4f 100644 --- a/modules/ContentStore/ContentStore.csproj +++ b/modules/ContentStore/ContentStore.csproj @@ -14,7 +14,6 @@ - diff --git a/modules/ContentStore/Model/CatImage.cs b/modules/ContentStore/Model/AnimalImage.cs similarity index 100% rename from modules/ContentStore/Model/CatImage.cs rename to modules/ContentStore/Model/AnimalImage.cs diff --git a/modules/ContentStore/Model/RedPandaResponse.cs b/modules/ContentStore/Model/RedPandaResponse.cs new file mode 100644 index 0000000..bf61c02 --- /dev/null +++ b/modules/ContentStore/Model/RedPandaResponse.cs @@ -0,0 +1,7 @@ +namespace West.TelegramBot.ContentStore.Model; + +public class RedPandaResponse +{ + public string Image { get; set; } = null!; + public string Fact { get; set; } = null!; +} \ No newline at end of file diff --git a/modules/ContentStore/Service/RedPandaService.cs b/modules/ContentStore/Service/RedPandaService.cs new file mode 100644 index 0000000..a1b8de5 --- /dev/null +++ b/modules/ContentStore/Service/RedPandaService.cs @@ -0,0 +1,28 @@ +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 GetRandomMediaAsync() + { + var response = await _httpClient.GetStringAsync("https://some-random-api.ml/animal/red_panda"); + + var image = JsonConvert.DeserializeObject(response); + + return new RandomMedia(new InputFileUrl(image.Image), image.Fact); + } +} \ No newline at end of file