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;
|
|
|
|
|
2024-06-19 15:25:33 +02:00
|
|
|
namespace BTCPayServer.Client;
|
|
|
|
|
|
|
|
public partial class BTCPayServerClient
|
2020-03-12 14:59:24 +01:00
|
|
|
{
|
2024-06-19 15:25:33 +02:00
|
|
|
public virtual async Task<ApplicationUserData> GetCurrentUser(CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return await SendHttpRequest<ApplicationUserData>("api/v1/users/me", null, HttpMethod.Get, token);
|
|
|
|
}
|
|
|
|
|
2024-06-26 10:39:22 +02:00
|
|
|
public virtual async Task<ApplicationUserData> UpdateCurrentUser(UpdateApplicationUserRequest request, CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return await SendHttpRequest<ApplicationUserData>("api/v1/users/me", request, HttpMethod.Put, token);
|
|
|
|
}
|
|
|
|
|
2024-07-11 02:28:24 +02:00
|
|
|
public virtual async Task<ApplicationUserData> UploadCurrentUserProfilePicture(string filePath, string mimeType, CancellationToken token = default)
|
|
|
|
{
|
|
|
|
return await UploadFileRequest<ApplicationUserData>("api/v1/users/me/picture", filePath, mimeType, "file", HttpMethod.Post, token);
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual async Task DeleteCurrentUserProfilePicture(CancellationToken token = default)
|
|
|
|
{
|
|
|
|
await SendHttpRequest("api/v1/users/me/picture", null, HttpMethod.Delete, token);
|
|
|
|
}
|
|
|
|
|
2024-06-19 15:25:33 +02:00
|
|
|
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);
|
2020-03-12 14:59:24 +01:00
|
|
|
}
|
|
|
|
}
|