mirror of
https://github.com/btcpayserver/btcpayserver.git
synced 2024-11-19 01:43:50 +01:00
f8f98ab7f0
* Allow overrides on all methods * Add non-returning SendHttpRequest methods * Use SendHttpRequest consistently * Use file-scoped namespace * Rates: Set default null value for currencyPair * Ensure it works with instances which have BTCPAY_ROOTPATH set
57 lines
2.2 KiB
C#
57 lines
2.2 KiB
C#
#nullable enable
|
|
using System.Net.Http;
|
|
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)
|
|
{
|
|
return await SendHttpRequest<ApplicationUserData>("api/v1/users/me", null, HttpMethod.Get, token);
|
|
}
|
|
|
|
public virtual async Task<ApplicationUserData> CreateUser(CreateApplicationUserRequest request, CancellationToken token = default)
|
|
{
|
|
return await SendHttpRequest<ApplicationUserData>("api/v1/users", request, HttpMethod.Post, token);
|
|
}
|
|
|
|
public virtual async Task DeleteUser(string userId, CancellationToken token = default)
|
|
{
|
|
await SendHttpRequest($"api/v1/users/{userId}", null, HttpMethod.Delete, token);
|
|
}
|
|
|
|
public virtual async Task<ApplicationUserData> GetUserByIdOrEmail(string idOrEmail, CancellationToken token = default)
|
|
{
|
|
return await SendHttpRequest<ApplicationUserData>($"api/v1/users/{idOrEmail}", null, HttpMethod.Get, token);
|
|
}
|
|
|
|
public virtual async Task<bool> LockUser(string idOrEmail, bool locked, CancellationToken token = default)
|
|
{
|
|
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/users/{idOrEmail}/lock", null,
|
|
new LockUserRequest { Locked = locked }, HttpMethod.Post), token);
|
|
await HandleResponse(response);
|
|
return response.IsSuccessStatusCode;
|
|
}
|
|
|
|
public virtual async Task<bool> ApproveUser(string idOrEmail, bool approved, CancellationToken token = default)
|
|
{
|
|
var response = await _httpClient.SendAsync(CreateHttpRequest($"api/v1/users/{idOrEmail}/approve", null,
|
|
new ApproveUserRequest { Approved = approved }, HttpMethod.Post), token);
|
|
await HandleResponse(response);
|
|
return response.IsSuccessStatusCode;
|
|
}
|
|
|
|
public virtual async Task<ApplicationUserData[]> GetUsers(CancellationToken token = default)
|
|
{
|
|
return await SendHttpRequest<ApplicationUserData[]>("api/v1/users/", null, HttpMethod.Get, token);
|
|
}
|
|
|
|
public virtual async Task DeleteCurrentUser(CancellationToken token = default)
|
|
{
|
|
await DeleteUser("me", token);
|
|
}
|
|
}
|