[store] kitties now have own http client factory

This commit is contained in:
Andriy
2023-07-28 22:44:51 +03:00
parent 462f3c9836
commit c19696b360
8 changed files with 79 additions and 30 deletions
+28
View File
@@ -0,0 +1,28 @@
using System.Text;
using West.TelegramBot.ContentStore.Model;
namespace West.TelegramBot.ContentStore.API;
public class KittiesApi : IKittiesApi
{
private readonly HttpClient _client;
public KittiesApi(HttpClient client)
{
_client = client;
}
public async Task<KittiesResponse> GetKittiesImageAsync(string type)
{
var httpResponse = await _client.GetAsync($"v1/{type}");
var headers = httpResponse.Headers;
var titleBytes =
Convert.FromBase64String(headers.GetValues("X-Video-Title").First());
return new KittiesResponse(
await httpResponse.Content.ReadAsStreamAsync(),
headers.GetValues("X-Video-Source").First(),
Encoding.UTF8.GetString(titleBytes)
);
}
}