[core] client factory for SomeRandomApi

This commit is contained in:
Andriy
2023-07-28 23:13:56 +03:00
parent c19696b360
commit 42509dcacd
11 changed files with 62 additions and 18 deletions
@@ -0,0 +1,8 @@
using West.TelegramBot.ContentStore.Model;
namespace West.TelegramBot.ContentStore.API;
public interface ISomeRandomApi
{
public Task<SomeRandomApiAnimalResponse> GetAnimalAsync(string animalId);
}
+21
View File
@@ -0,0 +1,21 @@
using System.Net.Http.Json;
using West.TelegramBot.ContentStore.Model;
namespace West.TelegramBot.ContentStore.API;
public class SomeRandomApi : ISomeRandomApi
{
private readonly HttpClient _client;
public SomeRandomApi(HttpClient client)
{
_client = client;
}
public async Task<SomeRandomApiAnimalResponse> GetAnimalAsync(string animalId)
{
return (await _client.GetFromJsonAsync<SomeRandomApiAnimalResponse>(
$"animal/{animalId}"
))!;
}
}