sharp-chat/SharpChat/Flashii/FlashiiBan.cs

41 lines
1.3 KiB
C#
Raw Normal View History

2022-08-30 15:00:58 +00:00
using Hamakaze;
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace SharpChat.Flashii {
public class FlashiiBan {
private const string STRING = @"givemethebeans";
[JsonPropertyName(@"id")]
public int UserId { get; set; }
[JsonPropertyName(@"ip")]
public string UserIP { get; set; }
[JsonPropertyName(@"expires")]
public DateTimeOffset Expires { get; set; }
[JsonPropertyName(@"username")]
public string Username { get; set; }
public static void GetList(Action<IEnumerable<FlashiiBan>> onComplete, Action<Exception> onError) {
if(onComplete == null)
throw new ArgumentNullException(nameof(onComplete));
if(onError == null)
throw new ArgumentNullException(nameof(onError));
HttpRequestMessage hrm = new HttpRequestMessage(@"GET", FlashiiUrls.BANS);
hrm.AddHeader(@"X-SharpChat-Signature", STRING.GetSignedHash());
HttpClient.Send(hrm, (t, r) => {
try {
onComplete(JsonSerializer.Deserialize<IEnumerable<FlashiiBan>>(r.GetBodyBytes()));
} catch(Exception ex) {
onError(ex);
}
}, (t, e) => onError(e));
}
}
}