2020-12-11 15:11:08 +01:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Net.Http;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using BTCPayServer.Client.Models;
|
|
|
|
|
|
|
|
namespace BTCPayServer.Client
|
|
|
|
{
|
|
|
|
public partial class BTCPayServerClient
|
|
|
|
{
|
2021-12-31 08:59:02 +01:00
|
|
|
public virtual async Task<IEnumerable<NotificationData>> GetNotifications(bool? seen = null, int? skip = null,
|
2021-11-26 03:55:59 +01:00
|
|
|
int? take = null, CancellationToken token = default)
|
2020-12-11 15:11:08 +01:00
|
|
|
{
|
2021-11-26 03:55:59 +01:00
|
|
|
Dictionary<string, object> queryPayload = new Dictionary<string, object>();
|
2021-12-31 08:59:02 +01:00
|
|
|
|
2021-11-26 03:55:59 +01:00
|
|
|
if (seen != null)
|
|
|
|
queryPayload.Add(nameof(seen), seen);
|
|
|
|
if (skip != null)
|
|
|
|
queryPayload.Add(nameof(skip), skip);
|
|
|
|
if (take != null)
|
|
|
|
queryPayload.Add(nameof(take), take);
|
|
|
|
|
|
|
|
var response = await _httpClient.SendAsync(
|
|
|
|
CreateHttpRequest($"api/v1/users/me/notifications",
|
|
|
|
queryPayload), token);
|
|
|
|
|
2020-12-11 15:11:08 +01:00
|
|
|
return await HandleResponse<IEnumerable<NotificationData>>(response);
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual async Task<NotificationData> GetNotification(string notificationId,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
var response = await _httpClient.SendAsync(
|
|
|
|
CreateHttpRequest($"api/v1/users/me/notifications/{notificationId}"), token);
|
|
|
|
return await HandleResponse<NotificationData>(response);
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual async Task<NotificationData> UpdateNotification(string notificationId, bool? seen,
|
|
|
|
CancellationToken token = default)
|
|
|
|
{
|
|
|
|
var response = await _httpClient.SendAsync(
|
|
|
|
CreateHttpRequest($"api/v1/users/me/notifications/{notificationId}",
|
2021-12-31 08:59:02 +01:00
|
|
|
method: HttpMethod.Put, bodyPayload: new UpdateNotification() { Seen = seen }), token);
|
2020-12-11 15:11:08 +01:00
|
|
|
return await HandleResponse<NotificationData>(response);
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual async Task RemoveNotification(string notificationId, CancellationToken token = default)
|
|
|
|
{
|
|
|
|
var response = await _httpClient.SendAsync(
|
|
|
|
CreateHttpRequest($"api/v1/users/me/notifications/{notificationId}",
|
|
|
|
method: HttpMethod.Delete), token);
|
|
|
|
await HandleResponse(response);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|