diff --git a/README.md b/README.md index 1005d54..734379c 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![CircleCI branch](https://img.shields.io/circleci/project/github/OrionDevelop/Disboard.svg?style=flat-square)](https://circleci.com/gh/OrionDevelop/Disboard/tree/develop) -Collection of fediverse API wrapper libraries for .NET Standard 2.0. +Collection of fediverse fully-typed client API wrapper libraries for .NET Standard 2.0. ## Projects @@ -14,7 +14,7 @@ Collection of fediverse API wrapper libraries for .NET Standard 2.0. | -------- | ----------- | ----------------------------------------------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- | | N/A | N/A | [`Disboard`](Source/Disboard) | `Disboard` | [![Disboard](https://img.shields.io/nuget/v/Disboard.svg?style=flat-square)](https://nuget.org/packages/Disboard) | | Mastodon | 2.7.x | [`Disboard.Mastodon`](Source/Disboard.Mastodon) | `Disboard.Mastodon` | [![Disboard.Mastodon](https://img.shields.io/nuget/v/Disboard.Mastodon.svg?style=flat-square)](https://nuget.org/packages/Disboard.Mastodon) | -| Misskey | 10.90.0 | [`Disboard.Misskey`](Source/Disboard.Misskey) | `Disboard.Misskey` | [![Disboard.Misskey](https://img.shields.io/nuget/v/Disboard.Misskey.svg?style=flat-square)](https://nuget.org/packages/Disboard.Misskey) | +| Misskey | 11.23.x | [`Disboard.Misskey`](Source/Disboard.Misskey) | `Disboard.Misskey` | [![Disboard.Misskey](https://img.shields.io/nuget/v/Disboard.Misskey.svg?style=flat-square)](https://nuget.org/packages/Disboard.Misskey) | | Pleroma | `ad318189` | [`Disboard.Pleroma`](Source/Disboard.Pleroma) | `Disboard.Pleroma` | [![Disboard.Pleroma](https://img.shields.io/nuget/v/Disboard.Pleroma.svg?style=flat-square)](https://nuget.org/packages/Disboard.Pleroma) | diff --git a/Source/Disboard.Misskey/Clients/HashtagsClient.cs b/Source/Disboard.Misskey/Clients/HashtagsClient.cs index 3c88689..fb98a1c 100644 --- a/Source/Disboard.Misskey/Clients/HashtagsClient.cs +++ b/Source/Disboard.Misskey/Clients/HashtagsClient.cs @@ -35,7 +35,7 @@ public async Task> TrendAsync() return await PostAsync>("/trend").Stay(); } - public async Task> UsersAsync(string tag, string sort, int? limit = null, string state = null, string origin = null) + public async Task> UsersAsync(string tag, string sort, int? limit = null, string state = null, string origin = null) { var parameters = new List> { @@ -46,7 +46,7 @@ public async Task> UsersAsync(string tag, string sort, int? limit = n parameters.AddIfValidValue("state", state); parameters.AddIfValidValue("origin", origin); - return await PostAsync>("/users", parameters).Stay(); + return await PostAsync>("/users", parameters).Stay(); } } } \ No newline at end of file diff --git a/Source/Disboard.Misskey/Clients/UsersClient.Ws.cs b/Source/Disboard.Misskey/Clients/UsersClient.Ws.cs index afb50bb..bc0678d 100644 --- a/Source/Disboard.Misskey/Clients/UsersClient.Ws.cs +++ b/Source/Disboard.Misskey/Clients/UsersClient.Ws.cs @@ -8,30 +8,28 @@ namespace Disboard.Misskey.Clients { public partial class UsersClient { - public async Task FollowersWsAsync(string userId = null, string username = null, bool? iknow = null, int? limit = null, string cursor = null, string host = null) + public async Task> FollowersWsAsync(string userId = null, string username = null, int? limit = null, string sinceId = null, string untilId = null) { var parameters = new List>(); parameters.AddIfValidValue("userId", userId); parameters.AddIfValidValue("username", username); - parameters.AddIfValidValue("iknow", iknow); + parameters.AddIfValidValue("sinceId", sinceId); + parameters.AddIfValidValue("untilId", untilId); parameters.AddIfValidValue("limit", limit); - parameters.AddIfValidValue("cursor", cursor); - parameters.AddIfValidValue("host", host); - return await SendWsAsync("/followers", parameters).Stay(); + return await SendWsAsync>("/followers", parameters).Stay(); } - public async Task FollowingWsAsync(string userId, string username = null, bool? iknow = null, int? limit = null, string cursor = null, string host = null) + public async Task> FollowingWsAsync(string userId = null, string username = null, int? limit = null, string sinceId = null, string untilId = null) { var parameters = new List>(); parameters.AddIfValidValue("userId", userId); parameters.AddIfValidValue("username", username); - parameters.AddIfValidValue("iknow", iknow); + parameters.AddIfValidValue("sinceId", sinceId); + parameters.AddIfValidValue("untilId", untilId); parameters.AddIfValidValue("limit", limit); - parameters.AddIfValidValue("cursor", cursor); - parameters.AddIfValidValue("host", host); - return await SendWsAsync("/following", parameters).Stay(); + return await SendWsAsync>("/following", parameters).Stay(); } public async Task> GetFrequentlyRepliedUsersWsAsync(string userId, int? limit = null) diff --git a/Source/Disboard.Misskey/Clients/UsersClient.cs b/Source/Disboard.Misskey/Clients/UsersClient.cs index 22c0d23..9380553 100644 --- a/Source/Disboard.Misskey/Clients/UsersClient.cs +++ b/Source/Disboard.Misskey/Clients/UsersClient.cs @@ -16,30 +16,28 @@ protected internal UsersClient(MisskeyClient client) : base(client, "users") Lists = new ListsClient(client); } - public async Task FollowersAsync(string userId = null, string username = null, bool? iknow = null, int? limit = null, string cursor = null, string host = null) + public async Task> FollowersAsync(string userId = null, string username = null, int? limit = null, string sinceId = null, string untilId = null) { var parameters = new List>(); parameters.AddIfValidValue("userId", userId); parameters.AddIfValidValue("username", username); - parameters.AddIfValidValue("iknow", iknow); + parameters.AddIfValidValue("sinceId", sinceId); + parameters.AddIfValidValue("untilId", untilId); parameters.AddIfValidValue("limit", limit); - parameters.AddIfValidValue("cursor", cursor); - parameters.AddIfValidValue("host", host); - return await PostAsync("/followers", parameters).Stay(); + return await PostAsync>("/followers", parameters).Stay(); } - public async Task FollowingAsync(string userId, string username = null, bool? iknow = null, int? limit = null, string cursor = null, string host = null) + public async Task> FollowingAsync(string userId = null, string username = null, int? limit = null, string sinceId = null, string untilId = null) { var parameters = new List>(); parameters.AddIfValidValue("userId", userId); parameters.AddIfValidValue("username", username); - parameters.AddIfValidValue("iknow", iknow); + parameters.AddIfValidValue("sinceId", sinceId); + parameters.AddIfValidValue("untilId", untilId); parameters.AddIfValidValue("limit", limit); - parameters.AddIfValidValue("cursor", cursor); - parameters.AddIfValidValue("host", host); - return await PostAsync("/following", parameters).Stay(); + return await PostAsync>("/following", parameters).Stay(); } public async Task> GetFrequentlyRepliedUsersAsync(string userId, int? limit = null) diff --git a/Source/Disboard.Misskey/Enums/Permission.cs b/Source/Disboard.Misskey/Enums/Permission.cs index 25d09cd..ced44fd 100644 --- a/Source/Disboard.Misskey/Enums/Permission.cs +++ b/Source/Disboard.Misskey/Enums/Permission.cs @@ -2,37 +2,54 @@ { public enum Permission { - AccountRead = 0, + AccountRead = 1 << 0, - AccountWrite = 1, + AccountWrite = 1 << 1, - DriveRead = 1 << 1, + BlocksRead = 1 << 2, - DriveWrite = 1 << 2, + BlocksWrite = 1 << 3, - FavoritesRead = 1 << 3, + DriveRead = 1 << 4, - FavoriteWrite = 1 << 4, + DriveWrite = 1 << 5, - FollowingRead = 1 << 5, + FavoritesRead = 1 << 6, - FollowingWrite = 1 << 6, + FavoritesWrite = 1 << 7, - MessagingRead = 1 << 7, + FollowingRead = 1 << 8, - MessagingWrite = 1 << 8, + FollowingWrite = 1 << 9, - NoteWrite = 1 << 9, + MessagingRead = 1 << 10, - NotificationWrite = 1 << 10, + MessagingWrite = 1 << 11, - ReactionWrite = 1 << 11, + MutesRead = 1 << 12, - VoteWrite = 1 << 12, + MutesWrite = 1 << 13, - // old? - AccountRead2 = 1 << 13, + NotificationsRead = 1 << 14, - AccountWrite2 = 1 << 14 + NotificationsWrite = 1 << 15, + + ReactionsRead = 1 << 16, + + ReactionsWrite = 1 << 17, + + VotesWrite = 1 << 18, + + PagesRead = 1 << 19, + + PagesWrite = 1 << 20, + + PageLikesRead = 1 << 21, + + PageLikesWrite = 1 << 22, + + UserGroupsRead = 1 << 23, + + UserGroupsWrite = 1 << 24 } } \ No newline at end of file diff --git a/Source/Disboard.Misskey/Extensions/PermissionExtensions.cs b/Source/Disboard.Misskey/Extensions/PermissionExtensions.cs index 871b412..7fd7b2d 100644 --- a/Source/Disboard.Misskey/Extensions/PermissionExtensions.cs +++ b/Source/Disboard.Misskey/Extensions/PermissionExtensions.cs @@ -11,52 +11,79 @@ public static string ToStr(this Permission permission) switch (permission) { case Permission.AccountRead: - return "account-read"; + return "read:account"; case Permission.AccountWrite: - return "account-write"; + return "write:account"; + + case Permission.BlocksRead: + return "read:blocks"; + + case Permission.BlocksWrite: + return "write:blocks"; case Permission.DriveRead: - return "drive-read"; + return "read:drive"; case Permission.DriveWrite: - return "drive-write"; + return "write:drive"; case Permission.FavoritesRead: - return "favorites-read"; + return "read:favorites"; - case Permission.FavoriteWrite: - return "favorite-write"; - - case Permission.FollowingWrite: - return "following-write"; + case Permission.FavoritesWrite: + return "write:favorites"; case Permission.FollowingRead: - return "following-read"; + return "read:following"; + + case Permission.FollowingWrite: + return "write:following"; case Permission.MessagingRead: - return "messaging-read"; + return "read:messaging"; case Permission.MessagingWrite: - return "messaging-write"; + return "write:messaging"; + + case Permission.MutesRead: + return "read:mutes"; + + case Permission.MutesWrite: + return "write:mutes"; + + case Permission.NotificationsRead: + return "read:notifications"; + + case Permission.NotificationsWrite: + return "write:notification"; + + case Permission.ReactionsRead: + return "read:reactions"; + + case Permission.ReactionsWrite: + return "write:reactions"; + + case Permission.VotesWrite: + return "write:votes"; - case Permission.NoteWrite: - return "note-write"; + case Permission.PagesRead: + return "read:pages"; - case Permission.NotificationWrite: - return "notification-write"; + case Permission.PagesWrite: + return "write:pages"; - case Permission.ReactionWrite: - return "reaction-write"; + case Permission.PageLikesRead: + return "read:page-likes"; - case Permission.VoteWrite: - return "vote-write"; + case Permission.PageLikesWrite: + return "write:page-likes"; - case Permission.AccountRead2: - return "account/read"; + case Permission.UserGroupsRead: + return "read:user-groups"; - case Permission.AccountWrite2: - return "account/write"; + case Permission.UserGroupsWrite: + return "write:user-groups"; default: throw new ArgumentOutOfRangeException(nameof(permission), permission, null); diff --git a/Source/Disboard.Misskey/MisskeyClient.Api.Ws.cs b/Source/Disboard.Misskey/MisskeyClient.Api.Ws.cs index f9e0143..87bba0a 100644 --- a/Source/Disboard.Misskey/MisskeyClient.Api.Ws.cs +++ b/Source/Disboard.Misskey/MisskeyClient.Api.Ws.cs @@ -8,12 +8,32 @@ namespace Disboard.Misskey { public partial class MisskeyClient { - public async Task ChartWsAsync(int? limit = null) + public async Task EndpointWsAsync(string endpoint) + { + var parameters = new List> + { + new KeyValuePair("endpoint", endpoint) + }; + + return await SendWsAsync("endpoint", parameters).Stay(); + } + + public async Task> EndpointsWsAsync() + { + return await SendWsAsync>("endpoints").Stay(); + } + + public async Task MetaWsAsync(bool? detail = null) { var parameters = new List>(); - parameters.AddIfValidValue("limit", limit); + parameters.AddIfValidValue("detail", detail); + + return await SendWsAsync("meta", parameters).Stay(); + } - return await SendWsAsync("chart").Stay(); + public async Task> PinnedUsersWsAsync() + { + return await SendWsAsync>("pinned-users").Stay(); } public async Task DriveWsAsync() @@ -27,14 +47,6 @@ public async Task IWsAsync() return await SendWsAsync("i").Stay(); } - public async Task MetaWsAsync(bool? detail = null) - { - var parameters = new List>(); - parameters.AddIfValidValue("detail", detail); - - return await SendWsAsync("meta", parameters).Stay(); - } - public async Task> NotesWsAsync(bool? local = null, bool? reply = null, bool? renote = null, bool? withFiles = null, bool? poll = null, int? limit = null, string sinceId = null, string untilId = null) { var parameters = new List>(); diff --git a/Source/Disboard.Misskey/MisskeyClient.Api.cs b/Source/Disboard.Misskey/MisskeyClient.Api.cs index 469190f..8161d9a 100644 --- a/Source/Disboard.Misskey/MisskeyClient.Api.cs +++ b/Source/Disboard.Misskey/MisskeyClient.Api.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Threading.Tasks; using Disboard.Extensions; @@ -9,13 +8,32 @@ namespace Disboard.Misskey { public partial class MisskeyClient { - [Obsolete] - public async Task ChartAsync(int? limit = null) + public async Task EndpointAsync(string endpoint) + { + var parameters = new List> + { + new KeyValuePair("endpoint", endpoint) + }; + + return await PostAsync("/api/endpoint", parameters).Stay(); + } + + public async Task> EndpointsAsync() + { + return await PostAsync>("/api/endpoints").Stay(); + } + + public async Task MetaAsync(bool? detail = null) { var parameters = new List>(); - parameters.AddIfValidValue("limit", limit); + parameters.AddIfValidValue("detail", detail); + + return await PostAsync("/api/meta", parameters).Stay(); + } - return await PostAsync("/api/chart", parameters).Stay(); + public async Task> PinnedUsersAsync() + { + return await PostAsync>("/api/pinned-users").Stay(); } public async Task DriveAsync() @@ -29,14 +47,6 @@ public async Task IAsync() return await PostAsync("/api/i").Stay(); } - public async Task MetaAsync(bool? detail = null) - { - var parameters = new List>(); - parameters.AddIfValidValue("detail", detail); - - return await PostAsync("/api/meta", parameters).Stay(); - } - public async Task> NotesAsync(bool? local = null, bool? reply = null, bool? renote = null, bool? withFiles = null, bool? poll = null, int? limit = null, string sinceId = null, string untilId = null) { var parameters = new List>(); diff --git a/Source/Disboard.Misskey/Models/Announcement.cs b/Source/Disboard.Misskey/Models/Announcement.cs new file mode 100644 index 0000000..ba8e5b1 --- /dev/null +++ b/Source/Disboard.Misskey/Models/Announcement.cs @@ -0,0 +1,18 @@ +using Disboard.Models; + +using Newtonsoft.Json; + +namespace Disboard.Misskey.Models +{ + public class Announcement : ApiResponse + { + [JsonProperty("image")] + public string Image { get; set; } + + [JsonProperty("title")] + public string Title { get; set; } + + [JsonProperty("text")] + public string Text { get; set; } + } +} \ No newline at end of file diff --git a/Source/Disboard.Misskey/Models/App.cs b/Source/Disboard.Misskey/Models/App.cs index 62fa08b..b92c36e 100644 --- a/Source/Disboard.Misskey/Models/App.cs +++ b/Source/Disboard.Misskey/Models/App.cs @@ -1,10 +1,8 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using Disboard.Models; using Newtonsoft.Json; -using Newtonsoft.Json.Converters; namespace Disboard.Misskey.Models { @@ -13,16 +11,6 @@ public class App : ApiResponse [JsonProperty("callbackUrl")] public string CallbackUrl { get; set; } - [JsonProperty("createdAt")] - [JsonConverter(typeof(IsoDateTimeConverter))] - public DateTime CreatedAt { get; set; } - - [JsonProperty("description")] - public string Description { get; set; } - - [JsonProperty("iconUrl")] - public string IconUrl { get; set; } - [JsonProperty("id")] public string Id { get; set; } @@ -37,8 +25,5 @@ public class App : ApiResponse [JsonProperty("secret")] public string Secret { get; set; } - - [JsonProperty("userId")] - public string UserId { get; set; } } } \ No newline at end of file diff --git a/Source/Disboard.Misskey/Models/AuthSession.cs b/Source/Disboard.Misskey/Models/AuthSession.cs index 9427596..9b4fe4d 100644 --- a/Source/Disboard.Misskey/Models/AuthSession.cs +++ b/Source/Disboard.Misskey/Models/AuthSession.cs @@ -1,9 +1,6 @@ -using System; - -using Disboard.Models; +using Disboard.Models; using Newtonsoft.Json; -using Newtonsoft.Json.Converters; namespace Disboard.Misskey.Models { @@ -12,17 +9,10 @@ public class AuthSession : ApiResponse [JsonProperty("app")] public App App { get; set; } - [JsonProperty("appId")] - public string AppId { get; set; } - - [JsonProperty("createdAt")] - [JsonConverter(typeof(IsoDateTimeConverter))] - public DateTime CreatedAt { get; set; } + [JsonProperty("id")] + public string Id { get; set; } [JsonProperty("token")] public string Token { get; set; } - - [JsonProperty("userId")] - public string UserId { get; set; } } } \ No newline at end of file diff --git a/Source/Disboard.Misskey/Models/Discord.cs b/Source/Disboard.Misskey/Models/Discord.cs new file mode 100644 index 0000000..17f303d --- /dev/null +++ b/Source/Disboard.Misskey/Models/Discord.cs @@ -0,0 +1,18 @@ +using Disboard.Models; + +using Newtonsoft.Json; + +namespace Disboard.Misskey.Models +{ + public class Discord : ApiResponse + { + [JsonProperty("discriminator")] + public string Discriminator { get; set; } + + [JsonProperty("id")] + public long Id { get; set; } + + [JsonProperty("username")] + public string Username { get; set; } + } +} \ No newline at end of file diff --git a/Source/Disboard.Misskey/Models/Endpoint.cs b/Source/Disboard.Misskey/Models/Endpoint.cs new file mode 100644 index 0000000..bf5b51c --- /dev/null +++ b/Source/Disboard.Misskey/Models/Endpoint.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; + +using Disboard.Models; + +using Newtonsoft.Json; + +namespace Disboard.Misskey.Models +{ + public class Endpoint : ApiResponse + { + [JsonProperty("params")] + public IEnumerable Params { get; set; } + } +} \ No newline at end of file diff --git a/Source/Disboard.Misskey/Models/Features.cs b/Source/Disboard.Misskey/Models/Features.cs index bc39d39..d111a70 100644 --- a/Source/Disboard.Misskey/Models/Features.cs +++ b/Source/Disboard.Misskey/Models/Features.cs @@ -6,28 +6,34 @@ namespace Disboard.Misskey.Models { public class Features : ApiResponse { - [JsonProperty("registration")] - public bool Registration { get; set; } + [JsonProperty("discord")] + public bool Discord { get; set; } - [JsonProperty("localTimeline")] + [JsonProperty("elasticsearch")] + public bool Elasticsearch { get; set; } + + [JsonProperty("localTimeLine")] public bool LocalTimeline { get; set; } - [JsonProperty("elasticSearch")] - public bool ElasticSearch { get; set; } + [JsonProperty("github")] + public bool Github { get; set; } - [JsonProperty("recaptcha")] - public bool Recaptcha { get; set; } + [JsonProperty("globalTimeLine")] + public bool GlobalTimeline { get; set; } [JsonProperty("objectStorage")] public bool ObjectStorage { get; set; } - [JsonProperty("twitter")] - public bool Twitter { get; set; } + [JsonProperty("recaptcha")] + public bool Recaptcha { get; set; } + + [JsonProperty("registration")] + public bool Registration { get; set; } [JsonProperty("serviceWorker")] public bool ServiceWorker { get; set; } - [JsonProperty("userRecommendation")] - public UserRecommendation UserRecommendation { get; set; } + [JsonProperty("twitter")] + public bool Twitter { get; set; } } } \ No newline at end of file diff --git a/Source/Disboard.Misskey/Models/FollowerRelation.cs b/Source/Disboard.Misskey/Models/FollowerRelation.cs new file mode 100644 index 0000000..896abca --- /dev/null +++ b/Source/Disboard.Misskey/Models/FollowerRelation.cs @@ -0,0 +1,28 @@ +using System; + +using Disboard.Models; + +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace Disboard.Misskey.Models +{ + public class FollowerRelation : ApiResponse + { + [JsonProperty("createdAt")] + [JsonConverter(typeof(IsoDateTimeConverter))] + public DateTime CreatedAt { get; set; } + + [JsonProperty("followeeId")] + public string FolloweeId { get; set; } + + [JsonProperty("follower")] + public User Follower { get; set; } + + [JsonProperty("followerId")] + public string FollowerId { get; set; } + + [JsonProperty("id")] + public string Id { get; set; } + } +} \ No newline at end of file diff --git a/Source/Disboard.Misskey/Models/FollowingRelation.cs b/Source/Disboard.Misskey/Models/FollowingRelation.cs new file mode 100644 index 0000000..f3e2bbe --- /dev/null +++ b/Source/Disboard.Misskey/Models/FollowingRelation.cs @@ -0,0 +1,28 @@ +using System; + +using Disboard.Models; + +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace Disboard.Misskey.Models +{ + public class FollowingRelation : ApiResponse + { + [JsonProperty("createdAt")] + [JsonConverter(typeof(IsoDateTimeConverter))] + public DateTime CreatedAt { get; set; } + + [JsonProperty("followee")] + public User Followee { get; set; } + + [JsonProperty("followeeId")] + public string FolloweeId { get; set; } + + [JsonProperty("followerId")] + public string FollowerId { get; set; } + + [JsonProperty("id")] + public string Id { get; set; } + } +} \ No newline at end of file diff --git a/Source/Disboard.Misskey/Models/Github.cs b/Source/Disboard.Misskey/Models/Github.cs new file mode 100644 index 0000000..6632c30 --- /dev/null +++ b/Source/Disboard.Misskey/Models/Github.cs @@ -0,0 +1,15 @@ +using Disboard.Models; + +using Newtonsoft.Json; + +namespace Disboard.Misskey.Models +{ + public class Github : ApiResponse + { + [JsonProperty("id")] + public long Id { get; set; } + + [JsonProperty("login")] + public string Login { get; set; } + } +} \ No newline at end of file diff --git a/Source/Disboard.Misskey/Models/Instance.cs b/Source/Disboard.Misskey/Models/Instance.cs index 8df0c3f..686d562 100644 --- a/Source/Disboard.Misskey/Models/Instance.cs +++ b/Source/Disboard.Misskey/Models/Instance.cs @@ -9,59 +9,56 @@ namespace Disboard.Misskey.Models { public class Instance : ApiResponse { - [JsonProperty("_id")] + [JsonProperty("id")] public string Id { get; set; } - [JsonProperty("host")] - public string Host { get; set; } - [JsonProperty("caughtAt")] [JsonConverter(typeof(IsoDateTimeConverter))] public DateTime CaughtAt { get; set; } - [JsonProperty("system")] - public string System { get; set; } + [JsonProperty("driveFiles")] + public long DriveFiles { get; set; } - [JsonProperty("usersCount")] - public long UsersCount { get; set; } + [JsonProperty("driveUsage")] + public long DriveUsage { get; set; } - [JsonProperty("notesCount")] - public long NotesCount { get; set; } + [JsonProperty("followersCount")] + public long FollowersCount { get; set; } [JsonProperty("followingCount")] public long FollowingCount { get; set; } - [JsonProperty("followersCount")] - public long FollowersCount { get; set; } + [JsonProperty("host")] + public string Host { get; set; } - [JsonProperty("driveUsage")] - public long DriveUsage { get; set; } + [JsonProperty("isMarkedAsClosed")] + public bool IsMarkedAtClosed { get; set; } - [JsonProperty("driveFiles")] - public long DriveFiles { get; set; } + [JsonProperty("isNotResponding")] + public bool IsNotResponding { get; set; } - [JsonProperty("latestRequestSentAt")] + [JsonProperty("lastCommunicatedAt")] [JsonConverter(typeof(IsoDateTimeConverter))] - public DateTime? LatestRequestSentAt { get; set; } - - [JsonProperty("latestStatus")] - public int? LatestStatus { get; set; } + public DateTime LastCommunicatedAt { get; set; } [JsonProperty("latestRequestReceivedAt")] [JsonConverter(typeof(IsoDateTimeConverter))] public DateTime? LatestRequestReceivedAt { get; set; } - [JsonProperty("isNotResponding")] - public bool IsNotResponding { get; set; } - - [JsonProperty("lastCommunicatedAt")] + [JsonProperty("latestRequestSentAt")] [JsonConverter(typeof(IsoDateTimeConverter))] - public DateTime LastCommunicatedAt { get; set; } + public DateTime? LatestRequestSentAt { get; set; } - [JsonProperty("isBlocked")] - public bool IsBlocked { get; set; } + [JsonProperty("latestStatus")] + public int? LatestStatus { get; set; } - [JsonProperty("isMarkedAsClosed")] - public bool IsMarkedAtClosed { get; set; } + [JsonProperty("notesCount")] + public long NotesCount { get; set; } + + [JsonProperty("system")] + public string System { get; set; } + + [JsonProperty("usersCount")] + public long UsersCount { get; set; } } } \ No newline at end of file diff --git a/Source/Disboard.Misskey/Models/MediaProperty.cs b/Source/Disboard.Misskey/Models/MediaProperty.cs index 223e5bb..2165154 100644 --- a/Source/Disboard.Misskey/Models/MediaProperty.cs +++ b/Source/Disboard.Misskey/Models/MediaProperty.cs @@ -10,7 +10,7 @@ namespace Disboard.Misskey.Models public class MediaProperty : ApiResponse { [JsonProperty("avgColor")] - [JsonConverter(typeof(RgbArrayToColorConverter))] + [JsonConverter(typeof(RgbToColorConverter))] public Color AvgColor { get; set; } [JsonProperty("height")] diff --git a/Source/Disboard.Misskey/Models/Metadata.cs b/Source/Disboard.Misskey/Models/Metadata.cs index 75dff3b..d5a9d9b 100644 --- a/Source/Disboard.Misskey/Models/Metadata.cs +++ b/Source/Disboard.Misskey/Models/Metadata.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Disboard.Models; @@ -8,67 +9,130 @@ namespace Disboard.Misskey.Models { public class Metadata : ApiResponse { - [JsonProperty("maintainer")] - public Maintainer Maintainer { get; set; } + [JsonProperty("announcements")] + public IEnumerable Announcements { get; set; } - [JsonProperty("version")] - public string Version { get; set; } - - [JsonProperty("clientVersion")] - public string ClientVersion { get; set; } + [JsonProperty("bannerUrl")] + public string BannerUrl { get; set; } - [JsonProperty("emojis")] - public IEnumerable Emojis { get; set; } + [JsonProperty("cacheRemoteFiles")] + public bool IsCacheRemoteFiles { get; set; } - [JsonProperty("name")] - public string Name { get; set; } + [JsonProperty("cpu")] + public Cpu Cpu { get; set; } [JsonProperty("description")] public string Description { get; set; } - [JsonProperty("secure")] - public bool IsSecure { get; set; } + [JsonProperty("disableGlobalTimeline")] + public bool IsDisableGlobalTimeline { get; set; } + + [JsonProperty("disableLocalTimeline")] + public bool IsDisableLocalTimeline { get; set; } + + [JsonProperty("disableRegistration")] + public bool IsDisableRegistration { get; set; } + + [JsonProperty("driveCapacityPerLocalUserMb")] + public long DriveCapacityPerLocalUserMb { get; set; } + + [JsonProperty("driveCapacityPerRemoteUserMb")] + public long DriveCapacityPerRemoteUserMb { get; set; } + + [JsonProperty("emojis")] + public IEnumerable Emojis { get; set; } + + [JsonProperty("enableDiscordIntegration")] + public bool IsEnableDiscordIntegration { get; set; } + + [JsonProperty("enableEmail")] + public bool IsEnableEmail { get; set; } + + [JsonProperty("enableEmojiReaction")] + public bool IsEnableEmojiReaction { get; set; } + + [JsonProperty("enableGithubIntegration")] + public bool IsEnableGithubIntegration { get; set; } + + [JsonProperty("enableRecaptcha")] + public bool IsEnableRecaptcha { get; set; } + + [JsonProperty("enableServiceWorker")] + public bool IsEnableServiceWorker { get; set; } + + [JsonProperty("enableTwitterIntegration")] + public bool IsEnableTwitterIntegration { get; set; } + + [JsonProperty("errorImageUrl")] + public string ErrorImageUrl { get; set; } + + [JsonProperty("feedbackUrl")] + public string FeedbackUrl { get; set; } + + [JsonProperty("iconUrl")] + public string IconUrl { get; set; } + + [JsonProperty("langs")] + public IEnumerable Langs { get; set; } [JsonProperty("machine")] public string Machine { get; set; } - [JsonProperty("os")] - public string Os { get; set; } + [JsonProperty("maintainerEmail")] + public string MaintainerEmail { get; set; } + + [JsonProperty("maintainerName")] + public string MaintainerName { get; set; } + + [JsonProperty("mascotImageUrl")] + public string MascotImageUrl { get; set; } + + [JsonProperty("maxNoteTextLength")] + public long MaxNoteTextLength { get; set; } + + [JsonProperty("name")] + public string Name { get; set; } [JsonProperty("node")] public string Node { get; set; } - [JsonProperty("cpu")] - public Cpu Cpu { get; set; } + [JsonProperty("os")] + public string Os { get; set; } - [JsonProperty("broadcasts")] - public IEnumerable Broadcasts { get; set; } + [JsonProperty("psql")] + public string Psql { get; set; } - [JsonProperty("disableRegistration")] - public bool DisableRegistration { get; set; } + [JsonProperty("recaptchaSiteKey")] + public string RecaptchaSiteKey { get; set; } - [JsonProperty("disableLocalTimeline")] - public bool DisableLocalTimeline { get; set; } + [JsonProperty("redis")] + public string Redis { get; set; } - [JsonProperty("driveCapacityPerLocalUserMb")] - public long DriveCapacityPerLocalUserMb { get; set; } + [JsonProperty("repositoryUrl")] + public string RepositoryUrl { get; set; } - [JsonProperty("recaptchaSitekey")] - public string RecaptchaSitekey { get; set; } + [JsonProperty("secure")] + public bool IsSecure { get; set; } [JsonProperty("swPublickey")] public string SwPublickey { get; set; } - [JsonProperty("hidedTags")] - public bool? HidedTags { get; set; } + [JsonProperty("ToSUrl")] + public string ToSUrl { get; set; } - [JsonProperty("bannerUrl")] - public string BannerUrl { get; set; } + [JsonProperty("uri")] + public Uri Uri { get; set; } - [JsonProperty("maxNoteTextLength")] - public int MaxNoteTextLength { get; set; } + [JsonProperty("version")] + public string Version { get; set; } + + // if details set to true, includes below properties [JsonProperty("features")] public Features Features { get; set; } + + // if user is administrator or moderator, includes below properties + + // NOT SUPPORTED CURRENTLY BECAUSE RESPONSE TYPE IS UNKNOWN } } \ No newline at end of file diff --git a/Source/Disboard.Misskey/Models/Param.cs b/Source/Disboard.Misskey/Models/Param.cs new file mode 100644 index 0000000..33282f8 --- /dev/null +++ b/Source/Disboard.Misskey/Models/Param.cs @@ -0,0 +1,16 @@ +using Disboard.Models; + +using Newtonsoft.Json; + +namespace Disboard.Misskey.Models +{ + public class Param : ApiResponse + { + [JsonProperty("name")] + public string Name { get; set; } + + // NOTE: should I convert this value to .NET types? + [JsonProperty("type")] + public string Type { get; set; } + } +} \ No newline at end of file diff --git a/Source/Disboard.Misskey/Models/Stats.cs b/Source/Disboard.Misskey/Models/Stats.cs index d0729a4..254312a 100644 --- a/Source/Disboard.Misskey/Models/Stats.cs +++ b/Source/Disboard.Misskey/Models/Stats.cs @@ -6,16 +6,25 @@ namespace Disboard.Misskey.Models { public class Stats : ApiResponse { + [JsonProperty("driveUsageLocal")] + public long DriveUsageLocal { get; set; } + + [JsonProperty("driveUsageRemote")] + public long DriveUsageRemote { get; set; } + + [JsonProperty("instances")] + public long Instances { get; set; } + [JsonProperty("notesCount")] public long NotesCount { get; set; } - [JsonProperty("usersCount")] - public long UsersCount { get; set; } - [JsonProperty("originalNotesCount")] public long OriginalNotesCount { get; set; } [JsonProperty("originalUsersCount")] public long OriginalUsersCount { get; set; } + + [JsonProperty("usersCount")] + public long UsersCount { get; set; } } } \ No newline at end of file diff --git a/Source/Disboard.Misskey/Models/Twitter.cs b/Source/Disboard.Misskey/Models/Twitter.cs index 1894f73..3d3fdfd 100644 --- a/Source/Disboard.Misskey/Models/Twitter.cs +++ b/Source/Disboard.Misskey/Models/Twitter.cs @@ -6,8 +6,8 @@ namespace Disboard.Misskey.Models { public class Twitter : ApiResponse { - [JsonProperty("userId")] - public string UserId { get; set; } + [JsonProperty("id")] + public string Id { get; set; } [JsonProperty("screenName")] public string ScreenName { get; set; } diff --git a/Source/Disboard.Misskey/Models/User.cs b/Source/Disboard.Misskey/Models/User.cs index d06451d..ea8d6ba 100644 --- a/Source/Disboard.Misskey/Models/User.cs +++ b/Source/Disboard.Misskey/Models/User.cs @@ -12,8 +12,17 @@ namespace Disboard.Misskey.Models { public class User : ApiResponse { + [JsonProperty("alwaysMarkNsfw")] + public bool? IsAlwaysMarkNsfw { get; set; } + + [JsonProperty("autoAcceptFollowed")] + public bool? IsAutoAcceptFollowed { get; set; } + + [JsonProperty("autoWatch")] + public bool? IsAutoWatch { get; set; } + [JsonProperty("avatarColor")] - [JsonConverter(typeof(RgbArrayToColorConverter))] + [JsonConverter(typeof(RgbToColorConverter))] public Color? AvatarColor { get; set; } [JsonProperty("avatarId")] @@ -23,7 +32,7 @@ public class User : ApiResponse public string AvatarUrl { get; set; } [JsonProperty("bannerColor")] - [JsonConverter(typeof(RgbArrayToColorConverter))] + [JsonConverter(typeof(RgbToColorConverter))] public Color? BannerColor { get; set; } [JsonProperty("bannerId")] @@ -32,70 +41,37 @@ public class User : ApiResponse [JsonProperty("bannerUrl")] public string BannerUrl { get; set; } + [JsonProperty("birthday")] + [JsonConverter(typeof(IsoDateTimeConverter))] + public DateTime? Birthday { get; set; } + [JsonProperty("carefulBot")] - public bool IsCarefulBot { get; set; } + public bool? IsCarefulBot { get; set; } [JsonProperty("createdAt")] - [JsonConverter(typeof(UnionToDateTimeConverter))] public DateTime? CreatedAt { get; set; } [JsonProperty("description")] public string Description { get; set; } - [JsonProperty("driveCapacity")] - public long? DriveCapacity { get; set; } + [JsonProperty("discord")] + public Discord Discord { get; set; } [JsonProperty("emojis")] - public List Emojis { get; set; } - - [JsonProperty("endpoints")] - public Endpoints Endpoints { get; set; } - - [JsonProperty("featured")] - public string Featured { get; set; } - - [JsonProperty("followersCount")] - public long FollowersCount { get; set; } - - [JsonProperty("followersYouKnowCount")] - public long? FollowersYouKnowCount { get; set; } + public IEnumerable Emojis { get; set; } [JsonProperty("followingCount")] - public long FollowingCount { get; set; } - - [JsonProperty("followingYouKnowCount")] - public long? FollowingYouKnowCount { get; set; } - - [JsonProperty("hasPendingFollowRequestFromYou")] - public bool? HasPendingFollowRequestFromYou { get; set; } + public long? FollowingCount { get; set; } - [JsonProperty("hasPendingFollowRequestToYou")] - public bool? HasPendingFollowRequestToYou { get; set; } - - [JsonProperty("hasUnreadMentions")] - public bool? HasUnreadMentions { get; set; } - - [JsonProperty("hasUnreadMessage")] - public bool? HasUnreadMessage { get; set; } - - [JsonProperty("hasUnreadNotification")] - public bool? HasUnreadNotification { get; set; } - - [JsonProperty("hasUnreadSpecifiedNotes")] - public bool? HasUnreadSpecifiedNotes { get; set; } - - [JsonProperty("host")] - public string Host { get; set; } + [JsonProperty("followersCount")] + public long? FollowersCount { get; set; } - [JsonProperty("hostLower")] - public string HostLower { get; set; } + [JsonProperty("github")] + public Github Github { get; set; } [JsonProperty("id")] public string Id { get; set; } - [JsonProperty("Inbox")] - public string Inbox { get; set; } - [JsonProperty("isAdmin")] public bool? IsAdmin { get; set; } @@ -117,39 +93,47 @@ public class User : ApiResponse [JsonProperty("isFollowing")] public bool? IsFollowing { get; set; } + [JsonProperty("isLocked")] + public bool? IsLocked { get; set; } + + [JsonProperty("isModerator")] + public bool? IsModerator { get; set; } + [JsonProperty("isMuted")] public bool? IsMuted { get; set; } - [JsonProperty("isStalking")] - public bool? IsStalking { get; set; } + [JsonProperty("hasPendingFollowRequestFromYou")] + public bool? HasPendingFollowRequestFromYou { get; set; } - [JsonProperty("isPro")] - public bool? IsPro { get; set; } + [JsonProperty("hasPendingFollowRequestToYou")] + public bool? HasPendingFollowRequestToYou { get; set; } - [JsonProperty("isVerified")] - public bool? IsVerified { get; set; } + [JsonProperty("hasUnreadMentions")] + public bool? HasUnreadMentions { get; set; } - [JsonProperty("isLocked")] - public bool? IsLocked { get; set; } + [JsonProperty("hasUnreadMessagingMessage")] + public bool? HasUnreadMessagingMessage { get; set; } - [JsonProperty("isSuspended")] - public bool IsSuspended { get; set; } + [JsonProperty("hasUnreadNotification")] + public bool? HasUnreadNotification { get; set; } - [JsonProperty("lastUsedAt")] - [JsonConverter(typeof(IsoDateTimeConverter))] - public DateTime? LastUsedAt { get; set; } + [JsonProperty("hasUnreadSpecifiedNotes")] + public bool? HasUnreadSpecifiedNotes { get; set; } + + [JsonProperty("host")] + public string Host { get; set; } - [JsonProperty("links")] - public ApiResponse Links { get; set; } + [JsonProperty("location")] + public string Location { get; set; } [JsonProperty("name")] public string Name { get; set; } [JsonProperty("notesCount")] - public long NotesCount { get; set; } + public long? NotesCount { get; set; } [JsonProperty("pendingReceivedFollowRequestsCount")] - public long PendingReceivedFollowRequestsCount { get; set; } + public long? PendingReceivedFollowRequestsCount { get; set; } [JsonProperty("pinnedNotes")] public IEnumerable PinnedNotes { get; set; } @@ -157,42 +141,21 @@ public class User : ApiResponse [JsonProperty("pinnedNoteIds")] public IEnumerable PinnedNoteIds { get; set; } - [JsonProperty("profile")] - public Profile Profile { get; set; } - - [JsonProperty("sharedInbox")] - public string SharedInbox { get; set; } - [JsonProperty("twitter")] public Twitter Twitter { get; set; } [JsonProperty("twoFactorEnabled")] public bool? IsTwoFactorEnabled { get; set; } - [JsonProperty("uri")] - public string Uri { get; set; } + [JsonProperty("username")] + public string Username { get; set; } [JsonProperty("url")] public string Url { get; set; } [JsonProperty("updatedAt")] - [JsonConverter(typeof(IsoDateTimeConverter))] - public DateTime UpdatedAt { get; set; } - - [JsonProperty("username")] - public string Username { get; set; } - - [JsonProperty("usernameLower")] - public string UsernameLower { get; set; } - - [JsonProperty("wallpaperColor")] - [JsonConverter(typeof(RgbArrayToColorConverter))] - public Color? WallpaperColor { get; set; } - - [JsonProperty("wallpaperId")] - public string WallpaperId { get; set; } + public DateTime? UpdatedAt { get; set; } - [JsonProperty("wallpaperUrl")] - public string WallpaperUrl { get; set; } + // INCLUDE_SECRETS OPTS IS CURRENTLY NOT SUPPORTED IN DISBOARD } } \ No newline at end of file diff --git a/Source/Disboard.Misskey/Models/UserRecommendation.cs b/Source/Disboard.Misskey/Models/UserRecommendation.cs deleted file mode 100644 index 3204e81..0000000 --- a/Source/Disboard.Misskey/Models/UserRecommendation.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Disboard.Models; - -using Newtonsoft.Json; - -namespace Disboard.Misskey.Models -{ - public class UserRecommendation : ApiResponse - { - [JsonProperty("external")] - public bool External { get; set; } - - [JsonProperty("engine")] - public string Engine { get; set; } - - [JsonProperty("timeout")] - public int Timeout { get; set; } - } -} \ No newline at end of file diff --git a/Source/Disboard.Misskey/Models/UserWithCursor.cs b/Source/Disboard.Misskey/Models/UserWithCursor.cs deleted file mode 100644 index 513580d..0000000 --- a/Source/Disboard.Misskey/Models/UserWithCursor.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Collections.Generic; - -using Disboard.Models; - -using Newtonsoft.Json; - -namespace Disboard.Misskey.Models -{ - public class UserWithCursor : ApiResponse - { - [JsonProperty("users")] - public IEnumerable Users { get; set; } - - [JsonProperty("next")] - public string Next { get; set; } - } -} \ No newline at end of file diff --git a/Source/Disboard.Misskey/README.md b/Source/Disboard.Misskey/README.md index b87ada6..56a26a2 100644 --- a/Source/Disboard.Misskey/README.md +++ b/Source/Disboard.Misskey/README.md @@ -27,17 +27,21 @@ var misskey = new MisskeyClient("misskey.xyz"); // register app var permissions = new List { - Permission.AccountRead, Permission.AccountRead2, - Permission.AccountWrite, Permission.AccountWrite2, + Permission.AccountRead, Permission.AccountWrite, + Permission.BlocksRead, Permission.BlocksWrite, Permission.DriveRead, Permission.DriveWrite, - Permission.FavoritesRead, Permission.FavoriteWrite, + Permission.FavoritesRead, Permission.FavoritesWrite, Permission.FollowingRead, Permission.FollowingWrite, Permission.MessagingRead, Permission.MessagingWrite, - Permission.NoteWrite, - Permission.NotificationWrite, - Permission.ReactionWrite, - Permission.VoteWrite, + Permission.MutesRead, Permission.MutesWrite, + Permission.NotificationsRead, Permission.NotificationsWrite, + Permission.PagesRead, Permission.PagesWrite, + Permission.PageLikesRead, Permission.PageLikesWrite, + Permission.ReactionsRead, Permission.ReactionsWrite, + Permission.UserGroupsRead, Permission.UserGroupsWrite, + Permission.VotesWrite, }; + // permission is "string[]", because Misskey's permission is very flexible and possibility that it will increase in the future. await misskey.App.CreateAsync("Orion", "Orion is generic microblogging client", permissions.Select(w => w.ToStr()).ToArray(), "https://static.mochizuki.moe/callback.html"); @@ -46,8 +50,8 @@ var session = await misskey.Auth.Session.Generate(); Process.Start(session.Url); // Wait for user accepts client that access to your info -Console.ReadLine(); -await misskey.Auth.Session.UserKeyAsync(session.Token); +var token = Console.ReadLine(); +await misskey.Auth.Session.UserKeyAsync(token); // If you want to call REST API, please use method that has "Async()" suffix. await misskey.IAsync(); diff --git a/Source/Disboard/Converters/RgbArrayToColorConverter.cs b/Source/Disboard/Converters/RgbArrayToColorConverter.cs deleted file mode 100644 index bcad521..0000000 --- a/Source/Disboard/Converters/RgbArrayToColorConverter.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Linq; - -using Newtonsoft.Json; - -namespace Disboard.Converters -{ - /// - /// [r, g, b] to Color - /// - public class RgbArrayToColorConverter : JsonConverter - { - public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) - { - throw new NotImplementedException(); - } - - public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) - { - if (reader.TokenType == JsonToken.Null) - return null; - if (reader.TokenType != JsonToken.StartArray) - throw new NotSupportedException(); - - var array = new List(); - while (reader.Read() && reader.TokenType == JsonToken.Integer) - if (reader.Value is long l) - array.Add((int) l); - else - throw new NotSupportedException(); - - // XXX: たまーに 255 の範囲を超えるものが来る - array = array.Select(w => w >= 255 ? 255 : w).ToList(); - return Color.FromArgb(array[0], array[1], array[2]); - } - - public override bool CanConvert(Type objectType) - { - throw new NotImplementedException(); - } - } -} \ No newline at end of file diff --git a/Source/Disboard/Converters/RgbToColorConverter.cs b/Source/Disboard/Converters/RgbToColorConverter.cs new file mode 100644 index 0000000..49ae921 --- /dev/null +++ b/Source/Disboard/Converters/RgbToColorConverter.cs @@ -0,0 +1,46 @@ +using System; +using System.Drawing; +using System.Text.RegularExpressions; + +using Newtonsoft.Json; + +namespace Disboard.Converters +{ + /// + /// rgb(r,g,b) / rgba(r,g,b,a) to Color + /// + public class RgbToColorConverter : JsonConverter + { + private readonly Regex _color = new Regex(@"rgba?\((?\w{1,3}),\s?(?\w{1,3}),\s?(?\w{1,3})(,\s?(?\w{1,3}))?\)", RegexOptions.Compiled); + + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + throw new NotImplementedException(); + } + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + if (reader.TokenType == JsonToken.Null) + return null; + if (reader.TokenType != JsonToken.String) + throw new NotSupportedException(); + + var color = reader.Value as string; + if (!_color.IsMatch(color ?? throw new InvalidOperationException())) + throw new NotSupportedException(); + + var match = _color.Match(color); + var (r, g, b) = (int.Parse(match.Groups["red"].Value), int.Parse(match.Groups["green"].Value), int.Parse(match.Groups["blue"].Value)); + if (string.IsNullOrEmpty(match.Groups["alpha"].Value)) + return Color.FromArgb(r, g, b); + + var a = int.Parse(match.Groups["alpha"].Value); + return Color.FromArgb(a, r, g, b); + } + + public override bool CanConvert(Type objectType) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Source/Tests/Disboard.Test/Converters/RgbArrayToColorConverterTest.cs b/Source/Tests/Disboard.Test/Converters/RgbArrayToColorConverterTest.cs deleted file mode 100644 index fa239f1..0000000 --- a/Source/Tests/Disboard.Test/Converters/RgbArrayToColorConverterTest.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System.Drawing; - -using Disboard.Converters; - -using Newtonsoft.Json; - -using Xunit; - -namespace Disboard.Test.Converters -{ - public class RgbArrayToColorConverterTest - { - public class ExpectObject - { - [JsonProperty("color")] - [JsonConverter(typeof(RgbArrayToColorConverter))] - public Color Color { get; set; } - } - - [Fact] - public void ReadJsonInvalidColor() - { - const string json = "{\"color\":[0,256,10000]}"; - var r = JsonConvert.DeserializeObject(json); - r.Color.R.Is((byte) 0); - r.Color.G.Is((byte) 255); - r.Color.B.Is((byte) 255); - } - - [Fact] - public void ReadJsonValidColor() - { - const string json = "{\"color\":[125,172,253]}"; - var r = JsonConvert.DeserializeObject(json); - r.Color.R.Is((byte) 125); - r.Color.G.Is((byte) 172); - r.Color.B.Is((byte) 253); - } - } -} \ No newline at end of file diff --git a/Source/Tests/Disboard.Test/Converters/RgbToColorConverterTest.cs b/Source/Tests/Disboard.Test/Converters/RgbToColorConverterTest.cs new file mode 100644 index 0000000..f055e53 --- /dev/null +++ b/Source/Tests/Disboard.Test/Converters/RgbToColorConverterTest.cs @@ -0,0 +1,62 @@ +using System.Drawing; + +using Disboard.Converters; + +using Newtonsoft.Json; + +using Xunit; + +namespace Disboard.Test.Converters +{ + public class RgbToColorConverterTest + { + public class ExpectObject + { + [JsonProperty("color")] + [JsonConverter(typeof(RgbToColorConverter))] + public Color Color { get; set; } + } + + [Fact] + public void ReadJsonValidRgbaColor() + { + const string json = "{\"color\":\"rgba(125,255,63,128)\"}"; + var r = JsonConvert.DeserializeObject(json); + r.Color.R.Is((byte) 125); + r.Color.G.Is((byte) 255); + r.Color.B.Is((byte) 63); + r.Color.A.Is((byte) 128); + } + + [Fact] + public void ReadJsonValidRgbaColorIncludingSpaces() + { + const string json = "{\"color\":\"rgba(125, 255, 63, 128)\"}"; + var r = JsonConvert.DeserializeObject(json); + r.Color.R.Is((byte) 125); + r.Color.G.Is((byte) 255); + r.Color.B.Is((byte) 63); + r.Color.A.Is((byte) 128); + } + + [Fact] + public void ReadJsonValidRgbColor() + { + const string json = "{\"color\":\"rgb(125,172,253)\"}"; + var r = JsonConvert.DeserializeObject(json); + r.Color.R.Is((byte) 125); + r.Color.G.Is((byte) 172); + r.Color.B.Is((byte) 253); + } + + [Fact] + public void ReadJsonValidRgbColorIncludingSpaces() + { + const string json = "{\"color\":\"rgb(125, 172, 253)\"}"; + var r = JsonConvert.DeserializeObject(json); + r.Color.R.Is((byte) 125); + r.Color.G.Is((byte) 172); + r.Color.B.Is((byte) 253); + } + } +} \ No newline at end of file