Show champs ingame
This commit is contained in:
+17
-3
@@ -24,6 +24,8 @@ public class APIClient : IDisposable
|
||||
|
||||
private readonly Dictionary<string, ChampionResponse> _championResponseCache = [];
|
||||
|
||||
private readonly CachingHttpClient _ddragonClient = new();
|
||||
|
||||
public APIClient()
|
||||
{
|
||||
_lcuHttpClient = new(new LcuHttpClientHandler());
|
||||
@@ -81,12 +83,12 @@ public class APIClient : IDisposable
|
||||
}
|
||||
|
||||
#region DDragon
|
||||
private static async Task<string> DDragonGetAsync(string path)
|
||||
private async Task<string> DDragonGetAsync(string path)
|
||||
{
|
||||
return await CachingHttpClient.GetStringAsync($"{DDRAGON_BASE_URL}{path}");
|
||||
return await _ddragonClient.GetStringAsync($"{DDRAGON_BASE_URL}{path}");
|
||||
}
|
||||
|
||||
private static async Task<T?> DDragonGetAsync<T>(string path)
|
||||
private async Task<T?> DDragonGetAsync<T>(string path)
|
||||
{
|
||||
string json = await DDragonGetAsync(path);
|
||||
return JsonSerializer.Deserialize<T>(json);
|
||||
@@ -135,6 +137,17 @@ public class APIClient : IDisposable
|
||||
|
||||
return championData.FirstOrDefault(c => c.Id == id);
|
||||
}
|
||||
|
||||
public async Task<int> GetChampionIdByNameAsync(string name)
|
||||
{
|
||||
ChampionData[] championData = await GetAllChampionsAsync();
|
||||
if (championData is not { Length: > 0 })
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return championData.FirstOrDefault(c => c.Name == name)?.Id ?? -1;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region IDisposable
|
||||
@@ -145,6 +158,7 @@ public class APIClient : IDisposable
|
||||
if (disposing)
|
||||
{
|
||||
_lcuHttpClient?.Dispose();
|
||||
_ddragonClient?.Dispose();
|
||||
}
|
||||
_championResponseCache?.Clear();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user