Add project files.
This commit is contained in:
42
LeagueAPI/Utils/LcuHttpClient.cs
Normal file
42
LeagueAPI/Utils/LcuHttpClient.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace LeagueAPI.Utils;
|
||||
|
||||
public class LcuHttpClient : HttpClient
|
||||
{
|
||||
private static readonly Lazy<LcuHttpClient> LazyInstance = new(() => new LcuHttpClient(new LcuHttpClientHandler()));
|
||||
internal static LcuHttpClient Instance => LazyInstance.Value;
|
||||
|
||||
private LcuHttpClientHandler Handler { get; }
|
||||
public ProcessInfo? ProcessInfo
|
||||
{
|
||||
get
|
||||
{
|
||||
return Handler.ProcessInfo;
|
||||
}
|
||||
internal set
|
||||
{
|
||||
Handler.ProcessInfo = value;
|
||||
}
|
||||
}
|
||||
|
||||
public RiotAuthentication? RiotAuthentication => Handler.RiotAuthentication;
|
||||
|
||||
internal LcuHttpClient(LcuHttpClientHandler lcuHttpClientHandler)
|
||||
: base(lcuHttpClientHandler)
|
||||
{
|
||||
Handler = lcuHttpClientHandler;
|
||||
base.BaseAddress = new Uri("https://127.0.0.1");
|
||||
}
|
||||
|
||||
public async Task<T?> GetContentAsync<T>(string requestUri) where T : class
|
||||
{
|
||||
HttpResponseMessage response = await GetAsync(requestUri);
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
string content = await response.Content.ReadAsStringAsync();
|
||||
return JsonSerializer.Deserialize<T>(content);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user