more work on api
This commit is contained in:
@@ -14,7 +14,17 @@ public class ApiClient(string apiUrl) : IApiClient
|
||||
|
||||
public ILogger Log { get; set; } = NullLogger.Instance;
|
||||
|
||||
public virtual async Task<ApiResponse> SendMessage<TResponse>(string route, ApiMessage message, IMessageSerializer? serializer = null)
|
||||
public virtual Task<ApiResponse> SendRequest(string route)
|
||||
{
|
||||
return SendRequest(route, null);
|
||||
}
|
||||
|
||||
public virtual Task<ApiResponse> SendRequest(string route, ApiMessage? message)
|
||||
{
|
||||
return SendRequest(route, message, null);
|
||||
}
|
||||
|
||||
public virtual async Task<ApiResponse> SendRequest(string route, ApiMessage? message, IMessageSerializer? serializer)
|
||||
{
|
||||
serializer ??= Serializer;
|
||||
|
||||
@@ -25,7 +35,17 @@ public class ApiClient(string apiUrl) : IApiClient
|
||||
return new(res.StatusCode);
|
||||
}
|
||||
|
||||
public virtual async Task<ApiResponse<TResponse>> SendRequest<TResponse>(string route, ApiMessage message, IMessageSerializer? serializer = null) where TResponse : ApiMessage
|
||||
public virtual Task<ApiResponse<TResponse>> SendRequest<TResponse>(string route) where TResponse : ApiMessage
|
||||
{
|
||||
return SendRequest<TResponse>(route, null);
|
||||
}
|
||||
|
||||
public virtual Task<ApiResponse<TResponse>> SendRequest<TResponse>(string route, ApiMessage? message) where TResponse : ApiMessage
|
||||
{
|
||||
return SendRequest<TResponse>(route, message, null);
|
||||
}
|
||||
|
||||
public virtual async Task<ApiResponse<TResponse>> SendRequest<TResponse>(string route, ApiMessage? message, IMessageSerializer? serializer) where TResponse : ApiMessage
|
||||
{
|
||||
serializer ??= Serializer;
|
||||
|
||||
@@ -40,11 +60,18 @@ public class ApiClient(string apiUrl) : IApiClient
|
||||
return new(res.StatusCode, result);
|
||||
}
|
||||
|
||||
protected virtual async Task<HttpResponseMessage> Send(string route, ApiMessage message, IMessageSerializer serializer)
|
||||
protected virtual async Task<HttpResponseMessage> Send(string route, ApiMessage? message, IMessageSerializer serializer)
|
||||
{
|
||||
var url = ApiUrl + route;
|
||||
var content = new StringContent(serializer.Serialize(message)!, null, "application/json");
|
||||
HttpContent content;
|
||||
|
||||
if (message is not null)
|
||||
content = new StringContent(serializer.Serialize(message)!, null, "application/json");
|
||||
else
|
||||
content = new StringContent(string.Empty, null, "application/json");
|
||||
|
||||
content.Headers.Add("API-AUTH-KEY", EncodeAuthKey());
|
||||
|
||||
return await httpClient.PostAsync(url, content);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user