PluralKit/PluralKit.API/APIJsonExt.cs

54 lines
1.4 KiB
C#
Raw Normal View History

2021-10-13 09:29:33 +00:00
using System;
2021-09-30 02:30:20 +00:00
using System.Collections.Generic;
2021-10-13 09:29:33 +00:00
using Newtonsoft.Json;
2021-09-30 02:30:20 +00:00
using Newtonsoft.Json.Linq;
2021-10-13 09:29:33 +00:00
using NodaTime;
2021-09-30 02:30:20 +00:00
using PluralKit.Core;
namespace PluralKit.API
{
public static class APIJsonExt
{
public static JArray ToJSON(this IEnumerable<PKShardInfo> shards)
{
var o = new JArray();
foreach (var shard in shards)
{
var s = new JObject();
s.Add("id", shard.Id);
if (shard.Status == PKShardInfo.ShardStatus.Down)
s.Add("status", "down");
else
s.Add("status", "up");
s.Add("ping", shard.Ping);
s.Add("last_heartbeat", shard.LastHeartbeat.ToString());
s.Add("last_connection", shard.LastConnection.ToString());
o.Add(s);
}
return o;
}
}
2021-10-13 09:29:33 +00:00
public struct FrontersReturnNew
{
[JsonProperty("id")] public Guid Uuid { get; set; }
[JsonProperty("timestamp")] public Instant Timestamp { get; set; }
[JsonProperty("members")] public IEnumerable<JObject> Members { get; set; }
}
public struct SwitchesReturnNew
{
[JsonProperty("id")] public Guid Uuid { get; set; }
[JsonProperty("timestamp")] public Instant Timestamp { get; set; }
[JsonProperty("members")] public IEnumerable<string> Members { get; set; }
}
2021-09-30 02:30:20 +00:00
}