2024-03-12 18:05:27 +00:00
|
|
|
using TwitchChatTTS.Helpers;
|
|
|
|
using TwitchChatTTS;
|
|
|
|
using System.Text.Json;
|
2024-06-17 00:19:31 +00:00
|
|
|
using TwitchChatTTS.Hermes;
|
2024-08-04 23:46:10 +00:00
|
|
|
using Serilog;
|
2023-12-30 09:27:31 +00:00
|
|
|
|
2024-06-17 00:19:31 +00:00
|
|
|
public class HermesApiClient
|
|
|
|
{
|
2024-06-24 22:11:36 +00:00
|
|
|
private readonly WebClientWrap _web;
|
2024-08-04 23:46:10 +00:00
|
|
|
private readonly ILogger _logger;
|
2024-08-06 19:29:29 +00:00
|
|
|
|
2024-07-12 17:36:09 +00:00
|
|
|
public const string BASE_URL = "tomtospeech.com";
|
2023-12-30 09:27:31 +00:00
|
|
|
|
2024-08-14 18:19:18 +00:00
|
|
|
public HermesApiClient(Configuration configuration, ILogger logger)
|
2024-06-17 00:19:31 +00:00
|
|
|
{
|
|
|
|
if (string.IsNullOrWhiteSpace(configuration.Hermes?.Token))
|
|
|
|
{
|
2023-12-30 09:27:31 +00:00
|
|
|
throw new Exception("Ensure you have written your API key in \".token\" file, in the same folder as this application.");
|
|
|
|
}
|
|
|
|
|
2024-06-17 00:19:31 +00:00
|
|
|
_web = new WebClientWrap(new JsonSerializerOptions()
|
|
|
|
{
|
2024-03-12 18:05:27 +00:00
|
|
|
PropertyNameCaseInsensitive = false,
|
|
|
|
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower
|
|
|
|
});
|
2024-03-15 12:27:35 +00:00
|
|
|
_web.AddHeader("x-api-key", configuration.Hermes.Token);
|
2024-08-04 23:46:10 +00:00
|
|
|
_logger = logger;
|
|
|
|
}
|
|
|
|
|
2024-07-12 17:36:09 +00:00
|
|
|
public async Task<TTSVersion?> GetLatestTTSVersion()
|
2024-06-17 00:19:31 +00:00
|
|
|
{
|
2024-07-12 17:36:09 +00:00
|
|
|
return await _web.GetJson<TTSVersion>($"https://{BASE_URL}/api/info/version");
|
2024-06-17 00:19:31 +00:00
|
|
|
}
|
2023-12-30 09:27:31 +00:00
|
|
|
}
|