2020-03-27 06:17:31 +01:00
|
|
|
using System;
|
2020-03-02 16:50:28 +01:00
|
|
|
using System.Net.Http;
|
|
|
|
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-02 16:50:28 +01:00
|
|
|
{
|
2024-06-19 15:25:33 +02:00
|
|
|
public virtual async Task<ApiKeyData> GetCurrentAPIKeyInfo(CancellationToken token = default)
|
2020-03-02 16:50:28 +01:00
|
|
|
{
|
2024-06-19 15:25:33 +02:00
|
|
|
return await SendHttpRequest<ApiKeyData>("api/v1/api-keys/current", null, HttpMethod.Get, token);
|
|
|
|
}
|
2020-03-27 06:17:31 +01:00
|
|
|
|
2024-06-19 15:25:33 +02:00
|
|
|
public virtual async Task<ApiKeyData> CreateAPIKey(CreateApiKeyRequest request, CancellationToken token = default)
|
|
|
|
{
|
|
|
|
if (request == null) throw new ArgumentNullException(nameof(request));
|
|
|
|
return await SendHttpRequest<ApiKeyData>("api/v1/api-keys", request, HttpMethod.Post, token);
|
|
|
|
}
|
2020-03-27 06:17:31 +01:00
|
|
|
|
2024-06-19 15:25:33 +02:00
|
|
|
public virtual async Task<ApiKeyData> CreateAPIKey(string userId, CreateApiKeyRequest request, CancellationToken token = default)
|
|
|
|
{
|
|
|
|
if (request == null) throw new ArgumentNullException(nameof(request));
|
|
|
|
return await SendHttpRequest<ApiKeyData>($"api/v1/users/{userId}/api-keys", request, HttpMethod.Post, token);
|
|
|
|
}
|
2023-02-24 08:19:03 +01:00
|
|
|
|
2024-06-19 15:25:33 +02:00
|
|
|
public virtual async Task RevokeCurrentAPIKeyInfo(CancellationToken token = default)
|
|
|
|
{
|
|
|
|
await SendHttpRequest("api/v1/api-keys/current", null, HttpMethod.Delete, token);
|
|
|
|
}
|
2020-03-27 06:46:51 +01:00
|
|
|
|
2024-06-19 15:25:33 +02:00
|
|
|
public virtual async Task RevokeAPIKey(string apikey, CancellationToken token = default)
|
|
|
|
{
|
|
|
|
if (apikey == null) throw new ArgumentNullException(nameof(apikey));
|
|
|
|
await SendHttpRequest($"api/v1/api-keys/{apikey}", null, HttpMethod.Delete, token);
|
|
|
|
}
|
|
|
|
public virtual async Task RevokeAPIKey(string userId, string apikey, CancellationToken token = default)
|
|
|
|
{
|
|
|
|
if (apikey == null) throw new ArgumentNullException(nameof(apikey));
|
|
|
|
if (userId is null) throw new ArgumentNullException(nameof(userId));
|
|
|
|
await SendHttpRequest($"api/v1/users/{userId}/api-keys/{apikey}", null, HttpMethod.Delete, token);
|
2020-03-02 16:50:28 +01:00
|
|
|
}
|
|
|
|
}
|