diff --git a/OwnChar/Api/OwnCharApiClient.cs b/OwnChar/Api/OwnCharApiClient.cs index aa851fb..8052a4f 100644 --- a/OwnChar/Api/OwnCharApiClient.cs +++ b/OwnChar/Api/OwnCharApiClient.cs @@ -1,29 +1,25 @@ -using Newtonsoft.Json; -using OwnChar.Api.Clients; +using OwnChar.Api.Clients; using OwnChar.Api.Exceptions; using OwnChar.Api.Packets; -using System.Net.Http.Headers; -using System.Net.Http.Json; +using Pilz.Cryptography; +using Pilz.Net.Api; namespace OwnChar.Api; -public class OwnCharApiClient +public class OwnCharApiClient : ApiClient { - private readonly HttpClient httpClient = new(); private readonly Dictionary clients = []; internal string? AuthSecret { get; set; } = null; public bool IsLoggedIn => AuthSecret != null; - public string ApiUrl { get; } public LoginApiClient Auth { get; } public UsersApiClient Users { get; } public CharactersApiClient Characters { get; } public GroupsApiClient Groups { get; } - public OwnCharApiClient(string apiUrl) + public OwnCharApiClient(string apiUrl) : base(apiUrl) { - this.ApiUrl = apiUrl; Auth = GetClient(); Users = GetClient(); Characters = GetClient(); @@ -46,24 +42,8 @@ public class OwnCharApiClient throw new Exception("Client could not be created!"); } - public async Task MakeRequest(string requestUrl, TRequest request) where TRequest : OwnCharRequest where TResponse : OwnCharResponse + protected override string? EncodeAuthKey() { - if (await TryMakeRequest(requestUrl, request) is TResponse response) - return response; - throw new ApiException(string.Format("The API request to \"{0}\" failed!", requestUrl)); - } - - public async Task TryMakeRequest(string requestUrl, TRequest request) where TRequest : OwnCharRequest where TResponse : OwnCharResponse - { - request.AuthSecret = AuthSecret; - - var fullRequestUrl = ApiUrl + requestUrl; - var content = new StringContent(JsonHelpers.SerializeRequest(request)!, null, "application/json"); - var res = await httpClient.PostAsync(fullRequestUrl, content); - - if (res.IsSuccessStatusCode) - return JsonHelpers.DeserializeResponse(await res.Content.ReadAsStringAsync()); - - return null; + return new SecureString(base.EncodeAuthKey(), false); } } diff --git a/OwnChar/OwnChar.csproj b/OwnChar/OwnChar.csproj index d240d82..37117cc 100644 --- a/OwnChar/OwnChar.csproj +++ b/OwnChar/OwnChar.csproj @@ -7,11 +7,12 @@ - - - - - + + + + + +