2021-04-11 07:36:34 +02:00
|
|
|
#nullable enable
|
2020-03-13 11:47:22 +01:00
|
|
|
using System.Net.Http;
|
2020-03-12 14:59:24 +01:00
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using BTCPayServer.Client.Models;
|
|
|
|
|
|
|
|
namespace BTCPayServer.Client
|
|
|
|
{
|
|
|
|
public partial class BTCPayServerClient
|
|
|
|
{
|
|
|
|
public virtual async Task<ApplicationUserData> GetCurrentUser(CancellationToken token = default)
|
|
|
|
{
|
|
|
|
var response = await _httpClient.SendAsync(CreateHttpRequest("api/v1/users/me"), token);
|
|
|
|
return await HandleResponse<ApplicationUserData>(response);
|
|
|
|
}
|
2020-03-13 11:47:22 +01:00
|
|
|
|
|
|
|
public virtual async Task<ApplicationUserData> CreateUser(CreateApplicationUserRequest request,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
var response = await _httpClient.SendAsync(CreateHttpRequest("api/v1/users", null, request, HttpMethod.Post), token);
|
|
|
|
return await HandleResponse<ApplicationUserData>(response);
|
|
|
|
}
|
2021-04-11 07:36:34 +02:00
|
|
|
|
2021-06-04 12:20:45 +02:00
|
|
|
public virtual async Task DeleteUser(string userId, CancellationToken token = default)
|
2021-04-11 07:36:34 +02:00
|
|
|
{
|
|
|
|
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/users/{userId}", null, HttpMethod.Delete), token);
|
|
|
|
await HandleResponse(response);
|
2021-06-04 12:20:45 +02:00
|
|
|
}
|
|
|
|
|
2022-02-15 16:19:52 +01:00
|
|
|
public virtual async Task<ApplicationUserData> GetUserByIdOrEmail(string idOrEmail, CancellationToken token = default)
|
|
|
|
{
|
|
|
|
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/users/{idOrEmail}", null, HttpMethod.Get), token);
|
|
|
|
return await HandleResponse<ApplicationUserData>(response);
|
|
|
|
}
|
|
|
|
|
2022-12-07 19:01:50 +01:00
|
|
|
public virtual async Task<bool> LockUser(string idOrEmail, bool locked, CancellationToken token = default)
|
2022-04-26 14:27:35 +02:00
|
|
|
{
|
|
|
|
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/users/{idOrEmail}/lock", null,
|
2023-01-06 14:18:07 +01:00
|
|
|
new LockUserRequest { Locked = locked }, HttpMethod.Post), token);
|
2022-04-26 14:27:35 +02:00
|
|
|
await HandleResponse(response);
|
2022-12-07 19:01:50 +01:00
|
|
|
return response.IsSuccessStatusCode;
|
2022-04-26 14:27:35 +02:00
|
|
|
}
|
|
|
|
|
2023-01-06 14:18:07 +01:00
|
|
|
public virtual async Task<ApplicationUserData[]> GetUsers(CancellationToken token = default)
|
2022-02-15 16:19:52 +01:00
|
|
|
{
|
|
|
|
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/users/", null, HttpMethod.Get), token);
|
|
|
|
return await HandleResponse<ApplicationUserData[]>(response);
|
|
|
|
}
|
|
|
|
|
2021-06-04 12:20:45 +02:00
|
|
|
public virtual async Task DeleteCurrentUser(CancellationToken token = default)
|
|
|
|
{
|
|
|
|
await DeleteUser("me", token);
|
2021-04-11 07:36:34 +02:00
|
|
|
}
|
2020-03-12 14:59:24 +01:00
|
|
|
}
|
|
|
|
}
|