From 5db3fc8eee0c8ec725712ac64d9ff06291174d62 Mon Sep 17 00:00:00 2001 From: Andriy <30056636+West14@users.noreply.github.com> Date: Thu, 5 Jan 2023 02:09:53 +0200 Subject: [PATCH] [store] add red pandas, rename incorrectly named file --- modules/ContentStore/ContentStore.csproj | 1 - .../Model/{CatImage.cs => AnimalImage.cs} | 0 .../ContentStore/Model/RedPandaResponse.cs | 7 +++++ .../ContentStore/Service/RedPandaService.cs | 28 +++++++++++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) rename modules/ContentStore/Model/{CatImage.cs => AnimalImage.cs} (100%) create mode 100644 modules/ContentStore/Model/RedPandaResponse.cs create mode 100644 modules/ContentStore/Service/RedPandaService.cs 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