From cd034b94f95c7f10fc9a7c588b244196a0300d39 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Fri, 31 Dec 2021 15:31:03 +0530 Subject: [PATCH 001/216] =?UTF-8?q?Add=20support=20to=20update=20media=20t?= =?UTF-8?q?ypes=20=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UpdateBlocks/FileUpdateBlock.cs | 10 ++++++++++ .../UpdateBlocks/ImageUpdateBlock.cs | 10 ++++++++++ .../UpdateBlocks/PDFUpdateBlock.cs | 10 ++++++++++ .../UpdateBlocks/VideoUpdateBlock.cs | 10 ++++++++++ 4 files changed, 40 insertions(+) create mode 100644 Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/FileUpdateBlock.cs create mode 100644 Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/ImageUpdateBlock.cs create mode 100644 Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/PDFUpdateBlock.cs create mode 100644 Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/VideoUpdateBlock.cs diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/FileUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/FileUpdateBlock.cs new file mode 100644 index 00000000..30d0dd9c --- /dev/null +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/FileUpdateBlock.cs @@ -0,0 +1,10 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class FileUpdateBlock : UpdateBlock, IUpdateBlock + { + [JsonProperty("file")] + public IFileObjectInput File { get; set; } + } +} diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/ImageUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/ImageUpdateBlock.cs new file mode 100644 index 00000000..6679c61b --- /dev/null +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/ImageUpdateBlock.cs @@ -0,0 +1,10 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class ImageUpdateBlock : UpdateBlock, IUpdateBlock + { + [JsonProperty("image")] + public IFileObjectInput Image { get; set; } + } +} diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/PDFUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/PDFUpdateBlock.cs new file mode 100644 index 00000000..8c56b7ff --- /dev/null +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/PDFUpdateBlock.cs @@ -0,0 +1,10 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class PDFUpdateBlock : UpdateBlock, IUpdateBlock + { + [JsonProperty("pdf")] + public IFileObjectInput PDF { get; set; } + } +} diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/VideoUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/VideoUpdateBlock.cs new file mode 100644 index 00000000..ec28aae3 --- /dev/null +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/VideoUpdateBlock.cs @@ -0,0 +1,10 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class VideoUpdateBlock : UpdateBlock, IUpdateBlock + { + [JsonProperty("video")] + public IFileObjectInput Video { get; set; } + } +} From 1fbf465b7a4327bbb482f8cef2dd500c75f331a2 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Fri, 31 Dec 2021 15:31:33 +0530 Subject: [PATCH 002/216] =?UTF-8?q?Update=20integration=20test=20to=20veri?= =?UTF-8?q?fy=20media=20blocks=20are=20updated=20=E2=9C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IBlocksClientTests.cs | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Test/Notion.IntegrationTests/IBlocksClientTests.cs b/Test/Notion.IntegrationTests/IBlocksClientTests.cs index 0db08a7c..635f8caf 100644 --- a/Test/Notion.IntegrationTests/IBlocksClientTests.cs +++ b/Test/Notion.IntegrationTests/IBlocksClientTests.cs @@ -398,6 +398,36 @@ private static IEnumerable BlockData() Assert.Equal("Test 2", quoteBlock.Quote.Text.OfType().First().Text.Content); }) + }, + new object[] + { + new ImageBlock() { + Image = new ExternalFile + { + External = new ExternalFile.Info + { + Url = "https://zephoria.com/wp-content/uploads/2014/08/online-community.jpg" + } + } + }, + new ImageUpdateBlock() + { + Image = new ExternalFileInput + { + External = new ExternalFileInput.Data + { + Url = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg" + } + } + }, + new Action (block => + { + Assert.NotNull(block); + var imageBlock = Assert.IsType(block); + var imageFile = Assert.IsType(imageBlock.Image); + + Assert.Equal("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", imageFile.External.Url); + }) } }; } From bb87ec535bdba17170f991fe22d7bf5ffac6915c Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Fri, 31 Dec 2021 15:35:29 +0530 Subject: [PATCH 003/216] =?UTF-8?q?Fix:=20Use=20correct=20type=20?= =?UTF-8?q?=F0=9F=90=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Notion.Client/Models/Blocks/QuoteBlock.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/Notion.Client/Models/Blocks/QuoteBlock.cs b/Src/Notion.Client/Models/Blocks/QuoteBlock.cs index 3a4c6d9f..7108980c 100644 --- a/Src/Notion.Client/Models/Blocks/QuoteBlock.cs +++ b/Src/Notion.Client/Models/Blocks/QuoteBlock.cs @@ -13,7 +13,7 @@ public class QuoteBlock : Block, IColumnChildrenBlock, INonColumnBlock public class Info { [JsonProperty("text")] - public IEnumerable Text { get; set; } + public IEnumerable Text { get; set; } [JsonProperty("children")] public IEnumerable Children { get; set; } From 2039a3e7b7ad5d0902daf0c82bd44b2a8f45534b Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Fri, 31 Dec 2021 15:52:03 +0530 Subject: [PATCH 004/216] =?UTF-8?q?Add=20support=20to=20update=20embed=20b?= =?UTF-8?q?lock=20=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Added integration tests --- .../UpdateBlocks/EmbedUpdateBlock.cs | 16 +++++++++++++ .../IBlocksClientTests.cs | 24 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/EmbedUpdateBlock.cs diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/EmbedUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/EmbedUpdateBlock.cs new file mode 100644 index 00000000..35f509e2 --- /dev/null +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/EmbedUpdateBlock.cs @@ -0,0 +1,16 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class EmbedUpdateBlock : UpdateBlock, IUpdateBlock + { + [JsonProperty("embed")] + public Data Embed { get; set; } + + public class Data + { + [JsonProperty("url")] + public string Url { get; set; } + } + } +} diff --git a/Test/Notion.IntegrationTests/IBlocksClientTests.cs b/Test/Notion.IntegrationTests/IBlocksClientTests.cs index 635f8caf..a15c9014 100644 --- a/Test/Notion.IntegrationTests/IBlocksClientTests.cs +++ b/Test/Notion.IntegrationTests/IBlocksClientTests.cs @@ -428,6 +428,30 @@ private static IEnumerable BlockData() Assert.Equal("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", imageFile.External.Url); }) + }, + new object[] + { + new EmbedBlock() + { + Embed = new EmbedBlock.Info + { + Url = "https://zephoria.com/wp-content/uploads/2014/08/online-community.jpg" + } + }, + new EmbedUpdateBlock() + { + Embed = new EmbedUpdateBlock.Data + { + Url = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg" + } + }, + new Action (block => + { + Assert.NotNull(block); + var embedBlock = Assert.IsType(block); + + Assert.Equal("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", embedBlock.Embed.Url); + }) } }; } From 5969201131bdf5f736f8fb2d4395ecf56ac2adf1 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Fri, 31 Dec 2021 17:31:10 +0530 Subject: [PATCH 005/216] =?UTF-8?q?Add=20support=20for=20Template=20Block?= =?UTF-8?q?=20=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UpdateBlocks/TemplateUpdateBlock.cs | 17 +++++ Src/Notion.Client/Models/Blocks/BlockType.cs | 3 + Src/Notion.Client/Models/Blocks/IBlock.cs | 1 + .../Models/Blocks/IColumnChildrenBlock.cs | 64 ++----------------- .../Models/Blocks/TemplateBlock.cs | 22 +++++++ 5 files changed, 49 insertions(+), 58 deletions(-) create mode 100644 Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TemplateUpdateBlock.cs create mode 100644 Src/Notion.Client/Models/Blocks/TemplateBlock.cs diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TemplateUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TemplateUpdateBlock.cs new file mode 100644 index 00000000..032cb335 --- /dev/null +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TemplateUpdateBlock.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class TemplateUpdateBlock : UpdateBlock, IUpdateBlock + { + [JsonProperty("template")] + public Data Template { get; set; } + + public class Data + { + [JsonProperty("text")] + public IEnumerable Text { get; set; } + } + } +} diff --git a/Src/Notion.Client/Models/Blocks/BlockType.cs b/Src/Notion.Client/Models/Blocks/BlockType.cs index b46e6c9a..03b0d35d 100644 --- a/Src/Notion.Client/Models/Blocks/BlockType.cs +++ b/Src/Notion.Client/Models/Blocks/BlockType.cs @@ -82,6 +82,9 @@ public enum BlockType [EnumMember(Value = "column_list")] ColumnList, + [EnumMember(Value = "template")] + Template, + [EnumMember(Value = "unsupported")] Unsupported } diff --git a/Src/Notion.Client/Models/Blocks/IBlock.cs b/Src/Notion.Client/Models/Blocks/IBlock.cs index e36f371a..afabc915 100644 --- a/Src/Notion.Client/Models/Blocks/IBlock.cs +++ b/Src/Notion.Client/Models/Blocks/IBlock.cs @@ -28,6 +28,7 @@ namespace Notion.Client [JsonSubtypes.KnownSubType(typeof(PDFBlock), BlockType.PDF)] [JsonSubtypes.KnownSubType(typeof(QuoteBlock), BlockType.Quote)] [JsonSubtypes.KnownSubType(typeof(TableOfContentsBlock), BlockType.TableOfContents)] + [JsonSubtypes.KnownSubType(typeof(TemplateBlock), BlockType.Template)] [JsonSubtypes.KnownSubType(typeof(ToDoBlock), BlockType.ToDo)] [JsonSubtypes.KnownSubType(typeof(ToggleBlock), BlockType.Toggle)] [JsonSubtypes.KnownSubType(typeof(VideoBlock), BlockType.Video)] diff --git a/Src/Notion.Client/Models/Blocks/IColumnChildrenBlock.cs b/Src/Notion.Client/Models/Blocks/IColumnChildrenBlock.cs index 9eaa5622..35370460 100644 --- a/Src/Notion.Client/Models/Blocks/IColumnChildrenBlock.cs +++ b/Src/Notion.Client/Models/Blocks/IColumnChildrenBlock.cs @@ -1,65 +1,13 @@ -using JsonSubTypes; -using Newtonsoft.Json; - -namespace Notion.Client +namespace Notion.Client { - //[JsonConverter(typeof(JsonSubtypes), "type")] - //[JsonSubtypes.KnownSubType(typeof(AudioBlock), BlockType.Audio)] - //[JsonSubtypes.KnownSubType(typeof(BookmarkBlock), BlockType.Bookmark)] - //[JsonSubtypes.KnownSubType(typeof(BreadcrumbBlock), BlockType.Breadcrumb)] - //[JsonSubtypes.KnownSubType(typeof(BulletedListItemBlock), BlockType.BulletedListItem)] - //[JsonSubtypes.KnownSubType(typeof(CalloutBlock), BlockType.Callout)] - //[JsonSubtypes.KnownSubType(typeof(ChildDatabaseBlock), BlockType.ChildDatabase)] - //[JsonSubtypes.KnownSubType(typeof(ChildPageBlock), BlockType.ChildPage)] - //[JsonSubtypes.KnownSubType(typeof(CodeBlock), BlockType.Code)] - //[JsonSubtypes.KnownSubType(typeof(DividerBlock), BlockType.Divider)] - //[JsonSubtypes.KnownSubType(typeof(EmbedBlock), BlockType.Embed)] - //[JsonSubtypes.KnownSubType(typeof(EquationBlock), BlockType.Equation)] - //[JsonSubtypes.KnownSubType(typeof(FileBlock), BlockType.File)] - //[JsonSubtypes.KnownSubType(typeof(HeadingOneBlock), BlockType.Heading_1)] - //[JsonSubtypes.KnownSubType(typeof(HeadingTwoBlock), BlockType.Heading_2)] - //[JsonSubtypes.KnownSubType(typeof(HeadingThreeeBlock), BlockType.Heading_3)] - //[JsonSubtypes.KnownSubType(typeof(ImageBlock), BlockType.Image)] - //[JsonSubtypes.KnownSubType(typeof(NumberedListItemBlock), BlockType.NumberedListItem)] - //[JsonSubtypes.KnownSubType(typeof(ParagraphBlock), BlockType.Paragraph)] - //[JsonSubtypes.KnownSubType(typeof(PDFBlock), BlockType.PDF)] - //[JsonSubtypes.KnownSubType(typeof(QuoteBlock), BlockType.Quote)] - //[JsonSubtypes.KnownSubType(typeof(TableOfContentsBlock), BlockType.TableOfContents)] - //[JsonSubtypes.KnownSubType(typeof(ToDoBlock), BlockType.ToDo)] - //[JsonSubtypes.KnownSubType(typeof(ToggleBlock), BlockType.Toggle)] - //[JsonSubtypes.KnownSubType(typeof(VideoBlock), BlockType.Video)] - //[JsonSubtypes.KnownSubType(typeof(UnsupportedBlock), BlockType.Unsupported)] - public interface IColumnChildrenBlock : IBlock + public interface ITemplateChildrendBlock : IBlock + { + } + + public interface IColumnChildrenBlock : IBlock, ITemplateChildrendBlock { } - //[JsonConverter(typeof(JsonSubtypes), "type")] - //[JsonSubtypes.KnownSubType(typeof(AudioBlock), BlockType.Audio)] - //[JsonSubtypes.KnownSubType(typeof(BookmarkBlock), BlockType.Bookmark)] - //[JsonSubtypes.KnownSubType(typeof(BreadcrumbBlock), BlockType.Breadcrumb)] - //[JsonSubtypes.KnownSubType(typeof(BulletedListItemBlock), BlockType.BulletedListItem)] - //[JsonSubtypes.KnownSubType(typeof(CalloutBlock), BlockType.Callout)] - //[JsonSubtypes.KnownSubType(typeof(ChildPageBlock), BlockType.ChildPage)] - //[JsonSubtypes.KnownSubType(typeof(ChildDatabaseBlock), BlockType.ChildDatabase)] - //[JsonSubtypes.KnownSubType(typeof(CodeBlock), BlockType.Code)] - //[JsonSubtypes.KnownSubType(typeof(ColumnListBlock), BlockType.ColumnList)] - //[JsonSubtypes.KnownSubType(typeof(DividerBlock), BlockType.Divider)] - //[JsonSubtypes.KnownSubType(typeof(EmbedBlock), BlockType.Embed)] - //[JsonSubtypes.KnownSubType(typeof(EquationBlock), BlockType.Equation)] - //[JsonSubtypes.KnownSubType(typeof(FileBlock), BlockType.File)] - //[JsonSubtypes.KnownSubType(typeof(HeadingOneBlock), BlockType.Heading_1)] - //[JsonSubtypes.KnownSubType(typeof(HeadingTwoBlock), BlockType.Heading_2)] - //[JsonSubtypes.KnownSubType(typeof(HeadingThreeeBlock), BlockType.Heading_3)] - //[JsonSubtypes.KnownSubType(typeof(ImageBlock), BlockType.Image)] - //[JsonSubtypes.KnownSubType(typeof(NumberedListItemBlock), BlockType.NumberedListItem)] - //[JsonSubtypes.KnownSubType(typeof(ParagraphBlock), BlockType.Paragraph)] - //[JsonSubtypes.KnownSubType(typeof(PDFBlock), BlockType.PDF)] - //[JsonSubtypes.KnownSubType(typeof(QuoteBlock), BlockType.Quote)] - //[JsonSubtypes.KnownSubType(typeof(TableOfContentsBlock), BlockType.TableOfContents)] - //[JsonSubtypes.KnownSubType(typeof(ToDoBlock), BlockType.ToDo)] - //[JsonSubtypes.KnownSubType(typeof(ToggleBlock), BlockType.Toggle)] - //[JsonSubtypes.KnownSubType(typeof(VideoBlock), BlockType.Video)] - //[JsonSubtypes.KnownSubType(typeof(UnsupportedBlock), BlockType.Unsupported)] public interface INonColumnBlock : IBlock { } diff --git a/Src/Notion.Client/Models/Blocks/TemplateBlock.cs b/Src/Notion.Client/Models/Blocks/TemplateBlock.cs new file mode 100644 index 00000000..2fceb845 --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/TemplateBlock.cs @@ -0,0 +1,22 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class TemplateBlock : Block, IColumnChildrenBlock, INonColumnBlock + { + public override BlockType Type => BlockType.Template; + + [JsonProperty("template")] + public Data Template { get; set; } + + public class Data + { + [JsonProperty("text")] + public IEnumerable Text { get; set; } + + [JsonProperty("children")] + public IEnumerable Children { get; set; } + } + } +} From 85a73d72947ba3c5f4cfa5a4b69a6c5a1130c7a3 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Fri, 31 Dec 2021 17:31:41 +0530 Subject: [PATCH 006/216] =?UTF-8?q?Add=20integration=20test=20for=20Templa?= =?UTF-8?q?te=20block=20=E2=9C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IBlocksClientTests.cs | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/Test/Notion.IntegrationTests/IBlocksClientTests.cs b/Test/Notion.IntegrationTests/IBlocksClientTests.cs index a15c9014..bea88c1b 100644 --- a/Test/Notion.IntegrationTests/IBlocksClientTests.cs +++ b/Test/Notion.IntegrationTests/IBlocksClientTests.cs @@ -452,6 +452,60 @@ private static IEnumerable BlockData() Assert.Equal("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", embedBlock.Embed.Url); }) + }, + new object[] + { + new TemplateBlock() + { + Template = new TemplateBlock.Data + { + Text = new List + { + new RichTextText + { + Text = new Text + { + Content = "Test Template" + } + } + }, + Children = new List + { + new EmbedBlock() + { + Embed = new EmbedBlock.Info + { + Url = "https://zephoria.com/wp-content/uploads/2014/08/online-community.jpg" + } + } + } + } + }, + new TemplateUpdateBlock() + { + Template = new TemplateUpdateBlock.Data + { + Text = new List + { + new RichTextTextInput + { + Text = new Text + { + Content = "Test Template 2" + } + } + } + } + }, + new Action (block => + { + Assert.NotNull(block); + var templateBlock = Assert.IsType(block); + + Assert.Single(templateBlock.Template.Text); + Assert.Null(templateBlock.Template.Children); + Assert.Equal("Test Template 2", templateBlock.Template.Text.OfType().First().Text.Content); + }) } }; } From ad84cfd0237a7b55b982d48f136de3211c91ff71 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Fri, 31 Dec 2021 18:25:59 +0530 Subject: [PATCH 007/216] =?UTF-8?q?Add=20support=20for=20link=5Fto=5Fpage?= =?UTF-8?q?=20block=20type=20=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UpdateBlocks/LinkToPageUpdateBlock.cs | 10 ++++++++++ Src/Notion.Client/Models/Blocks/BlockType.cs | 3 +++ Src/Notion.Client/Models/Blocks/IBlock.cs | 1 + Src/Notion.Client/Models/Blocks/LinkToPageBlock.cs | 12 ++++++++++++ 4 files changed, 26 insertions(+) create mode 100644 Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/LinkToPageUpdateBlock.cs create mode 100644 Src/Notion.Client/Models/Blocks/LinkToPageBlock.cs diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/LinkToPageUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/LinkToPageUpdateBlock.cs new file mode 100644 index 00000000..f6407cd4 --- /dev/null +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/LinkToPageUpdateBlock.cs @@ -0,0 +1,10 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class LinkToPageUpdateBlock : UpdateBlock, IUpdateBlock + { + [JsonProperty("link_to_page")] + public IPageParentInput LinkToPage { get; set; } + } +} diff --git a/Src/Notion.Client/Models/Blocks/BlockType.cs b/Src/Notion.Client/Models/Blocks/BlockType.cs index 03b0d35d..ab7fdb19 100644 --- a/Src/Notion.Client/Models/Blocks/BlockType.cs +++ b/Src/Notion.Client/Models/Blocks/BlockType.cs @@ -85,6 +85,9 @@ public enum BlockType [EnumMember(Value = "template")] Template, + [EnumMember(Value = "link_to_page")] + LinkToPage, + [EnumMember(Value = "unsupported")] Unsupported } diff --git a/Src/Notion.Client/Models/Blocks/IBlock.cs b/Src/Notion.Client/Models/Blocks/IBlock.cs index afabc915..a7e925d1 100644 --- a/Src/Notion.Client/Models/Blocks/IBlock.cs +++ b/Src/Notion.Client/Models/Blocks/IBlock.cs @@ -23,6 +23,7 @@ namespace Notion.Client [JsonSubtypes.KnownSubType(typeof(HeadingTwoBlock), BlockType.Heading_2)] [JsonSubtypes.KnownSubType(typeof(HeadingThreeeBlock), BlockType.Heading_3)] [JsonSubtypes.KnownSubType(typeof(ImageBlock), BlockType.Image)] + [JsonSubtypes.KnownSubType(typeof(LinkToPageBlock), BlockType.LinkToPage)] [JsonSubtypes.KnownSubType(typeof(NumberedListItemBlock), BlockType.NumberedListItem)] [JsonSubtypes.KnownSubType(typeof(ParagraphBlock), BlockType.Paragraph)] [JsonSubtypes.KnownSubType(typeof(PDFBlock), BlockType.PDF)] diff --git a/Src/Notion.Client/Models/Blocks/LinkToPageBlock.cs b/Src/Notion.Client/Models/Blocks/LinkToPageBlock.cs new file mode 100644 index 00000000..30d3d7dd --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/LinkToPageBlock.cs @@ -0,0 +1,12 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class LinkToPageBlock : Block, IColumnChildrenBlock, INonColumnBlock + { + public override BlockType Type => BlockType.LinkToPage; + + [JsonProperty("link_to_page")] + public IPageParent LinkToPage { get; set; } + } +} From 20ed7092f08c252dfdc9038b64b389d899fab14b Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Fri, 31 Dec 2021 18:26:38 +0530 Subject: [PATCH 008/216] =?UTF-8?q?Add=20integration=20test=20to=20check?= =?UTF-8?q?=20link=5Fto=5Fpage=20block=20=E2=9C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IBlocksClientTests.cs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Test/Notion.IntegrationTests/IBlocksClientTests.cs b/Test/Notion.IntegrationTests/IBlocksClientTests.cs index bea88c1b..986ed5b6 100644 --- a/Test/Notion.IntegrationTests/IBlocksClientTests.cs +++ b/Test/Notion.IntegrationTests/IBlocksClientTests.cs @@ -506,6 +506,35 @@ private static IEnumerable BlockData() Assert.Null(templateBlock.Template.Children); Assert.Equal("Test Template 2", templateBlock.Template.Text.OfType().First().Text.Content); }) + }, + new object[] + { + new LinkToPageBlock() + { + LinkToPage = new PageParent + { + Type = ParentType.PageId, + PageId = "533578e3edf14c0a91a9da6b09bac3ee" + } + }, + new LinkToPageUpdateBlock() + { + LinkToPage = new ParentPageInput + { + PageId = "3c357473a28149a488c010d2b245a589" + } + }, + new Action(block => + { + Assert.NotNull(block); + var linkToPageBlock = Assert.IsType(block); + + var pageParent = Assert.IsType(linkToPageBlock.LinkToPage); + + // TODO: Currently the api doesn't allow to update the link_to_page block type + // This will change to updated ID once api start to support + Assert.Equal(Guid.Parse("533578e3edf14c0a91a9da6b09bac3ee"), Guid.Parse(pageParent.PageId)); + }) } }; } From 049b5034a051d0fbb6e69b2827c7a47c674dbdd4 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Fri, 31 Dec 2021 19:06:14 +0530 Subject: [PATCH 009/216] =?UTF-8?q?Add=20support=20for=20Syncedblock=20typ?= =?UTF-8?q?e=20=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UpdateBlocks/AudioUpdateBlock.cs | 3 +- .../UpdateBlocks/SyncedBlockUpdateBlock.cs | 22 +++++++++++++ Src/Notion.Client/Models/Blocks/BlockType.cs | 3 ++ .../Models/Blocks/IColumnChildrenBlock.cs | 6 +++- .../Models/Blocks/SyncedBlockBlock.cs | 31 +++++++++++++++++++ 5 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/SyncedBlockUpdateBlock.cs create mode 100644 Src/Notion.Client/Models/Blocks/SyncedBlockBlock.cs diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/AudioUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/AudioUpdateBlock.cs index f341e441..8747ad63 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/AudioUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/AudioUpdateBlock.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json; +using System.Collections.Generic; +using Newtonsoft.Json; namespace Notion.Client { diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/SyncedBlockUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/SyncedBlockUpdateBlock.cs new file mode 100644 index 00000000..97f393fe --- /dev/null +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/SyncedBlockUpdateBlock.cs @@ -0,0 +1,22 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class SyncedBlockUpdateBlock : UpdateBlock, IUpdateBlock + { + [JsonProperty("synced_block")] + public Data SyncedBlock { get; set; } + + public class Data + { + [JsonProperty("synced_from")] + public SyncedFromBlockId SyncedFrom { get; set; } + + public class SyncedFromBlockId + { + [JsonProperty("block_id")] + public string BlockId { get; set; } + } + } + } +} diff --git a/Src/Notion.Client/Models/Blocks/BlockType.cs b/Src/Notion.Client/Models/Blocks/BlockType.cs index ab7fdb19..6ebec8f1 100644 --- a/Src/Notion.Client/Models/Blocks/BlockType.cs +++ b/Src/Notion.Client/Models/Blocks/BlockType.cs @@ -88,6 +88,9 @@ public enum BlockType [EnumMember(Value = "link_to_page")] LinkToPage, + [EnumMember(Value = "synced_block")] + SyncedBlock, + [EnumMember(Value = "unsupported")] Unsupported } diff --git a/Src/Notion.Client/Models/Blocks/IColumnChildrenBlock.cs b/Src/Notion.Client/Models/Blocks/IColumnChildrenBlock.cs index 35370460..673bc156 100644 --- a/Src/Notion.Client/Models/Blocks/IColumnChildrenBlock.cs +++ b/Src/Notion.Client/Models/Blocks/IColumnChildrenBlock.cs @@ -4,7 +4,11 @@ public interface ITemplateChildrendBlock : IBlock { } - public interface IColumnChildrenBlock : IBlock, ITemplateChildrendBlock + public interface ISyncedBlockChildren : IBlock + { + } + + public interface IColumnChildrenBlock : IBlock, ITemplateChildrendBlock, ISyncedBlockChildren { } diff --git a/Src/Notion.Client/Models/Blocks/SyncedBlockBlock.cs b/Src/Notion.Client/Models/Blocks/SyncedBlockBlock.cs new file mode 100644 index 00000000..33c4dd25 --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/SyncedBlockBlock.cs @@ -0,0 +1,31 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class SyncedBlockBlock : Block, IColumnChildrenBlock, INonColumnBlock + { + public override BlockType Type => BlockType.SyncedBlock; + + [JsonProperty("synced_block")] + public Data SyncedBlock { get; set; } + + public class Data + { + [JsonProperty("synced_from")] + public SyncedFromBlockId SyncedFrom { get; set; } + + [JsonProperty("children")] + public IEnumerable Children { get; set; } + + public class SyncedFromBlockId + { + [JsonProperty("type")] + public string Type { get; set; } + + [JsonProperty("block_id")] + public string BlockId { get; set; } + } + } + } +} From 74cea63fd776d6abb503b8551434f9f0a73bf9d3 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 1 Jan 2022 23:20:53 +0530 Subject: [PATCH 010/216] Update VersionPrefix to 2.2.3-preview --- Src/Notion.Client/Notion.Client.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/Notion.Client/Notion.Client.csproj b/Src/Notion.Client/Notion.Client.csproj index faaa9fb0..c1b237d1 100644 --- a/Src/Notion.Client/Notion.Client.csproj +++ b/Src/Notion.Client/Notion.Client.csproj @@ -1,7 +1,7 @@  - 2.2.1-preview + 2.2.3-preview netstandard2.0 7.3 From e67ec288fa444faed9a1ca3c3d2685880db0e0a9 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sun, 9 Jan 2022 19:32:22 +0530 Subject: [PATCH 011/216] Convert Rollup Function type to string --- .../RollupConfigPropertySchema.cs | 4 +- .../RollupConfigUpdatePropertySchema.cs | 4 +- .../Database/Properties/RollupProperty.cs | 57 +------------------ 3 files changed, 4 insertions(+), 61 deletions(-) diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/RollupConfigPropertySchema.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/RollupConfigPropertySchema.cs index e4065344..ac3c5220 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/RollupConfigPropertySchema.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/RollupConfigPropertySchema.cs @@ -1,5 +1,4 @@ using Newtonsoft.Json; -using Newtonsoft.Json.Converters; namespace Notion.Client { @@ -18,7 +17,6 @@ public class RollupConfigPropertySchema : IPropertySchema public string RollupPropertyId { get; set; } [JsonProperty("function")] - [JsonConverter(typeof(StringEnumConverter))] - public Function Function { get; set; } + public string Function { get; set; } } } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/RollupConfigUpdatePropertySchema.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/RollupConfigUpdatePropertySchema.cs index 8d3395f6..2f38731b 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/RollupConfigUpdatePropertySchema.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/RollupConfigUpdatePropertySchema.cs @@ -1,5 +1,4 @@ using Newtonsoft.Json; -using Newtonsoft.Json.Converters; namespace Notion.Client { @@ -18,7 +17,6 @@ public class RollupConfigUpdatePropertySchema : UpdatePropertySchema, IUpdatePro public string RollupPropertyId { get; set; } [JsonProperty("function")] - [JsonConverter(typeof(StringEnumConverter))] - public Function Function { get; set; } + public string Function { get; set; } } } diff --git a/Src/Notion.Client/Models/Database/Properties/RollupProperty.cs b/Src/Notion.Client/Models/Database/Properties/RollupProperty.cs index 5176dd88..8ce88b15 100644 --- a/Src/Notion.Client/Models/Database/Properties/RollupProperty.cs +++ b/Src/Notion.Client/Models/Database/Properties/RollupProperty.cs @@ -1,6 +1,4 @@ -using System.Runtime.Serialization; -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; +using Newtonsoft.Json; namespace Notion.Client { @@ -27,57 +25,6 @@ public class Rollup public string RollupPropertyId { get; set; } [JsonProperty("function")] - [JsonConverter(typeof(StringEnumConverter))] - public Function Function { get; set; } - } - - public enum Function - { - [EnumMember(Value = null)] - Unknown, - - [EnumMember(Value = "count_all")] - CountAll, - [EnumMember(Value = "count_values")] - CountValues, - - [EnumMember(Value = "count_unique_values")] - CountUniqueValues, - - [EnumMember(Value = "count_empty")] - CountEmpty, - - [EnumMember(Value = "count_not_empty")] - CountNotEmpty, - - [EnumMember(Value = "percent_empty")] - PercentEmpty, - - [EnumMember(Value = "percent_not_empty")] - PercentNotEmpty, - - [EnumMember(Value = "sum")] - Sum, - - [EnumMember(Value = "average")] - Average, - - [EnumMember(Value = "median")] - Median, - - [EnumMember(Value = "min")] - Min, - - [EnumMember(Value = "max")] - Max, - - [EnumMember(Value = "range")] - Range, - - [EnumMember(Value = "show_original")] - ShowOriginal, - - [EnumMember(Value = "show_unique")] - ShowUnique + public string Function { get; set; } } } From 3eaf5c839f1ced42bbe3fd9c224c98778de6b3c6 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sun, 9 Jan 2022 19:47:44 +0530 Subject: [PATCH 012/216] Remove variable enums types --- .../PropertySchema/SelectOptionSchema.cs | 4 +- .../Database/Properties/NumberProperty.cs | 106 +----------------- .../Database/Properties/SelectProperty.cs | 41 +------ Test/Notion.UnitTests/DatabasesClientTests.cs | 32 +++--- Test/Notion.UnitTests/PropertyTests.cs | 38 ------- 5 files changed, 20 insertions(+), 201 deletions(-) diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/SelectOptionSchema.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/SelectOptionSchema.cs index c31aef9f..12989d1f 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/SelectOptionSchema.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/SelectOptionSchema.cs @@ -1,5 +1,4 @@ using Newtonsoft.Json; -using Newtonsoft.Json.Converters; namespace Notion.Client { @@ -9,7 +8,6 @@ public class SelectOptionSchema public string Name { get; set; } [JsonProperty("color")] - [JsonConverter(typeof(StringEnumConverter))] - public Color Color { get; set; } + public string Color { get; set; } } } diff --git a/Src/Notion.Client/Models/Database/Properties/NumberProperty.cs b/Src/Notion.Client/Models/Database/Properties/NumberProperty.cs index a00d7d9b..f50e11a2 100644 --- a/Src/Notion.Client/Models/Database/Properties/NumberProperty.cs +++ b/Src/Notion.Client/Models/Database/Properties/NumberProperty.cs @@ -1,6 +1,4 @@ -using System.Runtime.Serialization; -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; +using Newtonsoft.Json; namespace Notion.Client { @@ -15,106 +13,6 @@ public class NumberProperty : Property public class Number { [JsonProperty("format")] - [JsonConverter(typeof(StringEnumConverter))] - public NumberFormat Format { get; set; } - } - - public enum NumberFormat - { - [EnumMember(Value = null)] - Unknown, - - [EnumMember(Value = "number")] - Number, - - [EnumMember(Value = "number_with_commas")] - NumberWithCommas, - - [EnumMember(Value = "percent")] - Percent, - - [EnumMember(Value = "dollar")] - Dollar, - - [EnumMember(Value = "euro")] - Euro, - - [EnumMember(Value = "pound")] - Pound, - - [EnumMember(Value = "yen")] - Yen, - - [EnumMember(Value = "ruble")] - Ruble, - - [EnumMember(Value = "rupee")] - Rupee, - - [EnumMember(Value = "won")] - Won, - - [EnumMember(Value = "yuan")] - Yuan, - - [EnumMember(Value = "hong_kong_dollar")] - HongKongDollar, - - [EnumMember(Value = "new_zealand_dollar")] - NewZealandDollar, - - [EnumMember(Value = "krona")] - Krona, - - [EnumMember(Value = "norwegian_krone")] - NorwegianKrone, - - [EnumMember(Value = "mexican_peso")] - MexicanPeso, - - [EnumMember(Value = "rand")] - Rand, - - [EnumMember(Value = "new_taiwan_dollar")] - NewTaiwanDollar, - - [EnumMember(Value = "danish_krone")] - DanishKrone, - - [EnumMember(Value = "zloty")] - Zloty, - - [EnumMember(Value = "baht")] - Baht, - - [EnumMember(Value = "forint")] - Forint, - - [EnumMember(Value = "koruna")] - Koruna, - - [EnumMember(Value = "shekel")] - Shekel, - - [EnumMember(Value = "chilean_peso")] - ChileanPeso, - - [EnumMember(Value = "philippine_peso")] - PhilippinePeso, - - [EnumMember(Value = "dirham")] - Dirham, - - [EnumMember(Value = "colombian_peso")] - ColombianPeso, - - [EnumMember(Value = "riyal")] - Riyal, - - [EnumMember(Value = "ringgit")] - Ringgit, - - [EnumMember(Value = "leu")] - Leu + public string Format { get; set; } } } diff --git a/Src/Notion.Client/Models/Database/Properties/SelectProperty.cs b/Src/Notion.Client/Models/Database/Properties/SelectProperty.cs index 4aaa0f06..47e6fa64 100644 --- a/Src/Notion.Client/Models/Database/Properties/SelectProperty.cs +++ b/Src/Notion.Client/Models/Database/Properties/SelectProperty.cs @@ -1,7 +1,5 @@ using System.Collections.Generic; -using System.Runtime.Serialization; using Newtonsoft.Json; -using Newtonsoft.Json.Converters; namespace Notion.Client { @@ -35,44 +33,7 @@ public class SelectOption /// Color of the option. Possible values are: "default", "gray", "brown", "red", "orange", "yellow", "green", "blue", "purple", "pink". Defaults to "default". /// [JsonProperty("color")] - [JsonConverter(typeof(StringEnumConverter))] - public Color? Color { get; set; } - } - - public enum Color - { - [EnumMember(Value = null)] - Unknown, - - [EnumMember(Value = "default")] - Default, - - [EnumMember(Value = "gray")] - Gray, - - [EnumMember(Value = "brown")] - Brown, - - [EnumMember(Value = "orange")] - Orange, - - [EnumMember(Value = "yellow")] - Yellow, - - [EnumMember(Value = "green")] - Green, - - [EnumMember(Value = "blue")] - Blue, - - [EnumMember(Value = "purple")] - Purple, - - [EnumMember(Value = "pink")] - Pink, - - [EnumMember(Value = "red")] - Red + public string Color { get; set; } } public class MultiSelectProperty : Property diff --git a/Test/Notion.UnitTests/DatabasesClientTests.cs b/Test/Notion.UnitTests/DatabasesClientTests.cs index d6a440a0..25bfc79f 100644 --- a/Test/Notion.UnitTests/DatabasesClientTests.cs +++ b/Test/Notion.UnitTests/DatabasesClientTests.cs @@ -203,7 +203,7 @@ public async Task CreateDatabaseAsync() createDatabaseParameters.Properties = new Dictionary { { "Name", new TitlePropertySchema { Title = new Dictionary() } }, - { "Price", new NumberPropertySchema { Number = new Number { Format = NumberFormat.Dollar } } }, + { "Price", new NumberPropertySchema { Number = new Number { Format = "dollar" } } }, { "Food group", new SelectPropertySchema { Select = new OptionWrapper @@ -212,17 +212,17 @@ public async Task CreateDatabaseAsync() { new SelectOptionSchema { - Color = Color.Green, + Color = "green", Name = "🥦Vegetable" }, new SelectOptionSchema { - Color = Color.Red, + Color = "red", Name = "🍎Fruit" }, new SelectOptionSchema { - Color = Color.Yellow, + Color = "yellow", Name = "💪Protein" } } @@ -246,17 +246,17 @@ public async Task CreateDatabaseAsync() option => { option.Name.Should().Be("🥦Vegetable"); - option.Color.Should().Be(Color.Green); + option.Color.Should().Be("green"); }, option => { option.Name.Should().Be("🍎Fruit"); - option.Color.Should().Be(Color.Red); + option.Color.Should().Be("red"); }, option => { option.Name.Should().Be("💪Protein"); - option.Color.Should().Be(Color.Yellow); + option.Color.Should().Be("yellow"); } ); } @@ -292,7 +292,7 @@ public async Task UpdateDatabaseAsync() updateDatabaseParameters.Properties = new Dictionary { { "Name", new TitleUpdatePropertySchema { Title = new Dictionary() } }, - { "Price", new NumberUpdatePropertySchema { Number = new Number { Format = NumberFormat.Yen } } }, + { "Price", new NumberUpdatePropertySchema { Number = new Number { Format = "yen" } } }, { "Food group", new SelectUpdatePropertySchema { Select = new OptionWrapper @@ -301,17 +301,17 @@ public async Task UpdateDatabaseAsync() { new SelectOption { - Color = Color.Green, + Color = "green", Name = "🥦Vegetables" }, new SelectOption { - Color = Color.Red, + Color = "red", Name = "🍎Fruit" }, new SelectOption { - Color = Color.Yellow, + Color = "yellow", Name = "💪Protein" } } @@ -344,22 +344,22 @@ public async Task UpdateDatabaseAsync() option => { option.Name.Should().Be("🥦Vegetables"); - option.Color.Should().Be(Color.Green); + option.Color.Should().Be("green"); }, option => { option.Name.Should().Be("🍎Fruit"); - option.Color.Should().Be(Color.Red); + option.Color.Should().Be("red"); }, option => { option.Name.Should().Be("💪Protein"); - option.Color.Should().Be(Color.Yellow); + option.Color.Should().Be("yellow"); } ); var price = (NumberProperty)database.Properties["Price"]; - price.Number.Format.Should().Be(NumberFormat.Yen); + price.Number.Format.Should().Be("yen"); } [Fact] @@ -398,7 +398,7 @@ public async Task FormulaPropertyCanBeSetWhenCreatingDatabase() createDatabaseParameters.Properties = new Dictionary { { "Cost of next trip", new FormulaPropertySchema { Formula = new Formula { Expression = "if(prop(\"In stock\"), 0, prop(\"Price\"))" } } }, - { "Price", new NumberPropertySchema { Number = new Number { Format = NumberFormat.Dollar } } } + { "Price", new NumberPropertySchema { Number = new Number { Format = "dollar" } } } }; var database = await _client.CreateAsync(createDatabaseParameters); diff --git a/Test/Notion.UnitTests/PropertyTests.cs b/Test/Notion.UnitTests/PropertyTests.cs index 57747568..d09e4a87 100644 --- a/Test/Notion.UnitTests/PropertyTests.cs +++ b/Test/Notion.UnitTests/PropertyTests.cs @@ -63,43 +63,5 @@ public void TestPropertyTypeText(Type type, string expectedPropertyType) Assert.Equal(expectedPropertyType, actualPropertyType); } - - [Theory] - [InlineData(null, NumberFormat.Unknown)] - [InlineData("number", NumberFormat.Number)] - [InlineData("number_with_commas", NumberFormat.NumberWithCommas)] - [InlineData("percent", NumberFormat.Percent)] - [InlineData("dollar", NumberFormat.Dollar)] - [InlineData("euro", NumberFormat.Euro)] - [InlineData("pound", NumberFormat.Pound)] - [InlineData("yen", NumberFormat.Yen)] - [InlineData("ruble", NumberFormat.Ruble)] - [InlineData("rupee", NumberFormat.Rupee)] - [InlineData("won", NumberFormat.Won)] - [InlineData("yuan", NumberFormat.Yuan)] - [InlineData("hong_kong_dollar", NumberFormat.HongKongDollar)] - [InlineData("new_zealand_dollar", NumberFormat.NewZealandDollar)] - [InlineData("krona", NumberFormat.Krona)] - [InlineData("norwegian_krone", NumberFormat.NorwegianKrone)] - [InlineData("mexican_peso", NumberFormat.MexicanPeso)] - [InlineData("rand", NumberFormat.Rand)] - [InlineData("new_taiwan_dollar", NumberFormat.NewTaiwanDollar)] - [InlineData("danish_krone", NumberFormat.DanishKrone)] - [InlineData("zloty", NumberFormat.Zloty)] - [InlineData("baht", NumberFormat.Baht)] - [InlineData("forint", NumberFormat.Forint)] - [InlineData("koruna", NumberFormat.Koruna)] - [InlineData("shekel", NumberFormat.Shekel)] - [InlineData("chilean_peso", NumberFormat.ChileanPeso)] - [InlineData("philippine_peso", NumberFormat.PhilippinePeso)] - [InlineData("dirham", NumberFormat.Dirham)] - [InlineData("colombian_peso", NumberFormat.ColombianPeso)] - [InlineData("riyal", NumberFormat.Riyal)] - [InlineData("ringgit", NumberFormat.Ringgit)] - [InlineData("leu", NumberFormat.Leu)] - public void NumberFormatEnumTypes(string textValue, NumberFormat numberFormat) - { - numberFormat.GetEnumMemberValue().Should().Be(textValue); - } } } From 6f81e40fe5987b98a88928381abd2f6d0da362ae Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Tue, 18 Jan 2022 20:58:22 +0530 Subject: [PATCH 013/216] Update README.md Update related links for status shields else blank to point them to repo. --- README.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 8e12bbd8..fffe62cf 100644 --- a/README.md +++ b/README.md @@ -6,30 +6,30 @@
-![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/notion-dotnet/notion-sdk-net) -![GitHub](https://img.shields.io/github/license/notion-dotnet/notion-sdk-net) +[![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/notion-dotnet/notion-sdk-net)]() +[![GitHub](https://img.shields.io/github/license/notion-dotnet/notion-sdk-net)]() [![Build Status](https://github.com/notion-dotnet/notion-sdk-net/actions/workflows/ci-build.yml/badge.svg)](https://github.com/notion-dotnet/notion-sdk-net/actions/workflows/ci-build.yml) [![Build artifacts](https://github.com/notion-dotnet/notion-sdk-net/actions/workflows/build-artifacts-code.yml/badge.svg)](https://github.com/notion-dotnet/notion-sdk-net/actions/workflows/build-artifacts-code.yml) [![Publish Code](https://github.com/notion-dotnet/notion-sdk-net/actions/workflows/publish-code.yml/badge.svg)](https://github.com/notion-dotnet/notion-sdk-net/actions/workflows/publish-code.yml) [![CodeQL](https://github.com/notion-dotnet/notion-sdk-net/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/notion-dotnet/notion-sdk-net/actions/workflows/codeql-analysis.yml) -![LGTM Alerts](https://img.shields.io/lgtm/alerts/github/notion-dotnet/notion-sdk-net) -![LGTM Grade](https://img.shields.io/lgtm/grade/csharp/github/notion-dotnet/notion-sdk-net) +[![LGTM Alerts](https://img.shields.io/lgtm/alerts/github/notion-dotnet/notion-sdk-net)](https://lgtm.com/projects/g/notion-dotnet/notion-sdk-net/alerts/?mode=list) +[![LGTM Grade](https://img.shields.io/lgtm/grade/csharp/github/notion-dotnet/notion-sdk-net)](https://lgtm.com/projects/g/notion-dotnet/notion-sdk-net/alerts/?mode=list) -![GitHub last commit](https://img.shields.io/github/last-commit/notion-dotnet/notion-sdk-net) -![GitHub commit activity](https://img.shields.io/github/commit-activity/w/notion-dotnet/notion-sdk-net) -![GitHub commit activity](https://img.shields.io/github/commit-activity/m/notion-dotnet/notion-sdk-net) -![GitHub commit activity](https://img.shields.io/github/commit-activity/y/notion-dotnet/notion-sdk-net) +[![GitHub last commit](https://img.shields.io/github/last-commit/notion-dotnet/notion-sdk-net)]() +[![GitHub commit activity](https://img.shields.io/github/commit-activity/w/notion-dotnet/notion-sdk-net)]() +[![GitHub commit activity](https://img.shields.io/github/commit-activity/m/notion-dotnet/notion-sdk-net)]() +[![GitHub commit activity](https://img.shields.io/github/commit-activity/y/notion-dotnet/notion-sdk-net)]() -![GitHub repo size](https://img.shields.io/github/repo-size/notion-dotnet/notion-sdk-net) -![Lines of code](https://img.shields.io/tokei/lines/github/notion-dotnet/notion-sdk-net) +[![GitHub repo size](https://img.shields.io/github/repo-size/notion-dotnet/notion-sdk-net)]() +[![Lines of code](https://img.shields.io/tokei/lines/github/notion-dotnet/notion-sdk-net)]() Provides the following packages: | Package | Downloads | Nuget | |---|---|---| -| Notion.Net | ![Nuget](https://img.shields.io/nuget/dt/Notion.Net?color=success) | ![Nuget](https://img.shields.io/nuget/v/Notion.Net) ![Nuget (with prereleases)](https://img.shields.io/nuget/vpre/Notion.Net) | +| Notion.Net | [![Nuget](https://img.shields.io/nuget/dt/Notion.Net?color=success)](https://www.nuget.org/packages/Notion.Net) | [![Nuget](https://img.shields.io/nuget/v/Notion.Net) ![Nuget (with prereleases)](https://img.shields.io/nuget/vpre/Notion.Net)](https://www.nuget.org/packages/Notion.Net) | From 84f190e17b7c59c3a320065ef41adeb0932c4c01 Mon Sep 17 00:00:00 2001 From: Thierry Bouquain Date: Mon, 7 Mar 2022 17:42:43 +0100 Subject: [PATCH 014/216] Fix wrong field used in relation field --- .../Models/Database/Properties/RelationProperty.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/Notion.Client/Models/Database/Properties/RelationProperty.cs b/Src/Notion.Client/Models/Database/Properties/RelationProperty.cs index 8c55bc80..48ffc4e3 100644 --- a/Src/Notion.Client/Models/Database/Properties/RelationProperty.cs +++ b/Src/Notion.Client/Models/Database/Properties/RelationProperty.cs @@ -13,7 +13,7 @@ public class RelationProperty : Property public class Relation { - [JsonProperty("datebase_id")] + [JsonProperty("database_id")] public string DatabaseId { get; set; } [JsonProperty("synced_property_name")] From 8ab6edd0d99a437c624c60a1fecef65b22c0ee67 Mon Sep 17 00:00:00 2001 From: Thierry Bouquain Date: Mon, 7 Mar 2022 18:19:36 +0100 Subject: [PATCH 015/216] add unit tests --- Test/Notion.UnitTests/DatabasesClientTests.cs | 30 +++++++ Test/Notion.UnitTests/Notion.UnitTests.csproj | 3 + ...DatabasePropertyObjectContainRelation.json | 89 +++++++++++++++++++ 3 files changed, 122 insertions(+) create mode 100644 Test/Notion.UnitTests/data/databases/DatabasePropertyObjectContainRelation.json diff --git a/Test/Notion.UnitTests/DatabasesClientTests.cs b/Test/Notion.UnitTests/DatabasesClientTests.cs index 25bfc79f..8462b42d 100644 --- a/Test/Notion.UnitTests/DatabasesClientTests.cs +++ b/Test/Notion.UnitTests/DatabasesClientTests.cs @@ -146,6 +146,36 @@ public async Task DatabasePropertyObjectContainNameProperty() } } + [Fact] + public async Task DatabasePropertyObjectContainRelationProperty() + { + var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1"; + var path = ApiEndpoints.DatabasesApiUrls.Retrieve(databaseId); + var jsonData = await File.ReadAllTextAsync("data/databases/DatabasePropertyObjectContainRelation.json"); + + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( + Response.Create() + .WithStatusCode(200) + .WithBody(jsonData) + ); + + var database = await _client.RetrieveAsync(databaseId); + + database.Properties.Should().ContainKey("Property").WhichValue.Should().BeEquivalentTo( + new RelationProperty() + { + Id = "zDGa", + Name = "Property", + Relation = new Relation() + { + DatabaseId = "f86f2262-0751-40f2-8f63-e3f7a3c39fcb", + SyncedPropertyName = "Related to sample table (Property)", + SyncedPropertyId = "VQ}{" + } + }); + } + [Fact] public async Task DatabasePropertyObjectContainParentProperty() { diff --git a/Test/Notion.UnitTests/Notion.UnitTests.csproj b/Test/Notion.UnitTests/Notion.UnitTests.csproj index 3b729bf5..0d5ec118 100644 --- a/Test/Notion.UnitTests/Notion.UnitTests.csproj +++ b/Test/Notion.UnitTests/Notion.UnitTests.csproj @@ -93,6 +93,9 @@ Always + + Always +
diff --git a/Test/Notion.UnitTests/data/databases/DatabasePropertyObjectContainRelation.json b/Test/Notion.UnitTests/data/databases/DatabasePropertyObjectContainRelation.json new file mode 100644 index 00000000..5ed09bb1 --- /dev/null +++ b/Test/Notion.UnitTests/data/databases/DatabasePropertyObjectContainRelation.json @@ -0,0 +1,89 @@ +{ + "object": "database", + "id": "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1", + "created_time": "2021-05-22T18:44:00.000Z", + "last_edited_time": "2021-05-23T12:29:00.000Z", + "title": [ + { + "type": "text", + "text": { + "content": "sample table", + "link": null + }, + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "plain_text": "sample table", + "href": null + } + ], + "properties": { + "Tags": { + "id": "YG~h", + "name": "Tags", + "type": "multi_select", + "multi_select": { + "options": [] + } + }, + "SimpleText": { + "id": "_Dfp", + "name": "SimpleText", + "type": "rich_text", + "rich_text": {} + }, + "Column": { + "id": "bxhl", + "name": "Column", + "type": "multi_select", + "multi_select": { + "options": [ + { + "id": "5a44a233-33be-435e-b358-2c0ed1799dcf", + "name": "what", + "color": "gray" + } + ] + } + }, + "SelectProp": { + "id": "eZ[y", + "name": "SelectProp", + "type": "select", + "select": { + "options": [ + { + "id": "362dc255-c867-4543-b3ea-7bd988638228", + "name": "Female", + "color": "green" + } + ] + } + }, + "Property": { + "id": "zDGa", + "name": "Property", + "type": "relation", + "relation": { + "database_id": "f86f2262-0751-40f2-8f63-e3f7a3c39fcb", + "synced_property_name": "Related to sample table (Property)", + "synced_property_id": "VQ}{" + } + }, + "Name": { + "id": "title", + "name": "Name", + "type": "title", + "title": {} + } + }, + "parent": { + "type": "page_id", + "page_id": "649089db-8984-4051-98fb-a03593b852d8" + } +} From b0ce20f955c7660469541b0faf15aa3e6d0939b4 Mon Sep 17 00:00:00 2001 From: Ken Date: Thu, 7 Apr 2022 19:44:58 +1000 Subject: [PATCH 016/216] Update README.md Fixed syntax error in code example --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fffe62cf..29cc826b 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ Library also provides extension method to register NotionClient with Microsoft d ``` services.AddNotionClient(options => { - AuthToken = "" + options.AuthToken = ""; }); ``` From 682dc0c7c5ef349d2227cd48c34026c51e56826b Mon Sep 17 00:00:00 2001 From: winl Date: Thu, 12 May 2022 01:20:36 +0800 Subject: [PATCH 017/216] add caption property in file block --- Src/Notion.Client/Models/File/FileObject.cs | 6 +++- Test/Notion.UnitTests/BlocksClientTests.cs | 2 +- .../blocks/RetrieveBlockChildrenResponse.json | 35 +++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/Src/Notion.Client/Models/File/FileObject.cs b/Src/Notion.Client/Models/File/FileObject.cs index 88c701ae..ce4d02f0 100644 --- a/Src/Notion.Client/Models/File/FileObject.cs +++ b/Src/Notion.Client/Models/File/FileObject.cs @@ -1,4 +1,5 @@ -using JsonSubTypes; +using System.Collections.Generic; +using JsonSubTypes; using Newtonsoft.Json; namespace Notion.Client @@ -10,5 +11,8 @@ public abstract class FileObject : IPageIcon { [JsonProperty("type")] public virtual string Type { get; set; } + + [JsonProperty("caption")] + public IEnumerable Caption { get; set; } } } diff --git a/Test/Notion.UnitTests/BlocksClientTests.cs b/Test/Notion.UnitTests/BlocksClientTests.cs index 3e1a1b53..6f89cc7b 100644 --- a/Test/Notion.UnitTests/BlocksClientTests.cs +++ b/Test/Notion.UnitTests/BlocksClientTests.cs @@ -38,7 +38,7 @@ public async Task RetrieveBlockChildren() // Assert var children = childrenResult.Results; - children.Should().HaveCount(7); + children.Should().HaveCount(8); } [Fact] diff --git a/Test/Notion.UnitTests/data/blocks/RetrieveBlockChildrenResponse.json b/Test/Notion.UnitTests/data/blocks/RetrieveBlockChildrenResponse.json index 6ab04fea..fe30ff6b 100644 --- a/Test/Notion.UnitTests/data/blocks/RetrieveBlockChildrenResponse.json +++ b/Test/Notion.UnitTests/data/blocks/RetrieveBlockChildrenResponse.json @@ -120,6 +120,41 @@ "paragraph": { "text": [] } + }, + { + "object": "block", + "id": "ABD0E698-ABE6-42F2-80B1-24497AAE16F1", + "created_time": "2022-05-03T13:28:00.000Z", + "last_edited_time": "2022-05-03T13:29:00.000Z", + "has_children": false, + "archived": false, + "type": "image", + "image": { + "caption": [ + { + "type": "text", + "text": { + "content": "caption text", + "link": null + }, + "annotations": { + "bold": false, + "italic": false, + "strikethrough": false, + "underline": false, + "code": false, + "color": "default" + }, + "plain_text": "caption text", + "href": null + } + ], + "type": "file", + "file": { + "url": "https://s3.us-west-2.amazonaws.com/secure.notion-static.com/xxx", + "expiry_time": "2022-05-11T17:55:32.613Z" + } + } } ], "next_cursor": null, From 19fb0eadc75e24fd6bd630e57790ed20e4ea7f98 Mon Sep 17 00:00:00 2001 From: Herman Schoenfeld Date: Wed, 1 Jun 2022 09:10:23 +1000 Subject: [PATCH 018/216] Added missing caption to file object in object model --- Src/Notion.Client/Models/File/FileObject.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Src/Notion.Client/Models/File/FileObject.cs b/Src/Notion.Client/Models/File/FileObject.cs index 88c701ae..ce4d02f0 100644 --- a/Src/Notion.Client/Models/File/FileObject.cs +++ b/Src/Notion.Client/Models/File/FileObject.cs @@ -1,4 +1,5 @@ -using JsonSubTypes; +using System.Collections.Generic; +using JsonSubTypes; using Newtonsoft.Json; namespace Notion.Client @@ -10,5 +11,8 @@ public abstract class FileObject : IPageIcon { [JsonProperty("type")] public virtual string Type { get; set; } + + [JsonProperty("caption")] + public IEnumerable Caption { get; set; } } } From 3420df90385617a6bb28f9bfe91f1f45fab9af69 Mon Sep 17 00:00:00 2001 From: D Vijay Varma Date: Sat, 25 Jun 2022 23:47:07 +0530 Subject: [PATCH 019/216] matched the naming convention for property url across project --- .../{URLPropertyScheam.cs => UrlPropertySchema.cs} | 2 +- .../PropertySchema/URLUpdatePropertySchema.cs | 2 +- Src/Notion.Client/NotionAPIErrorCode.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/{URLPropertyScheam.cs => UrlPropertySchema.cs} (78%) diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/URLPropertyScheam.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/UrlPropertySchema.cs similarity index 78% rename from Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/URLPropertyScheam.cs rename to Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/UrlPropertySchema.cs index 468244d8..0860fa97 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/URLPropertyScheam.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/UrlPropertySchema.cs @@ -3,7 +3,7 @@ namespace Notion.Client { - public class URLPropertyScheam : IPropertySchema + public class UrlPropertySchema : IPropertySchema { [JsonProperty("url")] public Dictionary Url { get; set; } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/URLUpdatePropertySchema.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/URLUpdatePropertySchema.cs index 5ea7ac4c..7aa9c701 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/URLUpdatePropertySchema.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/URLUpdatePropertySchema.cs @@ -3,7 +3,7 @@ namespace Notion.Client { - public class URLUpdatePropertySchema : UpdatePropertySchema, IUpdatePropertySchema + public class UrlUpdatePropertySchema : UpdatePropertySchema, IUpdatePropertySchema { [JsonProperty("url")] public Dictionary Url { get; set; } diff --git a/Src/Notion.Client/NotionAPIErrorCode.cs b/Src/Notion.Client/NotionAPIErrorCode.cs index 209aef11..f4cf699c 100644 --- a/Src/Notion.Client/NotionAPIErrorCode.cs +++ b/Src/Notion.Client/NotionAPIErrorCode.cs @@ -8,7 +8,7 @@ public enum NotionAPIErrorCode InvalidJSON, [EnumMember(Value = "invalid_request_url")] - InvalidRequestURL, + InvalidRequestUrl, [EnumMember(Value = "invalid_request")] InvalidRequest, From 3f80b305b5d75b84569f295a23c03c5ab5b38e9f Mon Sep 17 00:00:00 2001 From: D Vijay Varma Date: Sun, 26 Jun 2022 04:48:19 +0530 Subject: [PATCH 020/216] Issue: 237 - Made Date Property Nullable Updated c# from 7.3 to 8 for nullable reference type support --- Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs | 4 ++-- Src/Notion.Client/Notion.Client.csproj | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs index 6182b197..24d2ff8f 100644 --- a/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs @@ -13,8 +13,8 @@ public class DatePropertyValue : PropertyValue /// /// Date /// - [JsonProperty("date")] - public Date Date { get; set; } + [JsonProperty("date", NullValueHandling = NullValueHandling.Include)] + public Date? Date { get; set; } } /// diff --git a/Src/Notion.Client/Notion.Client.csproj b/Src/Notion.Client/Notion.Client.csproj index c1b237d1..d41d5d7f 100644 --- a/Src/Notion.Client/Notion.Client.csproj +++ b/Src/Notion.Client/Notion.Client.csproj @@ -3,7 +3,7 @@ 2.2.3-preview netstandard2.0 - 7.3 + 8.0 Notion.Net Vedant Koditkar From abd0ea1363eaebd1d3c0bc576931cbaf49aca04f Mon Sep 17 00:00:00 2001 From: D Vijay Varma Date: Mon, 27 Jun 2022 08:08:36 +0530 Subject: [PATCH 021/216] Revert "Issue: 237 - Made Date Property Nullable" This reverts commit 3f80b305b5d75b84569f295a23c03c5ab5b38e9f. --- Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs | 4 ++-- Src/Notion.Client/Notion.Client.csproj | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs index 24d2ff8f..6182b197 100644 --- a/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs @@ -13,8 +13,8 @@ public class DatePropertyValue : PropertyValue /// /// Date /// - [JsonProperty("date", NullValueHandling = NullValueHandling.Include)] - public Date? Date { get; set; } + [JsonProperty("date")] + public Date Date { get; set; } } /// diff --git a/Src/Notion.Client/Notion.Client.csproj b/Src/Notion.Client/Notion.Client.csproj index d41d5d7f..c1b237d1 100644 --- a/Src/Notion.Client/Notion.Client.csproj +++ b/Src/Notion.Client/Notion.Client.csproj @@ -3,7 +3,7 @@ 2.2.3-preview netstandard2.0 - 8.0 + 7.3 Notion.Net Vedant Koditkar From 2219fc4b74f2c79aa6c94c7aabc2f4b6f05d0324 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sun, 10 Jul 2022 23:54:25 +0530 Subject: [PATCH 022/216] rename text property of blocks to rich_text --- .../Models/Blocks/BulletedListItemBlock.cs | 4 ++-- .../Models/Blocks/CalloutBlock.cs | 4 ++-- Src/Notion.Client/Models/Blocks/CodeBlock.cs | 4 ++-- .../Models/Blocks/HeadingOneBlock.cs | 4 ++-- .../Models/Blocks/HeadingThreeeBlock.cs | 4 ++-- .../Models/Blocks/HeadingTwoBlock.cs | 4 ++-- .../Models/Blocks/NumberedListItemBlock.cs | 4 ++-- .../Models/Blocks/ParagraphBlock.cs | 4 ++-- Src/Notion.Client/Models/Blocks/QuoteBlock.cs | 4 ++-- .../Models/Blocks/TemplateBlock.cs | 4 ++-- Src/Notion.Client/Models/Blocks/ToDoBlock.cs | 4 ++-- .../Models/Blocks/ToggleBlock.cs | 4 ++-- .../IBlocksClientTests.cs | 16 +++++++-------- Test/Notion.UnitTests/BlocksClientTests.cs | 20 +++++++++---------- 14 files changed, 42 insertions(+), 42 deletions(-) diff --git a/Src/Notion.Client/Models/Blocks/BulletedListItemBlock.cs b/Src/Notion.Client/Models/Blocks/BulletedListItemBlock.cs index 15d168af..145a37e5 100644 --- a/Src/Notion.Client/Models/Blocks/BulletedListItemBlock.cs +++ b/Src/Notion.Client/Models/Blocks/BulletedListItemBlock.cs @@ -12,8 +12,8 @@ public class BulletedListItemBlock : Block, IColumnChildrenBlock, INonColumnBloc public class Info { - [JsonProperty("text")] - public IEnumerable Text { get; set; } + [JsonProperty("rich_text")] + public IEnumerable RichText { get; set; } [JsonProperty("children")] public IEnumerable Children { get; set; } diff --git a/Src/Notion.Client/Models/Blocks/CalloutBlock.cs b/Src/Notion.Client/Models/Blocks/CalloutBlock.cs index 9fed148a..f995e3be 100644 --- a/Src/Notion.Client/Models/Blocks/CalloutBlock.cs +++ b/Src/Notion.Client/Models/Blocks/CalloutBlock.cs @@ -12,8 +12,8 @@ public class CalloutBlock : Block, IColumnChildrenBlock, INonColumnBlock public class Info { - [JsonProperty("text")] - public IEnumerable Text { get; set; } + [JsonProperty("rich_text")] + public IEnumerable RichText { get; set; } [JsonProperty("icon")] public IPageIcon Icon { get; set; } diff --git a/Src/Notion.Client/Models/Blocks/CodeBlock.cs b/Src/Notion.Client/Models/Blocks/CodeBlock.cs index 7eb4205d..810e3864 100644 --- a/Src/Notion.Client/Models/Blocks/CodeBlock.cs +++ b/Src/Notion.Client/Models/Blocks/CodeBlock.cs @@ -12,8 +12,8 @@ public class CodeBlock : Block, IColumnChildrenBlock, INonColumnBlock public class Info { - [JsonProperty("text")] - public IEnumerable Text { get; set; } + [JsonProperty("rich_text")] + public IEnumerable RichText { get; set; } [JsonProperty("language")] public string Language { get; set; } diff --git a/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs b/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs index d9c107c3..67132fe5 100644 --- a/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs +++ b/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs @@ -14,8 +14,8 @@ public class HeadingOneBlock : Block, IColumnChildrenBlock, INonColumnBlock public class Info { - [JsonProperty("text")] - public IEnumerable Text { get; set; } + [JsonProperty("rich_text")] + public IEnumerable RichText { get; set; } } } } diff --git a/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs b/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs index 0728f200..2e4dde99 100644 --- a/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs +++ b/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs @@ -14,8 +14,8 @@ public class HeadingThreeeBlock : Block, IColumnChildrenBlock, INonColumnBlock public class Info { - [JsonProperty("text")] - public IEnumerable Text { get; set; } + [JsonProperty("rich_text")] + public IEnumerable RichText { get; set; } } } } diff --git a/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs b/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs index c9caec09..82c75047 100644 --- a/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs +++ b/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs @@ -14,8 +14,8 @@ public class HeadingTwoBlock : Block, IColumnChildrenBlock, INonColumnBlock public class Info { - [JsonProperty("text")] - public IEnumerable Text { get; set; } + [JsonProperty("rich_text")] + public IEnumerable RichText { get; set; } } } } diff --git a/Src/Notion.Client/Models/Blocks/NumberedListItemBlock.cs b/Src/Notion.Client/Models/Blocks/NumberedListItemBlock.cs index 90823f57..581d8977 100644 --- a/Src/Notion.Client/Models/Blocks/NumberedListItemBlock.cs +++ b/Src/Notion.Client/Models/Blocks/NumberedListItemBlock.cs @@ -12,8 +12,8 @@ public class NumberedListItemBlock : Block, IColumnChildrenBlock, INonColumnBloc public class Info { - [JsonProperty("text")] - public IEnumerable Text { get; set; } + [JsonProperty("rich_text")] + public IEnumerable RichText { get; set; } [JsonProperty("children")] public IEnumerable Children { get; set; } diff --git a/Src/Notion.Client/Models/Blocks/ParagraphBlock.cs b/Src/Notion.Client/Models/Blocks/ParagraphBlock.cs index 4a0b5d07..02560aee 100644 --- a/Src/Notion.Client/Models/Blocks/ParagraphBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ParagraphBlock.cs @@ -12,8 +12,8 @@ public class ParagraphBlock : Block, IColumnChildrenBlock, INonColumnBlock public class Info { - [JsonProperty("text")] - public IEnumerable Text { get; set; } + [JsonProperty("rich_text")] + public IEnumerable RichText { get; set; } [JsonProperty("children")] public IEnumerable Children { get; set; } diff --git a/Src/Notion.Client/Models/Blocks/QuoteBlock.cs b/Src/Notion.Client/Models/Blocks/QuoteBlock.cs index 7108980c..9a8dda8e 100644 --- a/Src/Notion.Client/Models/Blocks/QuoteBlock.cs +++ b/Src/Notion.Client/Models/Blocks/QuoteBlock.cs @@ -12,8 +12,8 @@ public class QuoteBlock : Block, IColumnChildrenBlock, INonColumnBlock public class Info { - [JsonProperty("text")] - public IEnumerable Text { get; set; } + [JsonProperty("rich_text")] + public IEnumerable RichText { get; set; } [JsonProperty("children")] public IEnumerable Children { get; set; } diff --git a/Src/Notion.Client/Models/Blocks/TemplateBlock.cs b/Src/Notion.Client/Models/Blocks/TemplateBlock.cs index 2fceb845..69a78b62 100644 --- a/Src/Notion.Client/Models/Blocks/TemplateBlock.cs +++ b/Src/Notion.Client/Models/Blocks/TemplateBlock.cs @@ -12,8 +12,8 @@ public class TemplateBlock : Block, IColumnChildrenBlock, INonColumnBlock public class Data { - [JsonProperty("text")] - public IEnumerable Text { get; set; } + [JsonProperty("rich_text")] + public IEnumerable RichText { get; set; } [JsonProperty("children")] public IEnumerable Children { get; set; } diff --git a/Src/Notion.Client/Models/Blocks/ToDoBlock.cs b/Src/Notion.Client/Models/Blocks/ToDoBlock.cs index 2d033c95..0417827d 100644 --- a/Src/Notion.Client/Models/Blocks/ToDoBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ToDoBlock.cs @@ -12,8 +12,8 @@ public class ToDoBlock : Block, IColumnChildrenBlock, INonColumnBlock public class Info { - [JsonProperty("text")] - public IEnumerable Text { get; set; } + [JsonProperty("rich_text")] + public IEnumerable RichText { get; set; } [JsonProperty("checked")] public bool IsChecked { get; set; } diff --git a/Src/Notion.Client/Models/Blocks/ToggleBlock.cs b/Src/Notion.Client/Models/Blocks/ToggleBlock.cs index 95eef646..2653cd1b 100644 --- a/Src/Notion.Client/Models/Blocks/ToggleBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ToggleBlock.cs @@ -12,8 +12,8 @@ public class ToggleBlock : Block, IColumnChildrenBlock, INonColumnBlock public class Info { - [JsonProperty("text")] - public IEnumerable Text { get; set; } + [JsonProperty("rich_text")] + public IEnumerable RichText { get; set; } [JsonProperty("children")] public IEnumerable Children { get; set; } diff --git a/Test/Notion.IntegrationTests/IBlocksClientTests.cs b/Test/Notion.IntegrationTests/IBlocksClientTests.cs index 986ed5b6..c1e94e4e 100644 --- a/Test/Notion.IntegrationTests/IBlocksClientTests.cs +++ b/Test/Notion.IntegrationTests/IBlocksClientTests.cs @@ -58,7 +58,7 @@ public async Task AppendChildrenAsync_AppendsBlocksGivenBlocks() { Callout = new CalloutBlock.Info { - Text = new List { + RichText = new List { new RichTextTextInput { Text = new Text @@ -321,7 +321,7 @@ private static IEnumerable BlockData() { Callout = new CalloutBlock.Info { - Text = new List + RichText = new List { new RichTextTextInput { @@ -354,7 +354,7 @@ private static IEnumerable BlockData() Assert.NotNull(block); var calloutBlock = Assert.IsType(block); - Assert.Equal("Test 2", calloutBlock.Callout.Text.OfType().First().Text.Content); + Assert.Equal("Test 2", calloutBlock.Callout.RichText.OfType().First().Text.Content); }) }, new object[] @@ -363,7 +363,7 @@ private static IEnumerable BlockData() { Quote = new QuoteBlock.Info { - Text = new List + RichText = new List { new RichTextTextInput { @@ -396,7 +396,7 @@ private static IEnumerable BlockData() Assert.NotNull(block); var quoteBlock = Assert.IsType(block); - Assert.Equal("Test 2", quoteBlock.Quote.Text.OfType().First().Text.Content); + Assert.Equal("Test 2", quoteBlock.Quote.RichText.OfType().First().Text.Content); }) }, new object[] @@ -459,7 +459,7 @@ private static IEnumerable BlockData() { Template = new TemplateBlock.Data { - Text = new List + RichText = new List { new RichTextText { @@ -502,9 +502,9 @@ private static IEnumerable BlockData() Assert.NotNull(block); var templateBlock = Assert.IsType(block); - Assert.Single(templateBlock.Template.Text); + Assert.Single(templateBlock.Template.RichText); Assert.Null(templateBlock.Template.Children); - Assert.Equal("Test Template 2", templateBlock.Template.Text.OfType().First().Text.Content); + Assert.Equal("Test Template 2", templateBlock.Template.RichText.OfType().First().Text.Content); }) }, new object[] diff --git a/Test/Notion.UnitTests/BlocksClientTests.cs b/Test/Notion.UnitTests/BlocksClientTests.cs index 6f89cc7b..8bfe218e 100644 --- a/Test/Notion.UnitTests/BlocksClientTests.cs +++ b/Test/Notion.UnitTests/BlocksClientTests.cs @@ -65,7 +65,7 @@ public async Task AppendBlockChildren() { Heading_2 = new HeadingTwoBlock.Info { - Text = new List + RichText = new List { new RichTextText { @@ -81,7 +81,7 @@ public async Task AppendBlockChildren() { Paragraph = new ParagraphBlock.Info { - Text = new List + RichText = new List { new RichTextText { @@ -110,14 +110,14 @@ public async Task AppendBlockChildren() { block.Type.Should().Be(BlockType.Heading_2); var headingBlock = (HeadingTwoBlock)block; - var text = headingBlock.Heading_2.Text.OfType().FirstOrDefault(); + var text = headingBlock.Heading_2.RichText.OfType().FirstOrDefault(); text.Text.Content.Should().Be("Lacinato kale"); }, block => { block.Type.Should().Be(BlockType.Paragraph); var paragraphBlock = (ParagraphBlock)block; - var text = paragraphBlock.Paragraph.Text.OfType().LastOrDefault(); + var text = paragraphBlock.Paragraph.RichText.OfType().LastOrDefault(); text.Text.Content.Should().Be("Lacinato kale is a variety of kale with a long tradition in Italian cuisine, especially that of Tuscany. It is also known as Tuscan kale, Italian kale, dinosaur kale, kale, flat back kale, palm tree kale, or black Tuscan palm."); text.Text.Link.Url.Should().Be("https://en.wikipedia.org/wiki/Lacinato_kale"); } @@ -145,9 +145,9 @@ public async Task RetrieveAsync() block.Type.Should().Be(BlockType.ToDo); var todoBlock = ((ToDoBlock)block); - todoBlock.ToDo.Text.Should().ContainSingle(); - todoBlock.ToDo.Text.First().Should().BeAssignableTo(); - ((RichTextText)todoBlock.ToDo.Text.First()).Text.Content.Should().Be("Lacinato kale"); + todoBlock.ToDo.RichText.Should().ContainSingle(); + todoBlock.ToDo.RichText.First().Should().BeAssignableTo(); + ((RichTextText)todoBlock.ToDo.RichText.First()).Text.Content.Should().Be("Lacinato kale"); } [Fact] @@ -189,9 +189,9 @@ public async Task UpdateAsync() block.Type.Should().Be(BlockType.ToDo); var todoBlock = ((ToDoBlock)block); - todoBlock.ToDo.Text.Should().ContainSingle(); - todoBlock.ToDo.Text.First().Should().BeAssignableTo(); - ((RichTextText)todoBlock.ToDo.Text.First()).Text.Content.Should().Be("Lacinato kale"); + todoBlock.ToDo.RichText.Should().ContainSingle(); + todoBlock.ToDo.RichText.First().Should().BeAssignableTo(); + ((RichTextText)todoBlock.ToDo.RichText.First()).Text.Content.Should().Be("Lacinato kale"); } } } From 9f294d13450fe186ecab8dc1678c94b61182bf2c Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Mon, 11 Jul 2022 00:17:08 +0530 Subject: [PATCH 023/216] rename text to rich_text in updateblock models --- .../UpdateBlocks/BookmarkUpdateBlock.cs | 4 ++-- .../UpdateBlocks/BreadcrumbUpdateBlock.cs | 6 +++--- .../UpdateBlocks/BulletedListItemUpdateBlock.cs | 11 +++++++++-- .../UpdateBlocks/CalloutUpdateBlock.cs | 4 ++-- .../UpdateBlocks/CodeUpdateBlock.cs | 4 ++-- .../UpdateBlocks/DividerUpdateBlock.cs | 6 +++--- .../UpdateBlocks/EmbedUpdateBlock.cs | 4 ++-- .../UpdateBlocks/EquationUpdateBlock.cs | 4 ++-- .../UpdateBlocks/HeadingOneUpdateBlock.cs | 11 +++++++++-- .../UpdateBlocks/HeadingThreeeUpdateBlock.cs | 11 +++++++++-- .../UpdateBlocks/HeadingTwoUpdateBlock.cs | 11 +++++++++-- .../UpdateBlocks/NumberedListItemUpdateBlock.cs | 11 +++++++++-- .../UpdateBlocks/ParagraphUpdateBlock.cs | 11 +++++++++-- .../UpdateBlocks/QuoteUpdateBlock.cs | 4 ++-- .../UpdateBlocks/SyncedBlockUpdateBlock.cs | 4 ++-- .../UpdateBlocks/TableOfContentsUpdateBlock.cs | 6 +++--- .../UpdateBlocks/TemplateUpdateBlock.cs | 8 ++++---- .../UpdateBlocks/TextContentUpdate.cs | 11 ----------- .../UpdateBlocks/ToDoUpdateBlock.cs | 4 ++-- .../UpdateBlocks/ToggleUpdateBlock.cs | 11 +++++++++-- Test/Notion.IntegrationTests/IBlocksClientTests.cs | 14 +++++++------- Test/Notion.UnitTests/BlocksClientTests.cs | 2 +- 22 files changed, 100 insertions(+), 62 deletions(-) delete mode 100644 Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TextContentUpdate.cs diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BookmarkUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BookmarkUpdateBlock.cs index 71b0cec6..c3333737 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BookmarkUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BookmarkUpdateBlock.cs @@ -8,9 +8,9 @@ public class BookmarkUpdateBlock : IUpdateBlock public bool Archived { get; set; } [JsonProperty("bookmark")] - public Data Bookmark { get; set; } + public Info Bookmark { get; set; } - public class Data + public class Info { [JsonProperty("url")] public string Url { get; set; } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BreadcrumbUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BreadcrumbUpdateBlock.cs index 2e504dff..2bb8be38 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BreadcrumbUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BreadcrumbUpdateBlock.cs @@ -7,15 +7,15 @@ public class BreadcrumbUpdateBlock : IUpdateBlock public bool Archived { get; set; } [JsonProperty("breadcrumb")] - public Data Breadcrumb { get; set; } + public Info Breadcrumb { get; set; } - public class Data + public class Info { } public BreadcrumbUpdateBlock() { - Breadcrumb = new Data(); + Breadcrumb = new Info(); } } } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BulletedListItemUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BulletedListItemUpdateBlock.cs index 8ea533b3..9225942f 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BulletedListItemUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BulletedListItemUpdateBlock.cs @@ -1,10 +1,17 @@ -using Newtonsoft.Json; +using System.Collections.Generic; +using Newtonsoft.Json; namespace Notion.Client { public class BulletedListItemUpdateBlock : UpdateBlock, IUpdateBlock { [JsonProperty("bulleted_list_item")] - public TextContentUpdate BulletedListItem { get; set; } + public Info BulletedListItem { get; set; } + + public class Info + { + [JsonProperty("rich_text")] + public IEnumerable RichText { get; set; } + } } } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/CalloutUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/CalloutUpdateBlock.cs index d26e59a9..f8562ff3 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/CalloutUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/CalloutUpdateBlock.cs @@ -10,8 +10,8 @@ public class CalloutUpdateBlock : UpdateBlock, IUpdateBlock public class Info { - [JsonProperty("text")] - public IEnumerable Text { get; set; } + [JsonProperty("rich_text")] + public IEnumerable RichText { get; set; } [JsonProperty("icon")] public IPageIcon Icon { get; set; } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/CodeUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/CodeUpdateBlock.cs index 1364adb0..b71fdf14 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/CodeUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/CodeUpdateBlock.cs @@ -10,8 +10,8 @@ public class CodeUpdateBlock : UpdateBlock, IUpdateBlock public class Info { - [JsonProperty("text")] - public IEnumerable Text { get; set; } + [JsonProperty("rich_text")] + public IEnumerable RichText { get; set; } [JsonProperty("language")] public string Language { get; set; } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/DividerUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/DividerUpdateBlock.cs index eb21ca28..6c5b447c 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/DividerUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/DividerUpdateBlock.cs @@ -7,15 +7,15 @@ public class DividerUpdateBlock : IUpdateBlock public bool Archived { get; set; } [JsonProperty("divider")] - public Data Divider { get; set; } + public Info Divider { get; set; } - public class Data + public class Info { } public DividerUpdateBlock() { - Divider = new Data(); + Divider = new Info(); } } } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/EmbedUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/EmbedUpdateBlock.cs index 35f509e2..b0419a23 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/EmbedUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/EmbedUpdateBlock.cs @@ -5,9 +5,9 @@ namespace Notion.Client public class EmbedUpdateBlock : UpdateBlock, IUpdateBlock { [JsonProperty("embed")] - public Data Embed { get; set; } + public Info Embed { get; set; } - public class Data + public class Info { [JsonProperty("url")] public string Url { get; set; } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/EquationUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/EquationUpdateBlock.cs index c0f32894..b7cb0ad9 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/EquationUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/EquationUpdateBlock.cs @@ -5,9 +5,9 @@ namespace Notion.Client public class EquationUpdateBlock : UpdateBlock, IUpdateBlock { [JsonProperty("equation")] - public Data Equation { get; set; } + public Info Equation { get; set; } - public class Data + public class Info { [JsonProperty("expression")] public string Expression { get; set; } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/HeadingOneUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/HeadingOneUpdateBlock.cs index 31c3d968..aeb4e087 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/HeadingOneUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/HeadingOneUpdateBlock.cs @@ -1,10 +1,17 @@ -using Newtonsoft.Json; +using System.Collections.Generic; +using Newtonsoft.Json; namespace Notion.Client { public class HeadingOneUpdateBlock : UpdateBlock, IUpdateBlock { [JsonProperty("heading_1")] - public TextContentUpdate Heading_1 { get; set; } + public Info Heading_1 { get; set; } + + public class Info + { + [JsonProperty("rich_text")] + public IEnumerable RichText { get; set; } + } } } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/HeadingThreeeUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/HeadingThreeeUpdateBlock.cs index 2f413e35..574ea0f0 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/HeadingThreeeUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/HeadingThreeeUpdateBlock.cs @@ -1,10 +1,17 @@ -using Newtonsoft.Json; +using System.Collections.Generic; +using Newtonsoft.Json; namespace Notion.Client { public class HeadingThreeeUpdateBlock : UpdateBlock, IUpdateBlock { [JsonProperty("heading_3")] - public TextContentUpdate Heading_3 { get; set; } + public Info Heading_3 { get; set; } + + public class Info + { + [JsonProperty("rich_text")] + public IEnumerable RichText { get; set; } + } } } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/HeadingTwoUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/HeadingTwoUpdateBlock.cs index 9b314a03..0269a0ce 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/HeadingTwoUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/HeadingTwoUpdateBlock.cs @@ -1,10 +1,17 @@ -using Newtonsoft.Json; +using System.Collections.Generic; +using Newtonsoft.Json; namespace Notion.Client { public class HeadingTwoUpdateBlock : UpdateBlock, IUpdateBlock { [JsonProperty("heading_2")] - public TextContentUpdate Heading_2 { get; set; } + public Info Heading_2 { get; set; } + + public class Info + { + [JsonProperty("rich_text")] + public IEnumerable RichText { get; set; } + } } } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/NumberedListItemUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/NumberedListItemUpdateBlock.cs index 03e6f20b..c27363d3 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/NumberedListItemUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/NumberedListItemUpdateBlock.cs @@ -1,10 +1,17 @@ -using Newtonsoft.Json; +using System.Collections.Generic; +using Newtonsoft.Json; namespace Notion.Client { public class NumberedListItemUpdateBlock : UpdateBlock, IUpdateBlock { [JsonProperty("numbered_list_item")] - public TextContentUpdate NumberedListItem { get; set; } + public Info NumberedListItem { get; set; } + + public class Info + { + [JsonProperty("rich_text")] + public IEnumerable RichText { get; set; } + } } } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/ParagraphUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/ParagraphUpdateBlock.cs index 43fca06e..2e49c64a 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/ParagraphUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/ParagraphUpdateBlock.cs @@ -1,10 +1,17 @@ -using Newtonsoft.Json; +using System.Collections.Generic; +using Newtonsoft.Json; namespace Notion.Client { public class ParagraphUpdateBlock : UpdateBlock, IUpdateBlock { [JsonProperty("paragraph")] - public TextContentUpdate Paragraph { get; set; } + public Info Paragraph { get; set; } + + public class Info + { + [JsonProperty("rich_text")] + public IEnumerable RichText { get; set; } + } } } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/QuoteUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/QuoteUpdateBlock.cs index 9d0405f0..fdfd189c 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/QuoteUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/QuoteUpdateBlock.cs @@ -10,8 +10,8 @@ public class QuoteUpdateBlock : UpdateBlock, IUpdateBlock public class Info { - [JsonProperty("text")] - public IEnumerable Text { get; set; } + [JsonProperty("rich_text")] + public IEnumerable RichText { get; set; } } } } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/SyncedBlockUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/SyncedBlockUpdateBlock.cs index 97f393fe..9cb234d8 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/SyncedBlockUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/SyncedBlockUpdateBlock.cs @@ -5,9 +5,9 @@ namespace Notion.Client public class SyncedBlockUpdateBlock : UpdateBlock, IUpdateBlock { [JsonProperty("synced_block")] - public Data SyncedBlock { get; set; } + public Info SyncedBlock { get; set; } - public class Data + public class Info { [JsonProperty("synced_from")] public SyncedFromBlockId SyncedFrom { get; set; } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableOfContentsUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableOfContentsUpdateBlock.cs index 9e742597..36eee182 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableOfContentsUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableOfContentsUpdateBlock.cs @@ -7,15 +7,15 @@ public class TableOfContentsUpdateBlock : IUpdateBlock public bool Archived { get; set; } [JsonProperty("table_of_contents")] - public Data TableOfContents { get; set; } + public Info TableOfContents { get; set; } - public class Data + public class Info { } public TableOfContentsUpdateBlock() { - TableOfContents = new Data(); + TableOfContents = new Info(); } } } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TemplateUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TemplateUpdateBlock.cs index 032cb335..62457971 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TemplateUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TemplateUpdateBlock.cs @@ -6,12 +6,12 @@ namespace Notion.Client public class TemplateUpdateBlock : UpdateBlock, IUpdateBlock { [JsonProperty("template")] - public Data Template { get; set; } + public Info Template { get; set; } - public class Data + public class Info { - [JsonProperty("text")] - public IEnumerable Text { get; set; } + [JsonProperty("rich_text")] + public IEnumerable RichText { get; set; } } } } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TextContentUpdate.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TextContentUpdate.cs deleted file mode 100644 index b0388162..00000000 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TextContentUpdate.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Collections.Generic; -using Newtonsoft.Json; - -namespace Notion.Client -{ - public class TextContentUpdate - { - [JsonProperty("text")] - public IEnumerable Text { get; set; } - } -} diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/ToDoUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/ToDoUpdateBlock.cs index e5b5cd5b..f1accfc8 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/ToDoUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/ToDoUpdateBlock.cs @@ -10,8 +10,8 @@ public class ToDoUpdateBlock : UpdateBlock, IUpdateBlock public class Info { - [JsonProperty("text")] - public IEnumerable Text { get; set; } + [JsonProperty("rich_text")] + public IEnumerable RichText { get; set; } [JsonProperty("checked")] public bool IsChecked { get; set; } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/ToggleUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/ToggleUpdateBlock.cs index 89b71ac9..b87834d1 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/ToggleUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/ToggleUpdateBlock.cs @@ -1,10 +1,17 @@ -using Newtonsoft.Json; +using System.Collections.Generic; +using Newtonsoft.Json; namespace Notion.Client { public class ToggleUpdateBlock : UpdateBlock, IUpdateBlock { [JsonProperty("toggle")] - public TextContentUpdate Toggle { get; set; } + public Info Toggle { get; set; } + + public class Info + { + [JsonProperty("rich_text")] + public IEnumerable RichText { get; set; } + } } } diff --git a/Test/Notion.IntegrationTests/IBlocksClientTests.cs b/Test/Notion.IntegrationTests/IBlocksClientTests.cs index c1e94e4e..eabef5b4 100644 --- a/Test/Notion.IntegrationTests/IBlocksClientTests.cs +++ b/Test/Notion.IntegrationTests/IBlocksClientTests.cs @@ -230,7 +230,7 @@ private static IEnumerable BlockData() } }, new BookmarkUpdateBlock { - Bookmark = new BookmarkUpdateBlock.Data + Bookmark = new BookmarkUpdateBlock.Info { Url = "https://github.com/notion-dotnet/notion-sdk-net", Caption = new List @@ -260,7 +260,7 @@ private static IEnumerable BlockData() } }, new EquationUpdateBlock { - Equation = new EquationUpdateBlock.Data + Equation = new EquationUpdateBlock.Info { Expression = "e=mc^2" } @@ -337,7 +337,7 @@ private static IEnumerable BlockData() { Callout = new CalloutUpdateBlock.Info { - Text = new List + RichText = new List { new RichTextTextInput { @@ -379,7 +379,7 @@ private static IEnumerable BlockData() { Quote = new QuoteUpdateBlock.Info { - Text = new List + RichText = new List { new RichTextTextInput { @@ -440,7 +440,7 @@ private static IEnumerable BlockData() }, new EmbedUpdateBlock() { - Embed = new EmbedUpdateBlock.Data + Embed = new EmbedUpdateBlock.Info { Url = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg" } @@ -483,9 +483,9 @@ private static IEnumerable BlockData() }, new TemplateUpdateBlock() { - Template = new TemplateUpdateBlock.Data + Template = new TemplateUpdateBlock.Info { - Text = new List + RichText = new List { new RichTextTextInput { diff --git a/Test/Notion.UnitTests/BlocksClientTests.cs b/Test/Notion.UnitTests/BlocksClientTests.cs index 8bfe218e..753e5464 100644 --- a/Test/Notion.UnitTests/BlocksClientTests.cs +++ b/Test/Notion.UnitTests/BlocksClientTests.cs @@ -168,7 +168,7 @@ public async Task UpdateAsync() { ToDo = new ToDoUpdateBlock.Info { - Text = new List() + RichText = new List() { new RichTextTextInput { From 5cb1c5dc4447286e092b73a5f6cf79407bcbbde0 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Mon, 11 Jul 2022 01:09:11 +0530 Subject: [PATCH 024/216] Fix text filter properties and rename files --- .../{Checkbox.cs => CheckboxFilter.cs} | 68 ++--- .../Models/Filters/{Date.cs => DateFilter.cs} | 246 +++++++++--------- .../Models/Filters/EmailFilter.cs | 34 +++ .../Filters/{Files.cs => FilesFilter.cs} | 73 +++--- .../Filters/{Formula.cs => FormulaFilter.cs} | 104 ++++---- .../{Multiselect.cs => MultiSelectFilter.cs} | 110 ++++---- .../Filters/{Number.cs => NumberFilter.cs} | 164 ++++++------ .../Filters/{People.cs => PeopleFilter.cs} | 106 ++++---- .../Models/Filters/PhoneNumberFilter.cs | 34 +++ .../{Relation.cs => RelationFilter.cs} | 106 ++++---- .../Filters/{Text.cs => RichTextFilter.cs} | 165 ++++++------ .../Filters/{Select.cs => SelectFilter.cs} | 106 ++++---- .../Models/Filters/TitleFilter.cs | 34 +++ Src/Notion.Client/Models/Filters/URLFilter.cs | 34 +++ Test/Notion.UnitTests/FilterTests.cs | 4 +- 15 files changed, 763 insertions(+), 625 deletions(-) rename Src/Notion.Client/Models/Filters/{Checkbox.cs => CheckboxFilter.cs} (96%) rename Src/Notion.Client/Models/Filters/{Date.cs => DateFilter.cs} (97%) create mode 100644 Src/Notion.Client/Models/Filters/EmailFilter.cs rename Src/Notion.Client/Models/Filters/{Files.cs => FilesFilter.cs} (95%) rename Src/Notion.Client/Models/Filters/{Formula.cs => FormulaFilter.cs} (96%) rename Src/Notion.Client/Models/Filters/{Multiselect.cs => MultiSelectFilter.cs} (96%) rename Src/Notion.Client/Models/Filters/{Number.cs => NumberFilter.cs} (96%) rename Src/Notion.Client/Models/Filters/{People.cs => PeopleFilter.cs} (96%) create mode 100644 Src/Notion.Client/Models/Filters/PhoneNumberFilter.cs rename Src/Notion.Client/Models/Filters/{Relation.cs => RelationFilter.cs} (96%) rename Src/Notion.Client/Models/Filters/{Text.cs => RichTextFilter.cs} (89%) rename Src/Notion.Client/Models/Filters/{Select.cs => SelectFilter.cs} (96%) create mode 100644 Src/Notion.Client/Models/Filters/TitleFilter.cs create mode 100644 Src/Notion.Client/Models/Filters/URLFilter.cs diff --git a/Src/Notion.Client/Models/Filters/Checkbox.cs b/Src/Notion.Client/Models/Filters/CheckboxFilter.cs similarity index 96% rename from Src/Notion.Client/Models/Filters/Checkbox.cs rename to Src/Notion.Client/Models/Filters/CheckboxFilter.cs index 1eb73e2e..f0c2b41d 100644 --- a/Src/Notion.Client/Models/Filters/Checkbox.cs +++ b/Src/Notion.Client/Models/Filters/CheckboxFilter.cs @@ -1,35 +1,35 @@ -using System; -using Newtonsoft.Json; - -namespace Notion.Client -{ - public class CheckboxFilter : SinglePropertyFilter - { - [JsonProperty("checkbox")] - public Condition Checkbox { get; set; } - - public CheckboxFilter( - string propertyName, - bool? equal = null, - bool? doesNotEqual = null) - { - Property = propertyName; - Checkbox = new Condition(equal: equal, doesNotEqual: doesNotEqual); - } - - public class Condition - { - [JsonProperty("equals")] - public bool? Equal { get; set; } - - [JsonProperty("does_not_equal")] - public bool? DoesNotEqual { get; set; } - - public Condition(Nullable equal = null, Nullable doesNotEqual = null) - { - Equal = equal; - DoesNotEqual = doesNotEqual; - } - } - } +using System; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class CheckboxFilter : SinglePropertyFilter + { + [JsonProperty("checkbox")] + public Condition Checkbox { get; set; } + + public CheckboxFilter( + string propertyName, + bool? equal = null, + bool? doesNotEqual = null) + { + Property = propertyName; + Checkbox = new Condition(equal: equal, doesNotEqual: doesNotEqual); + } + + public class Condition + { + [JsonProperty("equals")] + public bool? Equal { get; set; } + + [JsonProperty("does_not_equal")] + public bool? DoesNotEqual { get; set; } + + public Condition(Nullable equal = null, Nullable doesNotEqual = null) + { + Equal = equal; + DoesNotEqual = doesNotEqual; + } + } + } } diff --git a/Src/Notion.Client/Models/Filters/Date.cs b/Src/Notion.Client/Models/Filters/DateFilter.cs similarity index 97% rename from Src/Notion.Client/Models/Filters/Date.cs rename to Src/Notion.Client/Models/Filters/DateFilter.cs index 44b29fb9..a472ff49 100644 --- a/Src/Notion.Client/Models/Filters/Date.cs +++ b/Src/Notion.Client/Models/Filters/DateFilter.cs @@ -1,124 +1,124 @@ -using System; -using System.Collections.Generic; -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; - -namespace Notion.Client -{ - public class DateFilter : SinglePropertyFilter - { - [JsonProperty("date")] - public Condition Date { get; set; } - - public DateFilter( - string propertyName, - DateTime? equal = null, - DateTime? before = null, - DateTime? after = null, - DateTime? onOrBefore = null, - DateTime? onOrAfter = null, - Dictionary pastWeek = null, - Dictionary pastMonth = null, - Dictionary pastYear = null, - Dictionary nextWeek = null, - Dictionary nextMonth = null, - Dictionary nextYear = null, - bool? isEmpty = null, - bool? isNotEmpty = null) - { - Property = propertyName; - Date = new Condition( - equal: equal, - before: before, - after: after, - onOrBefore: onOrBefore, - onOrAfter: onOrAfter, - pastWeek: pastWeek, - pastMonth: pastMonth, - pastYear: pastYear, - nextWeek: nextWeek, - nextMonth: nextMonth, - nextYear: nextYear, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty - ); - } - - public class Condition - { - [JsonProperty("equals")] - [JsonConverter(typeof(IsoDateTimeConverter))] - public DateTime? Equal { get; set; } - - [JsonProperty("before")] - [JsonConverter(typeof(IsoDateTimeConverter))] - public DateTime? Before { get; set; } - - [JsonProperty("after")] - [JsonConverter(typeof(IsoDateTimeConverter))] - public DateTime? After { get; set; } - - [JsonProperty("on_or_before")] - [JsonConverter(typeof(IsoDateTimeConverter))] - public DateTime? OnOrBefore { get; set; } - - [JsonProperty("on_or_after")] - [JsonConverter(typeof(IsoDateTimeConverter))] - public DateTime? OnOrAfter { get; set; } - - [JsonProperty("past_week")] - public Dictionary PastWeek { get; set; } - - [JsonProperty("past_month")] - public Dictionary PastMonth { get; set; } - - [JsonProperty("past_year")] - public Dictionary PastYear { get; set; } - - [JsonProperty("next_week")] - public Dictionary NextWeek { get; set; } - - [JsonProperty("next_month")] - public Dictionary NextMonth { get; set; } - - [JsonProperty("next_year")] - public Dictionary NextYear { get; set; } - - [JsonProperty("is_empty")] - public bool? IsEmpty { get; set; } - - [JsonProperty("is_not_empty")] - public bool? IsNotEmpty { get; set; } - - public Condition( - DateTime? equal = null, - DateTime? before = null, - DateTime? after = null, - DateTime? onOrBefore = null, - DateTime? onOrAfter = null, - Dictionary pastWeek = null, - Dictionary pastMonth = null, - Dictionary pastYear = null, - Dictionary nextWeek = null, - Dictionary nextMonth = null, - Dictionary nextYear = null, - bool? isEmpty = null, - bool? isNotEmpty = null) - { - Equal = equal; - Before = before; - After = after; - OnOrBefore = onOrBefore; - OnOrAfter = onOrAfter; - PastWeek = pastWeek; - PastMonth = pastMonth; - PastYear = pastYear; - NextWeek = nextWeek; - NextMonth = nextMonth; - NextYear = nextYear; - IsEmpty = isEmpty; - IsNotEmpty = isNotEmpty; - } - } - } +using System; +using System.Collections.Generic; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace Notion.Client +{ + public class DateFilter : SinglePropertyFilter + { + [JsonProperty("date")] + public Condition Date { get; set; } + + public DateFilter( + string propertyName, + DateTime? equal = null, + DateTime? before = null, + DateTime? after = null, + DateTime? onOrBefore = null, + DateTime? onOrAfter = null, + Dictionary pastWeek = null, + Dictionary pastMonth = null, + Dictionary pastYear = null, + Dictionary nextWeek = null, + Dictionary nextMonth = null, + Dictionary nextYear = null, + bool? isEmpty = null, + bool? isNotEmpty = null) + { + Property = propertyName; + Date = new Condition( + equal: equal, + before: before, + after: after, + onOrBefore: onOrBefore, + onOrAfter: onOrAfter, + pastWeek: pastWeek, + pastMonth: pastMonth, + pastYear: pastYear, + nextWeek: nextWeek, + nextMonth: nextMonth, + nextYear: nextYear, + isEmpty: isEmpty, + isNotEmpty: isNotEmpty + ); + } + + public class Condition + { + [JsonProperty("equals")] + [JsonConverter(typeof(IsoDateTimeConverter))] + public DateTime? Equal { get; set; } + + [JsonProperty("before")] + [JsonConverter(typeof(IsoDateTimeConverter))] + public DateTime? Before { get; set; } + + [JsonProperty("after")] + [JsonConverter(typeof(IsoDateTimeConverter))] + public DateTime? After { get; set; } + + [JsonProperty("on_or_before")] + [JsonConverter(typeof(IsoDateTimeConverter))] + public DateTime? OnOrBefore { get; set; } + + [JsonProperty("on_or_after")] + [JsonConverter(typeof(IsoDateTimeConverter))] + public DateTime? OnOrAfter { get; set; } + + [JsonProperty("past_week")] + public Dictionary PastWeek { get; set; } + + [JsonProperty("past_month")] + public Dictionary PastMonth { get; set; } + + [JsonProperty("past_year")] + public Dictionary PastYear { get; set; } + + [JsonProperty("next_week")] + public Dictionary NextWeek { get; set; } + + [JsonProperty("next_month")] + public Dictionary NextMonth { get; set; } + + [JsonProperty("next_year")] + public Dictionary NextYear { get; set; } + + [JsonProperty("is_empty")] + public bool? IsEmpty { get; set; } + + [JsonProperty("is_not_empty")] + public bool? IsNotEmpty { get; set; } + + public Condition( + DateTime? equal = null, + DateTime? before = null, + DateTime? after = null, + DateTime? onOrBefore = null, + DateTime? onOrAfter = null, + Dictionary pastWeek = null, + Dictionary pastMonth = null, + Dictionary pastYear = null, + Dictionary nextWeek = null, + Dictionary nextMonth = null, + Dictionary nextYear = null, + bool? isEmpty = null, + bool? isNotEmpty = null) + { + Equal = equal; + Before = before; + After = after; + OnOrBefore = onOrBefore; + OnOrAfter = onOrAfter; + PastWeek = pastWeek; + PastMonth = pastMonth; + PastYear = pastYear; + NextWeek = nextWeek; + NextMonth = nextMonth; + NextYear = nextYear; + IsEmpty = isEmpty; + IsNotEmpty = isNotEmpty; + } + } + } } diff --git a/Src/Notion.Client/Models/Filters/EmailFilter.cs b/Src/Notion.Client/Models/Filters/EmailFilter.cs new file mode 100644 index 00000000..ff5feda9 --- /dev/null +++ b/Src/Notion.Client/Models/Filters/EmailFilter.cs @@ -0,0 +1,34 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class EmailFilter : SinglePropertyFilter + { + [JsonProperty("email")] + public TextFilter.Condition Email { get; set; } + + public EmailFilter( + string propertyName, + string equal = null, + string doesNotEqual = null, + string contains = null, + string doesNotContain = null, + string startsWith = null, + string endsWith = null, + bool? isEmpty = null, + bool? isNotEmpty = null) + { + Property = propertyName; + Email = new TextFilter.Condition( + equal: equal, + doesNotEqual: doesNotEqual, + contains: contains, + doesNotContain: doesNotContain, + startsWith: startsWith, + endsWith: endsWith, + isEmpty: isEmpty, + isNotEmpty: isNotEmpty + ); + } + } +} diff --git a/Src/Notion.Client/Models/Filters/Files.cs b/Src/Notion.Client/Models/Filters/FilesFilter.cs similarity index 95% rename from Src/Notion.Client/Models/Filters/Files.cs rename to Src/Notion.Client/Models/Filters/FilesFilter.cs index e20f863d..a3dca061 100644 --- a/Src/Notion.Client/Models/Filters/Files.cs +++ b/Src/Notion.Client/Models/Filters/FilesFilter.cs @@ -1,37 +1,36 @@ -using Newtonsoft.Json; - -namespace Notion.Client -{ - - public class FilesFilter : SinglePropertyFilter - { - [JsonProperty("files")] - public Condition Files { get; set; } - - public FilesFilter( - string propertyName, - bool? isEmpty = null, - bool? isNotEmpty = null) - { - Property = propertyName; - Files = new Condition(isEmpty: isEmpty, isNotEmpty: isNotEmpty); - } - - public class Condition - { - [JsonProperty("is_empty")] - public bool? IsEmpty { get; set; } - - [JsonProperty("is_not_empty")] - public bool? IsNotEmpty { get; set; } - - public Condition( - bool? isEmpty = null, - bool? isNotEmpty = null) - { - IsEmpty = isEmpty; - IsNotEmpty = isNotEmpty; - } - } - } -} +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class FilesFilter : SinglePropertyFilter + { + [JsonProperty("files")] + public Condition Files { get; set; } + + public FilesFilter( + string propertyName, + bool? isEmpty = null, + bool? isNotEmpty = null) + { + Property = propertyName; + Files = new Condition(isEmpty: isEmpty, isNotEmpty: isNotEmpty); + } + + public class Condition + { + [JsonProperty("is_empty")] + public bool? IsEmpty { get; set; } + + [JsonProperty("is_not_empty")] + public bool? IsNotEmpty { get; set; } + + public Condition( + bool? isEmpty = null, + bool? isNotEmpty = null) + { + IsEmpty = isEmpty; + IsNotEmpty = isNotEmpty; + } + } + } +} diff --git a/Src/Notion.Client/Models/Filters/Formula.cs b/Src/Notion.Client/Models/Filters/FormulaFilter.cs similarity index 96% rename from Src/Notion.Client/Models/Filters/Formula.cs rename to Src/Notion.Client/Models/Filters/FormulaFilter.cs index 82b58cc8..9e6fdc19 100644 --- a/Src/Notion.Client/Models/Filters/Formula.cs +++ b/Src/Notion.Client/Models/Filters/FormulaFilter.cs @@ -1,53 +1,53 @@ -using Newtonsoft.Json; - -namespace Notion.Client -{ - public class FormulaFilter : SinglePropertyFilter - { - [JsonProperty("formula")] - public Condition Formula { get; set; } - - public FormulaFilter( - string propertyName, - TextFilter.Condition text = null, - CheckboxFilter.Condition checkbox = null, - NumberFilter.Condition number = null, - DateFilter.Condition date = null) - { - Property = propertyName; - Formula = new Condition( - text: text, - checkbox: checkbox, - number: number, - date: date - ); - } - - public class Condition - { - [JsonProperty("text")] - public TextFilter.Condition Text { get; set; } - - [JsonProperty("checkbox")] - public CheckboxFilter.Condition Checkbox { get; set; } - - [JsonProperty("number")] - public NumberFilter.Condition Number { get; set; } - - [JsonProperty("date")] - public DateFilter.Condition Date { get; set; } - - public Condition( - TextFilter.Condition text = null, - CheckboxFilter.Condition checkbox = null, - NumberFilter.Condition number = null, - DateFilter.Condition date = null) - { - Text = text; - Checkbox = checkbox; - Number = number; - Date = date; - } - } - } +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class FormulaFilter : SinglePropertyFilter + { + [JsonProperty("formula")] + public Condition Formula { get; set; } + + public FormulaFilter( + string propertyName, + TextFilter.Condition text = null, + CheckboxFilter.Condition checkbox = null, + NumberFilter.Condition number = null, + DateFilter.Condition date = null) + { + Property = propertyName; + Formula = new Condition( + text: text, + checkbox: checkbox, + number: number, + date: date + ); + } + + public class Condition + { + [JsonProperty("text")] + public TextFilter.Condition Text { get; set; } + + [JsonProperty("checkbox")] + public CheckboxFilter.Condition Checkbox { get; set; } + + [JsonProperty("number")] + public NumberFilter.Condition Number { get; set; } + + [JsonProperty("date")] + public DateFilter.Condition Date { get; set; } + + public Condition( + TextFilter.Condition text = null, + CheckboxFilter.Condition checkbox = null, + NumberFilter.Condition number = null, + DateFilter.Condition date = null) + { + Text = text; + Checkbox = checkbox; + Number = number; + Date = date; + } + } + } } diff --git a/Src/Notion.Client/Models/Filters/Multiselect.cs b/Src/Notion.Client/Models/Filters/MultiSelectFilter.cs similarity index 96% rename from Src/Notion.Client/Models/Filters/Multiselect.cs rename to Src/Notion.Client/Models/Filters/MultiSelectFilter.cs index bf69d110..69615b3d 100644 --- a/Src/Notion.Client/Models/Filters/Multiselect.cs +++ b/Src/Notion.Client/Models/Filters/MultiSelectFilter.cs @@ -1,55 +1,55 @@ -using Newtonsoft.Json; - -namespace Notion.Client -{ - public class MultiSelectFilter : SinglePropertyFilter - { - [JsonProperty("multi_select")] - public Condition MultiSelect { get; set; } - - public MultiSelectFilter( - string propertyName, - string contains = null, - string doesNotContain = null, - bool? isEmpty = null, - bool? isNotEmpty = null) - { - Property = propertyName; - MultiSelect = new Condition( - contains: contains, - doesNotContain: doesNotContain, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty - ); - } - - - public class Condition - { - [JsonProperty("contains")] - public string Contains { get; set; } - - [JsonProperty("does_not_contain")] - public string DoesNotContain { get; set; } - - [JsonProperty("is_empty")] - public bool? IsEmpty { get; set; } - - [JsonProperty("is_not_empty")] - public bool? IsNotEmpty { get; set; } - - public Condition( - string contains = null, - string doesNotContain = null, - bool? isEmpty = null, - bool? isNotEmpty = null) - { - Contains = contains; - DoesNotContain = doesNotContain; - IsEmpty = isEmpty; - IsNotEmpty = isNotEmpty; - } - } - - } -} +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class MultiSelectFilter : SinglePropertyFilter + { + [JsonProperty("multi_select")] + public Condition MultiSelect { get; set; } + + public MultiSelectFilter( + string propertyName, + string contains = null, + string doesNotContain = null, + bool? isEmpty = null, + bool? isNotEmpty = null) + { + Property = propertyName; + MultiSelect = new Condition( + contains: contains, + doesNotContain: doesNotContain, + isEmpty: isEmpty, + isNotEmpty: isNotEmpty + ); + } + + + public class Condition + { + [JsonProperty("contains")] + public string Contains { get; set; } + + [JsonProperty("does_not_contain")] + public string DoesNotContain { get; set; } + + [JsonProperty("is_empty")] + public bool? IsEmpty { get; set; } + + [JsonProperty("is_not_empty")] + public bool? IsNotEmpty { get; set; } + + public Condition( + string contains = null, + string doesNotContain = null, + bool? isEmpty = null, + bool? isNotEmpty = null) + { + Contains = contains; + DoesNotContain = doesNotContain; + IsEmpty = isEmpty; + IsNotEmpty = isNotEmpty; + } + } + + } +} diff --git a/Src/Notion.Client/Models/Filters/Number.cs b/Src/Notion.Client/Models/Filters/NumberFilter.cs similarity index 96% rename from Src/Notion.Client/Models/Filters/Number.cs rename to Src/Notion.Client/Models/Filters/NumberFilter.cs index 9282226a..58e0c38a 100644 --- a/Src/Notion.Client/Models/Filters/Number.cs +++ b/Src/Notion.Client/Models/Filters/NumberFilter.cs @@ -1,82 +1,82 @@ -using Newtonsoft.Json; - -namespace Notion.Client -{ - public class NumberFilter : SinglePropertyFilter - { - [JsonProperty("number")] - public Condition Number { get; set; } - - public NumberFilter( - string propertyName, - double? equal = null, - double? doesNotEqual = null, - double? greaterThan = null, - double? lessThan = null, - double? greaterThanOrEqualTo = null, - double? lessThanOrEqualTo = null, - bool? isEmpty = null, - bool? isNotEmpty = null) - { - Property = propertyName; - Number = new Condition( - equal: equal, - doesNotEqual: doesNotEqual, - greaterThan: greaterThan, - lessThan: lessThan, - greaterThanOrEqualTo: greaterThanOrEqualTo, - lessThanOrEqualTo: lessThanOrEqualTo, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty - ); - } - - public class Condition - { - [JsonProperty("equals")] - public double? Equal { get; set; } - - [JsonProperty("does_not_equal")] - public double? DoesNotEqual { get; set; } - - [JsonProperty("greater_than")] - public double? GreaterThan { get; set; } - - [JsonProperty("less_than")] - public double? LessThan { get; set; } - - [JsonProperty("greater_than_or_equal_to")] - public double? GreaterThanOrEqualTo { get; set; } - - [JsonProperty("less_than_or_equal_to")] - public double? LessThanOrEqualTo { get; set; } - - [JsonProperty("is_empty")] - public bool? IsEmpty { get; set; } - - [JsonProperty("is_not_empty")] - public bool? IsNotEmpty { get; set; } - - public Condition( - double? equal = null, - double? doesNotEqual = null, - double? greaterThan = null, - double? lessThan = null, - double? greaterThanOrEqualTo = null, - double? lessThanOrEqualTo = null, - bool? isEmpty = null, - bool? isNotEmpty = null) - { - Equal = equal; - DoesNotEqual = doesNotEqual; - GreaterThan = greaterThan; - LessThan = lessThan; - GreaterThanOrEqualTo = greaterThanOrEqualTo; - LessThanOrEqualTo = lessThanOrEqualTo; - IsEmpty = isEmpty; - IsNotEmpty = isNotEmpty; - } - } - - } -} +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class NumberFilter : SinglePropertyFilter + { + [JsonProperty("number")] + public Condition Number { get; set; } + + public NumberFilter( + string propertyName, + double? equal = null, + double? doesNotEqual = null, + double? greaterThan = null, + double? lessThan = null, + double? greaterThanOrEqualTo = null, + double? lessThanOrEqualTo = null, + bool? isEmpty = null, + bool? isNotEmpty = null) + { + Property = propertyName; + Number = new Condition( + equal: equal, + doesNotEqual: doesNotEqual, + greaterThan: greaterThan, + lessThan: lessThan, + greaterThanOrEqualTo: greaterThanOrEqualTo, + lessThanOrEqualTo: lessThanOrEqualTo, + isEmpty: isEmpty, + isNotEmpty: isNotEmpty + ); + } + + public class Condition + { + [JsonProperty("equals")] + public double? Equal { get; set; } + + [JsonProperty("does_not_equal")] + public double? DoesNotEqual { get; set; } + + [JsonProperty("greater_than")] + public double? GreaterThan { get; set; } + + [JsonProperty("less_than")] + public double? LessThan { get; set; } + + [JsonProperty("greater_than_or_equal_to")] + public double? GreaterThanOrEqualTo { get; set; } + + [JsonProperty("less_than_or_equal_to")] + public double? LessThanOrEqualTo { get; set; } + + [JsonProperty("is_empty")] + public bool? IsEmpty { get; set; } + + [JsonProperty("is_not_empty")] + public bool? IsNotEmpty { get; set; } + + public Condition( + double? equal = null, + double? doesNotEqual = null, + double? greaterThan = null, + double? lessThan = null, + double? greaterThanOrEqualTo = null, + double? lessThanOrEqualTo = null, + bool? isEmpty = null, + bool? isNotEmpty = null) + { + Equal = equal; + DoesNotEqual = doesNotEqual; + GreaterThan = greaterThan; + LessThan = lessThan; + GreaterThanOrEqualTo = greaterThanOrEqualTo; + LessThanOrEqualTo = lessThanOrEqualTo; + IsEmpty = isEmpty; + IsNotEmpty = isNotEmpty; + } + } + + } +} diff --git a/Src/Notion.Client/Models/Filters/People.cs b/Src/Notion.Client/Models/Filters/PeopleFilter.cs similarity index 96% rename from Src/Notion.Client/Models/Filters/People.cs rename to Src/Notion.Client/Models/Filters/PeopleFilter.cs index 6138e3d2..cd77c186 100644 --- a/Src/Notion.Client/Models/Filters/People.cs +++ b/Src/Notion.Client/Models/Filters/PeopleFilter.cs @@ -1,53 +1,53 @@ -using Newtonsoft.Json; - -namespace Notion.Client -{ - public class PeopleFilter : SinglePropertyFilter - { - [JsonProperty("people")] - public Condition People { get; set; } - - public PeopleFilter( - string propertyName, - string contains = null, - string doesNotContain = null, - bool? isEmpty = null, - bool? isNotEmpty = null) - { - Property = propertyName; - People = new Condition( - contains: contains, - doesNotContain: doesNotContain, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty - ); - } - - public class Condition - { - [JsonProperty("contains")] - public string Contains { get; set; } - - [JsonProperty("does_not_contain")] - public string DoesNotContain { get; set; } - - [JsonProperty("is_empty")] - public bool? IsEmpty { get; set; } - - [JsonProperty("is_not_empty")] - public bool? IsNotEmpty { get; set; } - - public Condition( - string contains = null, - string doesNotContain = null, - bool? isEmpty = null, - bool? isNotEmpty = null) - { - Contains = contains; - DoesNotContain = doesNotContain; - IsEmpty = isEmpty; - IsNotEmpty = isNotEmpty; - } - } - } -} +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class PeopleFilter : SinglePropertyFilter + { + [JsonProperty("people")] + public Condition People { get; set; } + + public PeopleFilter( + string propertyName, + string contains = null, + string doesNotContain = null, + bool? isEmpty = null, + bool? isNotEmpty = null) + { + Property = propertyName; + People = new Condition( + contains: contains, + doesNotContain: doesNotContain, + isEmpty: isEmpty, + isNotEmpty: isNotEmpty + ); + } + + public class Condition + { + [JsonProperty("contains")] + public string Contains { get; set; } + + [JsonProperty("does_not_contain")] + public string DoesNotContain { get; set; } + + [JsonProperty("is_empty")] + public bool? IsEmpty { get; set; } + + [JsonProperty("is_not_empty")] + public bool? IsNotEmpty { get; set; } + + public Condition( + string contains = null, + string doesNotContain = null, + bool? isEmpty = null, + bool? isNotEmpty = null) + { + Contains = contains; + DoesNotContain = doesNotContain; + IsEmpty = isEmpty; + IsNotEmpty = isNotEmpty; + } + } + } +} diff --git a/Src/Notion.Client/Models/Filters/PhoneNumberFilter.cs b/Src/Notion.Client/Models/Filters/PhoneNumberFilter.cs new file mode 100644 index 00000000..758a65db --- /dev/null +++ b/Src/Notion.Client/Models/Filters/PhoneNumberFilter.cs @@ -0,0 +1,34 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class PhoneNumberFilter : SinglePropertyFilter + { + [JsonProperty("phone_number")] + public TextFilter.Condition Text { get; set; } + + public PhoneNumberFilter( + string propertyName, + string equal = null, + string doesNotEqual = null, + string contains = null, + string doesNotContain = null, + string startsWith = null, + string endsWith = null, + bool? isEmpty = null, + bool? isNotEmpty = null) + { + Property = propertyName; + Text = new TextFilter.Condition( + equal: equal, + doesNotEqual: doesNotEqual, + contains: contains, + doesNotContain: doesNotContain, + startsWith: startsWith, + endsWith: endsWith, + isEmpty: isEmpty, + isNotEmpty: isNotEmpty + ); + } + } +} diff --git a/Src/Notion.Client/Models/Filters/Relation.cs b/Src/Notion.Client/Models/Filters/RelationFilter.cs similarity index 96% rename from Src/Notion.Client/Models/Filters/Relation.cs rename to Src/Notion.Client/Models/Filters/RelationFilter.cs index 26f7214a..e7eef130 100644 --- a/Src/Notion.Client/Models/Filters/Relation.cs +++ b/Src/Notion.Client/Models/Filters/RelationFilter.cs @@ -1,53 +1,53 @@ -using Newtonsoft.Json; - -namespace Notion.Client -{ - public class RelationFilter : SinglePropertyFilter - { - [JsonProperty("relation")] - public Condition Relation { get; set; } - - public RelationFilter( - string propertyName, - string contains = null, - string doesNotContain = null, - bool? isEmpty = null, - bool? isNotEmpty = null) - { - Property = propertyName; - Relation = new Condition( - contains: contains, - doesNotContain: doesNotContain, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty - ); - } - - public class Condition - { - [JsonProperty("contains")] - public string Contains { get; set; } - - [JsonProperty("does_not_contain")] - public string DoesNotContain { get; set; } - - [JsonProperty("is_empty")] - public bool? IsEmpty { get; set; } - - [JsonProperty("is_not_empty")] - public bool? IsNotEmpty { get; set; } - - public Condition( - string contains = null, - string doesNotContain = null, - bool? isEmpty = null, - bool? isNotEmpty = null) - { - Contains = contains; - DoesNotContain = doesNotContain; - IsEmpty = isEmpty; - IsNotEmpty = isNotEmpty; - } - } - } -} +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class RelationFilter : SinglePropertyFilter + { + [JsonProperty("relation")] + public Condition Relation { get; set; } + + public RelationFilter( + string propertyName, + string contains = null, + string doesNotContain = null, + bool? isEmpty = null, + bool? isNotEmpty = null) + { + Property = propertyName; + Relation = new Condition( + contains: contains, + doesNotContain: doesNotContain, + isEmpty: isEmpty, + isNotEmpty: isNotEmpty + ); + } + + public class Condition + { + [JsonProperty("contains")] + public string Contains { get; set; } + + [JsonProperty("does_not_contain")] + public string DoesNotContain { get; set; } + + [JsonProperty("is_empty")] + public bool? IsEmpty { get; set; } + + [JsonProperty("is_not_empty")] + public bool? IsNotEmpty { get; set; } + + public Condition( + string contains = null, + string doesNotContain = null, + bool? isEmpty = null, + bool? isNotEmpty = null) + { + Contains = contains; + DoesNotContain = doesNotContain; + IsEmpty = isEmpty; + IsNotEmpty = isNotEmpty; + } + } + } +} diff --git a/Src/Notion.Client/Models/Filters/Text.cs b/Src/Notion.Client/Models/Filters/RichTextFilter.cs similarity index 89% rename from Src/Notion.Client/Models/Filters/Text.cs rename to Src/Notion.Client/Models/Filters/RichTextFilter.cs index 3446e854..84128fcb 100644 --- a/Src/Notion.Client/Models/Filters/Text.cs +++ b/Src/Notion.Client/Models/Filters/RichTextFilter.cs @@ -1,81 +1,84 @@ -using Newtonsoft.Json; - -namespace Notion.Client -{ - public class TextFilter : SinglePropertyFilter - { - [JsonProperty("text")] - public Condition Text { get; set; } - - public TextFilter( - string propertyName, - string equal = null, - string doesNotEqual = null, - string contains = null, - string doesNotContain = null, - string startsWith = null, - string endsWith = null, - bool? isEmpty = null, - bool? isNotEmpty = null) - { - Property = propertyName; - Text = new Condition( - equal: equal, - doesNotEqual: doesNotEqual, - contains: contains, - doesNotContain: doesNotContain, - startsWith: startsWith, - endsWith: endsWith, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty - ); - } - - public class Condition - { - [JsonProperty("equals")] - public string Equal { get; set; } - - [JsonProperty("does_not_equal")] - public string DoesNotEqual { get; set; } - - [JsonProperty("contains")] - public string Contains { get; set; } - - [JsonProperty("does_not_contain")] - public string DoesNotContain { get; set; } - - [JsonProperty("starts_with")] - public string StartsWith { get; set; } - - [JsonProperty("ends_with")] - public string EndsWith { get; set; } - - [JsonProperty("is_empty")] - public bool? IsEmpty { get; set; } - - [JsonProperty("is_not_empty")] - public bool? IsNotEmpty { get; set; } - - public Condition( - string equal = null, - string doesNotEqual = null, - string contains = null, - string doesNotContain = null, - string startsWith = null, - string endsWith = null, - bool? isEmpty = null, - bool? isNotEmpty = null) - { - Equal = equal; - DoesNotEqual = doesNotEqual; - Contains = contains; - DoesNotContain = doesNotContain; - StartsWith = startsWith; - EndsWith = endsWith; - IsEmpty = isEmpty; - IsNotEmpty = isNotEmpty; - } - } - } -} +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class RichTextFilter : SinglePropertyFilter + { + [JsonProperty("rich_text")] + public TextFilter.Condition RichText { get; set; } + + public RichTextFilter( + string propertyName, + string equal = null, + string doesNotEqual = null, + string contains = null, + string doesNotContain = null, + string startsWith = null, + string endsWith = null, + bool? isEmpty = null, + bool? isNotEmpty = null) + { + Property = propertyName; + RichText = new TextFilter.Condition( + equal: equal, + doesNotEqual: doesNotEqual, + contains: contains, + doesNotContain: doesNotContain, + startsWith: startsWith, + endsWith: endsWith, + isEmpty: isEmpty, + isNotEmpty: isNotEmpty + ); + } + } + + public static class TextFilter + { + public class Condition + { + [JsonProperty("equals")] + public string Equal { get; set; } + + [JsonProperty("does_not_equal")] + public string DoesNotEqual { get; set; } + + [JsonProperty("contains")] + public string Contains { get; set; } + + [JsonProperty("does_not_contain")] + public string DoesNotContain { get; set; } + + [JsonProperty("starts_with")] + public string StartsWith { get; set; } + + [JsonProperty("ends_with")] + public string EndsWith { get; set; } + + [JsonProperty("is_empty")] + public bool? IsEmpty { get; set; } + + [JsonProperty("is_not_empty")] + public bool? IsNotEmpty { get; set; } + + public Condition( + string equal = null, + string doesNotEqual = null, + string contains = null, + string doesNotContain = null, + string startsWith = null, + string endsWith = null, + bool? isEmpty = null, + bool? isNotEmpty = null) + { + Equal = equal; + DoesNotEqual = doesNotEqual; + Contains = contains; + DoesNotContain = doesNotContain; + StartsWith = startsWith; + EndsWith = endsWith; + IsEmpty = isEmpty; + IsNotEmpty = isNotEmpty; + } + } + } +} diff --git a/Src/Notion.Client/Models/Filters/Select.cs b/Src/Notion.Client/Models/Filters/SelectFilter.cs similarity index 96% rename from Src/Notion.Client/Models/Filters/Select.cs rename to Src/Notion.Client/Models/Filters/SelectFilter.cs index bf246be2..a8d22cf7 100644 --- a/Src/Notion.Client/Models/Filters/Select.cs +++ b/Src/Notion.Client/Models/Filters/SelectFilter.cs @@ -1,53 +1,53 @@ -using Newtonsoft.Json; - -namespace Notion.Client -{ - public class SelectFilter : SinglePropertyFilter - { - [JsonProperty("select")] - public Condition Select { get; set; } - - public SelectFilter( - string propertyName, - string equal = null, - string doesNotEqual = null, - bool? isEmpty = null, - bool? isNotEmpty = null) - { - Property = propertyName; - Select = new Condition( - equal: equal, - doesNotEqual: doesNotEqual, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty - ); - } - - public class Condition - { - [JsonProperty("equals")] - public string Equal { get; set; } - - [JsonProperty("does_not_equal")] - public string DoesNotEqual { get; set; } - - [JsonProperty("is_empty")] - public bool? IsEmpty { get; set; } - - [JsonProperty("is_not_empty")] - public bool? IsNotEmpty { get; set; } - - public Condition( - string equal = null, - string doesNotEqual = null, - bool? isEmpty = null, - bool? isNotEmpty = null) - { - Equal = equal; - DoesNotEqual = doesNotEqual; - IsEmpty = isEmpty; - IsNotEmpty = isNotEmpty; - } - } - } -} +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class SelectFilter : SinglePropertyFilter + { + [JsonProperty("select")] + public Condition Select { get; set; } + + public SelectFilter( + string propertyName, + string equal = null, + string doesNotEqual = null, + bool? isEmpty = null, + bool? isNotEmpty = null) + { + Property = propertyName; + Select = new Condition( + equal: equal, + doesNotEqual: doesNotEqual, + isEmpty: isEmpty, + isNotEmpty: isNotEmpty + ); + } + + public class Condition + { + [JsonProperty("equals")] + public string Equal { get; set; } + + [JsonProperty("does_not_equal")] + public string DoesNotEqual { get; set; } + + [JsonProperty("is_empty")] + public bool? IsEmpty { get; set; } + + [JsonProperty("is_not_empty")] + public bool? IsNotEmpty { get; set; } + + public Condition( + string equal = null, + string doesNotEqual = null, + bool? isEmpty = null, + bool? isNotEmpty = null) + { + Equal = equal; + DoesNotEqual = doesNotEqual; + IsEmpty = isEmpty; + IsNotEmpty = isNotEmpty; + } + } + } +} diff --git a/Src/Notion.Client/Models/Filters/TitleFilter.cs b/Src/Notion.Client/Models/Filters/TitleFilter.cs new file mode 100644 index 00000000..7c21bb33 --- /dev/null +++ b/Src/Notion.Client/Models/Filters/TitleFilter.cs @@ -0,0 +1,34 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class TitleFilter : SinglePropertyFilter + { + [JsonProperty("title")] + public TextFilter.Condition Title { get; set; } + + public TitleFilter( + string propertyName, + string equal = null, + string doesNotEqual = null, + string contains = null, + string doesNotContain = null, + string startsWith = null, + string endsWith = null, + bool? isEmpty = null, + bool? isNotEmpty = null) + { + Property = propertyName; + Title = new TextFilter.Condition( + equal: equal, + doesNotEqual: doesNotEqual, + contains: contains, + doesNotContain: doesNotContain, + startsWith: startsWith, + endsWith: endsWith, + isEmpty: isEmpty, + isNotEmpty: isNotEmpty + ); + } + } +} diff --git a/Src/Notion.Client/Models/Filters/URLFilter.cs b/Src/Notion.Client/Models/Filters/URLFilter.cs new file mode 100644 index 00000000..b6a1fe6b --- /dev/null +++ b/Src/Notion.Client/Models/Filters/URLFilter.cs @@ -0,0 +1,34 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class URLFilter : SinglePropertyFilter + { + [JsonProperty("url")] + public TextFilter.Condition URL { get; set; } + + public URLFilter( + string propertyName, + string equal = null, + string doesNotEqual = null, + string contains = null, + string doesNotContain = null, + string startsWith = null, + string endsWith = null, + bool? isEmpty = null, + bool? isNotEmpty = null) + { + Property = propertyName; + URL = new TextFilter.Condition( + equal: equal, + doesNotEqual: doesNotEqual, + contains: contains, + doesNotContain: doesNotContain, + startsWith: startsWith, + endsWith: endsWith, + isEmpty: isEmpty, + isNotEmpty: isNotEmpty + ); + } + } +} diff --git a/Test/Notion.UnitTests/FilterTests.cs b/Test/Notion.UnitTests/FilterTests.cs index 38a0921b..87f317eb 100644 --- a/Test/Notion.UnitTests/FilterTests.cs +++ b/Test/Notion.UnitTests/FilterTests.cs @@ -122,9 +122,9 @@ public void PeopleFilter() } [Fact] - public void TextFilterTest() + public void RichTextFilterTest() { - var filter = new TextFilter("Some property", doesNotEqual: "Example text"); + var filter = new RichTextFilter("Some property", doesNotEqual: "Example text"); Assert.Equal( "{\"text\":{\"does_not_equal\":\"Example text\"},\"property\":\"Some property\"}", SerializeFilter(filter) From f9ddfff781b4b840adac5117da728590b81b370e Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Mon, 11 Jul 2022 01:46:03 +0530 Subject: [PATCH 025/216] add rollup property filter --- .../Models/Filters/CheckboxFilter.cs | 2 +- .../Models/Filters/DateFilter.cs | 2 +- .../Models/Filters/FilesFilter.cs | 2 +- .../Models/Filters/MultiSelectFilter.cs | 2 +- .../Models/Filters/NumberFilter.cs | 2 +- .../Models/Filters/PeopleFilter.cs | 2 +- .../Models/Filters/RelationFilter.cs | 2 +- .../Models/Filters/RichTextFilter.cs | 2 +- .../Rollup/IRollupSubPropertyFilter.cs | 6 ++ .../Models/Filters/Rollup/RollupFilter.cs | 60 +++++++++++++++++++ .../Models/Filters/SelectFilter.cs | 2 +- 11 files changed, 75 insertions(+), 9 deletions(-) create mode 100644 Src/Notion.Client/Models/Filters/Rollup/IRollupSubPropertyFilter.cs create mode 100644 Src/Notion.Client/Models/Filters/Rollup/RollupFilter.cs diff --git a/Src/Notion.Client/Models/Filters/CheckboxFilter.cs b/Src/Notion.Client/Models/Filters/CheckboxFilter.cs index f0c2b41d..da144aec 100644 --- a/Src/Notion.Client/Models/Filters/CheckboxFilter.cs +++ b/Src/Notion.Client/Models/Filters/CheckboxFilter.cs @@ -3,7 +3,7 @@ namespace Notion.Client { - public class CheckboxFilter : SinglePropertyFilter + public class CheckboxFilter : SinglePropertyFilter, IRollupSubPropertyFilter { [JsonProperty("checkbox")] public Condition Checkbox { get; set; } diff --git a/Src/Notion.Client/Models/Filters/DateFilter.cs b/Src/Notion.Client/Models/Filters/DateFilter.cs index a472ff49..51b38dc2 100644 --- a/Src/Notion.Client/Models/Filters/DateFilter.cs +++ b/Src/Notion.Client/Models/Filters/DateFilter.cs @@ -5,7 +5,7 @@ namespace Notion.Client { - public class DateFilter : SinglePropertyFilter + public class DateFilter : SinglePropertyFilter, IRollupSubPropertyFilter { [JsonProperty("date")] public Condition Date { get; set; } diff --git a/Src/Notion.Client/Models/Filters/FilesFilter.cs b/Src/Notion.Client/Models/Filters/FilesFilter.cs index a3dca061..a32d4d7b 100644 --- a/Src/Notion.Client/Models/Filters/FilesFilter.cs +++ b/Src/Notion.Client/Models/Filters/FilesFilter.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - public class FilesFilter : SinglePropertyFilter + public class FilesFilter : SinglePropertyFilter, IRollupSubPropertyFilter { [JsonProperty("files")] public Condition Files { get; set; } diff --git a/Src/Notion.Client/Models/Filters/MultiSelectFilter.cs b/Src/Notion.Client/Models/Filters/MultiSelectFilter.cs index 69615b3d..14aec6d5 100644 --- a/Src/Notion.Client/Models/Filters/MultiSelectFilter.cs +++ b/Src/Notion.Client/Models/Filters/MultiSelectFilter.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - public class MultiSelectFilter : SinglePropertyFilter + public class MultiSelectFilter : SinglePropertyFilter, IRollupSubPropertyFilter { [JsonProperty("multi_select")] public Condition MultiSelect { get; set; } diff --git a/Src/Notion.Client/Models/Filters/NumberFilter.cs b/Src/Notion.Client/Models/Filters/NumberFilter.cs index 58e0c38a..4895d3e8 100644 --- a/Src/Notion.Client/Models/Filters/NumberFilter.cs +++ b/Src/Notion.Client/Models/Filters/NumberFilter.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - public class NumberFilter : SinglePropertyFilter + public class NumberFilter : SinglePropertyFilter, IRollupSubPropertyFilter { [JsonProperty("number")] public Condition Number { get; set; } diff --git a/Src/Notion.Client/Models/Filters/PeopleFilter.cs b/Src/Notion.Client/Models/Filters/PeopleFilter.cs index cd77c186..af1067c4 100644 --- a/Src/Notion.Client/Models/Filters/PeopleFilter.cs +++ b/Src/Notion.Client/Models/Filters/PeopleFilter.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - public class PeopleFilter : SinglePropertyFilter + public class PeopleFilter : SinglePropertyFilter, IRollupSubPropertyFilter { [JsonProperty("people")] public Condition People { get; set; } diff --git a/Src/Notion.Client/Models/Filters/RelationFilter.cs b/Src/Notion.Client/Models/Filters/RelationFilter.cs index e7eef130..b7e2924d 100644 --- a/Src/Notion.Client/Models/Filters/RelationFilter.cs +++ b/Src/Notion.Client/Models/Filters/RelationFilter.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - public class RelationFilter : SinglePropertyFilter + public class RelationFilter : SinglePropertyFilter, IRollupSubPropertyFilter { [JsonProperty("relation")] public Condition Relation { get; set; } diff --git a/Src/Notion.Client/Models/Filters/RichTextFilter.cs b/Src/Notion.Client/Models/Filters/RichTextFilter.cs index 84128fcb..90bae02e 100644 --- a/Src/Notion.Client/Models/Filters/RichTextFilter.cs +++ b/Src/Notion.Client/Models/Filters/RichTextFilter.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - public class RichTextFilter : SinglePropertyFilter + public class RichTextFilter : SinglePropertyFilter, IRollupSubPropertyFilter { [JsonProperty("rich_text")] public TextFilter.Condition RichText { get; set; } diff --git a/Src/Notion.Client/Models/Filters/Rollup/IRollupSubPropertyFilter.cs b/Src/Notion.Client/Models/Filters/Rollup/IRollupSubPropertyFilter.cs new file mode 100644 index 00000000..b9c850c5 --- /dev/null +++ b/Src/Notion.Client/Models/Filters/Rollup/IRollupSubPropertyFilter.cs @@ -0,0 +1,6 @@ +namespace Notion.Client +{ + public interface IRollupSubPropertyFilter + { + } +} diff --git a/Src/Notion.Client/Models/Filters/Rollup/RollupFilter.cs b/Src/Notion.Client/Models/Filters/Rollup/RollupFilter.cs new file mode 100644 index 00000000..41cb759e --- /dev/null +++ b/Src/Notion.Client/Models/Filters/Rollup/RollupFilter.cs @@ -0,0 +1,60 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class RollupFilter : SinglePropertyFilter + { + [JsonProperty("rollup")] + public Condition Rollup { get; set; } + + public RollupFilter( + string propertyName + , IRollupSubPropertyFilter any = null + , IRollupSubPropertyFilter none = null + , IRollupSubPropertyFilter every = null + , DateFilter.Condition date = null + , NumberFilter.Condition number = null) + { + Property = propertyName; + Rollup = new Condition( + any, + none, + every, + date, + number + ); + } + + public class Condition + { + public Condition( + IRollupSubPropertyFilter any = null + , IRollupSubPropertyFilter none = null + , IRollupSubPropertyFilter every = null + , DateFilter.Condition date = null + , NumberFilter.Condition number = null) + { + Any = any; + None = none; + Every = every; + Date = date; + Number = number; + } + + [JsonProperty("any")] + public IRollupSubPropertyFilter Any { get; set; } + + [JsonProperty("none")] + public IRollupSubPropertyFilter None { get; set; } + + [JsonProperty("every")] + public IRollupSubPropertyFilter Every { get; set; } + + [JsonProperty("date")] + public DateFilter.Condition Date { get; set; } + + [JsonProperty("number")] + public NumberFilter.Condition Number { get; set; } + } + } +} diff --git a/Src/Notion.Client/Models/Filters/SelectFilter.cs b/Src/Notion.Client/Models/Filters/SelectFilter.cs index a8d22cf7..6f0887a4 100644 --- a/Src/Notion.Client/Models/Filters/SelectFilter.cs +++ b/Src/Notion.Client/Models/Filters/SelectFilter.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - public class SelectFilter : SinglePropertyFilter + public class SelectFilter : SinglePropertyFilter, IRollupSubPropertyFilter { [JsonProperty("select")] public Condition Select { get; set; } From 4ecab195bd7c3e458edbe4745e85ca1dc1904598 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Mon, 11 Jul 2022 02:08:50 +0530 Subject: [PATCH 026/216] =?UTF-8?q?fix=20breaking=20test=20cases=20?= =?UTF-8?q?=E2=9C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Test/Notion.UnitTests/FilterTests.cs | 2 +- .../data/blocks/AppendBlockChildrenResponse.json | 4 ++-- .../data/blocks/RetrieveBlockChildrenResponse.json | 10 +++++----- .../data/blocks/RetrieveBlockResponse.json | 2 +- .../data/blocks/UpdateBlockResponse.json | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Test/Notion.UnitTests/FilterTests.cs b/Test/Notion.UnitTests/FilterTests.cs index 87f317eb..5b4650a5 100644 --- a/Test/Notion.UnitTests/FilterTests.cs +++ b/Test/Notion.UnitTests/FilterTests.cs @@ -126,7 +126,7 @@ public void RichTextFilterTest() { var filter = new RichTextFilter("Some property", doesNotEqual: "Example text"); Assert.Equal( - "{\"text\":{\"does_not_equal\":\"Example text\"},\"property\":\"Some property\"}", + "{\"rich_text\":{\"does_not_equal\":\"Example text\"},\"property\":\"Some property\"}", SerializeFilter(filter) ); } diff --git a/Test/Notion.UnitTests/data/blocks/AppendBlockChildrenResponse.json b/Test/Notion.UnitTests/data/blocks/AppendBlockChildrenResponse.json index 7cba0666..32612405 100644 --- a/Test/Notion.UnitTests/data/blocks/AppendBlockChildrenResponse.json +++ b/Test/Notion.UnitTests/data/blocks/AppendBlockChildrenResponse.json @@ -9,7 +9,7 @@ "has_children": false, "type": "heading_2", "heading_2": { - "text": [ + "rich_text": [ { "type": "text", "text": { @@ -38,7 +38,7 @@ "has_children": false, "type": "paragraph", "paragraph": { - "text": [ + "rich_text": [ { "type": "text", "text": { diff --git a/Test/Notion.UnitTests/data/blocks/RetrieveBlockChildrenResponse.json b/Test/Notion.UnitTests/data/blocks/RetrieveBlockChildrenResponse.json index fe30ff6b..649185e7 100644 --- a/Test/Notion.UnitTests/data/blocks/RetrieveBlockChildrenResponse.json +++ b/Test/Notion.UnitTests/data/blocks/RetrieveBlockChildrenResponse.json @@ -10,7 +10,7 @@ "archived": false, "type": "paragraph", "paragraph": { - "text": [] + "rich_text": [] } }, { @@ -22,7 +22,7 @@ "archived": false, "type": "heading_2", "heading_2": { - "text": [ + "rich_text": [ { "type": "text", "text": { @@ -52,7 +52,7 @@ "archived": false, "type": "heading_2", "heading_2": { - "text": [ + "rich_text": [ { "type": "text", "text": { @@ -82,7 +82,7 @@ "archived": false, "type": "paragraph", "paragraph": { - "text": [] + "rich_text": [] } }, { @@ -118,7 +118,7 @@ "archived": false, "type": "paragraph", "paragraph": { - "text": [] + "rich_text": [] } }, { diff --git a/Test/Notion.UnitTests/data/blocks/RetrieveBlockResponse.json b/Test/Notion.UnitTests/data/blocks/RetrieveBlockResponse.json index 201a2a96..9c7deabe 100644 --- a/Test/Notion.UnitTests/data/blocks/RetrieveBlockResponse.json +++ b/Test/Notion.UnitTests/data/blocks/RetrieveBlockResponse.json @@ -6,7 +6,7 @@ "has_children": false, "type": "to_do", "to_do": { - "text": [ + "rich_text": [ { "type": "text", "text": { diff --git a/Test/Notion.UnitTests/data/blocks/UpdateBlockResponse.json b/Test/Notion.UnitTests/data/blocks/UpdateBlockResponse.json index c9fb6a9a..497aba34 100644 --- a/Test/Notion.UnitTests/data/blocks/UpdateBlockResponse.json +++ b/Test/Notion.UnitTests/data/blocks/UpdateBlockResponse.json @@ -6,7 +6,7 @@ "has_children": false, "type": "to_do", "to_do": { - "text": [ + "rich_text": [ { "type": "text", "text": { From 6d8a3452942dd65f47393cecbf231c762ce13a9e Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Mon, 11 Jul 2022 02:23:40 +0530 Subject: [PATCH 027/216] Rename Text prop to String in formula property filter --- Src/Notion.Client/Models/Filters/FormulaFilter.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Src/Notion.Client/Models/Filters/FormulaFilter.cs b/Src/Notion.Client/Models/Filters/FormulaFilter.cs index 9e6fdc19..eee9fc52 100644 --- a/Src/Notion.Client/Models/Filters/FormulaFilter.cs +++ b/Src/Notion.Client/Models/Filters/FormulaFilter.cs @@ -9,14 +9,14 @@ public class FormulaFilter : SinglePropertyFilter public FormulaFilter( string propertyName, - TextFilter.Condition text = null, + TextFilter.Condition @string = null, CheckboxFilter.Condition checkbox = null, NumberFilter.Condition number = null, DateFilter.Condition date = null) { Property = propertyName; Formula = new Condition( - text: text, + @string: @string, checkbox: checkbox, number: number, date: date @@ -25,8 +25,8 @@ public FormulaFilter( public class Condition { - [JsonProperty("text")] - public TextFilter.Condition Text { get; set; } + [JsonProperty("string")] + public TextFilter.Condition String { get; set; } [JsonProperty("checkbox")] public CheckboxFilter.Condition Checkbox { get; set; } @@ -38,12 +38,12 @@ public class Condition public DateFilter.Condition Date { get; set; } public Condition( - TextFilter.Condition text = null, + TextFilter.Condition @string = null, CheckboxFilter.Condition checkbox = null, NumberFilter.Condition number = null, DateFilter.Condition date = null) { - Text = text; + String = @string; Checkbox = checkbox; Number = number; Date = date; From 3c252dd1c22dfaede06fad4940a202dce45d271d Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Mon, 11 Jul 2022 04:05:00 +0530 Subject: [PATCH 028/216] Add support for id, next_url & property_item prop * cleanup unused item --- .../Models/PropertyItems/IPropertyItemObject.cs | 9 +++++++++ .../Models/PropertyItems/ListPropertyItem.cs | 11 ++++++++--- .../Models/PropertyItems/RollupPropertyItem.cs | 12 ------------ .../Models/PropertyItems/SimplePropertyItem.cs | 4 ++++ 4 files changed, 21 insertions(+), 15 deletions(-) delete mode 100644 Src/Notion.Client/Models/PropertyItems/RollupPropertyItem.cs diff --git a/Src/Notion.Client/Models/PropertyItems/IPropertyItemObject.cs b/Src/Notion.Client/Models/PropertyItems/IPropertyItemObject.cs index e6eb91c2..5ebc7730 100644 --- a/Src/Notion.Client/Models/PropertyItems/IPropertyItemObject.cs +++ b/Src/Notion.Client/Models/PropertyItems/IPropertyItemObject.cs @@ -13,5 +13,14 @@ public interface IPropertyItemObject [JsonProperty("type")] string Type { get; } + + [JsonProperty("id")] + string Id { get; } + + /// + /// Only present in paginated property values with another page of results. If present, the url the user can request to get the next page of results. + /// + [JsonProperty("next_url")] + string NextURL { get; } } } diff --git a/Src/Notion.Client/Models/PropertyItems/ListPropertyItem.cs b/Src/Notion.Client/Models/PropertyItems/ListPropertyItem.cs index 3ca83d81..f539fcd6 100644 --- a/Src/Notion.Client/Models/PropertyItems/ListPropertyItem.cs +++ b/Src/Notion.Client/Models/PropertyItems/ListPropertyItem.cs @@ -4,14 +4,16 @@ namespace Notion.Client { - [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(RollupPropertyItem), "rollup")] - [JsonSubtypes.FallBackSubType(typeof(ListPropertyItem))] public class ListPropertyItem : IPropertyItemObject { public string Object => "list"; + public virtual string Type { get; set; } + public string Id { get; set; } + + public string NextURL { get; set; } + [JsonProperty("results")] public IEnumerable Results { get; set; } @@ -20,5 +22,8 @@ public class ListPropertyItem : IPropertyItemObject [JsonProperty("next_cursor")] public string NextCursor { get; set; } + + [JsonProperty("property_item")] + public SimplePropertyItem PropertyItem { get; set; } } } diff --git a/Src/Notion.Client/Models/PropertyItems/RollupPropertyItem.cs b/Src/Notion.Client/Models/PropertyItems/RollupPropertyItem.cs deleted file mode 100644 index 6e6e53cd..00000000 --- a/Src/Notion.Client/Models/PropertyItems/RollupPropertyItem.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Newtonsoft.Json; - -namespace Notion.Client -{ - public class RollupPropertyItem : ListPropertyItem - { - public override string Type => "rollup"; - - [JsonProperty("rollup")] - public RollupValue Rollup { get; set; } - } -} diff --git a/Src/Notion.Client/Models/PropertyItems/SimplePropertyItem.cs b/Src/Notion.Client/Models/PropertyItems/SimplePropertyItem.cs index 6cc1f52b..da753319 100644 --- a/Src/Notion.Client/Models/PropertyItems/SimplePropertyItem.cs +++ b/Src/Notion.Client/Models/PropertyItems/SimplePropertyItem.cs @@ -27,5 +27,9 @@ public abstract class SimplePropertyItem : IPropertyItemObject public string Object => "property_item"; public abstract string Type { get; } + + public string Id { get; set; } + + public string NextURL { get; set; } } } From f83606e3c7c26bae1e97698145e460cd4b9356f6 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Wed, 13 Jul 2022 16:12:57 +0530 Subject: [PATCH 029/216] Removed list database endpoint --- .../Api/Databases/DatabasesClient.cs | 18 +----------- .../Api/Databases/IDatabasesClient.cs | 11 +------- Test/Notion.UnitTests/DatabasesClientTests.cs | 28 ------------------- 3 files changed, 2 insertions(+), 55 deletions(-) diff --git a/Src/Notion.Client/Api/Databases/DatabasesClient.cs b/Src/Notion.Client/Api/Databases/DatabasesClient.cs index ee546aef..2ab17a8b 100644 --- a/Src/Notion.Client/Api/Databases/DatabasesClient.cs +++ b/Src/Notion.Client/Api/Databases/DatabasesClient.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; +using System.Threading.Tasks; using static Notion.Client.ApiEndpoints; namespace Notion.Client @@ -19,20 +17,6 @@ public async Task RetrieveAsync(string databaseId) return await _client.GetAsync(DatabasesApiUrls.Retrieve(databaseId)); } - [Obsolete("This endpoint is no longer recommended, use Search instead. This endpoint will only return explicitly shared pages, while search will also return child pages within explicitly shared pages. This endpoint's results cannot be filtered, while search can be used to match on page title.", false)] - public async Task> ListAsync(DatabasesListParameters databasesListParameters = null) - { - var databasesListQueryParmaters = (IDatabasesListQueryParmaters)databasesListParameters; - - var queryParams = new Dictionary() - { - { "start_cursor", databasesListQueryParmaters?.StartCursor }, - { "page_size", databasesListQueryParmaters?.PageSize?.ToString() } - }; - - return await _client.GetAsync>(DatabasesApiUrls.List(), queryParams); - } - public async Task> QueryAsync(string databaseId, DatabasesQueryParameters databasesQueryParameters) { var body = (IDatabaseQueryBodyParameters)databasesQueryParameters; diff --git a/Src/Notion.Client/Api/Databases/IDatabasesClient.cs b/Src/Notion.Client/Api/Databases/IDatabasesClient.cs index c339e4da..2b2c2746 100644 --- a/Src/Notion.Client/Api/Databases/IDatabasesClient.cs +++ b/Src/Notion.Client/Api/Databases/IDatabasesClient.cs @@ -1,5 +1,4 @@ -using System; -using System.Threading.Tasks; +using System.Threading.Tasks; namespace Notion.Client { @@ -8,14 +7,6 @@ public interface IDatabasesClient Task RetrieveAsync(string databaseId); Task> QueryAsync(string databaseId, DatabasesQueryParameters databasesQueryParameters); - /// - /// List all Databases shared with the authenticated integration. - /// - /// database list request parameters. - /// PaginatedList of databases. - [Obsolete("This endpoint is no longer recommended, use Search instead. This endpoint will only return explicitly shared pages, while search will also return child pages within explicitly shared pages. This endpoint's results cannot be filtered, while search can be used to match on page title.", false)] - Task> ListAsync(DatabasesListParameters databasesListParameters = null); - /// /// Creates a database as a subpage in the specified parent page, with the specified properties schema. /// diff --git a/Test/Notion.UnitTests/DatabasesClientTests.cs b/Test/Notion.UnitTests/DatabasesClientTests.cs index 8462b42d..b87fdd5e 100644 --- a/Test/Notion.UnitTests/DatabasesClientTests.cs +++ b/Test/Notion.UnitTests/DatabasesClientTests.cs @@ -18,34 +18,6 @@ public DatabasesClientTests() _client = new DatabasesClient(new RestClient(ClientOptions)); } - [Fact] - [Obsolete] - public async Task ListDatabasesAsync() - { - var path = ApiEndpoints.DatabasesApiUrls.List(); - var jsonData = await File.ReadAllTextAsync("data/databases/DatabasesListResponse.json"); - - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( - Response.Create() - .WithStatusCode(200) - .WithBody(jsonData) - ); - - var databases = await _client.ListAsync(); - - databases.Results.Should().HaveCount(3); - - foreach (var database in databases.Results) - { - database.Parent.Should().BeAssignableTo(); - foreach (var property in database.Properties) - { - property.Key.Should().Be(property.Value.Name); - } - } - } - [Fact] public async Task QueryAsync() { From 1172c4f8870b87f6fad5ff8e32f424f740457fb9 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Wed, 13 Jul 2022 16:16:30 +0530 Subject: [PATCH 030/216] =?UTF-8?q?updated=20document=20=F0=9F=93=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 - docs/README.md | 1 - 2 files changed, 2 deletions(-) diff --git a/README.md b/README.md index 29cc826b..7e552e88 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,6 @@ var complexFiler = new CompoundFilter( - [x] Create a database - [x] Update database - [x] Retrieve a database - - [x] List databases (Deprecated: use Search API instead) - [x] Pages - [x] Retrieve a page - [x] Create a page diff --git a/docs/README.md b/docs/README.md index 5ece487d..14a21997 100644 --- a/docs/README.md +++ b/docs/README.md @@ -80,7 +80,6 @@ var complexFiler = new CompoundFilter( - [x] Create a database - [x] Update database - [x] Retrieve a database - - [x] List databases (Deprecated: use Search API instead) - [x] Pages - [x] Retrieve a page - [x] Create a page From b261ba96aace4b49fdef222abcbb28e9567ec3ab Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Fri, 15 Jul 2022 23:14:56 +0530 Subject: [PATCH 031/216] add timezone support to date property --- Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs index 6182b197..cc0818ae 100644 --- a/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs @@ -33,5 +33,11 @@ public class Date /// [JsonProperty("end")] public DateTime? End { get; set; } + + /// + /// Optional time zone information for start and end. Possible values are extracted from the IANA database and they are based on the time zones from Moment.js. + /// + [JsonProperty("time_zone")] + public string TimeZone { get; set; } } } From ca5d611b919d76b6dec31a42183320a99f0bd1f1 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Fri, 15 Jul 2022 23:48:21 +0530 Subject: [PATCH 032/216] add caption property in code block --- .../BlocksUpdateParameters/UpdateBlocks/CodeUpdateBlock.cs | 3 +++ Src/Notion.Client/Models/Blocks/CodeBlock.cs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/CodeUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/CodeUpdateBlock.cs index 1364adb0..e6b26fad 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/CodeUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/CodeUpdateBlock.cs @@ -15,6 +15,9 @@ public class Info [JsonProperty("language")] public string Language { get; set; } + + [JsonProperty("caption")] + public IEnumerable Caption { get; set; } } } } diff --git a/Src/Notion.Client/Models/Blocks/CodeBlock.cs b/Src/Notion.Client/Models/Blocks/CodeBlock.cs index 7eb4205d..f00905f7 100644 --- a/Src/Notion.Client/Models/Blocks/CodeBlock.cs +++ b/Src/Notion.Client/Models/Blocks/CodeBlock.cs @@ -17,6 +17,9 @@ public class Info [JsonProperty("language")] public string Language { get; set; } + + [JsonProperty("caption")] + public IEnumerable Caption { get; set; } } } } From e57a2d7649284a945b63d883419a21292cd2de3d Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 16 Jul 2022 18:37:09 +0530 Subject: [PATCH 033/216] =?UTF-8?q?add=20ability=20to=20clear=20date=20pro?= =?UTF-8?q?perty=20=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs index cc0818ae..aeb3cd8e 100644 --- a/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs @@ -13,7 +13,7 @@ public class DatePropertyValue : PropertyValue /// /// Date /// - [JsonProperty("date")] + [JsonProperty("date", NullValueHandling = NullValueHandling.Include)] public Date Date { get; set; } } From 2e9767c5a6daadf8fd5c8a2072c360fc456bb509 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 16 Jul 2022 18:37:34 +0530 Subject: [PATCH 034/216] =?UTF-8?q?Add=20&=20refactor=20test=20cases=20?= =?UTF-8?q?=E2=9C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IPageClientTests.cs | 77 +++++++++++++++++-- 1 file changed, 72 insertions(+), 5 deletions(-) diff --git a/Test/Notion.IntegrationTests/IPageClientTests.cs b/Test/Notion.IntegrationTests/IPageClientTests.cs index ae1e317b..a2c73162 100644 --- a/Test/Notion.IntegrationTests/IPageClientTests.cs +++ b/Test/Notion.IntegrationTests/IPageClientTests.cs @@ -11,6 +11,7 @@ namespace Notion.IntegrationTests public class IPageClientTests { private readonly INotionClient _client; + private readonly string _databaseId; public IPageClientTests() { @@ -20,6 +21,7 @@ public IPageClientTests() }; _client = NotionClientFactory.Create(options); + _databaseId = Environment.GetEnvironmentVariable("DATABASE_ID") ?? "f86f2262-0751-40f2-8f63-e3f7a3c39fcb"; } [Fact] @@ -27,7 +29,7 @@ public async Task CreateAsync_CreatesANewPage() { PagesCreateParameters pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput { - DatabaseId = "f86f2262-0751-40f2-8f63-e3f7a3c39fcb" + DatabaseId = _databaseId }) .AddProperty("Name", new TitlePropertyValue { @@ -48,7 +50,7 @@ public async Task CreateAsync_CreatesANewPage() page.Should().NotBeNull(); page.Parent.Should().BeOfType().Which - .DatabaseId.Should().Be("f86f2262-0751-40f2-8f63-e3f7a3c39fcb"); + .DatabaseId.Should().Be(_databaseId); page.Properties.Should().ContainKey("Name"); page.Properties["Name"].Should().BeOfType().Which @@ -65,7 +67,7 @@ public async Task Bug_unable_to_create_page_with_select_property() { PagesCreateParameters pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput { - DatabaseId = "f86f2262-0751-40f2-8f63-e3f7a3c39fcb" + DatabaseId = _databaseId }) .AddProperty("Name", new TitlePropertyValue { @@ -93,7 +95,7 @@ public async Task Bug_unable_to_create_page_with_select_property() page.Should().NotBeNull(); page.Parent.Should().BeOfType().Which - .DatabaseId.Should().Be("f86f2262-0751-40f2-8f63-e3f7a3c39fcb"); + .DatabaseId.Should().Be(_databaseId); page.Properties.Should().ContainKey("Name"); page.Properties["Name"].Should().BeOfType().Which @@ -110,7 +112,7 @@ public async Task Test_RetrievePagePropertyItemAsync() { PagesCreateParameters pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput { - DatabaseId = "f86f2262-0751-40f2-8f63-e3f7a3c39fcb" + DatabaseId = _databaseId }) .AddProperty("Name", new TitlePropertyValue { @@ -155,5 +157,70 @@ public async Task Test_RetrievePagePropertyItemAsync() Archived = true }); } + + [Fact] + public async Task Test_UpdatePageProperty_with_date_as_null() + { + // setup - add property to db and create a page with the property having a date + + string datePropertyName = "Test Date Property"; + var updateDatabaseParameters = new DatabasesUpdateParameters(); + updateDatabaseParameters.Properties = new Dictionary + { + { "Name", new TitleUpdatePropertySchema { Title = new Dictionary() } }, + { "Test Date Property", new DateUpdatePropertySchema{ Date = new Dictionary() } } + }; + + PagesCreateParameters pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput + { + DatabaseId = _databaseId + }) + .AddProperty("Name", new TitlePropertyValue + { + Title = new List + { + new RichTextText + { + Text = new Text + { + Content = "Test Page Title" + } + } + } + }) + .AddProperty(datePropertyName, new DatePropertyValue + { + Date = new Date() + { + Start = Convert.ToDateTime("2020-12-08T12:00:00Z"), + End = Convert.ToDateTime("2025-12-08T12:00:00Z") + } + }) + .Build(); + + var updatedDb = await _client.Databases.UpdateAsync(_databaseId, updateDatabaseParameters); + + var page = await _client.Pages.CreateAsync(pagesCreateParameters); + + var setDate = page.Properties[datePropertyName] as DatePropertyValue; + + setDate?.Date?.Start.Should().Be(Convert.ToDateTime("2020-12-08T12:00:00Z")); + + // verify + IDictionary testProps = new Dictionary(); + testProps.Add(datePropertyName, new DatePropertyValue() { Date = null }); + + var updatedPage = await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters + { + Properties = testProps + }); + + var verifyDate = updatedPage.Properties[datePropertyName] as DatePropertyValue; + + verifyDate?.Date.Should().BeNull(); + + //cleanup + await _client.Blocks.DeleteAsync(page.Id); + } } } From d60b7421ae5c180a70b7d6006c4fa540b6d2976f Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 16 Jul 2022 19:11:59 +0530 Subject: [PATCH 035/216] Add support for Table and TableRow block --- .../UpdateBlocks/TableRowUpdateBlock.cs | 17 ++++++++++++ .../UpdateBlocks/TableUpdateBlock.cs | 19 +++++++++++++ Src/Notion.Client/Models/Blocks/BlockType.cs | 6 +++++ Src/Notion.Client/Models/Blocks/IBlock.cs | 2 ++ Src/Notion.Client/Models/Blocks/TableBlock.cs | 27 +++++++++++++++++++ .../Models/Blocks/TableRowBlock.cs | 19 +++++++++++++ 6 files changed, 90 insertions(+) create mode 100644 Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableRowUpdateBlock.cs create mode 100644 Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableUpdateBlock.cs create mode 100644 Src/Notion.Client/Models/Blocks/TableBlock.cs create mode 100644 Src/Notion.Client/Models/Blocks/TableRowBlock.cs diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableRowUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableRowUpdateBlock.cs new file mode 100644 index 00000000..be422530 --- /dev/null +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableRowUpdateBlock.cs @@ -0,0 +1,17 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class TableRowUpdateBlock : UpdateBlock, IUpdateBlock + { + [JsonProperty("table_row")] + public Info TableRow { get; set; } + + public class Info + { + [JsonProperty("cells")] + public IEnumerable> Cells { get; set; } + } + } +} diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableUpdateBlock.cs new file mode 100644 index 00000000..6079e27b --- /dev/null +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableUpdateBlock.cs @@ -0,0 +1,19 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class TableUpdateBlock : UpdateBlock, IUpdateBlock + { + [JsonProperty("table")] + public Info Table { get; set; } + + public class Info + { + [JsonProperty("has_column_header")] + public bool HasColumnHeader { get; set; } + + [JsonProperty("has_row_header")] + public bool HasRowHeader { get; set; } + } + } +} diff --git a/Src/Notion.Client/Models/Blocks/BlockType.cs b/Src/Notion.Client/Models/Blocks/BlockType.cs index 6ebec8f1..f3181b22 100644 --- a/Src/Notion.Client/Models/Blocks/BlockType.cs +++ b/Src/Notion.Client/Models/Blocks/BlockType.cs @@ -91,6 +91,12 @@ public enum BlockType [EnumMember(Value = "synced_block")] SyncedBlock, + [EnumMember(Value = "table")] + Table, + + [EnumMember(Value = "table_row")] + TableRow, + [EnumMember(Value = "unsupported")] Unsupported } diff --git a/Src/Notion.Client/Models/Blocks/IBlock.cs b/Src/Notion.Client/Models/Blocks/IBlock.cs index a7e925d1..f3c89d88 100644 --- a/Src/Notion.Client/Models/Blocks/IBlock.cs +++ b/Src/Notion.Client/Models/Blocks/IBlock.cs @@ -28,6 +28,8 @@ namespace Notion.Client [JsonSubtypes.KnownSubType(typeof(ParagraphBlock), BlockType.Paragraph)] [JsonSubtypes.KnownSubType(typeof(PDFBlock), BlockType.PDF)] [JsonSubtypes.KnownSubType(typeof(QuoteBlock), BlockType.Quote)] + [JsonSubtypes.KnownSubType(typeof(TableBlock), BlockType.Table)] + [JsonSubtypes.KnownSubType(typeof(TableRowBlock), BlockType.TableRow)] [JsonSubtypes.KnownSubType(typeof(TableOfContentsBlock), BlockType.TableOfContents)] [JsonSubtypes.KnownSubType(typeof(TemplateBlock), BlockType.Template)] [JsonSubtypes.KnownSubType(typeof(ToDoBlock), BlockType.ToDo)] diff --git a/Src/Notion.Client/Models/Blocks/TableBlock.cs b/Src/Notion.Client/Models/Blocks/TableBlock.cs new file mode 100644 index 00000000..e9f716df --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/TableBlock.cs @@ -0,0 +1,27 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class TableBlock : Block, IColumnChildrenBlock, INonColumnBlock + { + public override BlockType Type => BlockType.Table; + + [JsonProperty("table")] + public TableInfo Table { get; set; } + + public class TableInfo + { + [JsonProperty("table_width")] + public int TableWidth { get; set; } + + [JsonProperty("has_column_header")] + public bool HasColumnHeader { get; set; } + + [JsonProperty("has_row_header")] + public bool HasRowHeader { get; set; } + + [JsonProperty("children")] + public TableRowBlock Children { get; set; } + } + } +} diff --git a/Src/Notion.Client/Models/Blocks/TableRowBlock.cs b/Src/Notion.Client/Models/Blocks/TableRowBlock.cs new file mode 100644 index 00000000..978e7d8c --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/TableRowBlock.cs @@ -0,0 +1,19 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class TableRowBlock : Block, IColumnChildrenBlock, INonColumnBlock + { + public override BlockType Type => BlockType.TableRow; + + [JsonProperty("table_row")] + public Info TableRow { get; set; } + + public class Info + { + [JsonProperty("cells")] + public IEnumerable> Cells { get; set; } + } + } +} From f739b99ce5dac9e24acd62fa9921fa176283af2f Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 16 Jul 2022 19:19:03 +0530 Subject: [PATCH 036/216] =?UTF-8?q?Run=20linter=20=F0=9F=9A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BlocksUpdateParameters/UpdateBlocks/TableRowUpdateBlock.cs | 2 +- .../BlocksUpdateParameters/UpdateBlocks/TableUpdateBlock.cs | 2 +- Src/Notion.Client/Models/Blocks/TableBlock.cs | 2 +- Src/Notion.Client/Models/Blocks/TableRowBlock.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableRowUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableRowUpdateBlock.cs index be422530..c228de66 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableRowUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableRowUpdateBlock.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using Newtonsoft.Json; namespace Notion.Client diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableUpdateBlock.cs index 6079e27b..ef0e8933 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableUpdateBlock.cs @@ -1,4 +1,4 @@ -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Notion.Client { diff --git a/Src/Notion.Client/Models/Blocks/TableBlock.cs b/Src/Notion.Client/Models/Blocks/TableBlock.cs index e9f716df..dd20d94b 100644 --- a/Src/Notion.Client/Models/Blocks/TableBlock.cs +++ b/Src/Notion.Client/Models/Blocks/TableBlock.cs @@ -1,4 +1,4 @@ -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Notion.Client { diff --git a/Src/Notion.Client/Models/Blocks/TableRowBlock.cs b/Src/Notion.Client/Models/Blocks/TableRowBlock.cs index 978e7d8c..e7214e6c 100644 --- a/Src/Notion.Client/Models/Blocks/TableRowBlock.cs +++ b/Src/Notion.Client/Models/Blocks/TableRowBlock.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using Newtonsoft.Json; namespace Notion.Client From 59f6d11859d7d5b306a67845863ee2b18395ca45 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 16 Jul 2022 21:39:55 +0530 Subject: [PATCH 037/216] Set default Notion-Version to 2022-02-22 --- Src/Notion.Client/Constants.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/Notion.Client/Constants.cs b/Src/Notion.Client/Constants.cs index 5844bd6e..579e3db4 100644 --- a/Src/Notion.Client/Constants.cs +++ b/Src/Notion.Client/Constants.cs @@ -6,6 +6,6 @@ namespace Notion.Client internal class Constants { internal static string BASE_URL = "https://api.notion.com/"; - internal static string DEFAULT_NOTION_VERSION = "2021-08-16"; + internal static string DEFAULT_NOTION_VERSION = "2022-02-22"; } } From 85a8a6fa2f388431793e5d5088fd7a1a0f241b00 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 16 Jul 2022 21:41:22 +0530 Subject: [PATCH 038/216] =?UTF-8?q?Update=20readme=20to=20show=20default?= =?UTF-8?q?=20notion-version=20by=20NuGet=20package=20version=20?= =?UTF-8?q?=F0=9F=93=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 9 ++++++--- docs/README.md | 7 ++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7e552e88..c3cf6c95 100644 --- a/README.md +++ b/README.md @@ -41,9 +41,12 @@ Provides the following packages: dotnet add package Notion.Net ``` -> Note: From Nuget 2.0.0 notion client sdk default sets the Notion-Version header to 2021-08-16. - - +> Note: default Notion-Version used by NuGet package versions +> | Package version | Notion-Version | +> | --- | --- | +> | 3.0.0+ | 2022-02-22 | +> | 2.0.0+ | 2021-08-16 | +> | 1.0.0+ | 2021-05-13 | ## Usage diff --git a/docs/README.md b/docs/README.md index 14a21997..a662d6f3 100644 --- a/docs/README.md +++ b/docs/README.md @@ -10,7 +10,12 @@ A simple and easy to use client for the [Notion API](https://developers.notion.c dotnet add package Notion.Net ``` -> Note: From Nuget 2.0.0 notion client sdk default sets the Notion-Version header to 2021-08-16. +> Note: default Notion-Version used by NuGet package versions +> | Package version | Notion-Version | +> | --- | --- | +> | 3.0.0+ | 2022-02-22 | +> | 2.0.0+ | 2021-08-16 | +> | 1.0.0+ | 2021-05-13 | ## Usage From 01b5ed55869017ffc9c3c0faf354087a910ceb6a Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 16 Jul 2022 22:52:47 +0530 Subject: [PATCH 039/216] set version prefix to 3.0.0 --- Src/Notion.Client/Notion.Client.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/Notion.Client/Notion.Client.csproj b/Src/Notion.Client/Notion.Client.csproj index c1b237d1..541e191b 100644 --- a/Src/Notion.Client/Notion.Client.csproj +++ b/Src/Notion.Client/Notion.Client.csproj @@ -1,7 +1,7 @@  - 2.2.3-preview + 3.0.0-preview netstandard2.0 7.3 From 95f6b015f13250770e2a7e5138ef0aff5f2d89bd Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Mon, 18 Jul 2022 01:36:09 +0530 Subject: [PATCH 040/216] Set version prefix to 3.1.0-preview --- Src/Notion.Client/Notion.Client.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/Notion.Client/Notion.Client.csproj b/Src/Notion.Client/Notion.Client.csproj index 541e191b..e6b066ab 100644 --- a/Src/Notion.Client/Notion.Client.csproj +++ b/Src/Notion.Client/Notion.Client.csproj @@ -1,7 +1,7 @@  - 3.0.0-preview + 3.1.0-preview netstandard2.0 7.3 From 269a57a9fc0d692af5b253118c255d9c19596321 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Wed, 20 Jul 2022 23:54:39 +0530 Subject: [PATCH 041/216] Add archived property to database object --- .../DatabasesUpdateParameters.cs | 21 ++++------------- .../IDatabasesUpdateBodyParameters.cs | 23 +++++++++++++++++++ Src/Notion.Client/Models/Database/Database.cs | 6 +++++ 3 files changed, 34 insertions(+), 16 deletions(-) create mode 100644 Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/IDatabasesUpdateBodyParameters.cs diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs index ff2e129e..0f429ab1 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs @@ -1,28 +1,17 @@ using System.Collections.Generic; -using Newtonsoft.Json; namespace Notion.Client { - public interface IDatabasesUpdateBodyParameters - { - [JsonProperty("properties")] - Dictionary Properties { get; set; } - - [JsonProperty("title")] - List Title { get; set; } - - [JsonProperty("icon")] - IPageIcon Icon { get; set; } - - [JsonProperty("cover")] - FileObject Cover { get; set; } - } - public class DatabasesUpdateParameters : IDatabasesUpdateBodyParameters { public Dictionary Properties { get; set; } + public List Title { get; set; } + public IPageIcon Icon { get; set; } + public FileObject Cover { get; set; } + + public bool Archived { get; set; } } } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/IDatabasesUpdateBodyParameters.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/IDatabasesUpdateBodyParameters.cs new file mode 100644 index 00000000..cf2f989c --- /dev/null +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/IDatabasesUpdateBodyParameters.cs @@ -0,0 +1,23 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public interface IDatabasesUpdateBodyParameters + { + [JsonProperty("properties")] + Dictionary Properties { get; set; } + + [JsonProperty("title")] + List Title { get; set; } + + [JsonProperty("icon")] + IPageIcon Icon { get; set; } + + [JsonProperty("cover")] + FileObject Cover { get; set; } + + [JsonProperty("archived")] + bool Archived { get; set; } + } +} diff --git a/Src/Notion.Client/Models/Database/Database.cs b/Src/Notion.Client/Models/Database/Database.cs index 6943048f..b5e53141 100644 --- a/Src/Notion.Client/Models/Database/Database.cs +++ b/Src/Notion.Client/Models/Database/Database.cs @@ -36,5 +36,11 @@ public class Database : IObject /// [JsonProperty("url")] public string Url { get; set; } + + /// + /// The archived status of the database. + /// + [JsonProperty("archived")] + public bool IsArchived { get; set; } } } From 65068d2a4cb69b0214fee25046c8686bc86c7503 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Thu, 21 Jul 2022 00:21:39 +0530 Subject: [PATCH 042/216] renamed IsArchived to Archived --- Src/Notion.Client/Models/Database/Database.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/Notion.Client/Models/Database/Database.cs b/Src/Notion.Client/Models/Database/Database.cs index b5e53141..9699206e 100644 --- a/Src/Notion.Client/Models/Database/Database.cs +++ b/Src/Notion.Client/Models/Database/Database.cs @@ -41,6 +41,6 @@ public class Database : IObject /// The archived status of the database. /// [JsonProperty("archived")] - public bool IsArchived { get; set; } + public bool Archived { get; set; } } } From 47adf1df867ff905d95b1bf92d243fdd5698e9a1 Mon Sep 17 00:00:00 2001 From: Herman Schoenfeld Date: Fri, 22 Jul 2022 11:00:36 +1000 Subject: [PATCH 043/216] Added caption to EmbedBlock --- Src/Notion.Client/Models/Blocks/EmbedBlock.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Src/Notion.Client/Models/Blocks/EmbedBlock.cs b/Src/Notion.Client/Models/Blocks/EmbedBlock.cs index 8332b683..bbd93e10 100644 --- a/Src/Notion.Client/Models/Blocks/EmbedBlock.cs +++ b/Src/Notion.Client/Models/Blocks/EmbedBlock.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json; +using System.Collections.Generic; +using Newtonsoft.Json; namespace Notion.Client { @@ -13,6 +14,10 @@ public class Info { [JsonProperty("url")] public string Url { get; set; } + + [JsonProperty("caption")] + public IEnumerable Caption { get; set; } + } } } From 2c1ce68c91fc01050e56ef6adf153c6f97a08449 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sun, 31 Jul 2022 13:59:42 +0530 Subject: [PATCH 044/216] Add .gitattributes to force eol=lf except for bat files --- .gitattributes | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 00000000..cca2a078 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +* text=auto eol=lf +*.{cmd,[cC][mM][dD]} text eol=crlf +*.{bat, [bB][aA][tT]} text eol=crlf From cd8aaf1abf24558bb73cb2868b4aae79275d5a76 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sun, 31 Jul 2022 10:00:48 +0000 Subject: [PATCH 045/216] Fix .gitattributes --- .gitattributes | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitattributes b/.gitattributes index cca2a078..314766e9 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,3 @@ * text=auto eol=lf *.{cmd,[cC][mM][dD]} text eol=crlf -*.{bat, [bB][aA][tT]} text eol=crlf +*.{bat,[bB][aA][tT]} text eol=crlf From a9f29cc525c1512afe6f06fb8ec3bd39192f9130 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sun, 31 Jul 2022 10:01:10 +0000 Subject: [PATCH 046/216] Upgrade all projects to .net 6.0 --- Test/Notion.IntegrationTests/Notion.IntegrationTests.csproj | 2 +- Test/Notion.UnitTests/Notion.UnitTests.csproj | 2 +- examples/aspnet-core-app/aspnet-core-app.csproj | 4 ++-- examples/list-users/list-users.csproj | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Test/Notion.IntegrationTests/Notion.IntegrationTests.csproj b/Test/Notion.IntegrationTests/Notion.IntegrationTests.csproj index af02a55a..42a1975a 100644 --- a/Test/Notion.IntegrationTests/Notion.IntegrationTests.csproj +++ b/Test/Notion.IntegrationTests/Notion.IntegrationTests.csproj @@ -1,7 +1,7 @@ - net5.0 + net6.0 enable false diff --git a/Test/Notion.UnitTests/Notion.UnitTests.csproj b/Test/Notion.UnitTests/Notion.UnitTests.csproj index 0d5ec118..30ff0791 100644 --- a/Test/Notion.UnitTests/Notion.UnitTests.csproj +++ b/Test/Notion.UnitTests/Notion.UnitTests.csproj @@ -1,7 +1,7 @@ - net5.0 + net6.0 false diff --git a/examples/aspnet-core-app/aspnet-core-app.csproj b/examples/aspnet-core-app/aspnet-core-app.csproj index ecb2e709..8310dd1b 100644 --- a/examples/aspnet-core-app/aspnet-core-app.csproj +++ b/examples/aspnet-core-app/aspnet-core-app.csproj @@ -1,10 +1,10 @@ - net5.0 + net6.0 aspnet_core_app - \ No newline at end of file + diff --git a/examples/list-users/list-users.csproj b/examples/list-users/list-users.csproj index c3d3affe..22264436 100644 --- a/examples/list-users/list-users.csproj +++ b/examples/list-users/list-users.csproj @@ -1,7 +1,7 @@ Exe - net5.0 + net6.0 list_users From c3a41ccf910324e31e68b9926d31f7d370a16ea6 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sun, 31 Jul 2022 10:01:29 +0000 Subject: [PATCH 047/216] Add .devcontainer --- .devcontainer/Dockerfile | 16 +++++++++ .devcontainer/devcontainer.json | 62 +++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 00000000..5cb62058 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,16 @@ +# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.241.1/containers/dotnet/.devcontainer/base.Dockerfile + +# [Choice] .NET version: 6.0, 3.1, 6.0-bullseye, 3.1-bullseye, 6.0-focal, 3.1-focal +ARG VARIANT="6.0-bullseye-slim" +FROM mcr.microsoft.com/vscode/devcontainers/dotnet:0-${VARIANT} + +# [Choice] Node.js version: none, lts/*, 18, 16, 14 +ARG NODE_VERSION="none" +RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi + +# [Optional] Uncomment this section to install additional OS packages. +# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ +# && apt-get -y install --no-install-recommends + +# [Optional] Uncomment this line to install global node packages. +# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g " 2>&1 \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 00000000..54811cbd --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,62 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: +// https://github.com/microsoft/vscode-dev-containers/tree/v0.241.1/containers/dotnet +{ + "name": "C# (.NET)", + "build": { + "dockerfile": "Dockerfile", + "args": { + // Update 'VARIANT' to pick a .NET Core version: 3.1, 6.0 + // Append -bullseye or -focal to pin to an OS version. + "VARIANT": "6.0-bullseye", + // Options + "NODE_VERSION": "lts/*" + } + }, + + // Configure tool-specific properties. + "customizations": { + // Configure properties specific to VS Code. + "vscode": { + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "ms-dotnettools.csharp", + "aaron-bond.better-comments" + ] + } + }, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [5000, 5001], + + // [Optional] To reuse of your local HTTPS dev cert: + // + // 1. Export it locally using this command: + // * Windows PowerShell: + // dotnet dev-certs https --trust; dotnet dev-certs https -ep "$env:USERPROFILE/.aspnet/https/aspnetapp.pfx" -p "SecurePwdGoesHere" + // * macOS/Linux terminal: + // dotnet dev-certs https --trust; dotnet dev-certs https -ep "${HOME}/.aspnet/https/aspnetapp.pfx" -p "SecurePwdGoesHere" + // + // 2. Uncomment these 'remoteEnv' lines: + // "remoteEnv": { + // "ASPNETCORE_Kestrel__Certificates__Default__Password": "SecurePwdGoesHere", + // "ASPNETCORE_Kestrel__Certificates__Default__Path": "/home/vscode/.aspnet/https/aspnetapp.pfx", + // }, + // + // 3. Do one of the following depending on your scenario: + // * When using GitHub Codespaces and/or Remote - Containers: + // 1. Start the container + // 2. Drag ~/.aspnet/https/aspnetapp.pfx into the root of the file explorer + // 3. Open a terminal in VS Code and run "mkdir -p /home/vscode/.aspnet/https && mv aspnetapp.pfx /home/vscode/.aspnet/https" + // + // * If only using Remote - Containers with a local container, uncomment this line instead: + // "mounts": [ "source=${env:HOME}${env:USERPROFILE}/.aspnet/https,target=/home/vscode/.aspnet/https,type=bind" ], + + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "dotnet restore", + + // Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. + "remoteUser": "vscode", + "features": { + "fish": "latest" + } +} From 0dabd6607fb973099afdb32e562375d352cd2e12 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sun, 31 Jul 2022 11:03:08 +0000 Subject: [PATCH 048/216] Update github workflows to use .net 6 --- .github/workflows/build-artifacts-code.yml | 6 +++--- .github/workflows/ci-build.yml | 5 +++-- .github/workflows/publish-code.yml | 4 ++-- .github/workflows/test-publish-code.yml | 4 ++-- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build-artifacts-code.yml b/.github/workflows/build-artifacts-code.yml index 6ecda1a3..9acedc7c 100644 --- a/.github/workflows/build-artifacts-code.yml +++ b/.github/workflows/build-artifacts-code.yml @@ -18,10 +18,10 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Setup .NET 5.0 SDK - uses: actions/setup-dotnet@v1 + - name: Setup .NET + uses: actions/setup-dotnet@v2 with: - dotnet-version: 5.0.x + dotnet-version: 6.0.x source-url: https://nuget.pkg.github.com/notion-dotnet/index.json env: NUGET_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index e11118ff..3ac878a9 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -12,10 +12,11 @@ jobs: steps: - uses: actions/checkout@v2 + - name: Setup .NET - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v2 with: - dotnet-version: 5.0.x + dotnet-version: 6.0.x - name: Restore dependencies run: dotnet restore diff --git a/.github/workflows/publish-code.yml b/.github/workflows/publish-code.yml index ac41c7a1..ef76a197 100644 --- a/.github/workflows/publish-code.yml +++ b/.github/workflows/publish-code.yml @@ -12,9 +12,9 @@ jobs: - uses: actions/checkout@v2 - name: Setup .NET - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v2 with: - dotnet-version: 5.0.x + dotnet-version: 6.0.x source-url: https://api.nuget.org/v3/index.json env: NUGET_AUTH_TOKEN: ${{secrets.NUGET_API_KEY}} diff --git a/.github/workflows/test-publish-code.yml b/.github/workflows/test-publish-code.yml index 2184c513..e90afd73 100644 --- a/.github/workflows/test-publish-code.yml +++ b/.github/workflows/test-publish-code.yml @@ -15,9 +15,9 @@ jobs: - uses: actions/checkout@v2 - name: Setup .NET - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v2 with: - dotnet-version: 5.0.x + dotnet-version: 6.0.x source-url: https://api.nuget.org/v3/index.json env: NUGET_AUTH_TOKEN: ${{secrets.NUGET_API_KEY}} From 691c1e13cecbe1fc97865bb9dc11d067e1aac07a Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sun, 31 Jul 2022 18:40:42 +0530 Subject: [PATCH 049/216] Fix --check option renamed to --verify-no-changes for dotnet format cli --- .github/workflows/ci-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index 3ac878a9..c69148e8 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -29,7 +29,7 @@ jobs: - name: Install dotnet format run: | dotnet tool install --global dotnet-format - dotnet format --check --verbosity diagnostic + dotnet format --verify-no-changes --verbosity diagnostic - name: Build run: dotnet build --no-restore From 89c80850c2c9ef5ae48568c2693acefcdd31ad1f Mon Sep 17 00:00:00 2001 From: Herman Schoenfeld Date: Fri, 5 Aug 2022 11:59:06 +1000 Subject: [PATCH 050/216] Refactored Color abstraction - Color is now an enum in the DTO's - Added missing Color to ToggleBlock --- .../PropertySchema/SelectOptionSchema.cs | 4 +- Src/Notion.Client/Models/Blocks/BlockType.cs | 1 + .../Models/Blocks/BulletedListItemBlock.cs | 5 ++ .../Models/Blocks/CalloutBlock.cs | 5 ++ Src/Notion.Client/Models/Blocks/Color.cs | 65 +++++++++++++++++++ .../Models/Blocks/HeadingOneBlock.cs | 6 ++ .../Models/Blocks/HeadingThreeeBlock.cs | 6 ++ .../Models/Blocks/HeadingTwoBlock.cs | 6 ++ .../Models/Blocks/NumberedListItemBlock.cs | 5 ++ .../Models/Blocks/ParagraphBlock.cs | 5 ++ Src/Notion.Client/Models/Blocks/QuoteBlock.cs | 5 ++ .../Models/Blocks/TableOfContentsBlock.cs | 4 ++ Src/Notion.Client/Models/Blocks/ToDoBlock.cs | 5 ++ .../Models/Blocks/ToggleBlock.cs | 5 ++ .../Database/Properties/SelectProperty.cs | 4 +- .../Models/Database/RichText/RichTextBase.cs | 4 +- 16 files changed, 131 insertions(+), 4 deletions(-) create mode 100644 Src/Notion.Client/Models/Blocks/Color.cs diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/SelectOptionSchema.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/SelectOptionSchema.cs index 12989d1f..c31aef9f 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/SelectOptionSchema.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/SelectOptionSchema.cs @@ -1,4 +1,5 @@ using Newtonsoft.Json; +using Newtonsoft.Json.Converters; namespace Notion.Client { @@ -8,6 +9,7 @@ public class SelectOptionSchema public string Name { get; set; } [JsonProperty("color")] - public string Color { get; set; } + [JsonConverter(typeof(StringEnumConverter))] + public Color Color { get; set; } } } diff --git a/Src/Notion.Client/Models/Blocks/BlockType.cs b/Src/Notion.Client/Models/Blocks/BlockType.cs index f3181b22..6ad45f73 100644 --- a/Src/Notion.Client/Models/Blocks/BlockType.cs +++ b/Src/Notion.Client/Models/Blocks/BlockType.cs @@ -100,4 +100,5 @@ public enum BlockType [EnumMember(Value = "unsupported")] Unsupported } + } diff --git a/Src/Notion.Client/Models/Blocks/BulletedListItemBlock.cs b/Src/Notion.Client/Models/Blocks/BulletedListItemBlock.cs index 145a37e5..e6711de5 100644 --- a/Src/Notion.Client/Models/Blocks/BulletedListItemBlock.cs +++ b/Src/Notion.Client/Models/Blocks/BulletedListItemBlock.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Newtonsoft.Json; +using Newtonsoft.Json.Converters; namespace Notion.Client { @@ -15,6 +16,10 @@ public class Info [JsonProperty("rich_text")] public IEnumerable RichText { get; set; } + [JsonProperty("color")] + [JsonConverter(typeof(StringEnumConverter))] + public Color Color { get; set; } + [JsonProperty("children")] public IEnumerable Children { get; set; } } diff --git a/Src/Notion.Client/Models/Blocks/CalloutBlock.cs b/Src/Notion.Client/Models/Blocks/CalloutBlock.cs index f995e3be..d694e33c 100644 --- a/Src/Notion.Client/Models/Blocks/CalloutBlock.cs +++ b/Src/Notion.Client/Models/Blocks/CalloutBlock.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Newtonsoft.Json; +using Newtonsoft.Json.Converters; namespace Notion.Client { @@ -18,6 +19,10 @@ public class Info [JsonProperty("icon")] public IPageIcon Icon { get; set; } + [JsonProperty("color")] + [JsonConverter(typeof(StringEnumConverter))] + public Color Color { get; set; } + [JsonProperty("children")] public IEnumerable Children { get; set; } } diff --git a/Src/Notion.Client/Models/Blocks/Color.cs b/Src/Notion.Client/Models/Blocks/Color.cs new file mode 100644 index 00000000..ae75df22 --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/Color.cs @@ -0,0 +1,65 @@ +using System.Runtime.Serialization; + +namespace Notion.Client +{ + public enum Color + { + [EnumMember(Value = "default")] + Default, + + [EnumMember(Value = "gray")] + Gray, + + [EnumMember(Value = "brown")] + Brown, + + [EnumMember(Value = "orange")] + Orange, + + [EnumMember(Value = "yellow")] + Yellow, + + [EnumMember(Value = "green")] + Green, + + [EnumMember(Value = "blue")] + Blue, + + [EnumMember(Value = "purple")] + Purple, + + [EnumMember(Value = "pink")] + Pink, + + [EnumMember(Value = "red")] + Red, + + [EnumMember(Value = "gray_background")] + GrayBackground, + + [EnumMember(Value = "brown_background")] + BrownBackground, + + [EnumMember(Value = "orange_background")] + OrangeBackground, + + [EnumMember(Value = "yellow_background")] + YellowBackground, + + [EnumMember(Value = "green_background")] + GreenBackground, + + [EnumMember(Value = "blue_background")] + BlueBackground, + + [EnumMember(Value = "purple_background")] + PurpleBackground, + + [EnumMember(Value = "pink_background")] + PinkBackground, + + [EnumMember(Value = "red_background")] + RedBackground, + + } +} diff --git a/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs b/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs index 67132fe5..8c8d1659 100644 --- a/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs +++ b/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Newtonsoft.Json; +using Newtonsoft.Json.Converters; namespace Notion.Client { @@ -16,6 +17,11 @@ public class Info { [JsonProperty("rich_text")] public IEnumerable RichText { get; set; } + + [JsonProperty("color")] + [JsonConverter(typeof(StringEnumConverter))] + public Color Color { get; set; } + } } } diff --git a/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs b/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs index 2e4dde99..a9c3efd3 100644 --- a/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs +++ b/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Newtonsoft.Json; +using Newtonsoft.Json.Converters; namespace Notion.Client { @@ -16,6 +17,11 @@ public class Info { [JsonProperty("rich_text")] public IEnumerable RichText { get; set; } + + [JsonProperty("color")] + [JsonConverter(typeof(StringEnumConverter))] + public Color Color { get; set; } + } } } diff --git a/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs b/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs index 82c75047..47756093 100644 --- a/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs +++ b/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Newtonsoft.Json; +using Newtonsoft.Json.Converters; namespace Notion.Client { @@ -16,6 +17,11 @@ public class Info { [JsonProperty("rich_text")] public IEnumerable RichText { get; set; } + + [JsonProperty("color")] + [JsonConverter(typeof(StringEnumConverter))] + public Color Color { get; set; } + } } } diff --git a/Src/Notion.Client/Models/Blocks/NumberedListItemBlock.cs b/Src/Notion.Client/Models/Blocks/NumberedListItemBlock.cs index 581d8977..189eedf1 100644 --- a/Src/Notion.Client/Models/Blocks/NumberedListItemBlock.cs +++ b/Src/Notion.Client/Models/Blocks/NumberedListItemBlock.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Newtonsoft.Json; +using Newtonsoft.Json.Converters; namespace Notion.Client { @@ -15,6 +16,10 @@ public class Info [JsonProperty("rich_text")] public IEnumerable RichText { get; set; } + [JsonProperty("color")] + [JsonConverter(typeof(StringEnumConverter))] + public Color Color { get; set; } + [JsonProperty("children")] public IEnumerable Children { get; set; } } diff --git a/Src/Notion.Client/Models/Blocks/ParagraphBlock.cs b/Src/Notion.Client/Models/Blocks/ParagraphBlock.cs index 02560aee..ff3ae2a3 100644 --- a/Src/Notion.Client/Models/Blocks/ParagraphBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ParagraphBlock.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Newtonsoft.Json; +using Newtonsoft.Json.Converters; namespace Notion.Client { @@ -14,6 +15,10 @@ public class Info { [JsonProperty("rich_text")] public IEnumerable RichText { get; set; } + + [JsonProperty("color")] + [JsonConverter(typeof(StringEnumConverter))] + public Color Color { get; set; } [JsonProperty("children")] public IEnumerable Children { get; set; } diff --git a/Src/Notion.Client/Models/Blocks/QuoteBlock.cs b/Src/Notion.Client/Models/Blocks/QuoteBlock.cs index 9a8dda8e..68479075 100644 --- a/Src/Notion.Client/Models/Blocks/QuoteBlock.cs +++ b/Src/Notion.Client/Models/Blocks/QuoteBlock.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Newtonsoft.Json; +using Newtonsoft.Json.Converters; namespace Notion.Client { @@ -15,6 +16,10 @@ public class Info [JsonProperty("rich_text")] public IEnumerable RichText { get; set; } + [JsonProperty("color")] + [JsonConverter(typeof(StringEnumConverter))] + public Color Color { get; set; } + [JsonProperty("children")] public IEnumerable Children { get; set; } } diff --git a/Src/Notion.Client/Models/Blocks/TableOfContentsBlock.cs b/Src/Notion.Client/Models/Blocks/TableOfContentsBlock.cs index 49e11bf4..29305ca9 100644 --- a/Src/Notion.Client/Models/Blocks/TableOfContentsBlock.cs +++ b/Src/Notion.Client/Models/Blocks/TableOfContentsBlock.cs @@ -1,4 +1,5 @@ using Newtonsoft.Json; +using Newtonsoft.Json.Converters; namespace Notion.Client { @@ -11,6 +12,9 @@ public class TableOfContentsBlock : Block, IColumnChildrenBlock, INonColumnBlock public class Data { + [JsonProperty("color")] + [JsonConverter(typeof(StringEnumConverter))] + public Color Color { get; set; } } } } diff --git a/Src/Notion.Client/Models/Blocks/ToDoBlock.cs b/Src/Notion.Client/Models/Blocks/ToDoBlock.cs index 0417827d..d2fcc75e 100644 --- a/Src/Notion.Client/Models/Blocks/ToDoBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ToDoBlock.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Newtonsoft.Json; +using Newtonsoft.Json.Converters; namespace Notion.Client { @@ -18,6 +19,10 @@ public class Info [JsonProperty("checked")] public bool IsChecked { get; set; } + [JsonProperty("color")] + [JsonConverter(typeof(StringEnumConverter))] + public Color Color { get; set; } + [JsonProperty("children")] public IEnumerable Children { get; set; } } diff --git a/Src/Notion.Client/Models/Blocks/ToggleBlock.cs b/Src/Notion.Client/Models/Blocks/ToggleBlock.cs index 2653cd1b..1367f40b 100644 --- a/Src/Notion.Client/Models/Blocks/ToggleBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ToggleBlock.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Newtonsoft.Json; +using Newtonsoft.Json.Converters; namespace Notion.Client { @@ -15,6 +16,10 @@ public class Info [JsonProperty("rich_text")] public IEnumerable RichText { get; set; } + [JsonProperty("color")] + [JsonConverter(typeof(StringEnumConverter))] + public Color Color { get; set; } + [JsonProperty("children")] public IEnumerable Children { get; set; } } diff --git a/Src/Notion.Client/Models/Database/Properties/SelectProperty.cs b/Src/Notion.Client/Models/Database/Properties/SelectProperty.cs index 47e6fa64..dd1dfeb1 100644 --- a/Src/Notion.Client/Models/Database/Properties/SelectProperty.cs +++ b/Src/Notion.Client/Models/Database/Properties/SelectProperty.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using Newtonsoft.Json; +using Newtonsoft.Json.Converters; namespace Notion.Client { @@ -33,7 +34,8 @@ public class SelectOption /// Color of the option. Possible values are: "default", "gray", "brown", "red", "orange", "yellow", "green", "blue", "purple", "pink". Defaults to "default". /// [JsonProperty("color")] - public string Color { get; set; } + [JsonConverter(typeof(StringEnumConverter))] + public Color Color { get; set; } } public class MultiSelectProperty : Property diff --git a/Src/Notion.Client/Models/Database/RichText/RichTextBase.cs b/Src/Notion.Client/Models/Database/RichText/RichTextBase.cs index 1c9a7610..0b509325 100644 --- a/Src/Notion.Client/Models/Database/RichText/RichTextBase.cs +++ b/Src/Notion.Client/Models/Database/RichText/RichTextBase.cs @@ -42,7 +42,7 @@ public class Annotations public bool IsCode { get; set; } [JsonProperty("color")] - // color: Color | BackgroundColor - public string Color { get; set; } + [JsonConverter(typeof(StringEnumConverter))] + public Color Color { get; set; } } } From 3978493bb33d35cf608066428aa390226d4312d1 Mon Sep 17 00:00:00 2001 From: Herman Schoenfeld Date: Fri, 5 Aug 2022 12:11:06 +1000 Subject: [PATCH 051/216] Build error and code style compliance --- Src/Notion.Client/Models/Blocks/BlockType.cs | 1 - Src/Notion.Client/Models/Blocks/Color.cs | 1 - .../Models/Blocks/HeadingOneBlock.cs | 1 - .../Models/Blocks/HeadingThreeeBlock.cs | 1 - .../Models/Blocks/HeadingTwoBlock.cs | 1 - Test/Notion.UnitTests/DatabasesClientTests.cs | 24 +++++++++---------- 6 files changed, 12 insertions(+), 17 deletions(-) diff --git a/Src/Notion.Client/Models/Blocks/BlockType.cs b/Src/Notion.Client/Models/Blocks/BlockType.cs index 6ad45f73..f3181b22 100644 --- a/Src/Notion.Client/Models/Blocks/BlockType.cs +++ b/Src/Notion.Client/Models/Blocks/BlockType.cs @@ -100,5 +100,4 @@ public enum BlockType [EnumMember(Value = "unsupported")] Unsupported } - } diff --git a/Src/Notion.Client/Models/Blocks/Color.cs b/Src/Notion.Client/Models/Blocks/Color.cs index ae75df22..b4682a7b 100644 --- a/Src/Notion.Client/Models/Blocks/Color.cs +++ b/Src/Notion.Client/Models/Blocks/Color.cs @@ -60,6 +60,5 @@ public enum Color [EnumMember(Value = "red_background")] RedBackground, - } } diff --git a/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs b/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs index 8c8d1659..ccf29220 100644 --- a/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs +++ b/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs @@ -21,7 +21,6 @@ public class Info [JsonProperty("color")] [JsonConverter(typeof(StringEnumConverter))] public Color Color { get; set; } - } } } diff --git a/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs b/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs index a9c3efd3..73897da0 100644 --- a/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs +++ b/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs @@ -21,7 +21,6 @@ public class Info [JsonProperty("color")] [JsonConverter(typeof(StringEnumConverter))] public Color Color { get; set; } - } } } diff --git a/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs b/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs index 47756093..7b4e161e 100644 --- a/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs +++ b/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs @@ -21,7 +21,6 @@ public class Info [JsonProperty("color")] [JsonConverter(typeof(StringEnumConverter))] public Color Color { get; set; } - } } } diff --git a/Test/Notion.UnitTests/DatabasesClientTests.cs b/Test/Notion.UnitTests/DatabasesClientTests.cs index b87fdd5e..a3254131 100644 --- a/Test/Notion.UnitTests/DatabasesClientTests.cs +++ b/Test/Notion.UnitTests/DatabasesClientTests.cs @@ -214,17 +214,17 @@ public async Task CreateDatabaseAsync() { new SelectOptionSchema { - Color = "green", + Color = Color.Green, Name = "🥦Vegetable" }, new SelectOptionSchema { - Color = "red", + Color = Color.Red, Name = "🍎Fruit" }, new SelectOptionSchema { - Color = "yellow", + Color = Color.Yellow, Name = "💪Protein" } } @@ -248,17 +248,17 @@ public async Task CreateDatabaseAsync() option => { option.Name.Should().Be("🥦Vegetable"); - option.Color.Should().Be("green"); + option.Color.Should().Be(Color.Green); }, option => { option.Name.Should().Be("🍎Fruit"); - option.Color.Should().Be("red"); + option.Color.Should().Be(Color.Red); }, option => { option.Name.Should().Be("💪Protein"); - option.Color.Should().Be("yellow"); + option.Color.Should().Be(Color.Yellow); } ); } @@ -303,17 +303,17 @@ public async Task UpdateDatabaseAsync() { new SelectOption { - Color = "green", + Color = Color.Green, Name = "🥦Vegetables" }, new SelectOption { - Color = "red", + Color = Color.Red, Name = "🍎Fruit" }, new SelectOption { - Color = "yellow", + Color = Color.Yellow, Name = "💪Protein" } } @@ -346,17 +346,17 @@ public async Task UpdateDatabaseAsync() option => { option.Name.Should().Be("🥦Vegetables"); - option.Color.Should().Be("green"); + option.Color.Should().Be(Color.Green); }, option => { option.Name.Should().Be("🍎Fruit"); - option.Color.Should().Be("red"); + option.Color.Should().Be(Color.Red); }, option => { option.Name.Should().Be("💪Protein"); - option.Color.Should().Be("yellow"); + option.Color.Should().Be(Color.Yellow); } ); From 0024ce711502fe7ecefc24235661afc98c1a58be Mon Sep 17 00:00:00 2001 From: Herman Schoenfeld Date: Thu, 11 Aug 2022 10:54:11 +1000 Subject: [PATCH 052/216] Formatting issue on ParagraphBlock.cs --- Src/Notion.Client/Models/Blocks/ParagraphBlock.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/Notion.Client/Models/Blocks/ParagraphBlock.cs b/Src/Notion.Client/Models/Blocks/ParagraphBlock.cs index ff3ae2a3..f45e8628 100644 --- a/Src/Notion.Client/Models/Blocks/ParagraphBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ParagraphBlock.cs @@ -15,7 +15,7 @@ public class Info { [JsonProperty("rich_text")] public IEnumerable RichText { get; set; } - + [JsonProperty("color")] [JsonConverter(typeof(StringEnumConverter))] public Color Color { get; set; } From 78036273c4d17db5f7f6901b74afc9a82492b5ab Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 20 Aug 2022 11:55:06 +0530 Subject: [PATCH 053/216] Add IObjectModification interface --- Src/Notion.Client/Models/Blocks/Block.cs | 8 +++++--- Src/Notion.Client/Models/Blocks/IBlock.cs | 8 +------- .../Models/Common/IObjectModificationData.cs | 20 +++++++++++++++++++ Src/Notion.Client/Models/Database/Database.cs | 2 +- Src/Notion.Client/Models/Page/Page.cs | 2 +- 5 files changed, 28 insertions(+), 12 deletions(-) create mode 100644 Src/Notion.Client/Models/Common/IObjectModificationData.cs diff --git a/Src/Notion.Client/Models/Blocks/Block.cs b/Src/Notion.Client/Models/Blocks/Block.cs index 9ba90612..c9f501d0 100644 --- a/Src/Notion.Client/Models/Blocks/Block.cs +++ b/Src/Notion.Client/Models/Blocks/Block.cs @@ -1,4 +1,6 @@ -namespace Notion.Client +using System; + +namespace Notion.Client { public abstract class Block : IBlock { @@ -8,9 +10,9 @@ public abstract class Block : IBlock public virtual BlockType Type { get; set; } - public string CreatedTime { get; set; } + public DateTime CreatedTime { get; set; } - public string LastEditedTime { get; set; } + public DateTime LastEditedTime { get; set; } public virtual bool HasChildren { get; set; } } diff --git a/Src/Notion.Client/Models/Blocks/IBlock.cs b/Src/Notion.Client/Models/Blocks/IBlock.cs index f3c89d88..c8cee542 100644 --- a/Src/Notion.Client/Models/Blocks/IBlock.cs +++ b/Src/Notion.Client/Models/Blocks/IBlock.cs @@ -36,18 +36,12 @@ namespace Notion.Client [JsonSubtypes.KnownSubType(typeof(ToggleBlock), BlockType.Toggle)] [JsonSubtypes.KnownSubType(typeof(VideoBlock), BlockType.Video)] [JsonSubtypes.KnownSubType(typeof(UnsupportedBlock), BlockType.Unsupported)] - public interface IBlock : IObject + public interface IBlock : IObject, IObjectModificationData { [JsonProperty("type")] [JsonConverter(typeof(StringEnumConverter))] BlockType Type { get; set; } - [JsonProperty("created_time")] - string CreatedTime { get; set; } - - [JsonProperty("last_edited_time")] - string LastEditedTime { get; set; } - [JsonProperty("has_children")] bool HasChildren { get; set; } } diff --git a/Src/Notion.Client/Models/Common/IObjectModificationData.cs b/Src/Notion.Client/Models/Common/IObjectModificationData.cs new file mode 100644 index 00000000..2d7c3d3e --- /dev/null +++ b/Src/Notion.Client/Models/Common/IObjectModificationData.cs @@ -0,0 +1,20 @@ +using System; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public interface IObjectModificationData + { + /// + /// Date and time when this object was created. + /// + [JsonProperty("created_time")] + DateTime CreatedTime { get; set; } + + /// + /// Date and time when this object was updated. + /// + [JsonProperty("last_edited_time")] + DateTime LastEditedTime { get; set; } + } +} diff --git a/Src/Notion.Client/Models/Database/Database.cs b/Src/Notion.Client/Models/Database/Database.cs index 6943048f..bfb0db5e 100644 --- a/Src/Notion.Client/Models/Database/Database.cs +++ b/Src/Notion.Client/Models/Database/Database.cs @@ -4,7 +4,7 @@ namespace Notion.Client { - public class Database : IObject + public class Database : IObject, IObjectModificationData { public ObjectType Object => ObjectType.Database; diff --git a/Src/Notion.Client/Models/Page/Page.cs b/Src/Notion.Client/Models/Page/Page.cs index 352f9d13..f1fc404c 100644 --- a/Src/Notion.Client/Models/Page/Page.cs +++ b/Src/Notion.Client/Models/Page/Page.cs @@ -4,7 +4,7 @@ namespace Notion.Client { - public class Page : IObject + public class Page : IObject, IObjectModificationData { /// /// Object type From 93a4f764e65650eb15a066cfbe2a2a01553f560f Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 20 Aug 2022 11:55:51 +0530 Subject: [PATCH 054/216] Run linter --- Src/Notion.Client/Notion.Client.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Src/Notion.Client/Notion.Client.csproj b/Src/Notion.Client/Notion.Client.csproj index e6b066ab..b33398f8 100644 --- a/Src/Notion.Client/Notion.Client.csproj +++ b/Src/Notion.Client/Notion.Client.csproj @@ -22,8 +22,8 @@ - - + + From 5abdf165643a6b54648469c623ef47be3ecb2ac8 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 20 Aug 2022 12:08:26 +0530 Subject: [PATCH 055/216] Add created by and last edited by properties --- Src/Notion.Client/Models/Blocks/Block.cs | 4 ++++ .../Models/Common/IObjectModificationData.cs | 12 ++++++++++++ Src/Notion.Client/Models/Database/Database.cs | 4 ++++ Src/Notion.Client/Models/Page/Page.cs | 4 ++++ Src/Notion.Client/Models/User/PartialUser.cs | 9 +++++++++ 5 files changed, 33 insertions(+) create mode 100644 Src/Notion.Client/Models/User/PartialUser.cs diff --git a/Src/Notion.Client/Models/Blocks/Block.cs b/Src/Notion.Client/Models/Blocks/Block.cs index c9f501d0..e4a3eaeb 100644 --- a/Src/Notion.Client/Models/Blocks/Block.cs +++ b/Src/Notion.Client/Models/Blocks/Block.cs @@ -15,5 +15,9 @@ public abstract class Block : IBlock public DateTime LastEditedTime { get; set; } public virtual bool HasChildren { get; set; } + + public PartialUser CreatedBy { get; set; } + + public PartialUser LastEditedBy { get; set; } } } diff --git a/Src/Notion.Client/Models/Common/IObjectModificationData.cs b/Src/Notion.Client/Models/Common/IObjectModificationData.cs index 2d7c3d3e..06177ccd 100644 --- a/Src/Notion.Client/Models/Common/IObjectModificationData.cs +++ b/Src/Notion.Client/Models/Common/IObjectModificationData.cs @@ -16,5 +16,17 @@ public interface IObjectModificationData /// [JsonProperty("last_edited_time")] DateTime LastEditedTime { get; set; } + + /// + /// User who created the object. + /// + [JsonProperty("created_by")] + PartialUser CreatedBy { get; set; } + + /// + /// User who last modified the object. + /// + [JsonProperty("last_edited_by")] + PartialUser LastEditedBy { get; set; } } } diff --git a/Src/Notion.Client/Models/Database/Database.cs b/Src/Notion.Client/Models/Database/Database.cs index bfb0db5e..577dc581 100644 --- a/Src/Notion.Client/Models/Database/Database.cs +++ b/Src/Notion.Client/Models/Database/Database.cs @@ -36,5 +36,9 @@ public class Database : IObject, IObjectModificationData /// [JsonProperty("url")] public string Url { get; set; } + + public PartialUser CreatedBy { get; set; } + + public PartialUser LastEditedBy { get; set; } } } diff --git a/Src/Notion.Client/Models/Page/Page.cs b/Src/Notion.Client/Models/Page/Page.cs index f1fc404c..d96fef8a 100644 --- a/Src/Notion.Client/Models/Page/Page.cs +++ b/Src/Notion.Client/Models/Page/Page.cs @@ -63,5 +63,9 @@ public class Page : IObject, IObjectModificationData /// [JsonProperty("cover")] public FileObject Cover { get; set; } + + public PartialUser CreatedBy { get; set; } + + public PartialUser LastEditedBy { get; set; } } } diff --git a/Src/Notion.Client/Models/User/PartialUser.cs b/Src/Notion.Client/Models/User/PartialUser.cs new file mode 100644 index 00000000..5b335f0b --- /dev/null +++ b/Src/Notion.Client/Models/User/PartialUser.cs @@ -0,0 +1,9 @@ +namespace Notion.Client +{ + public class PartialUser : IObject + { + public string Id { get; set; } + + public ObjectType Object => ObjectType.User; + } +} From 94a08b2ccf3eb3471c6d71a96c0f39584324102e Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 20 Aug 2022 12:40:42 +0530 Subject: [PATCH 056/216] Add timestamp filters --- .../Filters/TimestampCreatedTimeFilter.cs | 47 +++++++++++++++++++ .../Filters/TimestampLastEditedTimeFilter.cs | 47 +++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 Src/Notion.Client/Models/Filters/TimestampCreatedTimeFilter.cs create mode 100644 Src/Notion.Client/Models/Filters/TimestampLastEditedTimeFilter.cs diff --git a/Src/Notion.Client/Models/Filters/TimestampCreatedTimeFilter.cs b/Src/Notion.Client/Models/Filters/TimestampCreatedTimeFilter.cs new file mode 100644 index 00000000..ac8f2244 --- /dev/null +++ b/Src/Notion.Client/Models/Filters/TimestampCreatedTimeFilter.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class TimestampCreatedTimeFilter : Filter + { + [JsonProperty("timestamp")] + public string Timestamp = "created_time"; + + [JsonProperty("created_time")] + public DateFilter.Condition CreatedTime { get; set; } + + public TimestampCreatedTimeFilter( + DateTime? equal = null, + DateTime? before = null, + DateTime? after = null, + DateTime? onOrBefore = null, + DateTime? onOrAfter = null, + Dictionary pastWeek = null, + Dictionary pastMonth = null, + Dictionary pastYear = null, + Dictionary nextWeek = null, + Dictionary nextMonth = null, + Dictionary nextYear = null, + bool? isEmpty = null, + bool? isNotEmpty = null) + { + CreatedTime = new DateFilter.Condition( + equal: equal, + before: before, + after: after, + onOrBefore: onOrBefore, + onOrAfter: onOrAfter, + pastWeek: pastWeek, + pastMonth: pastMonth, + pastYear: pastYear, + nextWeek: nextWeek, + nextMonth: nextMonth, + nextYear: nextYear, + isEmpty: isEmpty, + isNotEmpty: isNotEmpty + ); + } + } +} diff --git a/Src/Notion.Client/Models/Filters/TimestampLastEditedTimeFilter.cs b/Src/Notion.Client/Models/Filters/TimestampLastEditedTimeFilter.cs new file mode 100644 index 00000000..1d6acb7f --- /dev/null +++ b/Src/Notion.Client/Models/Filters/TimestampLastEditedTimeFilter.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class TimestampLastEditedTimeFilter : Filter + { + [JsonProperty("timestamp")] + public string Timestamp = "last_modified_time"; + + [JsonProperty("last_edited_time")] + public DateFilter.Condition LastEditedTime { get; set; } + + public TimestampLastEditedTimeFilter( + DateTime? equal = null, + DateTime? before = null, + DateTime? after = null, + DateTime? onOrBefore = null, + DateTime? onOrAfter = null, + Dictionary pastWeek = null, + Dictionary pastMonth = null, + Dictionary pastYear = null, + Dictionary nextWeek = null, + Dictionary nextMonth = null, + Dictionary nextYear = null, + bool? isEmpty = null, + bool? isNotEmpty = null) + { + LastEditedTime = new DateFilter.Condition( + equal: equal, + before: before, + after: after, + onOrBefore: onOrBefore, + onOrAfter: onOrAfter, + pastWeek: pastWeek, + pastMonth: pastMonth, + pastYear: pastYear, + nextWeek: nextWeek, + nextMonth: nextMonth, + nextYear: nextYear, + isEmpty: isEmpty, + isNotEmpty: isNotEmpty + ); + } + } +} From fd232641a3ca79f379f8ab221bca244c3a0e81a5 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 20 Aug 2022 12:52:27 +0530 Subject: [PATCH 057/216] Add support to create, update inline databases --- .../DatabasesCreateParameters/DatabasesCreateParameters.cs | 2 ++ .../IDatabasesCreateBodyParameters.cs | 3 +++ .../DatabasesUpdateParameters/DatabasesUpdateParameters.cs | 4 ++++ Src/Notion.Client/Models/Database/Database.cs | 3 +++ 4 files changed, 12 insertions(+) diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/DatabasesCreateParameters.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/DatabasesCreateParameters.cs index 79a984f9..81fe0d2f 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/DatabasesCreateParameters.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/DatabasesCreateParameters.cs @@ -19,5 +19,7 @@ public class DatabasesCreateParameters : IDatabasesCreateBodyParameters, IDataba [JsonProperty("cover")] public FileObject Cover { get; set; } + + public bool? IsInline { get; set; } } } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/IDatabasesCreateBodyParameters.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/IDatabasesCreateBodyParameters.cs index b0f97061..d069587b 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/IDatabasesCreateBodyParameters.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/IDatabasesCreateBodyParameters.cs @@ -13,5 +13,8 @@ public interface IDatabasesCreateBodyParameters [JsonProperty("title")] List Title { get; set; } + + [JsonProperty("is_inline")] + bool? IsInline { get; set; } } } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs index ff2e129e..a44f4f4b 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs @@ -16,6 +16,9 @@ public interface IDatabasesUpdateBodyParameters [JsonProperty("cover")] FileObject Cover { get; set; } + + [JsonProperty("is_inline")] + bool? IsInline { get; set; } } public class DatabasesUpdateParameters : IDatabasesUpdateBodyParameters @@ -24,5 +27,6 @@ public class DatabasesUpdateParameters : IDatabasesUpdateBodyParameters public List Title { get; set; } public IPageIcon Icon { get; set; } public FileObject Cover { get; set; } + public bool? IsInline { get; set; } } } diff --git a/Src/Notion.Client/Models/Database/Database.cs b/Src/Notion.Client/Models/Database/Database.cs index 6943048f..59722f72 100644 --- a/Src/Notion.Client/Models/Database/Database.cs +++ b/Src/Notion.Client/Models/Database/Database.cs @@ -36,5 +36,8 @@ public class Database : IObject /// [JsonProperty("url")] public string Url { get; set; } + + [JsonProperty("is_inline")] + public bool IsInline { get; set; } } } From 79287f6839e724f0a8345dea833c975af5138ded Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 20 Aug 2022 13:09:55 +0530 Subject: [PATCH 058/216] Add lgtm config --- lgtm.yaml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 lgtm.yaml diff --git a/lgtm.yaml b/lgtm.yaml new file mode 100644 index 00000000..c48771ea --- /dev/null +++ b/lgtm.yaml @@ -0,0 +1,5 @@ +extraction: + csharp: + index: + dotnet: + version: 6.0.400 From 0a1ba79a14b4febc6dc8b905a1f9d0568b5e134c Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 20 Aug 2022 13:34:36 +0530 Subject: [PATCH 059/216] Add support to create update description property --- .../DatabasesCreateParameters/DatabasesCreateParameters.cs | 2 ++ .../IDatabasesCreateBodyParameters.cs | 3 +++ .../DatabasesUpdateParameters/DatabasesUpdateParameters.cs | 4 ++++ Src/Notion.Client/Models/Database/Database.cs | 3 +++ 4 files changed, 12 insertions(+) diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/DatabasesCreateParameters.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/DatabasesCreateParameters.cs index 79a984f9..8f214d1e 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/DatabasesCreateParameters.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/DatabasesCreateParameters.cs @@ -19,5 +19,7 @@ public class DatabasesCreateParameters : IDatabasesCreateBodyParameters, IDataba [JsonProperty("cover")] public FileObject Cover { get; set; } + + public string Description { get; set; } } } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/IDatabasesCreateBodyParameters.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/IDatabasesCreateBodyParameters.cs index b0f97061..4825cd83 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/IDatabasesCreateBodyParameters.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/IDatabasesCreateBodyParameters.cs @@ -13,5 +13,8 @@ public interface IDatabasesCreateBodyParameters [JsonProperty("title")] List Title { get; set; } + + [JsonProperty("description")] + string Description { get; set; } } } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs index ff2e129e..900c2fe9 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs @@ -16,6 +16,9 @@ public interface IDatabasesUpdateBodyParameters [JsonProperty("cover")] FileObject Cover { get; set; } + + [JsonProperty("description")] + string Description { get; set; } } public class DatabasesUpdateParameters : IDatabasesUpdateBodyParameters @@ -24,5 +27,6 @@ public class DatabasesUpdateParameters : IDatabasesUpdateBodyParameters public List Title { get; set; } public IPageIcon Icon { get; set; } public FileObject Cover { get; set; } + public string Description { get; set; } } } diff --git a/Src/Notion.Client/Models/Database/Database.cs b/Src/Notion.Client/Models/Database/Database.cs index 6943048f..d1d5b7f9 100644 --- a/Src/Notion.Client/Models/Database/Database.cs +++ b/Src/Notion.Client/Models/Database/Database.cs @@ -36,5 +36,8 @@ public class Database : IObject /// [JsonProperty("url")] public string Url { get; set; } + + [JsonProperty("description")] + public string Description { get; set; } } } From 598316c2f7651c9ac84c168fb7e72a6ffceb4bcc Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 20 Aug 2022 13:58:11 +0530 Subject: [PATCH 060/216] Update lgtm to use extraction for whole solution --- lgtm.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/lgtm.yaml b/lgtm.yaml index c48771ea..5d5e1e4f 100644 --- a/lgtm.yaml +++ b/lgtm.yaml @@ -1,5 +1,6 @@ extraction: csharp: index: + all_solutions: true dotnet: version: 6.0.400 From 08c8ddb5e87a459b4f0d4c8271404c10be62d7ab Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 20 Aug 2022 14:21:54 +0530 Subject: [PATCH 061/216] Add support to read Status property value --- .../Models/PropertyValue/PropertyValue.cs | 1 + .../Models/PropertyValue/PropertyValueType.cs | 5 +- .../PropertyValue/StatusPropertyValue.cs | 72 +++++++++++++++++++ 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs diff --git a/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs index c85ebbdc..8437b4f8 100644 --- a/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs @@ -25,6 +25,7 @@ namespace Notion.Client [JsonSubtypes.KnownSubType(typeof(RichTextPropertyValue), PropertyValueType.RichText)] [JsonSubtypes.KnownSubType(typeof(RollupPropertyValue), PropertyValueType.Rollup)] [JsonSubtypes.KnownSubType(typeof(SelectPropertyValue), PropertyValueType.Select)] + [JsonSubtypes.KnownSubType(typeof(StatusPropertyValue), PropertyValueType.Status)] [JsonSubtypes.KnownSubType(typeof(TitlePropertyValue), PropertyValueType.Title)] [JsonSubtypes.KnownSubType(typeof(UrlPropertyValue), PropertyValueType.Url)] public class PropertyValue diff --git a/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs b/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs index 4a4b8189..fcbeae61 100644 --- a/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs +++ b/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs @@ -65,6 +65,9 @@ public enum PropertyValueType LastEditedTime, [EnumMember(Value = "last_edited_by")] - LastEditedBy + LastEditedBy, + + [EnumMember(Value = "status")] + Status, } } diff --git a/Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs new file mode 100644 index 00000000..f2027fef --- /dev/null +++ b/Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs @@ -0,0 +1,72 @@ +using System.Runtime.Serialization; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace Notion.Client +{ + /// + /// Status property value objects contain page status + /// + public class StatusPropertyValue : PropertyValue + { + public override PropertyValueType Type => PropertyValueType.Status; + + [JsonProperty("status")] + public Data Status { get; set; } + + public class Data + { + /// + /// ID of the option. + /// + [JsonProperty("id")] + public string Id { get; set; } + + /// + /// Name of the option as it appears in Notion. + /// + [JsonProperty("name")] + public string Name { get; set; } + + /// + /// Color of the option. + /// + [JsonProperty("color")] + [JsonConverter(typeof(StringEnumConverter))] + public Color Color { get; set; } + } + + public enum Color + { + [EnumMember(Value = "default")] + Default, + + [EnumMember(Value = "gray")] + Gray, + + [EnumMember(Value = "brown")] + Brown, + + [EnumMember(Value = "orange")] + Orange, + + [EnumMember(Value = "yellow")] + Yellow, + + [EnumMember(Value = "green")] + Green, + + [EnumMember(Value = "blue")] + Blue, + + [EnumMember(Value = "purple")] + Purple, + + [EnumMember(Value = "pink")] + Pink, + + [EnumMember(Value = "red")] + Red, + } + } +} From 3e1479322ce6292d04fab29bcd6d642a6731b114 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 20 Aug 2022 14:24:56 +0530 Subject: [PATCH 062/216] Add readonly Status property --- .../Models/Database/Properties/Property.cs | 1 + .../Models/Database/Properties/PropertyType.cs | 5 ++++- .../Models/Database/Properties/StatusProperty.cs | 13 +++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 Src/Notion.Client/Models/Database/Properties/StatusProperty.cs diff --git a/Src/Notion.Client/Models/Database/Properties/Property.cs b/Src/Notion.Client/Models/Database/Properties/Property.cs index 30ecd151..1f61b0dc 100644 --- a/Src/Notion.Client/Models/Database/Properties/Property.cs +++ b/Src/Notion.Client/Models/Database/Properties/Property.cs @@ -22,6 +22,7 @@ namespace Notion.Client [JsonSubtypes.KnownSubType(typeof(RichTextProperty), PropertyType.RichText)] [JsonSubtypes.KnownSubType(typeof(RollupProperty), PropertyType.Rollup)] [JsonSubtypes.KnownSubType(typeof(SelectProperty), PropertyType.Select)] + [JsonSubtypes.KnownSubType(typeof(StatusProperty), PropertyType.Status)] [JsonSubtypes.KnownSubType(typeof(TitleProperty), PropertyType.Title)] [JsonSubtypes.KnownSubType(typeof(UrlProperty), PropertyType.Url)] public class Property diff --git a/Src/Notion.Client/Models/Database/Properties/PropertyType.cs b/Src/Notion.Client/Models/Database/Properties/PropertyType.cs index bbc9eba7..a67b8cd8 100644 --- a/Src/Notion.Client/Models/Database/Properties/PropertyType.cs +++ b/Src/Notion.Client/Models/Database/Properties/PropertyType.cs @@ -62,6 +62,9 @@ public enum PropertyType LastEditedBy, [EnumMember(Value = "last_edited_time")] - LastEditedTime + LastEditedTime, + + [EnumMember(Value = "status")] + Status, } } diff --git a/Src/Notion.Client/Models/Database/Properties/StatusProperty.cs b/Src/Notion.Client/Models/Database/Properties/StatusProperty.cs new file mode 100644 index 00000000..92ec46fd --- /dev/null +++ b/Src/Notion.Client/Models/Database/Properties/StatusProperty.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class StatusProperty : Property + { + public override PropertyType Type => PropertyType.Status; + + [JsonProperty("status")] + public Dictionary Status { get; set; } + } +} From facdbdef74fe4f59221c2e1e8c00f7894d9480eb Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 20 Aug 2022 11:55:06 +0530 Subject: [PATCH 063/216] Add IObjectModification interface --- Src/Notion.Client/Models/Blocks/Block.cs | 8 +++++--- Src/Notion.Client/Models/Blocks/IBlock.cs | 8 +------- .../Models/Common/IObjectModificationData.cs | 20 +++++++++++++++++++ Src/Notion.Client/Models/Database/Database.cs | 2 +- Src/Notion.Client/Models/Page/Page.cs | 2 +- 5 files changed, 28 insertions(+), 12 deletions(-) create mode 100644 Src/Notion.Client/Models/Common/IObjectModificationData.cs diff --git a/Src/Notion.Client/Models/Blocks/Block.cs b/Src/Notion.Client/Models/Blocks/Block.cs index 9ba90612..c9f501d0 100644 --- a/Src/Notion.Client/Models/Blocks/Block.cs +++ b/Src/Notion.Client/Models/Blocks/Block.cs @@ -1,4 +1,6 @@ -namespace Notion.Client +using System; + +namespace Notion.Client { public abstract class Block : IBlock { @@ -8,9 +10,9 @@ public abstract class Block : IBlock public virtual BlockType Type { get; set; } - public string CreatedTime { get; set; } + public DateTime CreatedTime { get; set; } - public string LastEditedTime { get; set; } + public DateTime LastEditedTime { get; set; } public virtual bool HasChildren { get; set; } } diff --git a/Src/Notion.Client/Models/Blocks/IBlock.cs b/Src/Notion.Client/Models/Blocks/IBlock.cs index f3c89d88..c8cee542 100644 --- a/Src/Notion.Client/Models/Blocks/IBlock.cs +++ b/Src/Notion.Client/Models/Blocks/IBlock.cs @@ -36,18 +36,12 @@ namespace Notion.Client [JsonSubtypes.KnownSubType(typeof(ToggleBlock), BlockType.Toggle)] [JsonSubtypes.KnownSubType(typeof(VideoBlock), BlockType.Video)] [JsonSubtypes.KnownSubType(typeof(UnsupportedBlock), BlockType.Unsupported)] - public interface IBlock : IObject + public interface IBlock : IObject, IObjectModificationData { [JsonProperty("type")] [JsonConverter(typeof(StringEnumConverter))] BlockType Type { get; set; } - [JsonProperty("created_time")] - string CreatedTime { get; set; } - - [JsonProperty("last_edited_time")] - string LastEditedTime { get; set; } - [JsonProperty("has_children")] bool HasChildren { get; set; } } diff --git a/Src/Notion.Client/Models/Common/IObjectModificationData.cs b/Src/Notion.Client/Models/Common/IObjectModificationData.cs new file mode 100644 index 00000000..2d7c3d3e --- /dev/null +++ b/Src/Notion.Client/Models/Common/IObjectModificationData.cs @@ -0,0 +1,20 @@ +using System; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public interface IObjectModificationData + { + /// + /// Date and time when this object was created. + /// + [JsonProperty("created_time")] + DateTime CreatedTime { get; set; } + + /// + /// Date and time when this object was updated. + /// + [JsonProperty("last_edited_time")] + DateTime LastEditedTime { get; set; } + } +} diff --git a/Src/Notion.Client/Models/Database/Database.cs b/Src/Notion.Client/Models/Database/Database.cs index 6943048f..bfb0db5e 100644 --- a/Src/Notion.Client/Models/Database/Database.cs +++ b/Src/Notion.Client/Models/Database/Database.cs @@ -4,7 +4,7 @@ namespace Notion.Client { - public class Database : IObject + public class Database : IObject, IObjectModificationData { public ObjectType Object => ObjectType.Database; diff --git a/Src/Notion.Client/Models/Page/Page.cs b/Src/Notion.Client/Models/Page/Page.cs index 352f9d13..f1fc404c 100644 --- a/Src/Notion.Client/Models/Page/Page.cs +++ b/Src/Notion.Client/Models/Page/Page.cs @@ -4,7 +4,7 @@ namespace Notion.Client { - public class Page : IObject + public class Page : IObject, IObjectModificationData { /// /// Object type From 0940133f3ca8f92569d83b493a7db95eb01afa9c Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 20 Aug 2022 11:55:51 +0530 Subject: [PATCH 064/216] Run linter --- Src/Notion.Client/Notion.Client.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Src/Notion.Client/Notion.Client.csproj b/Src/Notion.Client/Notion.Client.csproj index e6b066ab..b33398f8 100644 --- a/Src/Notion.Client/Notion.Client.csproj +++ b/Src/Notion.Client/Notion.Client.csproj @@ -22,8 +22,8 @@ - - + + From 984d27935bae5df05fb08408e15cfa4795e1a55d Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 20 Aug 2022 12:08:26 +0530 Subject: [PATCH 065/216] Add created by and last edited by properties --- Src/Notion.Client/Models/Blocks/Block.cs | 4 ++++ .../Models/Common/IObjectModificationData.cs | 12 ++++++++++++ Src/Notion.Client/Models/Database/Database.cs | 4 ++++ Src/Notion.Client/Models/Page/Page.cs | 4 ++++ Src/Notion.Client/Models/User/PartialUser.cs | 9 +++++++++ 5 files changed, 33 insertions(+) create mode 100644 Src/Notion.Client/Models/User/PartialUser.cs diff --git a/Src/Notion.Client/Models/Blocks/Block.cs b/Src/Notion.Client/Models/Blocks/Block.cs index c9f501d0..e4a3eaeb 100644 --- a/Src/Notion.Client/Models/Blocks/Block.cs +++ b/Src/Notion.Client/Models/Blocks/Block.cs @@ -15,5 +15,9 @@ public abstract class Block : IBlock public DateTime LastEditedTime { get; set; } public virtual bool HasChildren { get; set; } + + public PartialUser CreatedBy { get; set; } + + public PartialUser LastEditedBy { get; set; } } } diff --git a/Src/Notion.Client/Models/Common/IObjectModificationData.cs b/Src/Notion.Client/Models/Common/IObjectModificationData.cs index 2d7c3d3e..06177ccd 100644 --- a/Src/Notion.Client/Models/Common/IObjectModificationData.cs +++ b/Src/Notion.Client/Models/Common/IObjectModificationData.cs @@ -16,5 +16,17 @@ public interface IObjectModificationData /// [JsonProperty("last_edited_time")] DateTime LastEditedTime { get; set; } + + /// + /// User who created the object. + /// + [JsonProperty("created_by")] + PartialUser CreatedBy { get; set; } + + /// + /// User who last modified the object. + /// + [JsonProperty("last_edited_by")] + PartialUser LastEditedBy { get; set; } } } diff --git a/Src/Notion.Client/Models/Database/Database.cs b/Src/Notion.Client/Models/Database/Database.cs index bfb0db5e..577dc581 100644 --- a/Src/Notion.Client/Models/Database/Database.cs +++ b/Src/Notion.Client/Models/Database/Database.cs @@ -36,5 +36,9 @@ public class Database : IObject, IObjectModificationData /// [JsonProperty("url")] public string Url { get; set; } + + public PartialUser CreatedBy { get; set; } + + public PartialUser LastEditedBy { get; set; } } } diff --git a/Src/Notion.Client/Models/Page/Page.cs b/Src/Notion.Client/Models/Page/Page.cs index f1fc404c..d96fef8a 100644 --- a/Src/Notion.Client/Models/Page/Page.cs +++ b/Src/Notion.Client/Models/Page/Page.cs @@ -63,5 +63,9 @@ public class Page : IObject, IObjectModificationData /// [JsonProperty("cover")] public FileObject Cover { get; set; } + + public PartialUser CreatedBy { get; set; } + + public PartialUser LastEditedBy { get; set; } } } diff --git a/Src/Notion.Client/Models/User/PartialUser.cs b/Src/Notion.Client/Models/User/PartialUser.cs new file mode 100644 index 00000000..5b335f0b --- /dev/null +++ b/Src/Notion.Client/Models/User/PartialUser.cs @@ -0,0 +1,9 @@ +namespace Notion.Client +{ + public class PartialUser : IObject + { + public string Id { get; set; } + + public ObjectType Object => ObjectType.User; + } +} From 98e5482ec0253260bb9c41f6858b34d9add83c2a Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 20 Aug 2022 14:36:35 +0530 Subject: [PATCH 066/216] Add lgtm.yaml to lgtm.yml --- lgtm.yaml => lgtm.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename lgtm.yaml => lgtm.yml (100%) diff --git a/lgtm.yaml b/lgtm.yml similarity index 100% rename from lgtm.yaml rename to lgtm.yml From b4c2882b5938069ece33662b05a0bdac0fb472dc Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 20 Aug 2022 12:40:42 +0530 Subject: [PATCH 067/216] Add timestamp filters --- .../Filters/TimestampCreatedTimeFilter.cs | 47 +++++++++++++++++++ .../Filters/TimestampLastEditedTimeFilter.cs | 47 +++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 Src/Notion.Client/Models/Filters/TimestampCreatedTimeFilter.cs create mode 100644 Src/Notion.Client/Models/Filters/TimestampLastEditedTimeFilter.cs diff --git a/Src/Notion.Client/Models/Filters/TimestampCreatedTimeFilter.cs b/Src/Notion.Client/Models/Filters/TimestampCreatedTimeFilter.cs new file mode 100644 index 00000000..ac8f2244 --- /dev/null +++ b/Src/Notion.Client/Models/Filters/TimestampCreatedTimeFilter.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class TimestampCreatedTimeFilter : Filter + { + [JsonProperty("timestamp")] + public string Timestamp = "created_time"; + + [JsonProperty("created_time")] + public DateFilter.Condition CreatedTime { get; set; } + + public TimestampCreatedTimeFilter( + DateTime? equal = null, + DateTime? before = null, + DateTime? after = null, + DateTime? onOrBefore = null, + DateTime? onOrAfter = null, + Dictionary pastWeek = null, + Dictionary pastMonth = null, + Dictionary pastYear = null, + Dictionary nextWeek = null, + Dictionary nextMonth = null, + Dictionary nextYear = null, + bool? isEmpty = null, + bool? isNotEmpty = null) + { + CreatedTime = new DateFilter.Condition( + equal: equal, + before: before, + after: after, + onOrBefore: onOrBefore, + onOrAfter: onOrAfter, + pastWeek: pastWeek, + pastMonth: pastMonth, + pastYear: pastYear, + nextWeek: nextWeek, + nextMonth: nextMonth, + nextYear: nextYear, + isEmpty: isEmpty, + isNotEmpty: isNotEmpty + ); + } + } +} diff --git a/Src/Notion.Client/Models/Filters/TimestampLastEditedTimeFilter.cs b/Src/Notion.Client/Models/Filters/TimestampLastEditedTimeFilter.cs new file mode 100644 index 00000000..1d6acb7f --- /dev/null +++ b/Src/Notion.Client/Models/Filters/TimestampLastEditedTimeFilter.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class TimestampLastEditedTimeFilter : Filter + { + [JsonProperty("timestamp")] + public string Timestamp = "last_modified_time"; + + [JsonProperty("last_edited_time")] + public DateFilter.Condition LastEditedTime { get; set; } + + public TimestampLastEditedTimeFilter( + DateTime? equal = null, + DateTime? before = null, + DateTime? after = null, + DateTime? onOrBefore = null, + DateTime? onOrAfter = null, + Dictionary pastWeek = null, + Dictionary pastMonth = null, + Dictionary pastYear = null, + Dictionary nextWeek = null, + Dictionary nextMonth = null, + Dictionary nextYear = null, + bool? isEmpty = null, + bool? isNotEmpty = null) + { + LastEditedTime = new DateFilter.Condition( + equal: equal, + before: before, + after: after, + onOrBefore: onOrBefore, + onOrAfter: onOrAfter, + pastWeek: pastWeek, + pastMonth: pastMonth, + pastYear: pastYear, + nextWeek: nextWeek, + nextMonth: nextMonth, + nextYear: nextYear, + isEmpty: isEmpty, + isNotEmpty: isNotEmpty + ); + } + } +} From ae577a636d81e7d5c929fd4dc4aebd39d0cdfefd Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 20 Aug 2022 15:38:31 +0530 Subject: [PATCH 068/216] Fix merge issues --- .../DatabasesUpdateParameters.cs | 19 +------------------ .../IDatabasesUpdateBodyParameters.cs | 3 +++ 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs index 628db2f3..42fc7c06 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs @@ -1,25 +1,8 @@ using System.Collections.Generic; +using Newtonsoft.Json; namespace Notion.Client { - public interface IDatabasesUpdateBodyParameters - { - [JsonProperty("properties")] - Dictionary Properties { get; set; } - - [JsonProperty("title")] - List Title { get; set; } - - [JsonProperty("icon")] - IPageIcon Icon { get; set; } - - [JsonProperty("cover")] - FileObject Cover { get; set; } - - [JsonProperty("is_inline")] - bool? IsInline { get; set; } - } - public class DatabasesUpdateParameters : IDatabasesUpdateBodyParameters { public Dictionary Properties { get; set; } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/IDatabasesUpdateBodyParameters.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/IDatabasesUpdateBodyParameters.cs index cf2f989c..7f9d3093 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/IDatabasesUpdateBodyParameters.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/IDatabasesUpdateBodyParameters.cs @@ -19,5 +19,8 @@ public interface IDatabasesUpdateBodyParameters [JsonProperty("archived")] bool Archived { get; set; } + + [JsonProperty("is_inline")] + bool? IsInline { get; set; } } } From 424fc85db6624451d14148a1cc425ffdf046b56d Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 20 Aug 2022 15:40:10 +0530 Subject: [PATCH 069/216] Fix merge conflicts --- .../DatabasesUpdateParameters.cs | 18 ------------------ .../IDatabasesUpdateBodyParameters.cs | 3 +++ 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs index dcf4032d..47b7ec01 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs @@ -2,24 +2,6 @@ namespace Notion.Client { - public interface IDatabasesUpdateBodyParameters - { - [JsonProperty("properties")] - Dictionary Properties { get; set; } - - [JsonProperty("title")] - List Title { get; set; } - - [JsonProperty("icon")] - IPageIcon Icon { get; set; } - - [JsonProperty("cover")] - FileObject Cover { get; set; } - - [JsonProperty("description")] - string Description { get; set; } - } - public class DatabasesUpdateParameters : IDatabasesUpdateBodyParameters { public Dictionary Properties { get; set; } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/IDatabasesUpdateBodyParameters.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/IDatabasesUpdateBodyParameters.cs index cf2f989c..00a7cbc9 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/IDatabasesUpdateBodyParameters.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/IDatabasesUpdateBodyParameters.cs @@ -19,5 +19,8 @@ public interface IDatabasesUpdateBodyParameters [JsonProperty("archived")] bool Archived { get; set; } + + [JsonProperty("description")] + string Description { get; set; } } } From 8974d175d5e169cf3933236165cc8bae60a03ede Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 20 Aug 2022 23:55:32 +0530 Subject: [PATCH 070/216] Fix issue when parsing description property --- .../DatabasesCreateParameters/DatabasesCreateParameters.cs | 2 +- .../DatabasesCreateParameters/IDatabasesCreateBodyParameters.cs | 2 +- .../DatabasesUpdateParameters/DatabasesUpdateParameters.cs | 2 +- .../DatabasesUpdateParameters/IDatabasesUpdateBodyParameters.cs | 2 +- Src/Notion.Client/Models/Database/Database.cs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/DatabasesCreateParameters.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/DatabasesCreateParameters.cs index 94d5ecc4..bafad0ec 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/DatabasesCreateParameters.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/DatabasesCreateParameters.cs @@ -22,6 +22,6 @@ public class DatabasesCreateParameters : IDatabasesCreateBodyParameters, IDataba public bool? IsInline { get; set; } - public string Description { get; set; } + public List Description { get; set; } } } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/IDatabasesCreateBodyParameters.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/IDatabasesCreateBodyParameters.cs index a15a8ee1..7eb252f2 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/IDatabasesCreateBodyParameters.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/IDatabasesCreateBodyParameters.cs @@ -18,6 +18,6 @@ public interface IDatabasesCreateBodyParameters bool? IsInline { get; set; } [JsonProperty("description")] - string Description { get; set; } + List Description { get; set; } } } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs index 65e9cafe..b9cb182e 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs @@ -17,6 +17,6 @@ public class DatabasesUpdateParameters : IDatabasesUpdateBodyParameters public bool? IsInline { get; set; } - public string Description { get; set; } + public List Description { get; set; } } } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/IDatabasesUpdateBodyParameters.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/IDatabasesUpdateBodyParameters.cs index 90e1d7ed..b1dc419a 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/IDatabasesUpdateBodyParameters.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/IDatabasesUpdateBodyParameters.cs @@ -24,6 +24,6 @@ public interface IDatabasesUpdateBodyParameters bool? IsInline { get; set; } [JsonProperty("description")] - string Description { get; set; } + List Description { get; set; } } } diff --git a/Src/Notion.Client/Models/Database/Database.cs b/Src/Notion.Client/Models/Database/Database.cs index 40371281..502d8a5a 100644 --- a/Src/Notion.Client/Models/Database/Database.cs +++ b/Src/Notion.Client/Models/Database/Database.cs @@ -51,6 +51,6 @@ public class Database : IObject, IObjectModificationData public bool IsInline { get; set; } [JsonProperty("description")] - public string Description { get; set; } + public IEnumerable Description { get; set; } } } From c76c1c4b9677c2abb14dd8203f83e4441d6c25d2 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sun, 21 Aug 2022 00:16:48 +0530 Subject: [PATCH 071/216] Make Color enum property nullable --- .../PropertySchema/SelectOptionSchema.cs | 2 +- Src/Notion.Client/Models/Blocks/BulletedListItemBlock.cs | 2 +- Src/Notion.Client/Models/Blocks/CalloutBlock.cs | 2 +- Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs | 2 +- Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs | 2 +- Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs | 2 +- Src/Notion.Client/Models/Blocks/NumberedListItemBlock.cs | 2 +- Src/Notion.Client/Models/Blocks/ParagraphBlock.cs | 2 +- Src/Notion.Client/Models/Blocks/QuoteBlock.cs | 2 +- Src/Notion.Client/Models/Blocks/TableOfContentsBlock.cs | 2 +- Src/Notion.Client/Models/Blocks/ToDoBlock.cs | 2 +- Src/Notion.Client/Models/Blocks/ToggleBlock.cs | 2 +- Src/Notion.Client/Models/Database/Properties/SelectProperty.cs | 2 +- Src/Notion.Client/Models/Database/RichText/RichTextBase.cs | 2 +- Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs | 2 +- 15 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/SelectOptionSchema.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/SelectOptionSchema.cs index c31aef9f..b7fd8d82 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/SelectOptionSchema.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/SelectOptionSchema.cs @@ -10,6 +10,6 @@ public class SelectOptionSchema [JsonProperty("color")] [JsonConverter(typeof(StringEnumConverter))] - public Color Color { get; set; } + public Color? Color { get; set; } } } diff --git a/Src/Notion.Client/Models/Blocks/BulletedListItemBlock.cs b/Src/Notion.Client/Models/Blocks/BulletedListItemBlock.cs index e6711de5..7eca3397 100644 --- a/Src/Notion.Client/Models/Blocks/BulletedListItemBlock.cs +++ b/Src/Notion.Client/Models/Blocks/BulletedListItemBlock.cs @@ -18,7 +18,7 @@ public class Info [JsonProperty("color")] [JsonConverter(typeof(StringEnumConverter))] - public Color Color { get; set; } + public Color? Color { get; set; } [JsonProperty("children")] public IEnumerable Children { get; set; } diff --git a/Src/Notion.Client/Models/Blocks/CalloutBlock.cs b/Src/Notion.Client/Models/Blocks/CalloutBlock.cs index d694e33c..8cc4bb7a 100644 --- a/Src/Notion.Client/Models/Blocks/CalloutBlock.cs +++ b/Src/Notion.Client/Models/Blocks/CalloutBlock.cs @@ -21,7 +21,7 @@ public class Info [JsonProperty("color")] [JsonConverter(typeof(StringEnumConverter))] - public Color Color { get; set; } + public Color? Color { get; set; } [JsonProperty("children")] public IEnumerable Children { get; set; } diff --git a/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs b/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs index ccf29220..853f9ae5 100644 --- a/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs +++ b/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs @@ -20,7 +20,7 @@ public class Info [JsonProperty("color")] [JsonConverter(typeof(StringEnumConverter))] - public Color Color { get; set; } + public Color? Color { get; set; } } } } diff --git a/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs b/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs index 73897da0..99d9b861 100644 --- a/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs +++ b/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs @@ -20,7 +20,7 @@ public class Info [JsonProperty("color")] [JsonConverter(typeof(StringEnumConverter))] - public Color Color { get; set; } + public Color? Color { get; set; } } } } diff --git a/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs b/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs index 7b4e161e..ea074e8a 100644 --- a/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs +++ b/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs @@ -20,7 +20,7 @@ public class Info [JsonProperty("color")] [JsonConverter(typeof(StringEnumConverter))] - public Color Color { get; set; } + public Color? Color { get; set; } } } } diff --git a/Src/Notion.Client/Models/Blocks/NumberedListItemBlock.cs b/Src/Notion.Client/Models/Blocks/NumberedListItemBlock.cs index 189eedf1..3fe0d76a 100644 --- a/Src/Notion.Client/Models/Blocks/NumberedListItemBlock.cs +++ b/Src/Notion.Client/Models/Blocks/NumberedListItemBlock.cs @@ -18,7 +18,7 @@ public class Info [JsonProperty("color")] [JsonConverter(typeof(StringEnumConverter))] - public Color Color { get; set; } + public Color? Color { get; set; } [JsonProperty("children")] public IEnumerable Children { get; set; } diff --git a/Src/Notion.Client/Models/Blocks/ParagraphBlock.cs b/Src/Notion.Client/Models/Blocks/ParagraphBlock.cs index f45e8628..67458b3c 100644 --- a/Src/Notion.Client/Models/Blocks/ParagraphBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ParagraphBlock.cs @@ -18,7 +18,7 @@ public class Info [JsonProperty("color")] [JsonConverter(typeof(StringEnumConverter))] - public Color Color { get; set; } + public Color? Color { get; set; } [JsonProperty("children")] public IEnumerable Children { get; set; } diff --git a/Src/Notion.Client/Models/Blocks/QuoteBlock.cs b/Src/Notion.Client/Models/Blocks/QuoteBlock.cs index 68479075..5fdad7da 100644 --- a/Src/Notion.Client/Models/Blocks/QuoteBlock.cs +++ b/Src/Notion.Client/Models/Blocks/QuoteBlock.cs @@ -18,7 +18,7 @@ public class Info [JsonProperty("color")] [JsonConverter(typeof(StringEnumConverter))] - public Color Color { get; set; } + public Color? Color { get; set; } [JsonProperty("children")] public IEnumerable Children { get; set; } diff --git a/Src/Notion.Client/Models/Blocks/TableOfContentsBlock.cs b/Src/Notion.Client/Models/Blocks/TableOfContentsBlock.cs index 29305ca9..991ff903 100644 --- a/Src/Notion.Client/Models/Blocks/TableOfContentsBlock.cs +++ b/Src/Notion.Client/Models/Blocks/TableOfContentsBlock.cs @@ -14,7 +14,7 @@ public class Data { [JsonProperty("color")] [JsonConverter(typeof(StringEnumConverter))] - public Color Color { get; set; } + public Color? Color { get; set; } } } } diff --git a/Src/Notion.Client/Models/Blocks/ToDoBlock.cs b/Src/Notion.Client/Models/Blocks/ToDoBlock.cs index d2fcc75e..8b153f3b 100644 --- a/Src/Notion.Client/Models/Blocks/ToDoBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ToDoBlock.cs @@ -21,7 +21,7 @@ public class Info [JsonProperty("color")] [JsonConverter(typeof(StringEnumConverter))] - public Color Color { get; set; } + public Color? Color { get; set; } [JsonProperty("children")] public IEnumerable Children { get; set; } diff --git a/Src/Notion.Client/Models/Blocks/ToggleBlock.cs b/Src/Notion.Client/Models/Blocks/ToggleBlock.cs index 1367f40b..6646e9be 100644 --- a/Src/Notion.Client/Models/Blocks/ToggleBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ToggleBlock.cs @@ -18,7 +18,7 @@ public class Info [JsonProperty("color")] [JsonConverter(typeof(StringEnumConverter))] - public Color Color { get; set; } + public Color? Color { get; set; } [JsonProperty("children")] public IEnumerable Children { get; set; } diff --git a/Src/Notion.Client/Models/Database/Properties/SelectProperty.cs b/Src/Notion.Client/Models/Database/Properties/SelectProperty.cs index dd1dfeb1..3ed99234 100644 --- a/Src/Notion.Client/Models/Database/Properties/SelectProperty.cs +++ b/Src/Notion.Client/Models/Database/Properties/SelectProperty.cs @@ -35,7 +35,7 @@ public class SelectOption /// [JsonProperty("color")] [JsonConverter(typeof(StringEnumConverter))] - public Color Color { get; set; } + public Color? Color { get; set; } } public class MultiSelectProperty : Property diff --git a/Src/Notion.Client/Models/Database/RichText/RichTextBase.cs b/Src/Notion.Client/Models/Database/RichText/RichTextBase.cs index 0b509325..88af1acd 100644 --- a/Src/Notion.Client/Models/Database/RichText/RichTextBase.cs +++ b/Src/Notion.Client/Models/Database/RichText/RichTextBase.cs @@ -43,6 +43,6 @@ public class Annotations [JsonProperty("color")] [JsonConverter(typeof(StringEnumConverter))] - public Color Color { get; set; } + public Color? Color { get; set; } } } diff --git a/Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs index f2027fef..497e4c18 100644 --- a/Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs @@ -33,7 +33,7 @@ public class Data /// [JsonProperty("color")] [JsonConverter(typeof(StringEnumConverter))] - public Color Color { get; set; } + public Color? Color { get; set; } } public enum Color From a7eef157a91a015591276da01e18c45d18b6992a Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sun, 21 Aug 2022 00:17:43 +0530 Subject: [PATCH 072/216] Fix broken integration tests --- Test/Notion.IntegrationTests/IPageClientTests.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Test/Notion.IntegrationTests/IPageClientTests.cs b/Test/Notion.IntegrationTests/IPageClientTests.cs index a2c73162..c1d78635 100644 --- a/Test/Notion.IntegrationTests/IPageClientTests.cs +++ b/Test/Notion.IntegrationTests/IPageClientTests.cs @@ -142,7 +142,7 @@ public async Task Test_RetrievePagePropertyItemAsync() var listProperty = (ListPropertyItem)property; - listProperty.Type.Should().BeNull(); + listProperty.Type.Should().NotBeNull(); listProperty.Results.Should().SatisfyRespectively(p => { p.Should().BeOfType(); @@ -202,7 +202,11 @@ public async Task Test_UpdatePageProperty_with_date_as_null() var page = await _client.Pages.CreateAsync(pagesCreateParameters); - var setDate = page.Properties[datePropertyName] as DatePropertyValue; + var setDate = (DatePropertyItem)await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters + { + PageId = page.Id, + PropertyId = page.Properties[datePropertyName].Id + }); setDate?.Date?.Start.Should().Be(Convert.ToDateTime("2020-12-08T12:00:00Z")); @@ -215,7 +219,11 @@ public async Task Test_UpdatePageProperty_with_date_as_null() Properties = testProps }); - var verifyDate = updatedPage.Properties[datePropertyName] as DatePropertyValue; + var verifyDate = (DatePropertyItem)await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters + { + PageId = page.Id, + PropertyId = updatedPage.Properties[datePropertyName].Id + }); verifyDate?.Date.Should().BeNull(); From b5cdc1e69ed47ef6a61eff28771990435a6ab37a Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 20 Aug 2022 16:33:21 +0530 Subject: [PATCH 073/216] update readme --- README.md | 12 ++++++------ docs/README.md | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index c3cf6c95..10893f28 100644 --- a/README.md +++ b/README.md @@ -41,12 +41,12 @@ Provides the following packages: dotnet add package Notion.Net ``` -> Note: default Notion-Version used by NuGet package versions -> | Package version | Notion-Version | -> | --- | --- | -> | 3.0.0+ | 2022-02-22 | -> | 2.0.0+ | 2021-08-16 | -> | 1.0.0+ | 2021-05-13 | +**Note:** default Notion-Version used by NuGet package versions +| Package version | Notion-Version | +| --- | --- | +| 3.0.0+ | 2022-02-22 | +| 2.0.0+ | 2021-08-16 | +| 1.0.0+ | 2021-05-13 | ## Usage diff --git a/docs/README.md b/docs/README.md index a662d6f3..d8d29422 100644 --- a/docs/README.md +++ b/docs/README.md @@ -10,12 +10,12 @@ A simple and easy to use client for the [Notion API](https://developers.notion.c dotnet add package Notion.Net ``` -> Note: default Notion-Version used by NuGet package versions -> | Package version | Notion-Version | -> | --- | --- | -> | 3.0.0+ | 2022-02-22 | -> | 2.0.0+ | 2021-08-16 | -> | 1.0.0+ | 2021-05-13 | +**Note:** default Notion-Version used by NuGet package versions +| Package version | Notion-Version | +| --- | --- | +| 3.0.0+ | 2022-02-22 | +| 2.0.0+ | 2021-08-16 | +| 1.0.0+ | 2021-05-13 | ## Usage From 75cbf61e72aca8817a5847571e4530b3e88b575c Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 20 Aug 2022 17:59:28 +0530 Subject: [PATCH 074/216] update page properties to only return property id --- Src/Notion.Client/Models/Page/Page.cs | 2 +- .../Models/Page/PagePropertyOnId.cs | 10 +++++++ Test/Notion.UnitTests/DatabasesClientTests.cs | 11 ++++++-- Test/Notion.UnitTests/PagesClientTests.cs | 27 ++++++++++++++++--- 4 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 Src/Notion.Client/Models/Page/PagePropertyOnId.cs diff --git a/Src/Notion.Client/Models/Page/Page.cs b/Src/Notion.Client/Models/Page/Page.cs index d96fef8a..a429d92d 100644 --- a/Src/Notion.Client/Models/Page/Page.cs +++ b/Src/Notion.Client/Models/Page/Page.cs @@ -44,7 +44,7 @@ public class Page : IObject, IObjectModificationData /// Property values of this page. /// [JsonProperty("properties")] - public IDictionary Properties { get; set; } + public IDictionary Properties { get; set; } /// /// The URL of the Notion page. diff --git a/Src/Notion.Client/Models/Page/PagePropertyOnId.cs b/Src/Notion.Client/Models/Page/PagePropertyOnId.cs new file mode 100644 index 00000000..00005986 --- /dev/null +++ b/Src/Notion.Client/Models/Page/PagePropertyOnId.cs @@ -0,0 +1,10 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class PagePropertyOnId + { + [JsonProperty("id")] + public string Id { get; set; } + } +} diff --git a/Test/Notion.UnitTests/DatabasesClientTests.cs b/Test/Notion.UnitTests/DatabasesClientTests.cs index a3254131..c857d61c 100644 --- a/Test/Notion.UnitTests/DatabasesClientTests.cs +++ b/Test/Notion.UnitTests/DatabasesClientTests.cs @@ -12,10 +12,11 @@ namespace Notion.UnitTests public class DatabasesClientTests : ApiTestBase { private readonly IDatabasesClient _client; - + private readonly IPagesClient _pagesClient; public DatabasesClientTests() { _client = new DatabasesClient(new RestClient(ClientOptions)); + _pagesClient = new PagesClient(new RestClient(ClientOptions)); } [Fact] @@ -463,7 +464,13 @@ public async Task Fix123_QueryAsync_DateFormulaValue_Returns_Null() page.Parent.Should().BeAssignableTo(); page.Object.Should().Be(ObjectType.Page); - var formulaPropertyValue = (FormulaPropertyValue)page.Properties["FormulaProp"]; + var formulaPropertyValue = (FormulaPropertyValue)await _pagesClient.RetrievePagePropertyItem(new RetrievePropertyItemParameters + { + PageId = page.Id, + PropertyId = page.Properties["FormulaProp"].Id + }); + + //var formulaPropertyValue = (FormulaPropertyValue)page.Properties["FormulaProp"]; formulaPropertyValue.Formula.Date.Start.Should().Be(DateTime.Parse("2021-06-28")); formulaPropertyValue.Formula.Date.End.Should().BeNull(); } diff --git a/Test/Notion.UnitTests/PagesClientTests.cs b/Test/Notion.UnitTests/PagesClientTests.cs index e80240d3..f2f0584b 100644 --- a/Test/Notion.UnitTests/PagesClientTests.cs +++ b/Test/Notion.UnitTests/PagesClientTests.cs @@ -109,7 +109,14 @@ public async Task UpdatePropertiesAsync() page.Id.Should().Be(pageId); page.Properties.Should().HaveCount(2); var updatedProperty = page.Properties.First(x => x.Key == "In stock"); - ((CheckboxPropertyValue)updatedProperty.Value).Checkbox.Should().BeTrue(); + + var checkboxPropertyValue = (CheckboxPropertyValue)await _client.RetrievePagePropertyItem(new RetrievePropertyItemParameters + { + PageId = page.Id, + PropertyId = updatedProperty.Value.Id + }); + + checkboxPropertyValue.Checkbox.Should().BeTrue(); } [Fact] @@ -160,7 +167,14 @@ public async Task UpdatePageAsync() page.IsArchived.Should().BeFalse(); page.Properties.Should().HaveCount(2); var updatedProperty = page.Properties.First(x => x.Key == "In stock"); - ((CheckboxPropertyValue)updatedProperty.Value).Checkbox.Should().BeTrue(); + + var checkboxPropertyValue = (CheckboxPropertyValue)await _client.RetrievePagePropertyItem(new RetrievePropertyItemParameters + { + PageId = page.Id, + PropertyId = updatedProperty.Value.Id + }); + + checkboxPropertyValue.Checkbox.Should().BeTrue(); } [Fact] @@ -193,7 +207,14 @@ public async Task ArchivePageAsync() page.IsArchived.Should().BeTrue(); page.Properties.Should().HaveCount(2); var updatedProperty = page.Properties.First(x => x.Key == "In stock"); - ((CheckboxPropertyValue)updatedProperty.Value).Checkbox.Should().BeTrue(); + + var checkboxPropertyValue = (CheckboxPropertyValue)await _client.RetrievePagePropertyItem(new RetrievePropertyItemParameters + { + PageId = page.Id, + PropertyId = updatedProperty.Value.Id + }); + + checkboxPropertyValue.Checkbox.Should().BeTrue(); } [Fact] From d9b152a74bd040cf87f34e5014c7b384ce596e04 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 20 Aug 2022 19:10:02 +0530 Subject: [PATCH 075/216] Fix broken test cases --- Test/Notion.UnitTests/DatabasesClientTests.cs | 9 +++++++- Test/Notion.UnitTests/PagesClientTests.cs | 22 ++++++++++++++++--- ...ncDateFormulaValueReturnsNullResponse.json | 2 +- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/Test/Notion.UnitTests/DatabasesClientTests.cs b/Test/Notion.UnitTests/DatabasesClientTests.cs index c857d61c..8e3689e8 100644 --- a/Test/Notion.UnitTests/DatabasesClientTests.cs +++ b/Test/Notion.UnitTests/DatabasesClientTests.cs @@ -464,7 +464,14 @@ public async Task Fix123_QueryAsync_DateFormulaValue_Returns_Null() page.Parent.Should().BeAssignableTo(); page.Object.Should().Be(ObjectType.Page); - var formulaPropertyValue = (FormulaPropertyValue)await _pagesClient.RetrievePagePropertyItem(new RetrievePropertyItemParameters + Server.Given(CreateGetRequestBuilder(ApiEndpoints.PagesApiUrls.RetrievePropertyItem(page.Id, page.Properties["FormulaProp"].Id))) + .RespondWith( + Response.Create() + .WithStatusCode(200) + .WithBody("{\"object\":\"property_item\",\"id\":\"JwY^\",\"type\":\"formula\",\"formula\":{\"type\":\"date\",\"date\":{\"start\":\"2021-06-28\",\"end\":null}}}") + ); + + var formulaPropertyValue = (FormulaPropertyItem)await _pagesClient.RetrievePagePropertyItem(new RetrievePropertyItemParameters { PageId = page.Id, PropertyId = page.Properties["FormulaProp"].Id diff --git a/Test/Notion.UnitTests/PagesClientTests.cs b/Test/Notion.UnitTests/PagesClientTests.cs index f2f0584b..13598b0f 100644 --- a/Test/Notion.UnitTests/PagesClientTests.cs +++ b/Test/Notion.UnitTests/PagesClientTests.cs @@ -88,6 +88,7 @@ public async Task CreateAsync() public async Task UpdatePropertiesAsync() { var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; + var propertyId = "{>U;"; var path = ApiEndpoints.PagesApiUrls.UpdateProperties(pageId); var jsonData = await File.ReadAllTextAsync("data/pages/UpdatePagePropertiesResponse.json"); @@ -99,6 +100,10 @@ public async Task UpdatePropertiesAsync() .WithBody(jsonData) ); + Server.Given(CreateGetRequestBuilder(ApiEndpoints.PagesApiUrls.RetrievePropertyItem(pageId, propertyId))) + .RespondWith( + Response.Create().WithStatusCode(200).WithBody("{\"object\":\"property_item\",\"id\":\"{>U;\",\"type\":\"checkbox\",\"checkbox\":true}")); + var updatedProperties = new Dictionary() { { "In stock", new CheckboxPropertyValue() { Checkbox = true } } @@ -110,7 +115,7 @@ public async Task UpdatePropertiesAsync() page.Properties.Should().HaveCount(2); var updatedProperty = page.Properties.First(x => x.Key == "In stock"); - var checkboxPropertyValue = (CheckboxPropertyValue)await _client.RetrievePagePropertyItem(new RetrievePropertyItemParameters + var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItem(new RetrievePropertyItemParameters { PageId = page.Id, PropertyId = updatedProperty.Value.Id @@ -142,6 +147,7 @@ public async Task PageObjectShouldHaveUrlProperty() public async Task UpdatePageAsync() { var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; + var propertyId = "{>U;"; var path = ApiEndpoints.PagesApiUrls.UpdateProperties(pageId); var jsonData = await File.ReadAllTextAsync("data/pages/UpdatePagePropertiesResponse.json"); @@ -153,6 +159,10 @@ public async Task UpdatePageAsync() .WithBody(jsonData) ); + Server.Given(CreateGetRequestBuilder(ApiEndpoints.PagesApiUrls.RetrievePropertyItem(pageId, propertyId))) + .RespondWith( + Response.Create().WithStatusCode(200).WithBody("{\"object\":\"property_item\",\"id\":\"{>U;\",\"type\":\"checkbox\",\"checkbox\":true}")); + var pagesUpdateParameters = new PagesUpdateParameters { Properties = new Dictionary() @@ -168,7 +178,7 @@ public async Task UpdatePageAsync() page.Properties.Should().HaveCount(2); var updatedProperty = page.Properties.First(x => x.Key == "In stock"); - var checkboxPropertyValue = (CheckboxPropertyValue)await _client.RetrievePagePropertyItem(new RetrievePropertyItemParameters + var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItem(new RetrievePropertyItemParameters { PageId = page.Id, PropertyId = updatedProperty.Value.Id @@ -181,6 +191,8 @@ public async Task UpdatePageAsync() public async Task ArchivePageAsync() { var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; + var propertyId = "{>U;"; + var path = ApiEndpoints.PagesApiUrls.UpdateProperties(pageId); var jsonData = await File.ReadAllTextAsync("data/pages/ArchivePageResponse.json"); @@ -192,6 +204,10 @@ public async Task ArchivePageAsync() .WithBody(jsonData) ); + Server.Given(CreateGetRequestBuilder(ApiEndpoints.PagesApiUrls.RetrievePropertyItem(pageId, propertyId))) + .RespondWith( + Response.Create().WithStatusCode(200).WithBody("{\"object\":\"property_item\",\"id\":\"{>U;\",\"type\":\"checkbox\",\"checkbox\":true}")); + var pagesUpdateParameters = new PagesUpdateParameters { Archived = true, @@ -208,7 +224,7 @@ public async Task ArchivePageAsync() page.Properties.Should().HaveCount(2); var updatedProperty = page.Properties.First(x => x.Key == "In stock"); - var checkboxPropertyValue = (CheckboxPropertyValue)await _client.RetrievePagePropertyItem(new RetrievePropertyItemParameters + var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItem(new RetrievePropertyItemParameters { PageId = page.Id, PropertyId = updatedProperty.Value.Id diff --git a/Test/Notion.UnitTests/data/databases/Fix123QueryAsyncDateFormulaValueReturnsNullResponse.json b/Test/Notion.UnitTests/data/databases/Fix123QueryAsyncDateFormulaValueReturnsNullResponse.json index bf54bf0b..8c1b95c0 100644 --- a/Test/Notion.UnitTests/data/databases/Fix123QueryAsyncDateFormulaValueReturnsNullResponse.json +++ b/Test/Notion.UnitTests/data/databases/Fix123QueryAsyncDateFormulaValueReturnsNullResponse.json @@ -36,7 +36,7 @@ } }, "FormulaProp": { - "id": "JwY^", + "id": "JwY", "type": "formula", "formula": { "type": "date", From e477ffde3ed81fedb14eaaa978d44f56329852a6 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 20 Aug 2022 18:04:22 +0530 Subject: [PATCH 076/216] set version prefix to 4.0.0-preview --- Src/Notion.Client/Notion.Client.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/Notion.Client/Notion.Client.csproj b/Src/Notion.Client/Notion.Client.csproj index b33398f8..274be515 100644 --- a/Src/Notion.Client/Notion.Client.csproj +++ b/Src/Notion.Client/Notion.Client.csproj @@ -1,7 +1,7 @@  - 3.1.0-preview + 4.0.0-preview netstandard2.0 7.3 From 220ca1b7e554c5dd182689395c20fd3707fba28c Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 20 Aug 2022 18:01:04 +0530 Subject: [PATCH 077/216] set default Notion-Version to 2022-06-28 --- Src/Notion.Client/Constants.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/Notion.Client/Constants.cs b/Src/Notion.Client/Constants.cs index 579e3db4..5034edae 100644 --- a/Src/Notion.Client/Constants.cs +++ b/Src/Notion.Client/Constants.cs @@ -6,6 +6,6 @@ namespace Notion.Client internal class Constants { internal static string BASE_URL = "https://api.notion.com/"; - internal static string DEFAULT_NOTION_VERSION = "2022-02-22"; + internal static string DEFAULT_NOTION_VERSION = "2022-06-28"; } } From 523e1802b99657cf0d5306a3f67b173e3a243464 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 20 Aug 2022 19:21:09 +0530 Subject: [PATCH 078/216] Add block as parent for page and database --- .../Models/Database/IDatabaseParent.cs | 1 + Src/Notion.Client/Models/Page/IPageParent.cs | 1 + .../Models/Parents/BlockParent.cs | 18 ++++++++++++++++++ Src/Notion.Client/Models/Parents/ParentType.cs | 5 ++++- 4 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 Src/Notion.Client/Models/Parents/BlockParent.cs diff --git a/Src/Notion.Client/Models/Database/IDatabaseParent.cs b/Src/Notion.Client/Models/Database/IDatabaseParent.cs index bc4b2703..59233c38 100644 --- a/Src/Notion.Client/Models/Database/IDatabaseParent.cs +++ b/Src/Notion.Client/Models/Database/IDatabaseParent.cs @@ -6,6 +6,7 @@ namespace Notion.Client [JsonConverter(typeof(JsonSubtypes), "type")] [JsonSubtypes.KnownSubType(typeof(PageParent), ParentType.PageId)] [JsonSubtypes.KnownSubType(typeof(WorkspaceParent), ParentType.Workspace)] + [JsonSubtypes.KnownSubType(typeof(BlockParent), ParentType.BlockId)] public interface IDatabaseParent : IParent { } diff --git a/Src/Notion.Client/Models/Page/IPageParent.cs b/Src/Notion.Client/Models/Page/IPageParent.cs index 8301d0d5..439b1a3f 100644 --- a/Src/Notion.Client/Models/Page/IPageParent.cs +++ b/Src/Notion.Client/Models/Page/IPageParent.cs @@ -7,6 +7,7 @@ namespace Notion.Client [JsonSubtypes.KnownSubType(typeof(DatabaseParent), ParentType.DatabaseId)] [JsonSubtypes.KnownSubType(typeof(PageParent), ParentType.PageId)] [JsonSubtypes.KnownSubType(typeof(WorkspaceParent), ParentType.Workspace)] + [JsonSubtypes.KnownSubType(typeof(BlockParent), ParentType.BlockId)] public interface IPageParent : IParent { } diff --git a/Src/Notion.Client/Models/Parents/BlockParent.cs b/Src/Notion.Client/Models/Parents/BlockParent.cs new file mode 100644 index 00000000..e0a9af48 --- /dev/null +++ b/Src/Notion.Client/Models/Parents/BlockParent.cs @@ -0,0 +1,18 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class BlockParent : IPageParent, IDatabaseParent + { + /// + /// Always has a value "block_id" + /// + public ParentType Type { get; set; } + + /// + /// The ID of the block that the element belongs to. + /// + [JsonProperty("block_id")] + public string BlockId { get; set; } + } +} diff --git a/Src/Notion.Client/Models/Parents/ParentType.cs b/Src/Notion.Client/Models/Parents/ParentType.cs index 488f81b0..96c2a00d 100644 --- a/Src/Notion.Client/Models/Parents/ParentType.cs +++ b/Src/Notion.Client/Models/Parents/ParentType.cs @@ -14,6 +14,9 @@ public enum ParentType PageId, [EnumMember(Value = "workspace")] - Workspace + Workspace, + + [EnumMember(Value = "block_id")] + BlockId, } } From 317d13bcde7862e908910e1a9dd79b774b27148d Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 20 Aug 2022 19:25:54 +0530 Subject: [PATCH 079/216] Add parent prop on Block object --- Src/Notion.Client/Models/Blocks/Block.cs | 6 ++++++ Src/Notion.Client/Models/Blocks/IBlock.cs | 4 ++++ Src/Notion.Client/Models/Blocks/IBlockParent.cs | 14 ++++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 Src/Notion.Client/Models/Blocks/IBlockParent.cs diff --git a/Src/Notion.Client/Models/Blocks/Block.cs b/Src/Notion.Client/Models/Blocks/Block.cs index e4a3eaeb..1baf2533 100644 --- a/Src/Notion.Client/Models/Blocks/Block.cs +++ b/Src/Notion.Client/Models/Blocks/Block.cs @@ -1,4 +1,5 @@ using System; +using Notion.Client.Models.Blocks; namespace Notion.Client { @@ -19,5 +20,10 @@ public abstract class Block : IBlock public PartialUser CreatedBy { get; set; } public PartialUser LastEditedBy { get; set; } + + /// + /// Information about the block's parent. + /// + public IBlockParent Parent { get; set; } } } diff --git a/Src/Notion.Client/Models/Blocks/IBlock.cs b/Src/Notion.Client/Models/Blocks/IBlock.cs index c8cee542..58b17b93 100644 --- a/Src/Notion.Client/Models/Blocks/IBlock.cs +++ b/Src/Notion.Client/Models/Blocks/IBlock.cs @@ -1,6 +1,7 @@ using JsonSubTypes; using Newtonsoft.Json; using Newtonsoft.Json.Converters; +using Notion.Client.Models.Blocks; namespace Notion.Client { @@ -44,5 +45,8 @@ public interface IBlock : IObject, IObjectModificationData [JsonProperty("has_children")] bool HasChildren { get; set; } + + [JsonProperty("parent")] + IBlockParent Parent { get; set; } } } diff --git a/Src/Notion.Client/Models/Blocks/IBlockParent.cs b/Src/Notion.Client/Models/Blocks/IBlockParent.cs new file mode 100644 index 00000000..4e1d7a17 --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/IBlockParent.cs @@ -0,0 +1,14 @@ +using JsonSubTypes; +using Newtonsoft.Json; + +namespace Notion.Client.Models.Blocks +{ + [JsonConverter(typeof(JsonSubtypes), "type")] + [JsonSubtypes.KnownSubType(typeof(DatabaseParent), ParentType.DatabaseId)] + [JsonSubtypes.KnownSubType(typeof(PageParent), ParentType.PageId)] + [JsonSubtypes.KnownSubType(typeof(WorkspaceParent), ParentType.Workspace)] + [JsonSubtypes.KnownSubType(typeof(BlockParent), ParentType.BlockId)] + public interface IBlockParent + { + } +} From 7b77b78f9387b0c88c1bff26fafc755d97b9db7e Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 20 Aug 2022 23:27:48 +0530 Subject: [PATCH 080/216] Add Single and Dual Relation Property type --- .../Database/Properties/RelationProperty.cs | 25 ------------------- .../RelationProperty/DualPropertyRelation.cs | 21 ++++++++++++++++ .../RelationProperty/RelationData.cs | 19 ++++++++++++++ .../RelationProperty/RelationProperty.cs | 14 +++++++++++ .../RelationProperty/RelationType.cs | 13 ++++++++++ .../SinglePropertyRelation.cs | 13 ++++++++++ 6 files changed, 80 insertions(+), 25 deletions(-) delete mode 100644 Src/Notion.Client/Models/Database/Properties/RelationProperty.cs create mode 100644 Src/Notion.Client/Models/Database/Properties/RelationProperty/DualPropertyRelation.cs create mode 100644 Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationData.cs create mode 100644 Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationProperty.cs create mode 100644 Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationType.cs create mode 100644 Src/Notion.Client/Models/Database/Properties/RelationProperty/SinglePropertyRelation.cs diff --git a/Src/Notion.Client/Models/Database/Properties/RelationProperty.cs b/Src/Notion.Client/Models/Database/Properties/RelationProperty.cs deleted file mode 100644 index 48ffc4e3..00000000 --- a/Src/Notion.Client/Models/Database/Properties/RelationProperty.cs +++ /dev/null @@ -1,25 +0,0 @@ -using Newtonsoft.Json; - -namespace Notion.Client -{ - public class RelationProperty : Property - { - public override PropertyType Type => PropertyType.Relation; - - - [JsonProperty("relation")] - public Relation Relation { get; set; } - } - - public class Relation - { - [JsonProperty("database_id")] - public string DatabaseId { get; set; } - - [JsonProperty("synced_property_name")] - public string SyncedPropertyName { get; set; } - - [JsonProperty("synced_property_id")] - public string SyncedPropertyId { get; set; } - } -} diff --git a/Src/Notion.Client/Models/Database/Properties/RelationProperty/DualPropertyRelation.cs b/Src/Notion.Client/Models/Database/Properties/RelationProperty/DualPropertyRelation.cs new file mode 100644 index 00000000..f1c8c1ec --- /dev/null +++ b/Src/Notion.Client/Models/Database/Properties/RelationProperty/DualPropertyRelation.cs @@ -0,0 +1,21 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class DualPropertyRelation : RelationData + { + public override RelationType Type => RelationType.Dual; + + [JsonProperty("dual_property")] + public Data DualProperty { get; set; } + + public class Data + { + [JsonProperty("synced_property_name")] + public string SyncedPropertyName { get; set; } + + [JsonProperty("synced_property_id")] + public string SyncedPropertyId { get; set; } + } + } +} diff --git a/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationData.cs b/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationData.cs new file mode 100644 index 00000000..87e4b10a --- /dev/null +++ b/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationData.cs @@ -0,0 +1,19 @@ +using JsonSubTypes; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace Notion.Client +{ + [JsonConverter(typeof(JsonSubtypes), "type")] + [JsonSubtypes.KnownSubType(typeof(SinglePropertyRelation), RelationType.Single)] + [JsonSubtypes.KnownSubType(typeof(DualPropertyRelation), RelationType.Dual)] + public abstract class RelationData + { + [JsonProperty("database_id")] + public string DatabaseId { get; set; } + + [JsonProperty("type")] + [JsonConverter(typeof(StringEnumConverter))] + public virtual RelationType Type { get; set; } + } +} diff --git a/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationProperty.cs b/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationProperty.cs new file mode 100644 index 00000000..103cdc0c --- /dev/null +++ b/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationProperty.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; +using System.Runtime.Serialization; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class RelationProperty : Property + { + public override PropertyType Type => PropertyType.Relation; + + [JsonProperty("relation")] + public RelationData Relation { get; set; } + } +} diff --git a/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationType.cs b/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationType.cs new file mode 100644 index 00000000..89ce1c56 --- /dev/null +++ b/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationType.cs @@ -0,0 +1,13 @@ +using System.Runtime.Serialization; + +namespace Notion.Client +{ + public enum RelationType + { + [EnumMember(Value = "single_property")] + Single, + + [EnumMember(Value = "dual_property")] + Dual + } +} diff --git a/Src/Notion.Client/Models/Database/Properties/RelationProperty/SinglePropertyRelation.cs b/Src/Notion.Client/Models/Database/Properties/RelationProperty/SinglePropertyRelation.cs new file mode 100644 index 00000000..9ba8ae12 --- /dev/null +++ b/Src/Notion.Client/Models/Database/Properties/RelationProperty/SinglePropertyRelation.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class SinglePropertyRelation : RelationData + { + public override RelationType Type => RelationType.Single; + + [JsonProperty("single_property")] + public Dictionary SingleProperty { get; set; } + } +} From 3a42540888194a41fc65d4fb677fad723be2cfd6 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 20 Aug 2022 23:28:03 +0530 Subject: [PATCH 081/216] Fix breaking test cases --- Test/Notion.UnitTests/DatabasesClientTests.cs | 9 ++++++--- .../DatabasePropertyObjectContainNameProperty.json | 7 +++++-- ...atabasePropertyObjectContainParentProperty.json | 7 +++++-- .../DatabasePropertyObjectContainRelation.json | 7 +++++-- .../data/databases/DatabaseRetrieveResponse.json | 7 +++++-- .../data/databases/DatabasesListResponse.json | 14 ++++++++++---- 6 files changed, 36 insertions(+), 15 deletions(-) diff --git a/Test/Notion.UnitTests/DatabasesClientTests.cs b/Test/Notion.UnitTests/DatabasesClientTests.cs index 8e3689e8..cc4c2396 100644 --- a/Test/Notion.UnitTests/DatabasesClientTests.cs +++ b/Test/Notion.UnitTests/DatabasesClientTests.cs @@ -140,11 +140,14 @@ public async Task DatabasePropertyObjectContainRelationProperty() { Id = "zDGa", Name = "Property", - Relation = new Relation() + Relation = new DualPropertyRelation() { DatabaseId = "f86f2262-0751-40f2-8f63-e3f7a3c39fcb", - SyncedPropertyName = "Related to sample table (Property)", - SyncedPropertyId = "VQ}{" + DualProperty = new DualPropertyRelation.Data + { + SyncedPropertyName = "Related to sample table (Property)", + SyncedPropertyId = "VQ}{" + } } }); } diff --git a/Test/Notion.UnitTests/data/databases/DatabasePropertyObjectContainNameProperty.json b/Test/Notion.UnitTests/data/databases/DatabasePropertyObjectContainNameProperty.json index 5ed09bb1..2951f5f3 100644 --- a/Test/Notion.UnitTests/data/databases/DatabasePropertyObjectContainNameProperty.json +++ b/Test/Notion.UnitTests/data/databases/DatabasePropertyObjectContainNameProperty.json @@ -71,8 +71,11 @@ "type": "relation", "relation": { "database_id": "f86f2262-0751-40f2-8f63-e3f7a3c39fcb", - "synced_property_name": "Related to sample table (Property)", - "synced_property_id": "VQ}{" + "type": "dual_property", + "dual_property": { + "synced_property_name": "Related to sample table (Property)", + "synced_property_id": "VQ}{" + } } }, "Name": { diff --git a/Test/Notion.UnitTests/data/databases/DatabasePropertyObjectContainParentProperty.json b/Test/Notion.UnitTests/data/databases/DatabasePropertyObjectContainParentProperty.json index 5ed09bb1..2951f5f3 100644 --- a/Test/Notion.UnitTests/data/databases/DatabasePropertyObjectContainParentProperty.json +++ b/Test/Notion.UnitTests/data/databases/DatabasePropertyObjectContainParentProperty.json @@ -71,8 +71,11 @@ "type": "relation", "relation": { "database_id": "f86f2262-0751-40f2-8f63-e3f7a3c39fcb", - "synced_property_name": "Related to sample table (Property)", - "synced_property_id": "VQ}{" + "type": "dual_property", + "dual_property": { + "synced_property_name": "Related to sample table (Property)", + "synced_property_id": "VQ}{" + } } }, "Name": { diff --git a/Test/Notion.UnitTests/data/databases/DatabasePropertyObjectContainRelation.json b/Test/Notion.UnitTests/data/databases/DatabasePropertyObjectContainRelation.json index 5ed09bb1..2951f5f3 100644 --- a/Test/Notion.UnitTests/data/databases/DatabasePropertyObjectContainRelation.json +++ b/Test/Notion.UnitTests/data/databases/DatabasePropertyObjectContainRelation.json @@ -71,8 +71,11 @@ "type": "relation", "relation": { "database_id": "f86f2262-0751-40f2-8f63-e3f7a3c39fcb", - "synced_property_name": "Related to sample table (Property)", - "synced_property_id": "VQ}{" + "type": "dual_property", + "dual_property": { + "synced_property_name": "Related to sample table (Property)", + "synced_property_id": "VQ}{" + } } }, "Name": { diff --git a/Test/Notion.UnitTests/data/databases/DatabaseRetrieveResponse.json b/Test/Notion.UnitTests/data/databases/DatabaseRetrieveResponse.json index ef374f2d..9b5cf45f 100644 --- a/Test/Notion.UnitTests/data/databases/DatabaseRetrieveResponse.json +++ b/Test/Notion.UnitTests/data/databases/DatabaseRetrieveResponse.json @@ -82,8 +82,11 @@ "type": "relation", "relation": { "database_id": "f86f2262-0751-40f2-8f63-e3f7a3c39fcb", - "synced_property_name": "Related to sample table (Property)", - "synced_property_id": "VQ}{" + "type": "dual_property", + "dual_property": { + "synced_property_name": "Related to sample table (Property)", + "synced_property_id": "VQ}{" + } } }, "Name": { diff --git a/Test/Notion.UnitTests/data/databases/DatabasesListResponse.json b/Test/Notion.UnitTests/data/databases/DatabasesListResponse.json index ea380375..713c0736 100644 --- a/Test/Notion.UnitTests/data/databases/DatabasesListResponse.json +++ b/Test/Notion.UnitTests/data/databases/DatabasesListResponse.json @@ -74,8 +74,11 @@ "type": "relation", "relation": { "database_id": "f86f2262-0751-40f2-8f63-e3f7a3c39fcb", - "synced_property_name": "Related to sample table (Property)", - "synced_property_id": "VQ}{" + "type": "dual_property", + "dual_property": { + "synced_property_name": "Related to sample table (Property)", + "synced_property_id": "VQ}{" + } } }, "Name": { @@ -188,8 +191,11 @@ "type": "relation", "relation": { "database_id": "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1", - "synced_property_name": "Property", - "synced_property_id": "zDGa" + "type": "dual_property", + "dual_property": { + "synced_property_name": "Property", + "synced_property_id": "zDGa" + } } }, "Column 1": { From f2d0781cce3a26867ad3369d0508928388024934 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sun, 21 Aug 2022 03:14:01 +0530 Subject: [PATCH 082/216] Fix Block parent parsing --- Src/Notion.Client/Models/Blocks/Block.cs | 1 - Src/Notion.Client/Models/Blocks/IBlock.cs | 1 - Src/Notion.Client/Models/Blocks/IBlockParent.cs | 4 ++-- Src/Notion.Client/Models/Parents/BlockParent.cs | 2 +- Src/Notion.Client/Models/Parents/DatabaseParent.cs | 2 +- Src/Notion.Client/Models/Parents/PageParent.cs | 2 +- Src/Notion.Client/Models/Parents/WorkspaceParent.cs | 2 +- 7 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Src/Notion.Client/Models/Blocks/Block.cs b/Src/Notion.Client/Models/Blocks/Block.cs index 1baf2533..81bcd6bb 100644 --- a/Src/Notion.Client/Models/Blocks/Block.cs +++ b/Src/Notion.Client/Models/Blocks/Block.cs @@ -1,5 +1,4 @@ using System; -using Notion.Client.Models.Blocks; namespace Notion.Client { diff --git a/Src/Notion.Client/Models/Blocks/IBlock.cs b/Src/Notion.Client/Models/Blocks/IBlock.cs index 58b17b93..70cd9755 100644 --- a/Src/Notion.Client/Models/Blocks/IBlock.cs +++ b/Src/Notion.Client/Models/Blocks/IBlock.cs @@ -1,7 +1,6 @@ using JsonSubTypes; using Newtonsoft.Json; using Newtonsoft.Json.Converters; -using Notion.Client.Models.Blocks; namespace Notion.Client { diff --git a/Src/Notion.Client/Models/Blocks/IBlockParent.cs b/Src/Notion.Client/Models/Blocks/IBlockParent.cs index 4e1d7a17..73634400 100644 --- a/Src/Notion.Client/Models/Blocks/IBlockParent.cs +++ b/Src/Notion.Client/Models/Blocks/IBlockParent.cs @@ -1,14 +1,14 @@ using JsonSubTypes; using Newtonsoft.Json; -namespace Notion.Client.Models.Blocks +namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] [JsonSubtypes.KnownSubType(typeof(DatabaseParent), ParentType.DatabaseId)] [JsonSubtypes.KnownSubType(typeof(PageParent), ParentType.PageId)] [JsonSubtypes.KnownSubType(typeof(WorkspaceParent), ParentType.Workspace)] [JsonSubtypes.KnownSubType(typeof(BlockParent), ParentType.BlockId)] - public interface IBlockParent + public interface IBlockParent : IParent { } } diff --git a/Src/Notion.Client/Models/Parents/BlockParent.cs b/Src/Notion.Client/Models/Parents/BlockParent.cs index e0a9af48..5cff9458 100644 --- a/Src/Notion.Client/Models/Parents/BlockParent.cs +++ b/Src/Notion.Client/Models/Parents/BlockParent.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - public class BlockParent : IPageParent, IDatabaseParent + public class BlockParent : IPageParent, IDatabaseParent, IBlockParent { /// /// Always has a value "block_id" diff --git a/Src/Notion.Client/Models/Parents/DatabaseParent.cs b/Src/Notion.Client/Models/Parents/DatabaseParent.cs index c3e028e7..2e680655 100644 --- a/Src/Notion.Client/Models/Parents/DatabaseParent.cs +++ b/Src/Notion.Client/Models/Parents/DatabaseParent.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - public class DatabaseParent : IPageParent + public class DatabaseParent : IPageParent, IBlockParent { /// /// Always "database_id" diff --git a/Src/Notion.Client/Models/Parents/PageParent.cs b/Src/Notion.Client/Models/Parents/PageParent.cs index ff185747..a1f32a01 100644 --- a/Src/Notion.Client/Models/Parents/PageParent.cs +++ b/Src/Notion.Client/Models/Parents/PageParent.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - public class PageParent : IPageParent, IDatabaseParent + public class PageParent : IPageParent, IDatabaseParent, IBlockParent { /// /// Always "page_id". diff --git a/Src/Notion.Client/Models/Parents/WorkspaceParent.cs b/Src/Notion.Client/Models/Parents/WorkspaceParent.cs index fc645b60..86c60a54 100644 --- a/Src/Notion.Client/Models/Parents/WorkspaceParent.cs +++ b/Src/Notion.Client/Models/Parents/WorkspaceParent.cs @@ -1,6 +1,6 @@ namespace Notion.Client { - public class WorkspaceParent : IPageParent, IDatabaseParent + public class WorkspaceParent : IPageParent, IDatabaseParent, IBlockParent { /// /// Always "workspace". From f044e58f25ac570f855cbaa2b42564027b087794 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sun, 21 Aug 2022 03:15:03 +0530 Subject: [PATCH 083/216] Fix breaking integration tests --- .../IPageClientTests.cs | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/Test/Notion.IntegrationTests/IPageClientTests.cs b/Test/Notion.IntegrationTests/IPageClientTests.cs index c1d78635..2b0ec368 100644 --- a/Test/Notion.IntegrationTests/IPageClientTests.cs +++ b/Test/Notion.IntegrationTests/IPageClientTests.cs @@ -53,8 +53,15 @@ public async Task CreateAsync_CreatesANewPage() .DatabaseId.Should().Be(_databaseId); page.Properties.Should().ContainKey("Name"); - page.Properties["Name"].Should().BeOfType().Which - .Title.First().PlainText.Should().Be("Test Page Title"); + var pageProperty = page.Properties["Name"].Should().BeOfType().Subject; + + var titleProperty = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters + { + PageId = page.Id, + PropertyId = pageProperty.Id + }); + + titleProperty.Results.First().As().Title.PlainText.Should().Be("Test Page Title"); await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { @@ -98,8 +105,15 @@ public async Task Bug_unable_to_create_page_with_select_property() .DatabaseId.Should().Be(_databaseId); page.Properties.Should().ContainKey("Name"); - page.Properties["Name"].Should().BeOfType().Which - .Title.First().PlainText.Should().Be("Test Page Title"); + var pageProperty = page.Properties["Name"].Should().BeOfType().Subject; + + var titleProperty = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters + { + PageId = page.Id, + PropertyId = pageProperty.Id + }); + + titleProperty.Results.First().As().Title.PlainText.Should().Be("Test Page Title"); await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { From f38a9398cb36e8549bba4f95741a5d8852149b5e Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sun, 21 Aug 2022 03:40:16 +0530 Subject: [PATCH 084/216] Update readme to show notion version supported by package --- README.md | 1 + docs/README.md | 7 ------- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/README.md b/README.md index 10893f28..e8155da7 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ dotnet add package Notion.Net **Note:** default Notion-Version used by NuGet package versions | Package version | Notion-Version | | --- | --- | +| 4.0.0-preview-1.8.21.2022 | 2022-06-28 | | 3.0.0+ | 2022-02-22 | | 2.0.0+ | 2021-08-16 | | 1.0.0+ | 2021-05-13 | diff --git a/docs/README.md b/docs/README.md index d8d29422..6bb50712 100644 --- a/docs/README.md +++ b/docs/README.md @@ -10,13 +10,6 @@ A simple and easy to use client for the [Notion API](https://developers.notion.c dotnet add package Notion.Net ``` -**Note:** default Notion-Version used by NuGet package versions -| Package version | Notion-Version | -| --- | --- | -| 3.0.0+ | 2022-02-22 | -| 2.0.0+ | 2021-08-16 | -| 1.0.0+ | 2021-05-13 | - ## Usage > Before getting started, you need to [create an integration](https://www.notion.com/my-integrations) and find the token. You can learn more about authorization [here](https://developers.notion.com/docs/authorization). From 074473f3c93a1e17d78c1f754685edd4d73350fc Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sun, 28 Aug 2022 19:45:30 +0530 Subject: [PATCH 085/216] Add xml document comments --- .../Api/Databases/IDatabasesClient.cs | 18 +++++++++++++-- Src/Notion.Client/Api/Pages/IPagesClient.cs | 22 ++++++++++++++----- Src/Notion.Client/Api/Search/ISearchClient.cs | 7 ++++++ Src/Notion.Client/Api/Users/IUsersClient.cs | 14 +++++++++++- Src/Notion.Client/Notion.Client.csproj | 2 +- 5 files changed, 54 insertions(+), 9 deletions(-) diff --git a/Src/Notion.Client/Api/Databases/IDatabasesClient.cs b/Src/Notion.Client/Api/Databases/IDatabasesClient.cs index 2b2c2746..115ccfed 100644 --- a/Src/Notion.Client/Api/Databases/IDatabasesClient.cs +++ b/Src/Notion.Client/Api/Databases/IDatabasesClient.cs @@ -4,14 +4,28 @@ namespace Notion.Client { public interface IDatabasesClient { + /// + /// Retrieves a Database object using the ID specified. + /// + /// Identifier for a Notion database + /// Task RetrieveAsync(string databaseId); + + /// + /// Gets a list of Pages contained in the database, filtered and ordered according to the + /// filter conditions and sort criteria provided in the request. The response may contain + /// fewer than page_size of results. + /// + /// + /// + /// Task> QueryAsync(string databaseId, DatabasesQueryParameters databasesQueryParameters); /// /// Creates a database as a subpage in the specified parent page, with the specified properties schema. /// /// - /// Database + /// Task CreateAsync(DatabasesCreateParameters databasesCreateParameters); /// @@ -19,7 +33,7 @@ public interface IDatabasesClient /// /// /// - /// Database + /// Task UpdateAsync(string databaseId, DatabasesUpdateParameters databasesUpdateParameters); } } diff --git a/Src/Notion.Client/Api/Pages/IPagesClient.cs b/Src/Notion.Client/Api/Pages/IPagesClient.cs index b4fc728f..90eac980 100644 --- a/Src/Notion.Client/Api/Pages/IPagesClient.cs +++ b/Src/Notion.Client/Api/Pages/IPagesClient.cs @@ -13,11 +13,23 @@ public interface IPagesClient /// If the parent is a page, the only valid property is title. /// /// Create page parameters - /// Created page. + /// Created object. Task CreateAsync(PagesCreateParameters pagesCreateParameters); + /// + /// Retrieves a Page object using the ID specified. + /// + /// Identifier for a Notion page + /// Task RetrieveAsync(string pageId); + /// + /// Updates page property values for the specified page. + /// Note: Properties that are not set via the properties parameter will remain unchanged. + /// + /// Identifier for a Notion page + /// Property values to update for this page. The keys are the names or IDs of the property and the values are property values. + /// Updated object Task UpdatePropertiesAsync( string pageId, IDictionary updatedProperties @@ -27,15 +39,15 @@ IDictionary updatedProperties /// Updates page property values for the specified page. /// Properties that are not set via the properties parameter will remain unchanged. /// - /// - /// - /// Updated page. + /// Identifier for a Notion page + /// Update property parameters + /// Updated object Task UpdateAsync(string pageId, PagesUpdateParameters pagesUpdateParameters); /// /// Retrieves a property_item object for a given pageId and propertyId. Depending on the property type, the object returned will either be a value or a paginated list of property item values. /// - /// sdf sd + /// Property body and query parameters /// Task RetrievePagePropertyItem(RetrievePropertyItemParameters retrievePropertyItemParameters); } diff --git a/Src/Notion.Client/Api/Search/ISearchClient.cs b/Src/Notion.Client/Api/Search/ISearchClient.cs index 883c86ba..9eb487d5 100644 --- a/Src/Notion.Client/Api/Search/ISearchClient.cs +++ b/Src/Notion.Client/Api/Search/ISearchClient.cs @@ -4,6 +4,13 @@ namespace Notion.Client { public interface ISearchClient { + /// + /// Searches all original pages, databases, and child pages/databases that are shared with the integration. + /// + /// It will not return linked databases, since these duplicate their source databases. + /// + /// Search filters and body parameters + /// Task> SearchAsync(SearchParameters parameters); } } diff --git a/Src/Notion.Client/Api/Users/IUsersClient.cs b/Src/Notion.Client/Api/Users/IUsersClient.cs index 95427f2b..41443678 100644 --- a/Src/Notion.Client/Api/Users/IUsersClient.cs +++ b/Src/Notion.Client/Api/Users/IUsersClient.cs @@ -4,13 +4,25 @@ namespace Notion.Client { public interface IUsersClient { + /// + /// Retrieves a User using the ID specified. + /// + /// Identifier for a Notion user + /// Task RetrieveAsync(string userId); + + /// + /// Returns a paginated list of Users for the workspace. + /// + /// The response may contain fewer than page_size of results. + /// + /// Task> ListAsync(); /// /// Retrieves the bot User associated with the API token provided in the authorization header. /// - /// User object of type bot having an owner field with information about the person who authorized the integration. + /// object of type bot having an owner field with information about the person who authorized the integration. Task MeAsync(); } } diff --git a/Src/Notion.Client/Notion.Client.csproj b/Src/Notion.Client/Notion.Client.csproj index 274be515..9b2d51f7 100644 --- a/Src/Notion.Client/Notion.Client.csproj +++ b/Src/Notion.Client/Notion.Client.csproj @@ -3,7 +3,7 @@ 4.0.0-preview netstandard2.0 - 7.3 + 9.0 Notion.Net Vedant Koditkar From c43475a1816d69d6e06ea7a9e853ab57306cdd9c Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sun, 28 Aug 2022 21:19:20 +0530 Subject: [PATCH 086/216] Add support to fetch comments --- Src/Notion.Client/Api/ApiEndpoints.cs | 5 +++ .../Api/Comments/CommentsClient.cs | 12 +++++++ .../Api/Comments/ICommentsClient.cs | 14 +++++++++ .../Api/Comments/Retrieve/CommentsClient.cs | 25 +++++++++++++++ .../IRetrieveCommentsQueryParameters.cs | 10 ++++++ .../Request/RetrieveCommentsParameters.cs | 9 ++++++ .../Api/Comments/Retrieve/Response/Comment.cs | 31 +++++++++++++++++++ .../Comments/Retrieve/Response/Comments.cs | 14 +++++++++ .../Retrieve/Response/ICommentParent.cs | 12 +++++++ Src/Notion.Client/Models/ObjectType.cs | 3 ++ .../Models/Parents/BlockParent.cs | 2 +- .../Models/Parents/PageParent.cs | 2 +- 12 files changed, 137 insertions(+), 2 deletions(-) create mode 100644 Src/Notion.Client/Api/Comments/CommentsClient.cs create mode 100644 Src/Notion.Client/Api/Comments/ICommentsClient.cs create mode 100644 Src/Notion.Client/Api/Comments/Retrieve/CommentsClient.cs create mode 100644 Src/Notion.Client/Api/Comments/Retrieve/Request/IRetrieveCommentsQueryParameters.cs create mode 100644 Src/Notion.Client/Api/Comments/Retrieve/Request/RetrieveCommentsParameters.cs create mode 100644 Src/Notion.Client/Api/Comments/Retrieve/Response/Comment.cs create mode 100644 Src/Notion.Client/Api/Comments/Retrieve/Response/Comments.cs create mode 100644 Src/Notion.Client/Api/Comments/Retrieve/Response/ICommentParent.cs diff --git a/Src/Notion.Client/Api/ApiEndpoints.cs b/Src/Notion.Client/Api/ApiEndpoints.cs index f9a9549b..0dd9ef2d 100644 --- a/Src/Notion.Client/Api/ApiEndpoints.cs +++ b/Src/Notion.Client/Api/ApiEndpoints.cs @@ -61,5 +61,10 @@ public static class SearchApiUrls { public static string Search() => "/v1/search"; } + + public static class CommentsApiUrls + { + public static string Retrieve() => "/v1/comments"; + } } } diff --git a/Src/Notion.Client/Api/Comments/CommentsClient.cs b/Src/Notion.Client/Api/Comments/CommentsClient.cs new file mode 100644 index 00000000..51dadeff --- /dev/null +++ b/Src/Notion.Client/Api/Comments/CommentsClient.cs @@ -0,0 +1,12 @@ +namespace Notion.Client +{ + public partial class CommentsClient : ICommentsClient + { + private readonly IRestClient _client; + + public CommentsClient(IRestClient restClient) + { + _client = restClient; + } + } +} diff --git a/Src/Notion.Client/Api/Comments/ICommentsClient.cs b/Src/Notion.Client/Api/Comments/ICommentsClient.cs new file mode 100644 index 00000000..b0d395af --- /dev/null +++ b/Src/Notion.Client/Api/Comments/ICommentsClient.cs @@ -0,0 +1,14 @@ +using System.Threading.Tasks; + +namespace Notion.Client +{ + public interface ICommentsClient + { + /// + /// Retrieves a list of un-resolved Comment objects from a page or block. + /// + /// Retrieve comments parameters + /// + Task Retrieve(RetrieveCommentsParameters retrieveCommentsParameters); + } +} diff --git a/Src/Notion.Client/Api/Comments/Retrieve/CommentsClient.cs b/Src/Notion.Client/Api/Comments/Retrieve/CommentsClient.cs new file mode 100644 index 00000000..d228200c --- /dev/null +++ b/Src/Notion.Client/Api/Comments/Retrieve/CommentsClient.cs @@ -0,0 +1,25 @@ +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Notion.Client +{ + public partial class CommentsClient + { + public async Task Retrieve(RetrieveCommentsParameters parameters) + { + var qp = (IRetrieveCommentsQueryParameters)parameters; + + var queryParams = new Dictionary() + { + { "block_id", qp.BlockId }, + { "start_cursor", qp.StartCursor }, + { "page_size", qp.PageSize.ToString() }, + }; + + return await _client.GetAsync( + ApiEndpoints.CommentsApiUrls.Retrieve(), + queryParams + ); + } + } +} diff --git a/Src/Notion.Client/Api/Comments/Retrieve/Request/IRetrieveCommentsQueryParameters.cs b/Src/Notion.Client/Api/Comments/Retrieve/Request/IRetrieveCommentsQueryParameters.cs new file mode 100644 index 00000000..123a5844 --- /dev/null +++ b/Src/Notion.Client/Api/Comments/Retrieve/Request/IRetrieveCommentsQueryParameters.cs @@ -0,0 +1,10 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public interface IRetrieveCommentsQueryParameters : IPaginationParameters + { + [JsonProperty("block_id")] + string BlockId { get; set; } + } +} diff --git a/Src/Notion.Client/Api/Comments/Retrieve/Request/RetrieveCommentsParameters.cs b/Src/Notion.Client/Api/Comments/Retrieve/Request/RetrieveCommentsParameters.cs new file mode 100644 index 00000000..e78c4cad --- /dev/null +++ b/Src/Notion.Client/Api/Comments/Retrieve/Request/RetrieveCommentsParameters.cs @@ -0,0 +1,9 @@ +namespace Notion.Client +{ + public class RetrieveCommentsParameters : IRetrieveCommentsQueryParameters + { + public string BlockId { get; set; } + public string StartCursor { get; set; } + public int? PageSize { get; set; } + } +} diff --git a/Src/Notion.Client/Api/Comments/Retrieve/Response/Comment.cs b/Src/Notion.Client/Api/Comments/Retrieve/Response/Comment.cs new file mode 100644 index 00000000..531fb43c --- /dev/null +++ b/Src/Notion.Client/Api/Comments/Retrieve/Response/Comment.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class Comment : IObject + { + public string Id { get; set; } + + public ObjectType Object => ObjectType.Comment; + + [JsonProperty("parent")] + public ICommentParent Parent { get; set; } + + [JsonProperty("discussion_id")] + public string DiscussionId { get; set; } + + [JsonProperty("rich_text")] + public IEnumerable RichText { get; set; } + + [JsonProperty("created_by")] + public PartialUser CreatedBy { get; set; } + + [JsonProperty("created_time")] + public DateTime CreatedTime { get; set; } + + [JsonProperty("last_edited_time")] + public DateTime LastEditedTime { get; set; } + } +} diff --git a/Src/Notion.Client/Api/Comments/Retrieve/Response/Comments.cs b/Src/Notion.Client/Api/Comments/Retrieve/Response/Comments.cs new file mode 100644 index 00000000..c89182a5 --- /dev/null +++ b/Src/Notion.Client/Api/Comments/Retrieve/Response/Comments.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class RetrieveCommentsResponse : PaginatedList + { + [JsonProperty("type")] + public string Type { get; set; } + + [JsonProperty("comment")] + public Dictionary Comment { get; set; } + } +} diff --git a/Src/Notion.Client/Api/Comments/Retrieve/Response/ICommentParent.cs b/Src/Notion.Client/Api/Comments/Retrieve/Response/ICommentParent.cs new file mode 100644 index 00000000..e323c7e1 --- /dev/null +++ b/Src/Notion.Client/Api/Comments/Retrieve/Response/ICommentParent.cs @@ -0,0 +1,12 @@ +using JsonSubTypes; +using Newtonsoft.Json; + +namespace Notion.Client +{ + [JsonConverter(typeof(JsonSubtypes), "type")] + [JsonSubtypes.KnownSubType(typeof(PageParent), ParentType.PageId)] + [JsonSubtypes.KnownSubType(typeof(BlockParent), ParentType.BlockId)] + public interface ICommentParent + { + } +} diff --git a/Src/Notion.Client/Models/ObjectType.cs b/Src/Notion.Client/Models/ObjectType.cs index d493254c..21995840 100644 --- a/Src/Notion.Client/Models/ObjectType.cs +++ b/Src/Notion.Client/Models/ObjectType.cs @@ -15,5 +15,8 @@ public enum ObjectType [EnumMember(Value = "user")] User, + + [EnumMember(Value = "comment")] + Comment, } } diff --git a/Src/Notion.Client/Models/Parents/BlockParent.cs b/Src/Notion.Client/Models/Parents/BlockParent.cs index 5cff9458..1ac1fd51 100644 --- a/Src/Notion.Client/Models/Parents/BlockParent.cs +++ b/Src/Notion.Client/Models/Parents/BlockParent.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - public class BlockParent : IPageParent, IDatabaseParent, IBlockParent + public class BlockParent : IPageParent, IDatabaseParent, IBlockParent, ICommentParent { /// /// Always has a value "block_id" diff --git a/Src/Notion.Client/Models/Parents/PageParent.cs b/Src/Notion.Client/Models/Parents/PageParent.cs index a1f32a01..13b1c95a 100644 --- a/Src/Notion.Client/Models/Parents/PageParent.cs +++ b/Src/Notion.Client/Models/Parents/PageParent.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - public class PageParent : IPageParent, IDatabaseParent, IBlockParent + public class PageParent : IPageParent, IDatabaseParent, IBlockParent, ICommentParent { /// /// Always "page_id". From 807a5388938b4d4193767dd890d76799be76ac59 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sun, 28 Aug 2022 22:04:21 +0530 Subject: [PATCH 087/216] Add support to create a comment --- Src/Notion.Client/Api/ApiEndpoints.cs | 2 + .../Api/Comments/Create/CommentsClient.cs | 17 +++++++ .../Create/Request/CreateCommentParameters.cs | 48 +++++++++++++++++++ .../Create/Response/CreateCommentResponse.cs | 6 +++ .../Api/Comments/ICommentsClient.cs | 2 + 5 files changed, 75 insertions(+) create mode 100644 Src/Notion.Client/Api/Comments/Create/CommentsClient.cs create mode 100644 Src/Notion.Client/Api/Comments/Create/Request/CreateCommentParameters.cs create mode 100644 Src/Notion.Client/Api/Comments/Create/Response/CreateCommentResponse.cs diff --git a/Src/Notion.Client/Api/ApiEndpoints.cs b/Src/Notion.Client/Api/ApiEndpoints.cs index 0dd9ef2d..ec6f5b1a 100644 --- a/Src/Notion.Client/Api/ApiEndpoints.cs +++ b/Src/Notion.Client/Api/ApiEndpoints.cs @@ -65,6 +65,8 @@ public static class SearchApiUrls public static class CommentsApiUrls { public static string Retrieve() => "/v1/comments"; + + public static string Create() => "/v1/comments"; } } } diff --git a/Src/Notion.Client/Api/Comments/Create/CommentsClient.cs b/Src/Notion.Client/Api/Comments/Create/CommentsClient.cs new file mode 100644 index 00000000..12f1207b --- /dev/null +++ b/Src/Notion.Client/Api/Comments/Create/CommentsClient.cs @@ -0,0 +1,17 @@ +using System.Threading.Tasks; + +namespace Notion.Client +{ + public partial class CommentsClient + { + public async Task Create(CreateCommentParameters parameters) + { + var body = (ICreateCommentsBodyParameters)parameters; + + return await _client.PostAsync( + ApiEndpoints.CommentsApiUrls.Create(), + body + ); + } + } +} diff --git a/Src/Notion.Client/Api/Comments/Create/Request/CreateCommentParameters.cs b/Src/Notion.Client/Api/Comments/Create/Request/CreateCommentParameters.cs new file mode 100644 index 00000000..aadaf1f1 --- /dev/null +++ b/Src/Notion.Client/Api/Comments/Create/Request/CreateCommentParameters.cs @@ -0,0 +1,48 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public interface ICreateCommentsBodyParameters + { + [JsonProperty("rich_text")] + public IEnumerable RichText { get; set; } + } + + public interface ICreateDiscussionCommentBodyParameters : ICreateCommentsBodyParameters + { + [JsonProperty("discussion_id")] + public string DiscussionId { get; set; } + } + + public interface ICreatePageCommentBodyParameters : ICreateCommentsBodyParameters + { + [JsonProperty("parent")] + public ParentPageInput Parent { get; set; } + } + + public class CreateCommentParameters : ICreateDiscussionCommentBodyParameters, ICreatePageCommentBodyParameters + { + public string DiscussionId { get; set; } + public IEnumerable RichText { get; set; } + public ParentPageInput Parent { get; set; } + + public static CreateCommentParameters CreatePageComment(ParentPageInput parent, IEnumerable richText) + { + return new CreateCommentParameters + { + Parent = parent, + RichText = richText + }; + } + + public static CreateCommentParameters CreateDiscussionComment(string discussionId, IEnumerable richText) + { + return new CreateCommentParameters + { + DiscussionId = discussionId, + RichText = richText + }; + } + } +} diff --git a/Src/Notion.Client/Api/Comments/Create/Response/CreateCommentResponse.cs b/Src/Notion.Client/Api/Comments/Create/Response/CreateCommentResponse.cs new file mode 100644 index 00000000..39bebd6b --- /dev/null +++ b/Src/Notion.Client/Api/Comments/Create/Response/CreateCommentResponse.cs @@ -0,0 +1,6 @@ +namespace Notion.Client +{ + public class CreateCommentResponse : Comment + { + } +} diff --git a/Src/Notion.Client/Api/Comments/ICommentsClient.cs b/Src/Notion.Client/Api/Comments/ICommentsClient.cs index b0d395af..d936203c 100644 --- a/Src/Notion.Client/Api/Comments/ICommentsClient.cs +++ b/Src/Notion.Client/Api/Comments/ICommentsClient.cs @@ -10,5 +10,7 @@ public interface ICommentsClient /// Retrieve comments parameters /// Task Retrieve(RetrieveCommentsParameters retrieveCommentsParameters); + + Task Create(CreateCommentParameters createCommentParameters); } } From 4bb2731a3c85cae7d3c93fb7ffd33666663564c9 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Mon, 29 Aug 2022 01:22:42 +0530 Subject: [PATCH 088/216] Add Comments API to NotionClient --- Src/Notion.Client/NotionClient.cs | 4 ++++ Src/Notion.Client/NotionClientFactory.cs | 1 + 2 files changed, 5 insertions(+) diff --git a/Src/Notion.Client/NotionClient.cs b/Src/Notion.Client/NotionClient.cs index 5bbc6dad..f1650b29 100644 --- a/Src/Notion.Client/NotionClient.cs +++ b/Src/Notion.Client/NotionClient.cs @@ -7,6 +7,7 @@ public interface INotionClient IPagesClient Pages { get; } ISearchClient Search { get; } IBlocksClient Blocks { get; } + ICommentsClient Comments { get; } IRestClient RestClient { get; } } @@ -18,6 +19,7 @@ public NotionClient( DatabasesClient databases, PagesClient pages, SearchClient search, + CommentsClient comments, BlocksClient blocks) { RestClient = restClient; @@ -25,6 +27,7 @@ public NotionClient( Databases = databases; Pages = pages; Search = search; + Comments = comments; Blocks = blocks; } @@ -33,6 +36,7 @@ public NotionClient( public IPagesClient Pages { get; } public ISearchClient Search { get; } public IBlocksClient Blocks { get; } + public ICommentsClient Comments { get; } public IRestClient RestClient { get; } } } diff --git a/Src/Notion.Client/NotionClientFactory.cs b/Src/Notion.Client/NotionClientFactory.cs index 4010eb8c..0a02eb3c 100644 --- a/Src/Notion.Client/NotionClientFactory.cs +++ b/Src/Notion.Client/NotionClientFactory.cs @@ -13,6 +13,7 @@ public static NotionClient Create(ClientOptions options) , pages: new PagesClient(restClient) , search: new SearchClient(restClient) , blocks: new BlocksClient(restClient) + , comments: new CommentsClient(restClient) ); } } From b931a36413a1ae654ef649ca7795ca4f95c29c40 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Mon, 29 Aug 2022 01:23:05 +0530 Subject: [PATCH 089/216] Add Integration tests for comments API --- .../CommentsClientTests.cs | 134 ++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 Test/Notion.IntegrationTests/CommentsClientTests.cs diff --git a/Test/Notion.IntegrationTests/CommentsClientTests.cs b/Test/Notion.IntegrationTests/CommentsClientTests.cs new file mode 100644 index 00000000..2ac7219d --- /dev/null +++ b/Test/Notion.IntegrationTests/CommentsClientTests.cs @@ -0,0 +1,134 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Notion.Client; +using Xunit; + +namespace Notion.IntegrationTests +{ + public class CommentsClientTests : IDisposable + { + private readonly INotionClient _client; + private readonly string _pageParentId; + private readonly Page _page; + + public CommentsClientTests() + { + var options = new ClientOptions + { + AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN") + }; + + _client = NotionClientFactory.Create(options); + _pageParentId = Environment.GetEnvironmentVariable("NOTION_PAGE_PARENT_ID") ?? throw new ArgumentNullException("Page parent id is required."); + + _page = _client.Pages.CreateAsync( + PagesCreateParametersBuilder.Create( + new ParentPageInput() + { + PageId = _pageParentId + } + ).Build() + ).Result; + } + + [Fact] + public async Task ShouldCreatePageComment() + { + // Arrange + var parameters = CreateCommentParameters.CreatePageComment( + new ParentPageInput + { + PageId = _page.Id + }, + new List { + new RichTextTextInput + { + Text = new Text + { + Content = "This is a comment" + } + } + } + ); + + // Act + var response = await _client.Comments.Create(parameters); + + // Arrange + + Assert.NotNull(response.Parent); + Assert.NotNull(response.Id); + Assert.NotNull(response.DiscussionId); + + Assert.NotNull(response.RichText); + Assert.Single(response.RichText); + var richText = Assert.IsType(response.RichText.First()); + Assert.Equal("This is a comment", richText.Text.Content); + + var pageParent = Assert.IsType(response.Parent); + Assert.Equal(_page.Id, pageParent.PageId); + } + + [Fact] + public async Task ShouldCreateADiscussionComment() + { + // Arrange + var comment = await _client.Comments.Create( + CreateCommentParameters.CreatePageComment( + new ParentPageInput + { + PageId = _page.Id + }, + new List { + new RichTextTextInput + { + Text = new Text + { + Content = "This is a comment" + } + } + } + ) + ); + + // Act + var response = await _client.Comments.Create( + CreateCommentParameters.CreateDiscussionComment( + comment.DiscussionId, + new List { + new RichTextTextInput + { + Text = new Text + { + Content = "This is a sub comment" + } + } + } + ) + ); + + // Arrange + Assert.Null(response.Parent); + Assert.NotNull(response.Id); + Assert.Equal(comment.DiscussionId, response.DiscussionId); + + Assert.NotNull(response.RichText); + Assert.Single(response.RichText); + var richText = Assert.IsType(response.RichText.First()); + Assert.Equal("This is a sub comment", richText.Text.Content); + + var pageParent = Assert.IsType(response.Parent); + Assert.Equal(_page.Id, pageParent.PageId); + } + + public void Dispose() + { + _client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters + { + Archived = true, + }).Wait(); + } + } +} From fb47b925464e6b61239419a927d63fae5fd81759 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Mon, 29 Aug 2022 01:34:11 +0530 Subject: [PATCH 090/216] Fix NumberPropertyItem parsing issue --- Src/Notion.Client/Models/PropertyItems/NumberPropertyItem.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/Notion.Client/Models/PropertyItems/NumberPropertyItem.cs b/Src/Notion.Client/Models/PropertyItems/NumberPropertyItem.cs index 144fc627..54938b1b 100644 --- a/Src/Notion.Client/Models/PropertyItems/NumberPropertyItem.cs +++ b/Src/Notion.Client/Models/PropertyItems/NumberPropertyItem.cs @@ -7,6 +7,6 @@ public class NumberPropertyItem : SimplePropertyItem public override string Type => "number"; [JsonProperty("number")] - public Number Number { get; set; } + public double Number { get; set; } } } From d8c4844eed31517fdbbe03ed76de051b2c01017d Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Mon, 29 Aug 2022 02:12:20 +0530 Subject: [PATCH 091/216] Number property can have null value --- Src/Notion.Client/Models/PropertyItems/NumberPropertyItem.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/Notion.Client/Models/PropertyItems/NumberPropertyItem.cs b/Src/Notion.Client/Models/PropertyItems/NumberPropertyItem.cs index 54938b1b..ea2ab0ad 100644 --- a/Src/Notion.Client/Models/PropertyItems/NumberPropertyItem.cs +++ b/Src/Notion.Client/Models/PropertyItems/NumberPropertyItem.cs @@ -7,6 +7,6 @@ public class NumberPropertyItem : SimplePropertyItem public override string Type => "number"; [JsonProperty("number")] - public double Number { get; set; } + public double? Number { get; set; } } } From 7a9889e0d9b1657955497cd806df1729ccdb6197 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Mon, 29 Aug 2022 02:14:06 +0530 Subject: [PATCH 092/216] Add integration test to verify the fix --- .../IPageClientTests.cs | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/Test/Notion.IntegrationTests/IPageClientTests.cs b/Test/Notion.IntegrationTests/IPageClientTests.cs index 2b0ec368..acdab301 100644 --- a/Test/Notion.IntegrationTests/IPageClientTests.cs +++ b/Test/Notion.IntegrationTests/IPageClientTests.cs @@ -244,5 +244,59 @@ public async Task Test_UpdatePageProperty_with_date_as_null() //cleanup await _client.Blocks.DeleteAsync(page.Id); } + + [Fact] + public async Task Bug_Unable_To_Parse_NumberPropertyItem() + { + // Arrange + var pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput + { + DatabaseId = _databaseId + }).AddProperty("Name", new TitlePropertyValue + { + Title = new List + { + new RichTextText + { + Text = new Text + { + Content = "Test Page Title" + } + } + } + }).AddProperty("Number", new NumberPropertyValue + { + Number = 200.00 + }).Build(); + + // Act + var page = await _client.Pages.CreateAsync(pagesCreateParameters); + + // Assert + Assert.NotNull(page); + var pageParent = Assert.IsType(page.Parent); + Assert.Equal(_databaseId, pageParent.DatabaseId); + + var titleProperty = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters + { + PageId = page.Id, + PropertyId = page.Properties["Name"].Id + }); + + Assert.Equal("Test Page Title", titleProperty.Results.First().As().Title.PlainText); + + var numberProperty = (NumberPropertyItem)await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters + { + PageId = page.Id, + PropertyId = page.Properties["Number"].Id + }); + + Assert.Equal(200.00, numberProperty.Number); + + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters + { + Archived = true + }); + } } } From 9252fe74b9bde7b3cabbdbf7530b919ac11ebee6 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Mon, 29 Aug 2022 02:31:43 +0530 Subject: [PATCH 093/216] Update readme with support of comments API --- README.md | 3 +++ docs/README.md | 3 +++ 2 files changed, 6 insertions(+) diff --git a/README.md b/README.md index e8155da7..5ab47338 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,9 @@ var complexFiler = new CompoundFilter( - [x] Retrieve block children - [x] Append block children - [x] Delete a block +- [x] Comments + - [x] Retrieve comments + - [x] Create comment - [x] Users - [x] Retrieve a User - [x] List all users diff --git a/docs/README.md b/docs/README.md index 6bb50712..54a041d2 100644 --- a/docs/README.md +++ b/docs/README.md @@ -89,6 +89,9 @@ var complexFiler = new CompoundFilter( - [x] Retrieve block children - [x] Append block children - [x] Delete a block +- [x] Comments + - [x] Retrieve comments + - [x] Create comment - [x] Users - [x] Retrieve a User - [x] List all users From 260c546a3efab46b5f2e3de2c3bc2edfe2e0789f Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Wed, 31 Aug 2022 02:00:37 +0530 Subject: [PATCH 094/216] fix lgtm alerts --- Src/Notion.Client/RestClient/RestClient.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Src/Notion.Client/RestClient/RestClient.cs b/Src/Notion.Client/RestClient/RestClient.cs index b52b0ce3..bba3a866 100644 --- a/Src/Notion.Client/RestClient/RestClient.cs +++ b/Src/Notion.Client/RestClient/RestClient.cs @@ -64,8 +64,9 @@ private static async Task BuildException(HttpResponseMessage response { errorResponse = JsonConvert.DeserializeObject(errorBody); } - catch + catch (Exception ex) { + Log.Error(ex, "Error when parsing the notion api response."); } } @@ -84,7 +85,7 @@ public async Task SendAsync( requestUri = AddQueryString(requestUri, queryParams); - HttpRequestMessage httpRequest = new HttpRequestMessage(httpMethod, requestUri); + using var httpRequest = new HttpRequestMessage(httpMethod, requestUri); httpRequest.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _options.AuthToken); httpRequest.Headers.Add("Notion-Version", _options.NotionVersion); From 95ffdd38f9e2e599c630770f6adc48e38d525335 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Wed, 31 Aug 2022 02:01:49 +0530 Subject: [PATCH 095/216] fix notion api error message parsing --- Src/Notion.Client/NotionApiErrorResponse.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Src/Notion.Client/NotionApiErrorResponse.cs b/Src/Notion.Client/NotionApiErrorResponse.cs index f21c6923..f27288fb 100644 --- a/Src/Notion.Client/NotionApiErrorResponse.cs +++ b/Src/Notion.Client/NotionApiErrorResponse.cs @@ -1,8 +1,13 @@ -namespace Notion.Client +using Newtonsoft.Json; + +namespace Notion.Client { class NotionApiErrorResponse { + [JsonProperty("code")] public NotionAPIErrorCode ErrorCode { get; set; } + + [JsonProperty("message")] public string Message { get; set; } } } From a4321f4426f15664b7fac9a8715fefd407a9e2b5 Mon Sep 17 00:00:00 2001 From: Herman Schoenfeld Date: Thu, 8 Sep 2022 08:28:31 +1000 Subject: [PATCH 096/216] Restored PropertyValue's in Page model - Note: NotionAPI rolled-back this active active on 2022-08-31 --- Src/Notion.Client/Models/Page/Page.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/Notion.Client/Models/Page/Page.cs b/Src/Notion.Client/Models/Page/Page.cs index a429d92d..d96fef8a 100644 --- a/Src/Notion.Client/Models/Page/Page.cs +++ b/Src/Notion.Client/Models/Page/Page.cs @@ -44,7 +44,7 @@ public class Page : IObject, IObjectModificationData /// Property values of this page. /// [JsonProperty("properties")] - public IDictionary Properties { get; set; } + public IDictionary Properties { get; set; } /// /// The URL of the Notion page. From 273e11ceec0744b7d260b6c9345f6e40457bf397 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sun, 11 Sep 2022 01:32:47 +0530 Subject: [PATCH 097/216] fix RichTextPropertyItem parsing --- .../Models/PropertyItems/RichTextPropertyItem.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Src/Notion.Client/Models/PropertyItems/RichTextPropertyItem.cs b/Src/Notion.Client/Models/PropertyItems/RichTextPropertyItem.cs index 513b7300..f9ce925a 100644 --- a/Src/Notion.Client/Models/PropertyItems/RichTextPropertyItem.cs +++ b/Src/Notion.Client/Models/PropertyItems/RichTextPropertyItem.cs @@ -1,9 +1,12 @@ -namespace Notion.Client +using Newtonsoft.Json; + +namespace Notion.Client { public class RichTextPropertyItem : SimplePropertyItem { public override string Type => "rich_text"; + [JsonProperty("rich_text")] public RichTextBase RichText { get; set; } } } From bd5054d9d88bbc4e42899ff0950e9d65f06b170a Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sun, 11 Sep 2022 01:43:23 +0530 Subject: [PATCH 098/216] fix broken integration tests --- Test/Notion.IntegrationTests/IPageClientTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Test/Notion.IntegrationTests/IPageClientTests.cs b/Test/Notion.IntegrationTests/IPageClientTests.cs index acdab301..dbf74a90 100644 --- a/Test/Notion.IntegrationTests/IPageClientTests.cs +++ b/Test/Notion.IntegrationTests/IPageClientTests.cs @@ -53,7 +53,7 @@ public async Task CreateAsync_CreatesANewPage() .DatabaseId.Should().Be(_databaseId); page.Properties.Should().ContainKey("Name"); - var pageProperty = page.Properties["Name"].Should().BeOfType().Subject; + var pageProperty = page.Properties["Name"].Should().BeOfType().Subject; var titleProperty = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters { @@ -105,7 +105,7 @@ public async Task Bug_unable_to_create_page_with_select_property() .DatabaseId.Should().Be(_databaseId); page.Properties.Should().ContainKey("Name"); - var pageProperty = page.Properties["Name"].Should().BeOfType().Subject; + var pageProperty = page.Properties["Name"].Should().BeOfType().Subject; var titleProperty = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters { From bf9aac56615623e0dbbd53abf49cc46e3a89b4e5 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Thu, 15 Sep 2022 01:28:44 +0530 Subject: [PATCH 099/216] Add support for link_preview block type --- Src/Notion.Client/Models/Blocks/BlockType.cs | 3 +++ Src/Notion.Client/Models/Blocks/IBlock.cs | 1 + .../Models/Blocks/LinkPreviewBlock.cs | 16 ++++++++++++++++ 3 files changed, 20 insertions(+) create mode 100644 Src/Notion.Client/Models/Blocks/LinkPreviewBlock.cs diff --git a/Src/Notion.Client/Models/Blocks/BlockType.cs b/Src/Notion.Client/Models/Blocks/BlockType.cs index f3181b22..8a2c626a 100644 --- a/Src/Notion.Client/Models/Blocks/BlockType.cs +++ b/Src/Notion.Client/Models/Blocks/BlockType.cs @@ -97,6 +97,9 @@ public enum BlockType [EnumMember(Value = "table_row")] TableRow, + [EnumMember(Value = "link_preview")] + LinkPreview, + [EnumMember(Value = "unsupported")] Unsupported } diff --git a/Src/Notion.Client/Models/Blocks/IBlock.cs b/Src/Notion.Client/Models/Blocks/IBlock.cs index 70cd9755..a09f923a 100644 --- a/Src/Notion.Client/Models/Blocks/IBlock.cs +++ b/Src/Notion.Client/Models/Blocks/IBlock.cs @@ -23,6 +23,7 @@ namespace Notion.Client [JsonSubtypes.KnownSubType(typeof(HeadingTwoBlock), BlockType.Heading_2)] [JsonSubtypes.KnownSubType(typeof(HeadingThreeeBlock), BlockType.Heading_3)] [JsonSubtypes.KnownSubType(typeof(ImageBlock), BlockType.Image)] + [JsonSubtypes.KnownSubType(typeof(LinkPreviewBlock), BlockType.LinkPreview)] [JsonSubtypes.KnownSubType(typeof(LinkToPageBlock), BlockType.LinkToPage)] [JsonSubtypes.KnownSubType(typeof(NumberedListItemBlock), BlockType.NumberedListItem)] [JsonSubtypes.KnownSubType(typeof(ParagraphBlock), BlockType.Paragraph)] diff --git a/Src/Notion.Client/Models/Blocks/LinkPreviewBlock.cs b/Src/Notion.Client/Models/Blocks/LinkPreviewBlock.cs new file mode 100644 index 00000000..83f138c6 --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/LinkPreviewBlock.cs @@ -0,0 +1,16 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class LinkPreviewBlock : Block, IColumnChildrenBlock, INonColumnBlock + { + public override BlockType Type => BlockType.LinkPreview; + + [JsonProperty("link_preview")] public Data LinkPreview { get; set; } + + public class Data + { + [JsonProperty("url")] public string Url { get; set; } + } + } +} From 421f407aa3eceb98a3bd5d3b8958f160d497baa9 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sun, 18 Sep 2022 23:45:41 +0530 Subject: [PATCH 100/216] Add StatusPropertyItem --- .../Models/PropertyItems/SimplePropertyItem.cs | 4 +++- .../Models/PropertyItems/StatusPropertyItem.cs | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 Src/Notion.Client/Models/PropertyItems/StatusPropertyItem.cs diff --git a/Src/Notion.Client/Models/PropertyItems/SimplePropertyItem.cs b/Src/Notion.Client/Models/PropertyItems/SimplePropertyItem.cs index da753319..baf991bb 100644 --- a/Src/Notion.Client/Models/PropertyItems/SimplePropertyItem.cs +++ b/Src/Notion.Client/Models/PropertyItems/SimplePropertyItem.cs @@ -1,4 +1,5 @@ -using JsonSubTypes; +using System.Collections; +using JsonSubTypes; using Newtonsoft.Json; namespace Notion.Client @@ -8,6 +9,7 @@ namespace Notion.Client [JsonSubtypes.KnownSubType(typeof(UrlPropertyItem), "url")] [JsonSubtypes.KnownSubType(typeof(SelectPropertyItem), "select")] [JsonSubtypes.KnownSubType(typeof(MultiSelectPropertyItem), "multi_select")] + [JsonSubtypes.KnownSubType(typeof(StatusPropertyItem), "status")] [JsonSubtypes.KnownSubType(typeof(DatePropertyItem), "date")] [JsonSubtypes.KnownSubType(typeof(EmailPropertyItem), "email")] [JsonSubtypes.KnownSubType(typeof(PhoneNumberPropertyItem), "phone_number")] diff --git a/Src/Notion.Client/Models/PropertyItems/StatusPropertyItem.cs b/Src/Notion.Client/Models/PropertyItems/StatusPropertyItem.cs new file mode 100644 index 00000000..46e70108 --- /dev/null +++ b/Src/Notion.Client/Models/PropertyItems/StatusPropertyItem.cs @@ -0,0 +1,11 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class StatusPropertyItem : SimplePropertyItem + { + public override string Type => "status"; + + [JsonProperty("status")] public SelectOption Status { get; set; } + } +} From e8404c8cbcdd5d92f9b14974b43b58ac21c4b695 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sun, 18 Sep 2022 23:49:10 +0530 Subject: [PATCH 101/216] Add RollupPropertyItem type --- .../PropertyItems/RollupPropertyItem.cs | 29 +++++++++++++++++++ .../PropertyItems/SimplePropertyItem.cs | 4 +-- 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 Src/Notion.Client/Models/PropertyItems/RollupPropertyItem.cs diff --git a/Src/Notion.Client/Models/PropertyItems/RollupPropertyItem.cs b/Src/Notion.Client/Models/PropertyItems/RollupPropertyItem.cs new file mode 100644 index 00000000..3df75fd7 --- /dev/null +++ b/Src/Notion.Client/Models/PropertyItems/RollupPropertyItem.cs @@ -0,0 +1,29 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class RollupPropertyItem : SimplePropertyItem + { + public override string Type => "rollup"; + + [JsonProperty("rollup")] public Data Rollup { get; set; } + + public class Data + { + [JsonProperty("type")] public string Type { get; set; } + + [JsonProperty("function")] public string Function { get; set; } + + [JsonProperty("number")] public double? Number { get; set; } + + [JsonProperty("date")] public Date Date { get; set; } + + [JsonProperty("array")] public IEnumerable> Array { get; set; } + + [JsonProperty("unsupported")] public Dictionary Unsupported { get; set; } + + [JsonProperty("incomplete")] public Dictionary Incomplete { get; set; } + } + } +} diff --git a/Src/Notion.Client/Models/PropertyItems/SimplePropertyItem.cs b/Src/Notion.Client/Models/PropertyItems/SimplePropertyItem.cs index baf991bb..50d95184 100644 --- a/Src/Notion.Client/Models/PropertyItems/SimplePropertyItem.cs +++ b/Src/Notion.Client/Models/PropertyItems/SimplePropertyItem.cs @@ -1,5 +1,4 @@ -using System.Collections; -using JsonSubTypes; +using JsonSubTypes; using Newtonsoft.Json; namespace Notion.Client @@ -24,6 +23,7 @@ namespace Notion.Client [JsonSubtypes.KnownSubType(typeof(RichTextPropertyItem), "rich_text")] [JsonSubtypes.KnownSubType(typeof(PeoplePropertyItem), "people")] [JsonSubtypes.KnownSubType(typeof(RelationPropertyItem), "relation")] + [JsonSubtypes.KnownSubType(typeof(RollupPropertyItem), "rollup")] public abstract class SimplePropertyItem : IPropertyItemObject { public string Object => "property_item"; From 5d67e3a59b2b2408ab6e18fb7b6b7c82d18a32a1 Mon Sep 17 00:00:00 2001 From: Jako Menkveld Date: Wed, 28 Sep 2022 13:32:54 +0200 Subject: [PATCH 102/216] Added StatusFilter --- .../Models/Filters/StatusFilter.cs | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Src/Notion.Client/Models/Filters/StatusFilter.cs diff --git a/Src/Notion.Client/Models/Filters/StatusFilter.cs b/Src/Notion.Client/Models/Filters/StatusFilter.cs new file mode 100644 index 00000000..7ed9b23f --- /dev/null +++ b/Src/Notion.Client/Models/Filters/StatusFilter.cs @@ -0,0 +1,53 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class StatusFilter : SinglePropertyFilter, IRollupSubPropertyFilter + { + [JsonProperty("status")] + public Condition Status { get; set; } + + public StatusFilter( + string propertyName, + string equal = null, + string doesNotEqual = null, + bool? isEmpty = null, + bool? isNotEmpty = null) + { + Property = propertyName; + Status = new Condition( + equal: equal, + doesNotEqual: doesNotEqual, + isEmpty: isEmpty, + isNotEmpty: isNotEmpty + ); + } + + public class Condition + { + [JsonProperty("equals")] + public string Equal { get; set; } + + [JsonProperty("does_not_equal")] + public string DoesNotEqual { get; set; } + + [JsonProperty("is_empty")] + public bool? IsEmpty { get; set; } + + [JsonProperty("is_not_empty")] + public bool? IsNotEmpty { get; set; } + + public Condition( + string equal = null, + string doesNotEqual = null, + bool? isEmpty = null, + bool? isNotEmpty = null) + { + Equal = equal; + DoesNotEqual = doesNotEqual; + IsEmpty = isEmpty; + IsNotEmpty = isNotEmpty; + } + } + } +} From 2c8f803243066f2f4fff8985a3e858d82132d14d Mon Sep 17 00:00:00 2001 From: Vincius Beloni Date: Tue, 4 Oct 2022 02:56:43 -0300 Subject: [PATCH 103/216] upgrade Microsoft.SourceLink.GitHub version --- Src/Notion.Client/Notion.Client.csproj | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Src/Notion.Client/Notion.Client.csproj b/Src/Notion.Client/Notion.Client.csproj index 9b2d51f7..048db729 100644 --- a/Src/Notion.Client/Notion.Client.csproj +++ b/Src/Notion.Client/Notion.Client.csproj @@ -16,8 +16,7 @@ - - all + runtime; build; native; contentfiles; analyzers; buildtransitive From 84d0bd8180d4dafae33c581ee7e14a790638c801 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Wed, 5 Oct 2022 21:09:10 +0530 Subject: [PATCH 104/216] =?UTF-8?q?Add=20jetbrains.resharper.globaltools?= =?UTF-8?q?=20=E2=9E=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .config/dotnet-tools.json | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .config/dotnet-tools.json diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json new file mode 100644 index 00000000..92211a4f --- /dev/null +++ b/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "jetbrains.resharper.globaltools": { + "version": "2022.2.3", + "commands": [ + "jb" + ] + } + } +} \ No newline at end of file From 9e1664ecef0d0fae9abe4397522ff605b98d33ce Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Wed, 5 Oct 2022 22:06:45 +0530 Subject: [PATCH 105/216] Updated editorconfig file --- .editorconfig | 291 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 273 insertions(+), 18 deletions(-) diff --git a/.editorconfig b/.editorconfig index f8d20ed2..7e8f258c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,11 +1,261 @@ +root = true # EditorConfig is awesome: https://EditorConfig.org # top-most EditorConfig file -root = true # Don't use tabs for indentation. [*] indent_style = space + +[*.cs] +# Microsoft .NET properties +csharp_preferred_modifier_order = public, private, protected, internal, new, static, abstract, virtual, sealed, readonly, override, extern, unsafe, volatile, async:suggestion +csharp_style_var_elsewhere = true:suggestion +csharp_style_var_for_built_in_types = true:suggestion +csharp_style_var_when_type_is_apparent = true:suggestion +dotnet_naming_rule.constants_rule.import_to_resharper = as_predefined +dotnet_naming_rule.constants_rule.resharper_style = AaBb, _ + aaBb +dotnet_naming_rule.constants_rule.severity = suggestion +dotnet_naming_rule.constants_rule.style = upper_camel_case_style +dotnet_naming_rule.constants_rule.symbols = constants_symbols +dotnet_naming_rule.constants_should_be_pascal_case_rule.import_to_resharper = True +dotnet_naming_rule.constants_should_be_pascal_case_rule.resharper_description = constants_should_be_pascal_case +dotnet_naming_rule.constants_should_be_pascal_case_rule.resharper_guid = a0135172-b297-46cb-bb0f-b1f267109d7b +dotnet_naming_rule.constants_should_be_pascal_case_rule.severity = suggestion +dotnet_naming_rule.constants_should_be_pascal_case_rule.style = upper_camel_case_style +dotnet_naming_rule.constants_should_be_pascal_case_rule.symbols = constants_should_be_pascal_case_symbols +dotnet_naming_rule.constants_should_be_pascal_case_rule_1.import_to_resharper = False +dotnet_naming_rule.constants_should_be_pascal_case_rule_1.severity = suggestion +dotnet_naming_rule.constants_should_be_pascal_case_rule_1.style = upper_camel_case_style +dotnet_naming_rule.constants_should_be_pascal_case_rule_1.symbols = constants_should_be_pascal_case_symbols_1 +dotnet_naming_rule.instance_fields_should_be_camel_case_rule.import_to_resharper = True +dotnet_naming_rule.instance_fields_should_be_camel_case_rule.resharper_description = instance_fields_should_be_camel_case +dotnet_naming_rule.instance_fields_should_be_camel_case_rule.resharper_guid = ed8be1d2-8aa4-45a9-a0fe-964e144ccec7 +dotnet_naming_rule.instance_fields_should_be_camel_case_rule.severity = suggestion +dotnet_naming_rule.instance_fields_should_be_camel_case_rule.style = lower_camel_case_style +dotnet_naming_rule.instance_fields_should_be_camel_case_rule.symbols = instance_fields_should_be_camel_case_symbols +dotnet_naming_rule.interfaces_rule.import_to_resharper = as_predefined +dotnet_naming_rule.interfaces_rule.severity = suggestion +dotnet_naming_rule.interfaces_rule.style = upper_camel_case_style +dotnet_naming_rule.interfaces_rule.symbols = interfaces_symbols +dotnet_naming_rule.locals_should_be_camel_case_rule.import_to_resharper = True +dotnet_naming_rule.locals_should_be_camel_case_rule.resharper_description = locals_should_be_camel_case +dotnet_naming_rule.locals_should_be_camel_case_rule.resharper_guid = dd900f14-6d42-4a58-8277-056e5dab89e7 +dotnet_naming_rule.locals_should_be_camel_case_rule.severity = suggestion +dotnet_naming_rule.locals_should_be_camel_case_rule.style = lower_camel_case_style_1 +dotnet_naming_rule.locals_should_be_camel_case_rule.symbols = locals_should_be_camel_case_symbols +dotnet_naming_rule.local_constants_rule.import_to_resharper = as_predefined +dotnet_naming_rule.local_constants_rule.resharper_style = AaBb, aaBb +dotnet_naming_rule.local_constants_rule.severity = suggestion +dotnet_naming_rule.local_constants_rule.style = upper_camel_case_style +dotnet_naming_rule.local_constants_rule.symbols = local_constants_symbols +dotnet_naming_rule.local_functions_should_be_pascal_case_rule.import_to_resharper = True +dotnet_naming_rule.local_functions_should_be_pascal_case_rule.resharper_description = local_functions_should_be_pascal_case +dotnet_naming_rule.local_functions_should_be_pascal_case_rule.resharper_guid = 67e7ac04-3277-4549-b0bb-98cbfad21765 +dotnet_naming_rule.local_functions_should_be_pascal_case_rule.severity = suggestion +dotnet_naming_rule.local_functions_should_be_pascal_case_rule.style = upper_camel_case_style +dotnet_naming_rule.local_functions_should_be_pascal_case_rule.symbols = local_functions_should_be_pascal_case_symbols +dotnet_naming_rule.members_should_be_pascal_case_rule.import_to_resharper = True +dotnet_naming_rule.members_should_be_pascal_case_rule.resharper_description = members_should_be_pascal_case +dotnet_naming_rule.members_should_be_pascal_case_rule.resharper_guid = 605fba47-8912-494e-9e4c-98aeb57fd884 +dotnet_naming_rule.members_should_be_pascal_case_rule.severity = suggestion +dotnet_naming_rule.members_should_be_pascal_case_rule.style = upper_camel_case_style +dotnet_naming_rule.members_should_be_pascal_case_rule.symbols = members_should_be_pascal_case_symbols +dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case_rule.import_to_resharper = True +dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case_rule.resharper_description = non_private_readonly_fields_should_be_pascal_case +dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case_rule.resharper_guid = e8e1b724-94dd-4cbe-9385-85343fea2b41 +dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case_rule.severity = suggestion +dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case_rule.style = upper_camel_case_style +dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case_rule.symbols = non_private_readonly_fields_should_be_pascal_case_symbols +dotnet_naming_rule.non_private_static_fields_should_be_pascal_case_rule.import_to_resharper = True +dotnet_naming_rule.non_private_static_fields_should_be_pascal_case_rule.resharper_description = non_private_static_fields_should_be_pascal_case +dotnet_naming_rule.non_private_static_fields_should_be_pascal_case_rule.resharper_guid = 51051115-1f5e-4eea-aa9d-2eac02e9b082 +dotnet_naming_rule.non_private_static_fields_should_be_pascal_case_rule.severity = suggestion +dotnet_naming_rule.non_private_static_fields_should_be_pascal_case_rule.style = upper_camel_case_style +dotnet_naming_rule.non_private_static_fields_should_be_pascal_case_rule.symbols = non_private_static_fields_should_be_pascal_case_symbols +dotnet_naming_rule.private_constants_rule.import_to_resharper = as_predefined +dotnet_naming_rule.private_constants_rule.resharper_style = AaBb, _ + aaBb +dotnet_naming_rule.private_constants_rule.severity = suggestion +dotnet_naming_rule.private_constants_rule.style = upper_camel_case_style +dotnet_naming_rule.private_constants_rule.symbols = private_constants_symbols +dotnet_naming_rule.private_static_fields_rule.import_to_resharper = as_predefined +dotnet_naming_rule.private_static_fields_rule.severity = suggestion +dotnet_naming_rule.private_static_fields_rule.style = s_lower_camel_case_style +dotnet_naming_rule.private_static_fields_rule.symbols = private_static_fields_symbols +dotnet_naming_rule.private_static_readonly_rule.import_to_resharper = as_predefined +dotnet_naming_rule.private_static_readonly_rule.severity = suggestion +dotnet_naming_rule.private_static_readonly_rule.style = s_lower_camel_case_style +dotnet_naming_rule.private_static_readonly_rule.symbols = private_static_readonly_symbols +dotnet_naming_rule.public_fields_rule.import_to_resharper = as_predefined +dotnet_naming_rule.public_fields_rule.severity = suggestion +dotnet_naming_rule.public_fields_rule.style = lower_camel_case_style +dotnet_naming_rule.public_fields_rule.symbols = public_fields_symbols +dotnet_naming_rule.static_fields_should_be_camel_case_rule.import_to_resharper = True +dotnet_naming_rule.static_fields_should_be_camel_case_rule.resharper_description = static_fields_should_be_camel_case +dotnet_naming_rule.static_fields_should_be_camel_case_rule.resharper_guid = f286ec29-34ab-4806-9c8a-586f11eedd52 +dotnet_naming_rule.static_fields_should_be_camel_case_rule.severity = suggestion +dotnet_naming_rule.static_fields_should_be_camel_case_rule.style = s_lower_camel_case_style +dotnet_naming_rule.static_fields_should_be_camel_case_rule.symbols = static_fields_should_be_camel_case_symbols +dotnet_naming_rule.static_readonly_rule.import_to_resharper = as_predefined +dotnet_naming_rule.static_readonly_rule.resharper_style = AaBb, s_ + aaBb +dotnet_naming_rule.static_readonly_rule.severity = suggestion +dotnet_naming_rule.static_readonly_rule.style = upper_camel_case_style +dotnet_naming_rule.static_readonly_rule.symbols = static_readonly_symbols +dotnet_naming_rule.type_parameters_rule.import_to_resharper = as_predefined +dotnet_naming_rule.type_parameters_rule.severity = suggestion +dotnet_naming_rule.type_parameters_rule.style = upper_camel_case_style +dotnet_naming_rule.type_parameters_rule.symbols = type_parameters_symbols +dotnet_naming_style.lower_camel_case_style.capitalization = camel_case +dotnet_naming_style.lower_camel_case_style.required_prefix = _ +dotnet_naming_style.lower_camel_case_style_1.capitalization = camel_case +dotnet_naming_style.s_lower_camel_case_style.capitalization = camel_case +dotnet_naming_style.s_lower_camel_case_style.required_prefix = s_ +dotnet_naming_style.upper_camel_case_style.capitalization = pascal_case +dotnet_naming_symbols.constants_should_be_pascal_case_symbols.applicable_accessibilities = local,public,internal,private,protected,protected_internal,private_protected +dotnet_naming_symbols.constants_should_be_pascal_case_symbols.applicable_kinds = local +dotnet_naming_symbols.constants_should_be_pascal_case_symbols.required_modifiers = const +dotnet_naming_symbols.constants_should_be_pascal_case_symbols.resharper_applicable_kinds = constant_field,local_constant +dotnet_naming_symbols.constants_should_be_pascal_case_symbols.resharper_required_modifiers = any +dotnet_naming_symbols.constants_should_be_pascal_case_symbols_1.applicable_accessibilities = local,public,internal,private,protected,protected_internal,private_protected +dotnet_naming_symbols.constants_should_be_pascal_case_symbols_1.applicable_kinds = field +dotnet_naming_symbols.constants_should_be_pascal_case_symbols_1.required_modifiers = const +dotnet_naming_symbols.constants_symbols.applicable_accessibilities = public,internal,protected,protected_internal,private_protected +dotnet_naming_symbols.constants_symbols.applicable_kinds = field +dotnet_naming_symbols.constants_symbols.required_modifiers = const +dotnet_naming_symbols.instance_fields_should_be_camel_case_symbols.applicable_accessibilities = local,public,internal,private,protected,protected_internal,private_protected +dotnet_naming_symbols.instance_fields_should_be_camel_case_symbols.applicable_kinds = field +dotnet_naming_symbols.instance_fields_should_be_camel_case_symbols.resharper_applicable_kinds = any_field +dotnet_naming_symbols.instance_fields_should_be_camel_case_symbols.resharper_required_modifiers = any +dotnet_naming_symbols.interfaces_symbols.applicable_accessibilities = * +dotnet_naming_symbols.interfaces_symbols.applicable_kinds = interface +dotnet_naming_symbols.locals_should_be_camel_case_symbols.applicable_accessibilities = local,public,internal,private,protected,protected_internal,private_protected +dotnet_naming_symbols.locals_should_be_camel_case_symbols.applicable_kinds = parameter,local +dotnet_naming_symbols.locals_should_be_camel_case_symbols.resharper_applicable_kinds = parameter,local +dotnet_naming_symbols.locals_should_be_camel_case_symbols.resharper_required_modifiers = any +dotnet_naming_symbols.local_constants_symbols.applicable_accessibilities = * +dotnet_naming_symbols.local_constants_symbols.applicable_kinds = local +dotnet_naming_symbols.local_constants_symbols.required_modifiers = const +dotnet_naming_symbols.local_functions_should_be_pascal_case_symbols.applicable_accessibilities = local,public,internal,private,protected,protected_internal,private_protected +dotnet_naming_symbols.local_functions_should_be_pascal_case_symbols.applicable_kinds = local_function +dotnet_naming_symbols.local_functions_should_be_pascal_case_symbols.resharper_applicable_kinds = local_function +dotnet_naming_symbols.local_functions_should_be_pascal_case_symbols.resharper_required_modifiers = any +dotnet_naming_symbols.members_should_be_pascal_case_symbols.applicable_accessibilities = local,public,internal,private,protected,protected_internal,private_protected +dotnet_naming_symbols.members_should_be_pascal_case_symbols.applicable_kinds = namespace,class,struct,interface,enum,property,method,field,event,delegate,parameter,type_parameter,local,local_function +dotnet_naming_symbols.members_should_be_pascal_case_symbols.resharper_applicable_kinds = namespace,class,struct,interface,enum,property,method,any_field,event,delegate,parameter,type_parameter,local,local_function +dotnet_naming_symbols.members_should_be_pascal_case_symbols.resharper_required_modifiers = any +dotnet_naming_symbols.non_private_readonly_fields_should_be_pascal_case_symbols.applicable_accessibilities = local,public,internal,protected,protected_internal,private_protected +dotnet_naming_symbols.non_private_readonly_fields_should_be_pascal_case_symbols.applicable_kinds = field +dotnet_naming_symbols.non_private_readonly_fields_should_be_pascal_case_symbols.required_modifiers = readonly +dotnet_naming_symbols.non_private_readonly_fields_should_be_pascal_case_symbols.resharper_applicable_kinds = readonly_field +dotnet_naming_symbols.non_private_readonly_fields_should_be_pascal_case_symbols.resharper_required_modifiers = any +dotnet_naming_symbols.non_private_static_fields_should_be_pascal_case_symbols.applicable_accessibilities = local,public,internal,protected,protected_internal,private_protected +dotnet_naming_symbols.non_private_static_fields_should_be_pascal_case_symbols.applicable_kinds = field +dotnet_naming_symbols.non_private_static_fields_should_be_pascal_case_symbols.required_modifiers = static +dotnet_naming_symbols.non_private_static_fields_should_be_pascal_case_symbols.resharper_applicable_kinds = any_field +dotnet_naming_symbols.non_private_static_fields_should_be_pascal_case_symbols.resharper_required_modifiers = static +dotnet_naming_symbols.private_constants_symbols.applicable_accessibilities = private +dotnet_naming_symbols.private_constants_symbols.applicable_kinds = field +dotnet_naming_symbols.private_constants_symbols.required_modifiers = const +dotnet_naming_symbols.private_static_fields_symbols.applicable_accessibilities = private +dotnet_naming_symbols.private_static_fields_symbols.applicable_kinds = field +dotnet_naming_symbols.private_static_fields_symbols.required_modifiers = static +dotnet_naming_symbols.private_static_readonly_symbols.applicable_accessibilities = private +dotnet_naming_symbols.private_static_readonly_symbols.applicable_kinds = field +dotnet_naming_symbols.private_static_readonly_symbols.required_modifiers = static,readonly +dotnet_naming_symbols.public_fields_symbols.applicable_accessibilities = public,internal,protected,protected_internal,private_protected +dotnet_naming_symbols.public_fields_symbols.applicable_kinds = field +dotnet_naming_symbols.static_fields_should_be_camel_case_symbols.applicable_accessibilities = local,public,internal,private,protected,protected_internal,private_protected +dotnet_naming_symbols.static_fields_should_be_camel_case_symbols.applicable_kinds = field +dotnet_naming_symbols.static_fields_should_be_camel_case_symbols.required_modifiers = static +dotnet_naming_symbols.static_fields_should_be_camel_case_symbols.resharper_applicable_kinds = any_field +dotnet_naming_symbols.static_fields_should_be_camel_case_symbols.resharper_required_modifiers = static +dotnet_naming_symbols.static_readonly_symbols.applicable_accessibilities = public,internal,protected,protected_internal,private_protected +dotnet_naming_symbols.static_readonly_symbols.applicable_kinds = field +dotnet_naming_symbols.static_readonly_symbols.required_modifiers = static,readonly +dotnet_naming_symbols.type_parameters_symbols.applicable_accessibilities = * +dotnet_naming_symbols.type_parameters_symbols.applicable_kinds = type_parameter +dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary:none +dotnet_style_parentheses_in_other_binary_operators = never_if_unnecessary:none +dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary:none +dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion +dotnet_style_predefined_type_for_member_access = true:suggestion +dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion + +# ReSharper properties +# resharper_arguments_anonymous_function = named +# resharper_arguments_literal = named +# resharper_arguments_named = named +# resharper_arguments_other = named +# resharper_arguments_string_literal = named +resharper_blank_lines_after_control_transfer_statements = 1 +resharper_blank_lines_after_multiline_statements = 1 +resharper_blank_lines_around_single_line_auto_property = 1 +resharper_blank_lines_around_single_line_local_method = 1 +resharper_blank_lines_around_single_line_property = 1 +resharper_blank_lines_before_block_statements = 1 +resharper_blank_lines_before_control_transfer_statements = 1 +resharper_blank_lines_before_multiline_statements = 1 +resharper_blank_lines_before_single_line_comment = 1 +resharper_braces_for_for = required +resharper_braces_for_foreach = required +resharper_braces_for_ifelse = required +resharper_braces_for_while = required +resharper_braces_redundant = false +resharper_case_block_braces = next_line_shifted_2 +resharper_csharp_blank_lines_around_single_line_invocable = 1 +resharper_csharp_keep_blank_lines_in_code = 1 +resharper_csharp_keep_blank_lines_in_declarations = 1 +resharper_csharp_wrap_after_declaration_lpar = true +resharper_csharp_wrap_extends_list_style = chop_if_long +resharper_csharp_wrap_parameters_style = chop_if_long +resharper_indent_nested_fixed_stmt = true +resharper_indent_nested_foreach_stmt = true +resharper_indent_nested_for_stmt = true +resharper_indent_nested_lock_stmt = true +resharper_indent_nested_usings_stmt = true +resharper_indent_nested_while_stmt = true +resharper_keep_existing_declaration_block_arrangement = true +resharper_keep_existing_declaration_parens_arrangement = false +resharper_keep_existing_embedded_block_arrangement = true +resharper_keep_existing_enum_arrangement = true +resharper_keep_existing_expr_member_arrangement = false +resharper_keep_existing_initializer_arrangement = false +resharper_local_function_body = expression_body +resharper_max_enum_members_on_line = 1 +resharper_max_formal_parameters_on_line = 4 +resharper_place_field_attribute_on_same_line = if_owner_is_single_line +resharper_space_within_single_line_array_initializer_braces = false +resharper_trailing_comma_in_multiline_lists = true +resharper_use_heuristics_for_body_style = false +resharper_use_indent_from_vs = false +resharper_wrap_before_eq = true +resharper_wrap_before_first_type_parameter_constraint = true + +# ReSharper inspection severities +resharper_arrange_accessor_owner_body_highlighting = none +resharper_arrange_local_function_body_highlighting = suggestion +resharper_arrange_namespace_body_highlighting = suggestion +resharper_arrange_redundant_parentheses_highlighting = hint +resharper_arrange_this_qualifier_highlighting = none +resharper_arrange_type_member_modifiers_highlighting = hint +resharper_arrange_type_modifiers_highlighting = hint +resharper_built_in_type_reference_style_for_member_access_highlighting = suggestion +resharper_built_in_type_reference_style_highlighting = suggestion +resharper_inconsistent_naming_highlighting = suggestion +resharper_redundant_base_qualifier_highlighting = none +resharper_suggest_var_or_type_built_in_types_highlighting = suggestion +resharper_suggest_var_or_type_elsewhere_highlighting = suggestion +resharper_suggest_var_or_type_simple_types_highlighting = suggestion + +resharper_csharp_force_attribute_style=separate +resharper_csharp_method_or_operator_body=expression_body +resharper_csharp_max_enum_members_on_line=1 +resharper_csharp_place_attribute_on_same_line=false +resharper_csharp_wrap_object_and_collection_initializer_style=chop_always +resharper_csharp_use_heuristics_for_body_style=true + +# Standard properties +insert_final_newline = true # (Please don't specify an indent_size here; that has too many unintended consequences.) # Code files @@ -39,7 +289,7 @@ indent_size = 2 [*.{cs,vb}] # IDE0055: Fix formatting -dotnet_diagnostic.IDE0055.severity = warning +dotnet_diagnostic.ide0055.severity = warning # Sort using and Import directives with System.* appearing first dotnet_sort_system_directives_first = true @@ -143,23 +393,23 @@ dotnet_naming_symbols.all_members.applicable_kinds = * dotnet_naming_style.pascal_case_style.capitalization = pascal_case # error RS2008: Enable analyzer release tracking for the analyzer project containing rule '{0}' -dotnet_diagnostic.RS2008.severity = none +dotnet_diagnostic.rs2008.severity = none # IDE0073: File header # dotnet_diagnostic.IDE0073.severity = warning # file_header_template = # IDE0035: Remove unreachable code -dotnet_diagnostic.IDE0035.severity = warning +dotnet_diagnostic.ide0035.severity = warning # IDE0036: Order modifiers -dotnet_diagnostic.IDE0036.severity = warning +dotnet_diagnostic.ide0036.severity = warning # IDE0043: Format string contains invalid placeholder -dotnet_diagnostic.IDE0043.severity = warning +dotnet_diagnostic.ide0043.severity = warning # IDE0044: Make field readonly -dotnet_diagnostic.IDE0044.severity = warning +dotnet_diagnostic.ide0044.severity = warning # RS0016: Only enable if API files are present dotnet_public_api_analyzer.require_api_files = true @@ -236,39 +486,39 @@ csharp_preserve_single_line_statements = true [src/CodeStyle/**.{cs,vb}] # warning RS0005: Do not use generic CodeAction.Create to create CodeAction -dotnet_diagnostic.RS0005.severity = none +dotnet_diagnostic.rs0005.severity = none [src/{Analyzers,CodeStyle,Features,Workspaces,EditorFeatures,VisualStudio}/**/*.{cs,vb}] # IDE0011: Add braces csharp_prefer_braces = when_multiline:warning # NOTE: We need the below severity entry for Add Braces due to https://github.com/dotnet/roslyn/issues/44201 -dotnet_diagnostic.IDE0011.severity = warning +dotnet_diagnostic.ide0011.severity = warning # IDE0040: Add accessibility modifiers -dotnet_diagnostic.IDE0040.severity = warning +dotnet_diagnostic.ide0040.severity = warning # CONSIDER: Are IDE0051 and IDE0052 too noisy to be warnings for IDE editing scenarios? Should they be made build-only warnings? # IDE0051: Remove unused private member -dotnet_diagnostic.IDE0051.severity = warning +dotnet_diagnostic.ide0051.severity = warning # IDE0052: Remove unread private member -dotnet_diagnostic.IDE0052.severity = warning +dotnet_diagnostic.ide0052.severity = warning # IDE0059: Unnecessary assignment to a value -dotnet_diagnostic.IDE0059.severity = warning +dotnet_diagnostic.ide0059.severity = warning # IDE0060: Remove unused parameter -dotnet_diagnostic.IDE0060.severity = warning +dotnet_diagnostic.ide0060.severity = warning # CA1012: Abstract types should not have public constructors -dotnet_diagnostic.CA1012.severity = warning +dotnet_diagnostic.ca1012.severity = warning # CA1822: Make member static -dotnet_diagnostic.CA1822.severity = warning +dotnet_diagnostic.ca1822.severity = warning # Prefer "var" everywhere -dotnet_diagnostic.IDE0007.severity = warning +dotnet_diagnostic.ide0007.severity = warning csharp_style_var_for_built_in_types = true:warning csharp_style_var_when_type_is_apparent = true:warning csharp_style_var_elsewhere = true:warning @@ -277,4 +527,9 @@ csharp_style_var_elsewhere = true:warning # CA1822: Make member static # Not enforced as a build 'warning' for 'VisualStudio' layer due to large number of false positives from https://github.com/dotnet/roslyn-analyzers/issues/3857 and https://github.com/dotnet/roslyn-analyzers/issues/3858 # Additionally, there is a risk of accidentally breaking an internal API that partners rely on though IVT. -dotnet_diagnostic.CA1822.severity = suggestion \ No newline at end of file +dotnet_diagnostic.ca1822.severity = suggestion + +[*.{appxmanifest,asax,ascx,aspx,axaml,axml,build,config,cs,cshtml,csproj,css,dbml,discomap,dtd,htm,html,js,json,jsproj,jsx,lsproj,master,njsproj,nuspec,paml,proj,props,proto,razor,resjson,resw,resx,skin,StyleCop,targets,tasks,ts,tsx,vb,vbproj,xaml,xamlx,xml,xoml,xsd}] +indent_style = space +indent_size = 4 +tab_width = 4 From af6b1af7b6f5d90b4c0f5d80bb7f038a9892ffd5 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Wed, 5 Oct 2022 22:08:51 +0530 Subject: [PATCH 106/216] =?UTF-8?q?Run=20solution=20wide=20linter=20?= =?UTF-8?q?=F0=9F=9A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Notion.Client/Api/ApiEndpoints.cs | 124 ++- Src/Notion.Client/Api/Blocks/BlocksClient.cs | 14 +- Src/Notion.Client/Api/Blocks/IBlocksClient.cs | 16 +- .../BlocksRetrieveChildrenParameters.cs | 1 + .../UpdateBlocks/AudioUpdateBlock.cs | 3 +- .../UpdateBlocks/BookmarkUpdateBlock.cs | 4 +- .../UpdateBlocks/BreadcrumbUpdateBlock.cs | 12 +- .../UpdateBlocks/DividerUpdateBlock.cs | 12 +- .../TableOfContentsUpdateBlock.cs | 12 +- .../Create/Request/CreateCommentParameters.cs | 22 +- .../Api/Comments/ICommentsClient.cs | 6 +- .../Api/Comments/Retrieve/CommentsClient.cs | 6 +- .../Request/RetrieveCommentsParameters.cs | 2 + .../Api/Comments/Retrieve/Response/Comment.cs | 8 +- .../Retrieve/Response/ICommentParent.cs | 4 +- .../Api/Databases/DatabasesClient.cs | 4 +- .../Api/Databases/IDatabasesClient.cs | 28 +- .../DatabasesCreateParameters.cs | 12 +- .../RequestParams/DatabasesListParameters.cs | 1 + .../RequestParams/DatabasesQueryParameters.cs | 3 + .../DatabasesUpdateParameters.cs | 1 - .../Api/Databases/RequestParams/Direction.cs | 2 +- .../Api/Databases/RequestParams/Timestamp.cs | 2 +- Src/Notion.Client/Api/Pages/IPagesClient.cs | 49 +- Src/Notion.Client/Api/Pages/PagesClient.cs | 23 +- .../PagesCreateParameters.cs | 4 + .../PagesCreateParametersBuilder.cs | 17 +- .../RequestParams/PagesUpdateParameters.cs | 12 +- Src/Notion.Client/Api/Search/ISearchClient.cs | 9 +- .../Api/Search/Parameters/SearchDirection.cs | 2 +- .../Api/Search/Parameters/SearchFilter.cs | 1 + .../Api/Search/Parameters/SearchObjectType.cs | 2 +- .../Api/Search/Parameters/SearchParameters.cs | 4 + Src/Notion.Client/Api/Users/IUsersClient.cs | 22 +- Src/Notion.Client/Api/Users/UsersClient.cs | 7 +- Src/Notion.Client/Constants.cs | 1 + .../DI/ServiceCollectionExtensions.cs | 4 +- .../Extensions/EnumExtensions.cs | 9 +- .../HttpResponseMessageExtensions.cs | 8 +- Src/Notion.Client/Models/Blocks/AudioBlock.cs | 4 +- Src/Notion.Client/Models/Blocks/Block.cs | 2 +- Src/Notion.Client/Models/Blocks/BlockType.cs | 2 +- .../Models/Blocks/BookmarkBlock.cs | 4 +- .../Models/Blocks/BreadcrumbBlock.cs | 4 +- .../Models/Blocks/BulletedListItemBlock.cs | 4 +- .../Models/Blocks/CalloutBlock.cs | 4 +- .../Models/Blocks/ChildDatabaseBlock.cs | 4 +- .../Models/Blocks/ChildPageBlock.cs | 4 +- Src/Notion.Client/Models/Blocks/CodeBlock.cs | 4 +- .../Models/Blocks/ColumnListBlock.cs | 4 +- .../Models/Blocks/DividerBlock.cs | 4 +- Src/Notion.Client/Models/Blocks/EmbedBlock.cs | 5 +- .../Models/Blocks/EquationBlock.cs | 4 +- Src/Notion.Client/Models/Blocks/FileBlock.cs | 4 +- .../Models/Blocks/HeadingOneBlock.cs | 4 +- .../Models/Blocks/HeadingThreeeBlock.cs | 4 +- .../Models/Blocks/HeadingTwoBlock.cs | 4 +- Src/Notion.Client/Models/Blocks/IBlock.cs | 64 +- .../Models/Blocks/IBlockParent.cs | 8 +- Src/Notion.Client/Models/Blocks/ImageBlock.cs | 4 +- .../Models/Blocks/LinkPreviewBlock.cs | 8 +- .../Models/Blocks/LinkToPageBlock.cs | 4 +- .../Models/Blocks/NumberedListItemBlock.cs | 4 +- Src/Notion.Client/Models/Blocks/PDFBlock.cs | 4 +- .../Models/Blocks/ParagraphBlock.cs | 4 +- Src/Notion.Client/Models/Blocks/QuoteBlock.cs | 4 +- .../Models/Blocks/SyncedBlockBlock.cs | 4 +- Src/Notion.Client/Models/Blocks/TableBlock.cs | 4 +- .../Models/Blocks/TableOfContentsBlock.cs | 4 +- .../Models/Blocks/TableRowBlock.cs | 4 +- .../Models/Blocks/TemplateBlock.cs | 4 +- Src/Notion.Client/Models/Blocks/ToDoBlock.cs | 4 +- .../Models/Blocks/ToggleBlock.cs | 4 +- Src/Notion.Client/Models/Blocks/VideoBlock.cs | 4 +- .../Models/Common/IObjectModificationData.cs | 8 +- Src/Notion.Client/Models/Database/Database.cs | 32 +- .../Models/Database/IDatabaseParent.cs | 6 +- .../Models/Database/Properties/Property.cs | 40 +- .../RelationProperty/RelationData.cs | 4 +- .../RelationProperty/RelationProperty.cs | 4 +- .../RelationProperty/RelationType.cs | 2 +- .../Database/Properties/SelectProperty.cs | 8 +- .../Models/Database/RichText/RichTextBase.cs | 6 +- .../Models/Database/RichText/RichTextType.cs | 2 +- Src/Notion.Client/Models/EmojiObject.cs | 6 +- Src/Notion.Client/Models/File/FileObject.cs | 10 +- .../Models/File/FileObjectWithName.cs | 4 +- .../Models/Filters/CheckboxFilter.cs | 23 +- .../Models/Filters/DateFilter.cs | 93 +-- .../Models/Filters/EmailFilter.cs | 23 +- .../Models/Filters/FilesFilter.cs | 20 +- Src/Notion.Client/Models/Filters/Filter.cs | 13 +- .../Models/Filters/FormulaFilter.cs | 39 +- .../Models/Filters/MultiSelectFilter.cs | 39 +- .../Models/Filters/NumberFilter.cs | 64 +- .../Models/Filters/PeopleFilter.cs | 39 +- .../Models/Filters/PhoneNumberFilter.cs | 23 +- .../Models/Filters/RelationFilter.cs | 39 +- .../Models/Filters/RichTextFilter.cs | 63 +- .../Models/Filters/Rollup/RollupFilter.cs | 29 +- .../Models/Filters/SelectFilter.cs | 39 +- .../Models/Filters/StatusFilter.cs | 39 +- .../Filters/TimestampCreatedTimeFilter.cs | 32 +- .../Filters/TimestampLastEditedTimeFilter.cs | 32 +- .../Models/Filters/TitleFilter.cs | 23 +- Src/Notion.Client/Models/Filters/URLFilter.cs | 23 +- Src/Notion.Client/Models/IObject.cs | 8 +- Src/Notion.Client/Models/Page/IPageIcon.cs | 6 +- Src/Notion.Client/Models/Page/IPageParent.cs | 8 +- Src/Notion.Client/Models/Page/Page.cs | 56 +- .../Models/Parents/BlockParent.cs | 10 +- .../Models/Parents/DatabaseParent.cs | 10 +- .../Models/Parents/PageParent.cs | 10 +- .../Models/Parents/WorkspaceParent.cs | 2 +- .../PropertyItems/IPropertyItemObject.cs | 7 +- .../Models/PropertyItems/ListPropertyItem.cs | 17 +- .../PropertyItems/RollupPropertyItem.cs | 24 +- .../PropertyItems/SimplePropertyItem.cs | 40 +- .../PropertyItems/StatusPropertyItem.cs | 3 +- .../PropertyValue/CheckboxPropertyValue.cs | 2 +- .../PropertyValue/CreatedByPropertyValue.cs | 4 +- .../PropertyValue/CreatedTimePropertyValue.cs | 4 +- .../Models/PropertyValue/DatePropertyValue.cs | 13 +- .../PropertyValue/EmailPropertyValue.cs | 4 +- .../PropertyValue/FilesPropertyValue.cs | 4 +- .../PropertyValue/FormulaPropertyValue.cs | 16 +- .../LastEditedByPropertyValue.cs | 4 +- .../LastEditedTimePropertyValue.cs | 4 +- .../PropertyValue/MultiSelectPropertyValue.cs | 4 +- .../PropertyValue/NumberPropertyValue.cs | 4 +- .../PropertyValue/PeoplePropertyValue.cs | 4 +- .../PropertyValue/PhoneNumberPropertyValue.cs | 4 +- .../Models/PropertyValue/PropertyValue.cs | 44 +- .../Models/PropertyValue/PropertyValueType.cs | 2 +- .../PropertyValue/RelationPropertyValue.cs | 4 +- .../PropertyValue/RichTextPropertyValue.cs | 4 +- .../PropertyValue/RollupPropertyValue.cs | 14 +- .../PropertyValue/SelectPropertyValue.cs | 2 +- .../PropertyValue/StatusPropertyValue.cs | 56 +- .../PropertyValue/TitlePropertyValue.cs | 4 +- .../Models/PropertyValue/UrlPropertyValue.cs | 4 +- .../Models/User/BotOwner/IBotOwner.cs | 4 +- .../Models/User/BotOwner/UserOwner.cs | 4 +- .../BotOwner/WorkspaceIntegrationOwner.cs | 4 +- Src/Notion.Client/Models/User/User.cs | 7 +- Src/Notion.Client/NotionApiErrorResponse.cs | 2 +- Src/Notion.Client/NotionApiException.cs | 1 + Src/Notion.Client/NotionClient.cs | 12 + Src/Notion.Client/NotionClientFactory.cs | 10 +- Src/Notion.Client/RestClient/ClientOptions.cs | 2 + .../RestClient/LoggingHandler.cs | 5 +- Src/Notion.Client/RestClient/RestClient.cs | 116 +-- Src/Notion.Client/http/QueryHelpers.cs | 8 +- .../CommentsClientTests.cs | 207 ++--- .../IBlocksClientTests.cs | 775 ++++++++---------- .../IPageClientTests.cs | 401 ++++----- Test/Notion.UnitTests/ApiTestBase.cs | 93 +-- Test/Notion.UnitTests/BlocksClientTests.cs | 265 +++--- Test/Notion.UnitTests/DatabasesClientTests.cs | 658 +++++++-------- Test/Notion.UnitTests/FilterTests.cs | 247 +++--- Test/Notion.UnitTests/HelperAsserts.cs | 61 +- Test/Notion.UnitTests/PagesClientTests.cs | 354 ++++---- Test/Notion.UnitTests/PropertyTests.cs | 104 ++- Test/Notion.UnitTests/SearchClientTest.cs | 92 +-- Test/Notion.UnitTests/UserClientTest.cs | 253 +++--- 165 files changed, 2744 insertions(+), 2852 deletions(-) diff --git a/Src/Notion.Client/Api/ApiEndpoints.cs b/Src/Notion.Client/Api/ApiEndpoints.cs index ec6f5b1a..51dbe7fd 100644 --- a/Src/Notion.Client/Api/ApiEndpoints.cs +++ b/Src/Notion.Client/Api/ApiEndpoints.cs @@ -1,72 +1,140 @@ -using System; - -namespace Notion.Client +namespace Notion.Client { public static class ApiEndpoints { public static class DatabasesApiUrls { - public static string Retrieve(string databaseId) => $"/v1/databases/{databaseId}"; - public static string List() => "/v1/databases"; - public static string Query(string databaseId) => $"/v1/databases/{databaseId}/query"; public static string Create => "/v1/databases"; - public static string Update(string databaseId) => $"/v1/databases/{databaseId}"; + + public static string Retrieve(string databaseId) + { + return $"/v1/databases/{databaseId}"; + } + + public static string List() + { + return "/v1/databases"; + } + + public static string Query(string databaseId) + { + return $"/v1/databases/{databaseId}/query"; + } + + public static string Update(string databaseId) + { + return $"/v1/databases/{databaseId}"; + } } public static class UsersApiUrls { - public static string Retrieve(string userId) => $"/v1/users/{userId}"; - public static string List() => "/v1/users"; + public static string Retrieve(string userId) + { + return $"/v1/users/{userId}"; + } + + public static string List() + { + return "/v1/users"; + } /// - /// Get the for retrieve your token's bot user. + /// Get the for retrieve your token's bot user. /// - /// Returns a retrieve your token's bot user. - public static string Me() => "/v1/users/me"; + /// Returns a retrieve your token's bot user. + public static string Me() + { + return "/v1/users/me"; + } } public static class BlocksApiUrls { - public static string Retrieve(string blockId) => $"/v1/blocks/{blockId}"; - public static string Update(string blockId) => $"/v1/blocks/{blockId}"; + public static string Retrieve(string blockId) + { + return $"/v1/blocks/{blockId}"; + } + + public static string Update(string blockId) + { + return $"/v1/blocks/{blockId}"; + } /// - /// Get the for deleting a block. + /// Get the for deleting a block. /// /// Identifier for a Notion block - /// Returns a for deleting a block. - public static string Delete(string blockId) => $"/v1/blocks/{blockId}"; + /// Returns a for deleting a block. + public static string Delete(string blockId) + { + return $"/v1/blocks/{blockId}"; + } + + public static string RetrieveChildren(string blockId) + { + return $"/v1/blocks/{blockId}/children"; + } - public static string RetrieveChildren(string blockId) => $"/v1/blocks/{blockId}/children"; - public static string AppendChildren(string blockId) => $"/v1/blocks/{blockId}/children"; + public static string AppendChildren(string blockId) + { + return $"/v1/blocks/{blockId}/children"; + } } public static class PagesApiUrls { - public static string Create() => $"/v1/pages"; - public static string Retrieve(string pageId) => $"/v1/pages/{pageId}"; - public static string Update(string pageId) => $"/v1/pages/{pageId}"; - public static string UpdateProperties(string pageId) => $"/v1/pages/{pageId}"; + public static string Create() + { + return "/v1/pages"; + } + + public static string Retrieve(string pageId) + { + return $"/v1/pages/{pageId}"; + } + + public static string Update(string pageId) + { + return $"/v1/pages/{pageId}"; + } + + public static string UpdateProperties(string pageId) + { + return $"/v1/pages/{pageId}"; + } /// - /// Get the for retrieve page property item + /// Get the for retrieve page property item /// /// Identifier for a Notion Page /// Identifier for a Notion Property /// - public static string RetrievePropertyItem(string pageId, string propertyId) => $"/v1/pages/{pageId}/properties/{propertyId}"; + public static string RetrievePropertyItem(string pageId, string propertyId) + { + return $"/v1/pages/{pageId}/properties/{propertyId}"; + } } public static class SearchApiUrls { - public static string Search() => "/v1/search"; + public static string Search() + { + return "/v1/search"; + } } public static class CommentsApiUrls { - public static string Retrieve() => "/v1/comments"; + public static string Retrieve() + { + return "/v1/comments"; + } - public static string Create() => "/v1/comments"; + public static string Create() + { + return "/v1/comments"; + } } } } diff --git a/Src/Notion.Client/Api/Blocks/BlocksClient.cs b/Src/Notion.Client/Api/Blocks/BlocksClient.cs index cc06642e..8fbdcd26 100644 --- a/Src/Notion.Client/Api/Blocks/BlocksClient.cs +++ b/Src/Notion.Client/Api/Blocks/BlocksClient.cs @@ -14,7 +14,9 @@ public BlocksClient(IRestClient client) _client = client; } - public async Task> RetrieveChildrenAsync(string blockId, BlocksRetrieveChildrenParameters parameters = null) + public async Task> RetrieveChildrenAsync( + string blockId, + BlocksRetrieveChildrenParameters parameters = null) { if (string.IsNullOrWhiteSpace(blockId)) { @@ -25,16 +27,18 @@ public async Task> RetrieveChildrenAsync(string blockId, B var queryParameters = (IBlocksRetrieveChildrenQueryParameters)parameters; - var queryParams = new Dictionary() + var queryParams = new Dictionary { - { "start_cursor", queryParameters?.StartCursor?.ToString() }, - { "page_size", queryParameters?.PageSize?.ToString() } + {"start_cursor", queryParameters?.StartCursor}, + {"page_size", queryParameters?.PageSize?.ToString()}, }; return await _client.GetAsync>(url, queryParams); } - public async Task> AppendChildrenAsync(string blockId, BlocksAppendChildrenParameters parameters = null) + public async Task> AppendChildrenAsync( + string blockId, + BlocksAppendChildrenParameters parameters = null) { if (string.IsNullOrWhiteSpace(blockId)) { diff --git a/Src/Notion.Client/Api/Blocks/IBlocksClient.cs b/Src/Notion.Client/Api/Blocks/IBlocksClient.cs index 90ebf073..f45611b7 100644 --- a/Src/Notion.Client/Api/Blocks/IBlocksClient.cs +++ b/Src/Notion.Client/Api/Blocks/IBlocksClient.cs @@ -5,32 +5,36 @@ namespace Notion.Client public interface IBlocksClient { /// - /// Retrieves a Block object using the ID specified. + /// Retrieves a Block object using the ID specified. /// /// /// Block Task RetrieveAsync(string blockId); /// - /// Updates the content for the specified block_id based on the block type. + /// Updates the content for the specified block_id based on the block type. /// /// /// /// Block Task UpdateAsync(string blockId, IUpdateBlock updateBlock); - Task> RetrieveChildrenAsync(string blockId, BlocksRetrieveChildrenParameters parameters = null); + Task> RetrieveChildrenAsync( + string blockId, + BlocksRetrieveChildrenParameters parameters = null); /// - /// Creates and appends new children blocks to the parent block_id specified. + /// Creates and appends new children blocks to the parent block_id specified. /// /// Identifier for a block /// /// A paginated list of newly created first level children block objects. - Task> AppendChildrenAsync(string blockId, BlocksAppendChildrenParameters parameters = null); + Task> AppendChildrenAsync( + string blockId, + BlocksAppendChildrenParameters parameters = null); /// - /// Sets a Block object, including page blocks, to archived: true using the ID specified. + /// Sets a Block object, including page blocks, to archived: true using the ID specified. /// /// Identifier for a Notion block Task DeleteAsync(string blockId); diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksRetrieveChildrenParameters.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksRetrieveChildrenParameters.cs index ddc73a91..30f9c17d 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksRetrieveChildrenParameters.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksRetrieveChildrenParameters.cs @@ -3,6 +3,7 @@ public class BlocksRetrieveChildrenParameters : IBlocksRetrieveChildrenQueryParameters { public string StartCursor { get; set; } + public int? PageSize { get; set; } } } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/AudioUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/AudioUpdateBlock.cs index 8747ad63..f341e441 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/AudioUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/AudioUpdateBlock.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Notion.Client { diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BookmarkUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BookmarkUpdateBlock.cs index c3333737..612b6dda 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BookmarkUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BookmarkUpdateBlock.cs @@ -5,11 +5,11 @@ namespace Notion.Client { public class BookmarkUpdateBlock : IUpdateBlock { - public bool Archived { get; set; } - [JsonProperty("bookmark")] public Info Bookmark { get; set; } + public bool Archived { get; set; } + public class Info { [JsonProperty("url")] diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BreadcrumbUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BreadcrumbUpdateBlock.cs index 2bb8be38..a90f6966 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BreadcrumbUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BreadcrumbUpdateBlock.cs @@ -4,18 +4,18 @@ namespace Notion.Client { public class BreadcrumbUpdateBlock : IUpdateBlock { - public bool Archived { get; set; } + public BreadcrumbUpdateBlock() + { + Breadcrumb = new Info(); + } [JsonProperty("breadcrumb")] public Info Breadcrumb { get; set; } - public class Info - { - } + public bool Archived { get; set; } - public BreadcrumbUpdateBlock() + public class Info { - Breadcrumb = new Info(); } } } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/DividerUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/DividerUpdateBlock.cs index 6c5b447c..79f332f0 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/DividerUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/DividerUpdateBlock.cs @@ -4,18 +4,18 @@ namespace Notion.Client { public class DividerUpdateBlock : IUpdateBlock { - public bool Archived { get; set; } + public DividerUpdateBlock() + { + Divider = new Info(); + } [JsonProperty("divider")] public Info Divider { get; set; } - public class Info - { - } + public bool Archived { get; set; } - public DividerUpdateBlock() + public class Info { - Divider = new Info(); } } } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableOfContentsUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableOfContentsUpdateBlock.cs index 36eee182..bef1f278 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableOfContentsUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableOfContentsUpdateBlock.cs @@ -4,18 +4,18 @@ namespace Notion.Client { public class TableOfContentsUpdateBlock : IUpdateBlock { - public bool Archived { get; set; } + public TableOfContentsUpdateBlock() + { + TableOfContents = new Info(); + } [JsonProperty("table_of_contents")] public Info TableOfContents { get; set; } - public class Info - { - } + public bool Archived { get; set; } - public TableOfContentsUpdateBlock() + public class Info { - TableOfContents = new Info(); } } } diff --git a/Src/Notion.Client/Api/Comments/Create/Request/CreateCommentParameters.cs b/Src/Notion.Client/Api/Comments/Create/Request/CreateCommentParameters.cs index aadaf1f1..3b676133 100644 --- a/Src/Notion.Client/Api/Comments/Create/Request/CreateCommentParameters.cs +++ b/Src/Notion.Client/Api/Comments/Create/Request/CreateCommentParameters.cs @@ -24,25 +24,23 @@ public interface ICreatePageCommentBodyParameters : ICreateCommentsBodyParameter public class CreateCommentParameters : ICreateDiscussionCommentBodyParameters, ICreatePageCommentBodyParameters { public string DiscussionId { get; set; } + public IEnumerable RichText { get; set; } + public ParentPageInput Parent { get; set; } - public static CreateCommentParameters CreatePageComment(ParentPageInput parent, IEnumerable richText) + public static CreateCommentParameters CreatePageComment( + ParentPageInput parent, + IEnumerable richText) { - return new CreateCommentParameters - { - Parent = parent, - RichText = richText - }; + return new CreateCommentParameters {Parent = parent, RichText = richText}; } - public static CreateCommentParameters CreateDiscussionComment(string discussionId, IEnumerable richText) + public static CreateCommentParameters CreateDiscussionComment( + string discussionId, + IEnumerable richText) { - return new CreateCommentParameters - { - DiscussionId = discussionId, - RichText = richText - }; + return new CreateCommentParameters {DiscussionId = discussionId, RichText = richText}; } } } diff --git a/Src/Notion.Client/Api/Comments/ICommentsClient.cs b/Src/Notion.Client/Api/Comments/ICommentsClient.cs index d936203c..871319da 100644 --- a/Src/Notion.Client/Api/Comments/ICommentsClient.cs +++ b/Src/Notion.Client/Api/Comments/ICommentsClient.cs @@ -5,10 +5,12 @@ namespace Notion.Client public interface ICommentsClient { /// - /// Retrieves a list of un-resolved Comment objects from a page or block. + /// Retrieves a list of un-resolved Comment objects from a page or block. /// /// Retrieve comments parameters - /// + /// + /// + /// Task Retrieve(RetrieveCommentsParameters retrieveCommentsParameters); Task Create(CreateCommentParameters createCommentParameters); diff --git a/Src/Notion.Client/Api/Comments/Retrieve/CommentsClient.cs b/Src/Notion.Client/Api/Comments/Retrieve/CommentsClient.cs index d228200c..b979086f 100644 --- a/Src/Notion.Client/Api/Comments/Retrieve/CommentsClient.cs +++ b/Src/Notion.Client/Api/Comments/Retrieve/CommentsClient.cs @@ -9,11 +9,9 @@ public async Task Retrieve(RetrieveCommentsParameters { var qp = (IRetrieveCommentsQueryParameters)parameters; - var queryParams = new Dictionary() + var queryParams = new Dictionary { - { "block_id", qp.BlockId }, - { "start_cursor", qp.StartCursor }, - { "page_size", qp.PageSize.ToString() }, + {"block_id", qp.BlockId}, {"start_cursor", qp.StartCursor}, {"page_size", qp.PageSize.ToString()}, }; return await _client.GetAsync( diff --git a/Src/Notion.Client/Api/Comments/Retrieve/Request/RetrieveCommentsParameters.cs b/Src/Notion.Client/Api/Comments/Retrieve/Request/RetrieveCommentsParameters.cs index e78c4cad..d42ec9e7 100644 --- a/Src/Notion.Client/Api/Comments/Retrieve/Request/RetrieveCommentsParameters.cs +++ b/Src/Notion.Client/Api/Comments/Retrieve/Request/RetrieveCommentsParameters.cs @@ -3,7 +3,9 @@ public class RetrieveCommentsParameters : IRetrieveCommentsQueryParameters { public string BlockId { get; set; } + public string StartCursor { get; set; } + public int? PageSize { get; set; } } } diff --git a/Src/Notion.Client/Api/Comments/Retrieve/Response/Comment.cs b/Src/Notion.Client/Api/Comments/Retrieve/Response/Comment.cs index 531fb43c..9b9ef2ae 100644 --- a/Src/Notion.Client/Api/Comments/Retrieve/Response/Comment.cs +++ b/Src/Notion.Client/Api/Comments/Retrieve/Response/Comment.cs @@ -6,10 +6,6 @@ namespace Notion.Client { public class Comment : IObject { - public string Id { get; set; } - - public ObjectType Object => ObjectType.Comment; - [JsonProperty("parent")] public ICommentParent Parent { get; set; } @@ -27,5 +23,9 @@ public class Comment : IObject [JsonProperty("last_edited_time")] public DateTime LastEditedTime { get; set; } + + public string Id { get; set; } + + public ObjectType Object => ObjectType.Comment; } } diff --git a/Src/Notion.Client/Api/Comments/Retrieve/Response/ICommentParent.cs b/Src/Notion.Client/Api/Comments/Retrieve/Response/ICommentParent.cs index e323c7e1..9e05d019 100644 --- a/Src/Notion.Client/Api/Comments/Retrieve/Response/ICommentParent.cs +++ b/Src/Notion.Client/Api/Comments/Retrieve/Response/ICommentParent.cs @@ -4,8 +4,8 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(PageParent), ParentType.PageId)] - [JsonSubtypes.KnownSubType(typeof(BlockParent), ParentType.BlockId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PageParent), ParentType.PageId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(BlockParent), ParentType.BlockId)] public interface ICommentParent { } diff --git a/Src/Notion.Client/Api/Databases/DatabasesClient.cs b/Src/Notion.Client/Api/Databases/DatabasesClient.cs index 2ab17a8b..5157dee9 100644 --- a/Src/Notion.Client/Api/Databases/DatabasesClient.cs +++ b/Src/Notion.Client/Api/Databases/DatabasesClient.cs @@ -17,7 +17,9 @@ public async Task RetrieveAsync(string databaseId) return await _client.GetAsync(DatabasesApiUrls.Retrieve(databaseId)); } - public async Task> QueryAsync(string databaseId, DatabasesQueryParameters databasesQueryParameters) + public async Task> QueryAsync( + string databaseId, + DatabasesQueryParameters databasesQueryParameters) { var body = (IDatabaseQueryBodyParameters)databasesQueryParameters; diff --git a/Src/Notion.Client/Api/Databases/IDatabasesClient.cs b/Src/Notion.Client/Api/Databases/IDatabasesClient.cs index 115ccfed..9c245ce3 100644 --- a/Src/Notion.Client/Api/Databases/IDatabasesClient.cs +++ b/Src/Notion.Client/Api/Databases/IDatabasesClient.cs @@ -5,35 +5,43 @@ namespace Notion.Client public interface IDatabasesClient { /// - /// Retrieves a Database object using the ID specified. + /// Retrieves a Database object using the ID specified. /// /// Identifier for a Notion database - /// + /// + /// + /// Task RetrieveAsync(string databaseId); /// - /// Gets a list of Pages contained in the database, filtered and ordered according to the - /// filter conditions and sort criteria provided in the request. The response may contain - /// fewer than page_size of results. + /// Gets a list of Pages contained in the database, filtered and ordered according to the + /// filter conditions and sort criteria provided in the request. The response may contain + /// fewer than page_size of results. /// /// /// - /// + /// + /// + /// Task> QueryAsync(string databaseId, DatabasesQueryParameters databasesQueryParameters); /// - /// Creates a database as a subpage in the specified parent page, with the specified properties schema. + /// Creates a database as a subpage in the specified parent page, with the specified properties schema. /// /// - /// + /// + /// + /// Task CreateAsync(DatabasesCreateParameters databasesCreateParameters); /// - /// Updates an existing database as specified by the parameters. + /// Updates an existing database as specified by the parameters. /// /// /// - /// + /// + /// + /// Task UpdateAsync(string databaseId, DatabasesUpdateParameters databasesUpdateParameters); } } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/DatabasesCreateParameters.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/DatabasesCreateParameters.cs index bafad0ec..9cb7086b 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/DatabasesCreateParameters.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/DatabasesCreateParameters.cs @@ -5,6 +5,12 @@ namespace Notion.Client { public class DatabasesCreateParameters : IDatabasesCreateBodyParameters, IDatabasesCreateQueryParameters { + [JsonProperty("icon")] + public IPageIcon Icon { get; set; } + + [JsonProperty("cover")] + public FileObject Cover { get; set; } + [JsonProperty("parent")] public ParentPageInput Parent { get; set; } @@ -14,12 +20,6 @@ public class DatabasesCreateParameters : IDatabasesCreateBodyParameters, IDataba [JsonProperty("title")] public List Title { get; set; } - [JsonProperty("icon")] - public IPageIcon Icon { get; set; } - - [JsonProperty("cover")] - public FileObject Cover { get; set; } - public bool? IsInline { get; set; } public List Description { get; set; } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesListParameters.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesListParameters.cs index 51136e47..922e54fc 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesListParameters.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesListParameters.cs @@ -3,6 +3,7 @@ public class DatabasesListParameters : IDatabasesListQueryParmaters { public string StartCursor { get; set; } + public int? PageSize { get; set; } } } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesQueryParameters.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesQueryParameters.cs index 454961a2..51bd8a06 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesQueryParameters.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesQueryParameters.cs @@ -5,8 +5,11 @@ namespace Notion.Client public class DatabasesQueryParameters : IDatabaseQueryBodyParameters { public Filter Filter { get; set; } + public List Sorts { get; set; } + public string StartCursor { get; set; } + public int? PageSize { get; set; } } } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs index b9cb182e..41da2d17 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using Newtonsoft.Json; namespace Notion.Client { diff --git a/Src/Notion.Client/Api/Databases/RequestParams/Direction.cs b/Src/Notion.Client/Api/Databases/RequestParams/Direction.cs index c79d501d..76b87da3 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/Direction.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/Direction.cs @@ -11,6 +11,6 @@ public enum Direction Ascending, [EnumMember(Value = "descending")] - Descending + Descending, } } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/Timestamp.cs b/Src/Notion.Client/Api/Databases/RequestParams/Timestamp.cs index 334b8c22..4eb359d4 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/Timestamp.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/Timestamp.cs @@ -11,6 +11,6 @@ public enum Timestamp CreatedTime, [EnumMember(Value = "last_edited_time")] - LastEditedTime + LastEditedTime, } } diff --git a/Src/Notion.Client/Api/Pages/IPagesClient.cs b/Src/Notion.Client/Api/Pages/IPagesClient.cs index 90eac980..f6b8f94f 100644 --- a/Src/Notion.Client/Api/Pages/IPagesClient.cs +++ b/Src/Notion.Client/Api/Pages/IPagesClient.cs @@ -6,49 +6,58 @@ namespace Notion.Client public interface IPagesClient { /// - /// Creates a new page in the specified database or as a child of an existing page. - /// - /// If the parent is a database, the property values of the new page in the properties parameter must conform to the parent database's property schema. - /// - /// If the parent is a page, the only valid property is title. + /// Creates a new page in the specified database or as a child of an existing page. + /// If the parent is a database, the + /// property values of the + /// new page in the properties parameter must conform to the parent + /// database's property schema. + /// If the parent is a page, the only valid property is title. /// /// Create page parameters - /// Created object. + /// Created object. Task CreateAsync(PagesCreateParameters pagesCreateParameters); /// - /// Retrieves a Page object using the ID specified. + /// Retrieves a Page object using the ID specified. /// /// Identifier for a Notion page - /// + /// + /// + /// Task RetrieveAsync(string pageId); /// - /// Updates page property values for the specified page. - /// Note: Properties that are not set via the properties parameter will remain unchanged. + /// Updates page property values for the specified page. + /// Note: Properties that are not set via the properties parameter will remain unchanged. /// /// Identifier for a Notion page - /// Property values to update for this page. The keys are the names or IDs of the property and the values are property values. - /// Updated object + /// + /// Property values to update for this page. The keys are the names or IDs of the property + /// and the values are property values. + /// + /// Updated object Task UpdatePropertiesAsync( string pageId, - IDictionary updatedProperties - ); + IDictionary updatedProperties); /// - /// Updates page property values for the specified page. - /// Properties that are not set via the properties parameter will remain unchanged. + /// Updates page property values for the specified page. + /// Properties that are not set via the properties parameter will remain unchanged. /// /// Identifier for a Notion page /// Update property parameters - /// Updated object + /// Updated object Task UpdateAsync(string pageId, PagesUpdateParameters pagesUpdateParameters); /// - /// Retrieves a property_item object for a given pageId and propertyId. Depending on the property type, the object returned will either be a value or a paginated list of property item values. + /// Retrieves a property_item object for a given pageId and propertyId. Depending on the property type, the object + /// returned will either be a value or a paginated list of property item values. /// /// Property body and query parameters - /// - Task RetrievePagePropertyItem(RetrievePropertyItemParameters retrievePropertyItemParameters); + /// + /// + /// + Task RetrievePagePropertyItem( + RetrievePropertyItemParameters retrievePropertyItemParameters); } } diff --git a/Src/Notion.Client/Api/Pages/PagesClient.cs b/Src/Notion.Client/Api/Pages/PagesClient.cs index 5bce1904..b71f924f 100644 --- a/Src/Notion.Client/Api/Pages/PagesClient.cs +++ b/Src/Notion.Client/Api/Pages/PagesClient.cs @@ -15,11 +15,12 @@ public PagesClient(IRestClient client) } /// - /// Creates a new page in the specified database or as a child of an existing page. - /// - /// If the parent is a database, the property values of the new page in the properties parameter must conform to the parent database's property schema. - /// - /// If the parent is a page, the only valid property is title. + /// Creates a new page in the specified database or as a child of an existing page. + /// If the parent is a database, the + /// property values of the + /// new page in the properties parameter must conform to the parent + /// database's property schema. + /// If the parent is a page, the only valid property is title. /// /// Create page parameters /// Created page. @@ -48,20 +49,22 @@ public async Task CreateAsync(PagesCreateParameters pagesCreateParameters) public async Task RetrieveAsync(string pageId) { var url = PagesApiUrls.Retrieve(pageId); + return await _client.GetAsync(url); } - public async Task RetrievePagePropertyItem(RetrievePropertyItemParameters retrievePropertyItemParameters) + public async Task RetrievePagePropertyItem( + RetrievePropertyItemParameters retrievePropertyItemParameters) { var pathParameters = (IRetrievePropertyItemPathParameters)retrievePropertyItemParameters; var queryParameters = (IRetrievePropertyQueryParameters)retrievePropertyItemParameters; var url = PagesApiUrls.RetrievePropertyItem(pathParameters.PageId, pathParameters.PropertyId); - var queryParams = new Dictionary() + var queryParams = new Dictionary { - { "start_cursor", queryParameters?.StartCursor }, - { "page_size", queryParameters?.PageSize?.ToString() } + {"start_cursor", queryParameters?.StartCursor}, + {"page_size", queryParameters?.PageSize?.ToString()}, }; return await _client.GetAsync(url, queryParams); @@ -81,7 +84,7 @@ public async Task UpdatePropertiesAsync( IDictionary updatedProperties) { var url = PagesApiUrls.UpdateProperties(pageId); - var body = new UpdatePropertiesParameters { Properties = updatedProperties }; + var body = new UpdatePropertiesParameters {Properties = updatedProperties}; return await _client.PatchAsync(url, body); } diff --git a/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParameters.cs b/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParameters.cs index 52cb0a89..08572811 100644 --- a/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParameters.cs +++ b/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParameters.cs @@ -5,9 +5,13 @@ namespace Notion.Client public class PagesCreateParameters : IPagesCreateBodyParameters, IPagesCreateQueryParameters { public IPageParentInput Parent { get; set; } + public IDictionary Properties { get; set; } + public IList Children { get; set; } + public IPageIcon Icon { get; set; } + public FileObject Cover { get; set; } } } diff --git a/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParametersBuilder.cs b/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParametersBuilder.cs index b86a207a..7df2fe4c 100644 --- a/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParametersBuilder.cs +++ b/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParametersBuilder.cs @@ -4,11 +4,11 @@ namespace Notion.Client { public class PagesCreateParametersBuilder { - private IPageParentInput parent; - private readonly Dictionary properties = new Dictionary(); private readonly IList children = new List(); - private IPageIcon icon; + private readonly Dictionary properties = new(); private FileObject cover; + private IPageIcon icon; + private IPageParentInput parent; private PagesCreateParametersBuilder() { @@ -16,33 +16,34 @@ private PagesCreateParametersBuilder() public static PagesCreateParametersBuilder Create(IPageParentInput parent) { - return new PagesCreateParametersBuilder - { - parent = parent - }; + return new PagesCreateParametersBuilder {parent = parent}; } public PagesCreateParametersBuilder AddProperty(string nameOrId, PropertyValue value) { properties[nameOrId] = value; + return this; } public PagesCreateParametersBuilder AddPageContent(IBlock block) { children.Add(block); + return this; } public PagesCreateParametersBuilder SetIcon(IPageIcon pageIcon) { icon = pageIcon; + return this; } public PagesCreateParametersBuilder SetCover(FileObject pageCover) { cover = pageCover; + return this; } @@ -54,7 +55,7 @@ public PagesCreateParameters Build() Properties = properties, Children = children, Icon = icon, - Cover = cover + Cover = cover, }; } } diff --git a/Src/Notion.Client/Api/Pages/RequestParams/PagesUpdateParameters.cs b/Src/Notion.Client/Api/Pages/RequestParams/PagesUpdateParameters.cs index 40f06b12..742ef8dd 100644 --- a/Src/Notion.Client/Api/Pages/RequestParams/PagesUpdateParameters.cs +++ b/Src/Notion.Client/Api/Pages/RequestParams/PagesUpdateParameters.cs @@ -5,16 +5,16 @@ namespace Notion.Client { public class PagesUpdateParameters : IPagesUpdateBodyParameters { - [JsonProperty("archived")] - public bool Archived { get; set; } - - [JsonProperty("properties")] - public IDictionary Properties { get; set; } - [JsonProperty("icon")] public IPageIcon Icon { get; set; } [JsonProperty("cover")] public FileObject Cover { get; set; } + + [JsonProperty("archived")] + public bool Archived { get; set; } + + [JsonProperty("properties")] + public IDictionary Properties { get; set; } } } diff --git a/Src/Notion.Client/Api/Search/ISearchClient.cs b/Src/Notion.Client/Api/Search/ISearchClient.cs index 9eb487d5..8071db6d 100644 --- a/Src/Notion.Client/Api/Search/ISearchClient.cs +++ b/Src/Notion.Client/Api/Search/ISearchClient.cs @@ -5,12 +5,13 @@ namespace Notion.Client public interface ISearchClient { /// - /// Searches all original pages, databases, and child pages/databases that are shared with the integration. - /// - /// It will not return linked databases, since these duplicate their source databases. + /// Searches all original pages, databases, and child pages/databases that are shared with the integration. + /// It will not return linked databases, since these duplicate their source databases. /// /// Search filters and body parameters - /// + /// + /// + /// Task> SearchAsync(SearchParameters parameters); } } diff --git a/Src/Notion.Client/Api/Search/Parameters/SearchDirection.cs b/Src/Notion.Client/Api/Search/Parameters/SearchDirection.cs index fdac0b59..0bde8d23 100644 --- a/Src/Notion.Client/Api/Search/Parameters/SearchDirection.cs +++ b/Src/Notion.Client/Api/Search/Parameters/SearchDirection.cs @@ -8,6 +8,6 @@ public enum SearchDirection Ascending, [EnumMember(Value = "descending")] - Descending + Descending, } } diff --git a/Src/Notion.Client/Api/Search/Parameters/SearchFilter.cs b/Src/Notion.Client/Api/Search/Parameters/SearchFilter.cs index cc84a9a3..dbd5cf5f 100644 --- a/Src/Notion.Client/Api/Search/Parameters/SearchFilter.cs +++ b/Src/Notion.Client/Api/Search/Parameters/SearchFilter.cs @@ -7,6 +7,7 @@ public class SearchFilter { [JsonConverter(typeof(StringEnumConverter))] public SearchObjectType Value { get; set; } + public string Property => "object"; } } diff --git a/Src/Notion.Client/Api/Search/Parameters/SearchObjectType.cs b/Src/Notion.Client/Api/Search/Parameters/SearchObjectType.cs index 78a012df..773ef95a 100644 --- a/Src/Notion.Client/Api/Search/Parameters/SearchObjectType.cs +++ b/Src/Notion.Client/Api/Search/Parameters/SearchObjectType.cs @@ -8,6 +8,6 @@ public enum SearchObjectType Page, [EnumMember(Value = "database")] - Database + Database, } } diff --git a/Src/Notion.Client/Api/Search/Parameters/SearchParameters.cs b/Src/Notion.Client/Api/Search/Parameters/SearchParameters.cs index ae02c0f4..e1c8ced8 100644 --- a/Src/Notion.Client/Api/Search/Parameters/SearchParameters.cs +++ b/Src/Notion.Client/Api/Search/Parameters/SearchParameters.cs @@ -3,9 +3,13 @@ public class SearchParameters : ISearchBodyParameters { public string Query { get; set; } + public SearchSort Sort { get; set; } + public SearchFilter Filter { get; set; } + public string StartCursor { get; set; } + public int? PageSize { get; set; } } } diff --git a/Src/Notion.Client/Api/Users/IUsersClient.cs b/Src/Notion.Client/Api/Users/IUsersClient.cs index 41443678..69981022 100644 --- a/Src/Notion.Client/Api/Users/IUsersClient.cs +++ b/Src/Notion.Client/Api/Users/IUsersClient.cs @@ -5,24 +5,30 @@ namespace Notion.Client public interface IUsersClient { /// - /// Retrieves a User using the ID specified. + /// Retrieves a User using the ID specified. /// /// Identifier for a Notion user - /// + /// + /// + /// Task RetrieveAsync(string userId); /// - /// Returns a paginated list of Users for the workspace. - /// - /// The response may contain fewer than page_size of results. + /// Returns a paginated list of Users for the workspace. + /// The response may contain fewer than page_size of results. /// - /// + /// + /// + /// Task> ListAsync(); /// - /// Retrieves the bot User associated with the API token provided in the authorization header. + /// Retrieves the bot User associated with the API token provided in the authorization header. /// - /// object of type bot having an owner field with information about the person who authorized the integration. + /// + /// object of type bot having an owner field with information about the person who authorized + /// the integration. + /// Task MeAsync(); } } diff --git a/Src/Notion.Client/Api/Users/UsersClient.cs b/Src/Notion.Client/Api/Users/UsersClient.cs index 5c745f72..957ac45e 100644 --- a/Src/Notion.Client/Api/Users/UsersClient.cs +++ b/Src/Notion.Client/Api/Users/UsersClient.cs @@ -23,9 +23,12 @@ public async Task> ListAsync() } /// - /// Retrieves the bot User associated with the API token provided in the authorization header. + /// Retrieves the bot User associated with the API token provided in the authorization header. /// - /// User object of type bot having an owner field with information about the person who authorized the integration. + /// + /// User object of type bot having an owner field with information about the person who authorized the + /// integration. + /// public async Task MeAsync() { return await _client.GetAsync(UsersApiUrls.Me()); diff --git a/Src/Notion.Client/Constants.cs b/Src/Notion.Client/Constants.cs index 5034edae..072291e1 100644 --- a/Src/Notion.Client/Constants.cs +++ b/Src/Notion.Client/Constants.cs @@ -1,6 +1,7 @@ using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("Notion.UnitTests")] + namespace Notion.Client { internal class Constants diff --git a/Src/Notion.Client/DI/ServiceCollectionExtensions.cs b/Src/Notion.Client/DI/ServiceCollectionExtensions.cs index a4aed7fd..866dc92d 100644 --- a/Src/Notion.Client/DI/ServiceCollectionExtensions.cs +++ b/Src/Notion.Client/DI/ServiceCollectionExtensions.cs @@ -5,7 +5,9 @@ namespace Microsoft.Extensions.DependencyInjection { public static class ServiceCollectionExtensions { - public static IServiceCollection AddNotionClient(this IServiceCollection services, Action options) + public static IServiceCollection AddNotionClient( + this IServiceCollection services, + Action options) { services.AddSingleton(sp => { diff --git a/Src/Notion.Client/Extensions/EnumExtensions.cs b/Src/Notion.Client/Extensions/EnumExtensions.cs index 987104b8..cd60aebd 100644 --- a/Src/Notion.Client/Extensions/EnumExtensions.cs +++ b/Src/Notion.Client/Extensions/EnumExtensions.cs @@ -1,15 +1,18 @@ -using System.Linq; +using System; +using System.Linq; using System.Runtime.Serialization; namespace Notion.Client.Extensions { public static class EnumExtensions { - public static string GetEnumMemberValue(this T enumValue) where T : System.Enum + public static string GetEnumMemberValue(this T enumValue) where T : Enum { var enumType = typeof(T); var memInfo = enumType.GetMember(enumValue.ToString()); - var attr = memInfo.FirstOrDefault()?.GetCustomAttributes(false).OfType().FirstOrDefault(); + + var attr = memInfo.FirstOrDefault()?.GetCustomAttributes(false).OfType() + .FirstOrDefault(); if (attr != null) { diff --git a/Src/Notion.Client/Extensions/HttpResponseMessageExtensions.cs b/Src/Notion.Client/Extensions/HttpResponseMessageExtensions.cs index 9b01580d..b6a9396d 100644 --- a/Src/Notion.Client/Extensions/HttpResponseMessageExtensions.cs +++ b/Src/Notion.Client/Extensions/HttpResponseMessageExtensions.cs @@ -7,11 +7,13 @@ namespace Notion.Client.Extensions { internal static class HttpResponseMessageExtensions { - internal static async Task ParseStreamAsync(this HttpResponseMessage response, JsonSerializerSettings serializerSettings = null) + internal static async Task ParseStreamAsync( + this HttpResponseMessage response, + JsonSerializerSettings serializerSettings = null) { - using (Stream stream = await response.Content.ReadAsStreamAsync()) + using (var stream = await response.Content.ReadAsStreamAsync()) { - using (StreamReader streamReader = new StreamReader(stream)) + using (var streamReader = new StreamReader(stream)) { using (JsonReader jsonReader = new JsonTextReader(streamReader)) { diff --git a/Src/Notion.Client/Models/Blocks/AudioBlock.cs b/Src/Notion.Client/Models/Blocks/AudioBlock.cs index 040f346b..1ba1a4a3 100644 --- a/Src/Notion.Client/Models/Blocks/AudioBlock.cs +++ b/Src/Notion.Client/Models/Blocks/AudioBlock.cs @@ -4,9 +4,9 @@ namespace Notion.Client { public class AudioBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Audio; - [JsonProperty("audio")] public FileObject Audio { get; set; } + + public override BlockType Type => BlockType.Audio; } } diff --git a/Src/Notion.Client/Models/Blocks/Block.cs b/Src/Notion.Client/Models/Blocks/Block.cs index 81bcd6bb..883399df 100644 --- a/Src/Notion.Client/Models/Blocks/Block.cs +++ b/Src/Notion.Client/Models/Blocks/Block.cs @@ -21,7 +21,7 @@ public abstract class Block : IBlock public PartialUser LastEditedBy { get; set; } /// - /// Information about the block's parent. + /// Information about the block's parent. /// public IBlockParent Parent { get; set; } } diff --git a/Src/Notion.Client/Models/Blocks/BlockType.cs b/Src/Notion.Client/Models/Blocks/BlockType.cs index 8a2c626a..f15c3b37 100644 --- a/Src/Notion.Client/Models/Blocks/BlockType.cs +++ b/Src/Notion.Client/Models/Blocks/BlockType.cs @@ -101,6 +101,6 @@ public enum BlockType LinkPreview, [EnumMember(Value = "unsupported")] - Unsupported + Unsupported, } } diff --git a/Src/Notion.Client/Models/Blocks/BookmarkBlock.cs b/Src/Notion.Client/Models/Blocks/BookmarkBlock.cs index 735b1725..73099c82 100644 --- a/Src/Notion.Client/Models/Blocks/BookmarkBlock.cs +++ b/Src/Notion.Client/Models/Blocks/BookmarkBlock.cs @@ -5,11 +5,11 @@ namespace Notion.Client { public class BookmarkBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Bookmark; - [JsonProperty("bookmark")] public Info Bookmark { get; set; } + public override BlockType Type => BlockType.Bookmark; + public class Info { [JsonProperty("url")] diff --git a/Src/Notion.Client/Models/Blocks/BreadcrumbBlock.cs b/Src/Notion.Client/Models/Blocks/BreadcrumbBlock.cs index 73ae614d..d5585a40 100644 --- a/Src/Notion.Client/Models/Blocks/BreadcrumbBlock.cs +++ b/Src/Notion.Client/Models/Blocks/BreadcrumbBlock.cs @@ -4,11 +4,11 @@ namespace Notion.Client { public class BreadcrumbBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Breadcrumb; - [JsonProperty("breadcrumb")] public Data Breadcrumb { get; set; } + public override BlockType Type => BlockType.Breadcrumb; + public class Data { } diff --git a/Src/Notion.Client/Models/Blocks/BulletedListItemBlock.cs b/Src/Notion.Client/Models/Blocks/BulletedListItemBlock.cs index 7eca3397..c823b4bd 100644 --- a/Src/Notion.Client/Models/Blocks/BulletedListItemBlock.cs +++ b/Src/Notion.Client/Models/Blocks/BulletedListItemBlock.cs @@ -6,11 +6,11 @@ namespace Notion.Client { public class BulletedListItemBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.BulletedListItem; - [JsonProperty("bulleted_list_item")] public Info BulletedListItem { get; set; } + public override BlockType Type => BlockType.BulletedListItem; + public class Info { [JsonProperty("rich_text")] diff --git a/Src/Notion.Client/Models/Blocks/CalloutBlock.cs b/Src/Notion.Client/Models/Blocks/CalloutBlock.cs index 8cc4bb7a..d4ef61c4 100644 --- a/Src/Notion.Client/Models/Blocks/CalloutBlock.cs +++ b/Src/Notion.Client/Models/Blocks/CalloutBlock.cs @@ -6,11 +6,11 @@ namespace Notion.Client { public class CalloutBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Callout; - [JsonProperty("callout")] public Info Callout { get; set; } + public override BlockType Type => BlockType.Callout; + public class Info { [JsonProperty("rich_text")] diff --git a/Src/Notion.Client/Models/Blocks/ChildDatabaseBlock.cs b/Src/Notion.Client/Models/Blocks/ChildDatabaseBlock.cs index 273836a9..e56fcadb 100644 --- a/Src/Notion.Client/Models/Blocks/ChildDatabaseBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ChildDatabaseBlock.cs @@ -4,11 +4,11 @@ namespace Notion.Client { public class ChildDatabaseBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.ChildDatabase; - [JsonProperty("child_database")] public Info ChildDatabase { get; set; } + public override BlockType Type => BlockType.ChildDatabase; + public class Info { [JsonProperty("title")] diff --git a/Src/Notion.Client/Models/Blocks/ChildPageBlock.cs b/Src/Notion.Client/Models/Blocks/ChildPageBlock.cs index 91c8f343..216b0d82 100644 --- a/Src/Notion.Client/Models/Blocks/ChildPageBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ChildPageBlock.cs @@ -4,11 +4,11 @@ namespace Notion.Client { public class ChildPageBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.ChildPage; - [JsonProperty("child_page")] public Info ChildPage { get; set; } + public override BlockType Type => BlockType.ChildPage; + public class Info { [JsonProperty("title")] diff --git a/Src/Notion.Client/Models/Blocks/CodeBlock.cs b/Src/Notion.Client/Models/Blocks/CodeBlock.cs index 5eb1456b..9cb2c350 100644 --- a/Src/Notion.Client/Models/Blocks/CodeBlock.cs +++ b/Src/Notion.Client/Models/Blocks/CodeBlock.cs @@ -5,11 +5,11 @@ namespace Notion.Client { public class CodeBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Code; - [JsonProperty("code")] public Info Code { get; set; } + public override BlockType Type => BlockType.Code; + public class Info { [JsonProperty("rich_text")] diff --git a/Src/Notion.Client/Models/Blocks/ColumnListBlock.cs b/Src/Notion.Client/Models/Blocks/ColumnListBlock.cs index f86ecba0..59bd6245 100644 --- a/Src/Notion.Client/Models/Blocks/ColumnListBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ColumnListBlock.cs @@ -5,11 +5,11 @@ namespace Notion.Client { public class ColumnListBlock : Block, INonColumnBlock { - public override BlockType Type => BlockType.ColumnList; - [JsonProperty("column_list")] public Info ColumnList { get; set; } + public override BlockType Type => BlockType.ColumnList; + public class Info { [JsonProperty("children")] diff --git a/Src/Notion.Client/Models/Blocks/DividerBlock.cs b/Src/Notion.Client/Models/Blocks/DividerBlock.cs index 61e0301b..26c55783 100644 --- a/Src/Notion.Client/Models/Blocks/DividerBlock.cs +++ b/Src/Notion.Client/Models/Blocks/DividerBlock.cs @@ -4,11 +4,11 @@ namespace Notion.Client { public class DividerBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Divider; - [JsonProperty("divider")] public Data Divider { get; set; } + public override BlockType Type => BlockType.Divider; + public class Data { } diff --git a/Src/Notion.Client/Models/Blocks/EmbedBlock.cs b/Src/Notion.Client/Models/Blocks/EmbedBlock.cs index bbd93e10..92c1dfdd 100644 --- a/Src/Notion.Client/Models/Blocks/EmbedBlock.cs +++ b/Src/Notion.Client/Models/Blocks/EmbedBlock.cs @@ -5,11 +5,11 @@ namespace Notion.Client { public class EmbedBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Embed; - [JsonProperty("embed")] public Info Embed { get; set; } + public override BlockType Type => BlockType.Embed; + public class Info { [JsonProperty("url")] @@ -17,7 +17,6 @@ public class Info [JsonProperty("caption")] public IEnumerable Caption { get; set; } - } } } diff --git a/Src/Notion.Client/Models/Blocks/EquationBlock.cs b/Src/Notion.Client/Models/Blocks/EquationBlock.cs index 310a76df..411c4e3b 100644 --- a/Src/Notion.Client/Models/Blocks/EquationBlock.cs +++ b/Src/Notion.Client/Models/Blocks/EquationBlock.cs @@ -4,11 +4,11 @@ namespace Notion.Client { public class EquationBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Equation; - [JsonProperty("equation")] public Info Equation { get; set; } + public override BlockType Type => BlockType.Equation; + public class Info { [JsonProperty("expression")] diff --git a/Src/Notion.Client/Models/Blocks/FileBlock.cs b/Src/Notion.Client/Models/Blocks/FileBlock.cs index 5495e4bc..7749a693 100644 --- a/Src/Notion.Client/Models/Blocks/FileBlock.cs +++ b/Src/Notion.Client/Models/Blocks/FileBlock.cs @@ -4,9 +4,9 @@ namespace Notion.Client { public class FileBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.File; - [JsonProperty("file")] public FileObject File { get; set; } + + public override BlockType Type => BlockType.File; } } diff --git a/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs b/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs index 853f9ae5..aced5461 100644 --- a/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs +++ b/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs @@ -6,11 +6,11 @@ namespace Notion.Client { public class HeadingOneBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Heading_1; - [JsonProperty("heading_1")] public Info Heading_1 { get; set; } + public override BlockType Type => BlockType.Heading_1; + public override bool HasChildren => false; public class Info diff --git a/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs b/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs index 99d9b861..10999e0e 100644 --- a/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs +++ b/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs @@ -6,11 +6,11 @@ namespace Notion.Client { public class HeadingThreeeBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Heading_3; - [JsonProperty("heading_3")] public Info Heading_3 { get; set; } + public override BlockType Type => BlockType.Heading_3; + public override bool HasChildren => false; public class Info diff --git a/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs b/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs index ea074e8a..553d56f2 100644 --- a/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs +++ b/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs @@ -6,11 +6,11 @@ namespace Notion.Client { public class HeadingTwoBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Heading_2; - [JsonProperty("heading_2")] public Info Heading_2 { get; set; } + public override BlockType Type => BlockType.Heading_2; + public override bool HasChildren => false; public class Info diff --git a/Src/Notion.Client/Models/Blocks/IBlock.cs b/Src/Notion.Client/Models/Blocks/IBlock.cs index a09f923a..fcf5364d 100644 --- a/Src/Notion.Client/Models/Blocks/IBlock.cs +++ b/Src/Notion.Client/Models/Blocks/IBlock.cs @@ -5,38 +5,38 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(AudioBlock), BlockType.Audio)] - [JsonSubtypes.KnownSubType(typeof(BookmarkBlock), BlockType.Bookmark)] - [JsonSubtypes.KnownSubType(typeof(BreadcrumbBlock), BlockType.Breadcrumb)] - [JsonSubtypes.KnownSubType(typeof(BulletedListItemBlock), BlockType.BulletedListItem)] - [JsonSubtypes.KnownSubType(typeof(CalloutBlock), BlockType.Callout)] - [JsonSubtypes.KnownSubType(typeof(ChildPageBlock), BlockType.ChildPage)] - [JsonSubtypes.KnownSubType(typeof(ChildDatabaseBlock), BlockType.ChildDatabase)] - [JsonSubtypes.KnownSubType(typeof(CodeBlock), BlockType.Code)] - [JsonSubtypes.KnownSubType(typeof(ColumnBlock), BlockType.Column)] - [JsonSubtypes.KnownSubType(typeof(ColumnListBlock), BlockType.ColumnList)] - [JsonSubtypes.KnownSubType(typeof(DividerBlock), BlockType.Divider)] - [JsonSubtypes.KnownSubType(typeof(EmbedBlock), BlockType.Embed)] - [JsonSubtypes.KnownSubType(typeof(EquationBlock), BlockType.Equation)] - [JsonSubtypes.KnownSubType(typeof(FileBlock), BlockType.File)] - [JsonSubtypes.KnownSubType(typeof(HeadingOneBlock), BlockType.Heading_1)] - [JsonSubtypes.KnownSubType(typeof(HeadingTwoBlock), BlockType.Heading_2)] - [JsonSubtypes.KnownSubType(typeof(HeadingThreeeBlock), BlockType.Heading_3)] - [JsonSubtypes.KnownSubType(typeof(ImageBlock), BlockType.Image)] - [JsonSubtypes.KnownSubType(typeof(LinkPreviewBlock), BlockType.LinkPreview)] - [JsonSubtypes.KnownSubType(typeof(LinkToPageBlock), BlockType.LinkToPage)] - [JsonSubtypes.KnownSubType(typeof(NumberedListItemBlock), BlockType.NumberedListItem)] - [JsonSubtypes.KnownSubType(typeof(ParagraphBlock), BlockType.Paragraph)] - [JsonSubtypes.KnownSubType(typeof(PDFBlock), BlockType.PDF)] - [JsonSubtypes.KnownSubType(typeof(QuoteBlock), BlockType.Quote)] - [JsonSubtypes.KnownSubType(typeof(TableBlock), BlockType.Table)] - [JsonSubtypes.KnownSubType(typeof(TableRowBlock), BlockType.TableRow)] - [JsonSubtypes.KnownSubType(typeof(TableOfContentsBlock), BlockType.TableOfContents)] - [JsonSubtypes.KnownSubType(typeof(TemplateBlock), BlockType.Template)] - [JsonSubtypes.KnownSubType(typeof(ToDoBlock), BlockType.ToDo)] - [JsonSubtypes.KnownSubType(typeof(ToggleBlock), BlockType.Toggle)] - [JsonSubtypes.KnownSubType(typeof(VideoBlock), BlockType.Video)] - [JsonSubtypes.KnownSubType(typeof(UnsupportedBlock), BlockType.Unsupported)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(AudioBlock), BlockType.Audio)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(BookmarkBlock), BlockType.Bookmark)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(BreadcrumbBlock), BlockType.Breadcrumb)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(BulletedListItemBlock), BlockType.BulletedListItem)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CalloutBlock), BlockType.Callout)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ChildPageBlock), BlockType.ChildPage)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ChildDatabaseBlock), BlockType.ChildDatabase)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CodeBlock), BlockType.Code)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ColumnBlock), BlockType.Column)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ColumnListBlock), BlockType.ColumnList)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(DividerBlock), BlockType.Divider)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(EmbedBlock), BlockType.Embed)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(EquationBlock), BlockType.Equation)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(FileBlock), BlockType.File)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(HeadingOneBlock), BlockType.Heading_1)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(HeadingTwoBlock), BlockType.Heading_2)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(HeadingThreeeBlock), BlockType.Heading_3)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ImageBlock), BlockType.Image)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(LinkPreviewBlock), BlockType.LinkPreview)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(LinkToPageBlock), BlockType.LinkToPage)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(NumberedListItemBlock), BlockType.NumberedListItem)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ParagraphBlock), BlockType.Paragraph)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PDFBlock), BlockType.PDF)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(QuoteBlock), BlockType.Quote)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(TableBlock), BlockType.Table)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(TableRowBlock), BlockType.TableRow)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(TableOfContentsBlock), BlockType.TableOfContents)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(TemplateBlock), BlockType.Template)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ToDoBlock), BlockType.ToDo)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ToggleBlock), BlockType.Toggle)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(VideoBlock), BlockType.Video)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(UnsupportedBlock), BlockType.Unsupported)] public interface IBlock : IObject, IObjectModificationData { [JsonProperty("type")] diff --git a/Src/Notion.Client/Models/Blocks/IBlockParent.cs b/Src/Notion.Client/Models/Blocks/IBlockParent.cs index 73634400..b2f8783f 100644 --- a/Src/Notion.Client/Models/Blocks/IBlockParent.cs +++ b/Src/Notion.Client/Models/Blocks/IBlockParent.cs @@ -4,10 +4,10 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(DatabaseParent), ParentType.DatabaseId)] - [JsonSubtypes.KnownSubType(typeof(PageParent), ParentType.PageId)] - [JsonSubtypes.KnownSubType(typeof(WorkspaceParent), ParentType.Workspace)] - [JsonSubtypes.KnownSubType(typeof(BlockParent), ParentType.BlockId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(DatabaseParent), ParentType.DatabaseId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PageParent), ParentType.PageId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(WorkspaceParent), ParentType.Workspace)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(BlockParent), ParentType.BlockId)] public interface IBlockParent : IParent { } diff --git a/Src/Notion.Client/Models/Blocks/ImageBlock.cs b/Src/Notion.Client/Models/Blocks/ImageBlock.cs index 17aa6bae..cd6b055f 100644 --- a/Src/Notion.Client/Models/Blocks/ImageBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ImageBlock.cs @@ -4,9 +4,9 @@ namespace Notion.Client { public class ImageBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Image; - [JsonProperty("image")] public FileObject Image { get; set; } + + public override BlockType Type => BlockType.Image; } } diff --git a/Src/Notion.Client/Models/Blocks/LinkPreviewBlock.cs b/Src/Notion.Client/Models/Blocks/LinkPreviewBlock.cs index 83f138c6..72107e48 100644 --- a/Src/Notion.Client/Models/Blocks/LinkPreviewBlock.cs +++ b/Src/Notion.Client/Models/Blocks/LinkPreviewBlock.cs @@ -4,13 +4,15 @@ namespace Notion.Client { public class LinkPreviewBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.LinkPreview; + [JsonProperty("link_preview")] + public Data LinkPreview { get; set; } - [JsonProperty("link_preview")] public Data LinkPreview { get; set; } + public override BlockType Type => BlockType.LinkPreview; public class Data { - [JsonProperty("url")] public string Url { get; set; } + [JsonProperty("url")] + public string Url { get; set; } } } } diff --git a/Src/Notion.Client/Models/Blocks/LinkToPageBlock.cs b/Src/Notion.Client/Models/Blocks/LinkToPageBlock.cs index 30d3d7dd..ad688ca2 100644 --- a/Src/Notion.Client/Models/Blocks/LinkToPageBlock.cs +++ b/Src/Notion.Client/Models/Blocks/LinkToPageBlock.cs @@ -4,9 +4,9 @@ namespace Notion.Client { public class LinkToPageBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.LinkToPage; - [JsonProperty("link_to_page")] public IPageParent LinkToPage { get; set; } + + public override BlockType Type => BlockType.LinkToPage; } } diff --git a/Src/Notion.Client/Models/Blocks/NumberedListItemBlock.cs b/Src/Notion.Client/Models/Blocks/NumberedListItemBlock.cs index 3fe0d76a..f4a645e9 100644 --- a/Src/Notion.Client/Models/Blocks/NumberedListItemBlock.cs +++ b/Src/Notion.Client/Models/Blocks/NumberedListItemBlock.cs @@ -6,11 +6,11 @@ namespace Notion.Client { public class NumberedListItemBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.NumberedListItem; - [JsonProperty("numbered_list_item")] public Info NumberedListItem { get; set; } + public override BlockType Type => BlockType.NumberedListItem; + public class Info { [JsonProperty("rich_text")] diff --git a/Src/Notion.Client/Models/Blocks/PDFBlock.cs b/Src/Notion.Client/Models/Blocks/PDFBlock.cs index 85458796..55e3ce42 100644 --- a/Src/Notion.Client/Models/Blocks/PDFBlock.cs +++ b/Src/Notion.Client/Models/Blocks/PDFBlock.cs @@ -4,9 +4,9 @@ namespace Notion.Client { public class PDFBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.PDF; - [JsonProperty("pdf")] public FileObject PDF { get; set; } + + public override BlockType Type => BlockType.PDF; } } diff --git a/Src/Notion.Client/Models/Blocks/ParagraphBlock.cs b/Src/Notion.Client/Models/Blocks/ParagraphBlock.cs index 67458b3c..f3b73f36 100644 --- a/Src/Notion.Client/Models/Blocks/ParagraphBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ParagraphBlock.cs @@ -6,11 +6,11 @@ namespace Notion.Client { public class ParagraphBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Paragraph; - [JsonProperty("paragraph")] public Info Paragraph { get; set; } + public override BlockType Type => BlockType.Paragraph; + public class Info { [JsonProperty("rich_text")] diff --git a/Src/Notion.Client/Models/Blocks/QuoteBlock.cs b/Src/Notion.Client/Models/Blocks/QuoteBlock.cs index 5fdad7da..e1466be6 100644 --- a/Src/Notion.Client/Models/Blocks/QuoteBlock.cs +++ b/Src/Notion.Client/Models/Blocks/QuoteBlock.cs @@ -6,11 +6,11 @@ namespace Notion.Client { public class QuoteBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Quote; - [JsonProperty("quote")] public Info Quote { get; set; } + public override BlockType Type => BlockType.Quote; + public class Info { [JsonProperty("rich_text")] diff --git a/Src/Notion.Client/Models/Blocks/SyncedBlockBlock.cs b/Src/Notion.Client/Models/Blocks/SyncedBlockBlock.cs index 33c4dd25..98aa1d0f 100644 --- a/Src/Notion.Client/Models/Blocks/SyncedBlockBlock.cs +++ b/Src/Notion.Client/Models/Blocks/SyncedBlockBlock.cs @@ -5,11 +5,11 @@ namespace Notion.Client { public class SyncedBlockBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.SyncedBlock; - [JsonProperty("synced_block")] public Data SyncedBlock { get; set; } + public override BlockType Type => BlockType.SyncedBlock; + public class Data { [JsonProperty("synced_from")] diff --git a/Src/Notion.Client/Models/Blocks/TableBlock.cs b/Src/Notion.Client/Models/Blocks/TableBlock.cs index dd20d94b..cf41440c 100644 --- a/Src/Notion.Client/Models/Blocks/TableBlock.cs +++ b/Src/Notion.Client/Models/Blocks/TableBlock.cs @@ -4,11 +4,11 @@ namespace Notion.Client { public class TableBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Table; - [JsonProperty("table")] public TableInfo Table { get; set; } + public override BlockType Type => BlockType.Table; + public class TableInfo { [JsonProperty("table_width")] diff --git a/Src/Notion.Client/Models/Blocks/TableOfContentsBlock.cs b/Src/Notion.Client/Models/Blocks/TableOfContentsBlock.cs index 991ff903..0a6c9f26 100644 --- a/Src/Notion.Client/Models/Blocks/TableOfContentsBlock.cs +++ b/Src/Notion.Client/Models/Blocks/TableOfContentsBlock.cs @@ -5,11 +5,11 @@ namespace Notion.Client { public class TableOfContentsBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.TableOfContents; - [JsonProperty("table_of_contents")] public Data TableOfContents { get; set; } + public override BlockType Type => BlockType.TableOfContents; + public class Data { [JsonProperty("color")] diff --git a/Src/Notion.Client/Models/Blocks/TableRowBlock.cs b/Src/Notion.Client/Models/Blocks/TableRowBlock.cs index e7214e6c..be105447 100644 --- a/Src/Notion.Client/Models/Blocks/TableRowBlock.cs +++ b/Src/Notion.Client/Models/Blocks/TableRowBlock.cs @@ -5,11 +5,11 @@ namespace Notion.Client { public class TableRowBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.TableRow; - [JsonProperty("table_row")] public Info TableRow { get; set; } + public override BlockType Type => BlockType.TableRow; + public class Info { [JsonProperty("cells")] diff --git a/Src/Notion.Client/Models/Blocks/TemplateBlock.cs b/Src/Notion.Client/Models/Blocks/TemplateBlock.cs index 69a78b62..705eaac3 100644 --- a/Src/Notion.Client/Models/Blocks/TemplateBlock.cs +++ b/Src/Notion.Client/Models/Blocks/TemplateBlock.cs @@ -5,11 +5,11 @@ namespace Notion.Client { public class TemplateBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Template; - [JsonProperty("template")] public Data Template { get; set; } + public override BlockType Type => BlockType.Template; + public class Data { [JsonProperty("rich_text")] diff --git a/Src/Notion.Client/Models/Blocks/ToDoBlock.cs b/Src/Notion.Client/Models/Blocks/ToDoBlock.cs index 8b153f3b..0c52201a 100644 --- a/Src/Notion.Client/Models/Blocks/ToDoBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ToDoBlock.cs @@ -6,11 +6,11 @@ namespace Notion.Client { public class ToDoBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.ToDo; - [JsonProperty("to_do")] public Info ToDo { get; set; } + public override BlockType Type => BlockType.ToDo; + public class Info { [JsonProperty("rich_text")] diff --git a/Src/Notion.Client/Models/Blocks/ToggleBlock.cs b/Src/Notion.Client/Models/Blocks/ToggleBlock.cs index 6646e9be..f61a1368 100644 --- a/Src/Notion.Client/Models/Blocks/ToggleBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ToggleBlock.cs @@ -6,11 +6,11 @@ namespace Notion.Client { public class ToggleBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Toggle; - [JsonProperty("toggle")] public Info Toggle { get; set; } + public override BlockType Type => BlockType.Toggle; + public class Info { [JsonProperty("rich_text")] diff --git a/Src/Notion.Client/Models/Blocks/VideoBlock.cs b/Src/Notion.Client/Models/Blocks/VideoBlock.cs index 015bed96..7713ff7b 100644 --- a/Src/Notion.Client/Models/Blocks/VideoBlock.cs +++ b/Src/Notion.Client/Models/Blocks/VideoBlock.cs @@ -4,9 +4,9 @@ namespace Notion.Client { public class VideoBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Video; - [JsonProperty("video")] public FileObject Video { get; set; } + + public override BlockType Type => BlockType.Video; } } diff --git a/Src/Notion.Client/Models/Common/IObjectModificationData.cs b/Src/Notion.Client/Models/Common/IObjectModificationData.cs index 06177ccd..0e70ffcf 100644 --- a/Src/Notion.Client/Models/Common/IObjectModificationData.cs +++ b/Src/Notion.Client/Models/Common/IObjectModificationData.cs @@ -6,25 +6,25 @@ namespace Notion.Client public interface IObjectModificationData { /// - /// Date and time when this object was created. + /// Date and time when this object was created. /// [JsonProperty("created_time")] DateTime CreatedTime { get; set; } /// - /// Date and time when this object was updated. + /// Date and time when this object was updated. /// [JsonProperty("last_edited_time")] DateTime LastEditedTime { get; set; } /// - /// User who created the object. + /// User who created the object. /// [JsonProperty("created_by")] PartialUser CreatedBy { get; set; } /// - /// User who last modified the object. + /// User who last modified the object. /// [JsonProperty("last_edited_by")] PartialUser LastEditedBy { get; set; } diff --git a/Src/Notion.Client/Models/Database/Database.cs b/Src/Notion.Client/Models/Database/Database.cs index 502d8a5a..33da29b7 100644 --- a/Src/Notion.Client/Models/Database/Database.cs +++ b/Src/Notion.Client/Models/Database/Database.cs @@ -6,16 +6,6 @@ namespace Notion.Client { public class Database : IObject, IObjectModificationData { - public ObjectType Object => ObjectType.Database; - - public string Id { get; set; } - - [JsonProperty("created_time")] - public DateTime CreatedTime { get; set; } - - [JsonProperty("last_edited_time")] - public DateTime LastEditedTime { get; set; } - [JsonProperty("title")] public List Title { get; set; } @@ -32,25 +22,35 @@ public class Database : IObject, IObjectModificationData public FileObject Cover { get; set; } /// - /// The URL of the Notion database. + /// The URL of the Notion database. /// [JsonProperty("url")] public string Url { get; set; } /// - /// The archived status of the database. + /// The archived status of the database. /// [JsonProperty("archived")] public bool Archived { get; set; } - public PartialUser CreatedBy { get; set; } - - public PartialUser LastEditedBy { get; set; } - [JsonProperty("is_inline")] public bool IsInline { get; set; } [JsonProperty("description")] public IEnumerable Description { get; set; } + + public ObjectType Object => ObjectType.Database; + + public string Id { get; set; } + + [JsonProperty("created_time")] + public DateTime CreatedTime { get; set; } + + [JsonProperty("last_edited_time")] + public DateTime LastEditedTime { get; set; } + + public PartialUser CreatedBy { get; set; } + + public PartialUser LastEditedBy { get; set; } } } diff --git a/Src/Notion.Client/Models/Database/IDatabaseParent.cs b/Src/Notion.Client/Models/Database/IDatabaseParent.cs index 59233c38..768f815b 100644 --- a/Src/Notion.Client/Models/Database/IDatabaseParent.cs +++ b/Src/Notion.Client/Models/Database/IDatabaseParent.cs @@ -4,9 +4,9 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(PageParent), ParentType.PageId)] - [JsonSubtypes.KnownSubType(typeof(WorkspaceParent), ParentType.Workspace)] - [JsonSubtypes.KnownSubType(typeof(BlockParent), ParentType.BlockId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PageParent), ParentType.PageId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(WorkspaceParent), ParentType.Workspace)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(BlockParent), ParentType.BlockId)] public interface IDatabaseParent : IParent { } diff --git a/Src/Notion.Client/Models/Database/Properties/Property.cs b/Src/Notion.Client/Models/Database/Properties/Property.cs index 1f61b0dc..163b7ef0 100644 --- a/Src/Notion.Client/Models/Database/Properties/Property.cs +++ b/Src/Notion.Client/Models/Database/Properties/Property.cs @@ -5,26 +5,26 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(CheckboxProperty), PropertyType.Checkbox)] - [JsonSubtypes.KnownSubType(typeof(CreatedByProperty), PropertyType.CreatedBy)] - [JsonSubtypes.KnownSubType(typeof(CreatedTimeProperty), PropertyType.CreatedTime)] - [JsonSubtypes.KnownSubType(typeof(DateProperty), PropertyType.Date)] - [JsonSubtypes.KnownSubType(typeof(EmailProperty), PropertyType.Email)] - [JsonSubtypes.KnownSubType(typeof(FilesProperty), PropertyType.Files)] - [JsonSubtypes.KnownSubType(typeof(FormulaProperty), PropertyType.Formula)] - [JsonSubtypes.KnownSubType(typeof(LastEditedByProperty), PropertyType.LastEditedBy)] - [JsonSubtypes.KnownSubType(typeof(LastEditedTimeProperty), PropertyType.LastEditedTime)] - [JsonSubtypes.KnownSubType(typeof(MultiSelectProperty), PropertyType.MultiSelect)] - [JsonSubtypes.KnownSubType(typeof(NumberProperty), PropertyType.Number)] - [JsonSubtypes.KnownSubType(typeof(PeopleProperty), PropertyType.People)] - [JsonSubtypes.KnownSubType(typeof(PhoneNumberProperty), PropertyType.PhoneNumber)] - [JsonSubtypes.KnownSubType(typeof(RelationProperty), PropertyType.Relation)] - [JsonSubtypes.KnownSubType(typeof(RichTextProperty), PropertyType.RichText)] - [JsonSubtypes.KnownSubType(typeof(RollupProperty), PropertyType.Rollup)] - [JsonSubtypes.KnownSubType(typeof(SelectProperty), PropertyType.Select)] - [JsonSubtypes.KnownSubType(typeof(StatusProperty), PropertyType.Status)] - [JsonSubtypes.KnownSubType(typeof(TitleProperty), PropertyType.Title)] - [JsonSubtypes.KnownSubType(typeof(UrlProperty), PropertyType.Url)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CheckboxProperty), PropertyType.Checkbox)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CreatedByProperty), PropertyType.CreatedBy)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CreatedTimeProperty), PropertyType.CreatedTime)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(DateProperty), PropertyType.Date)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(EmailProperty), PropertyType.Email)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(FilesProperty), PropertyType.Files)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(FormulaProperty), PropertyType.Formula)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(LastEditedByProperty), PropertyType.LastEditedBy)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(LastEditedTimeProperty), PropertyType.LastEditedTime)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(MultiSelectProperty), PropertyType.MultiSelect)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(NumberProperty), PropertyType.Number)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PeopleProperty), PropertyType.People)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PhoneNumberProperty), PropertyType.PhoneNumber)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RelationProperty), PropertyType.Relation)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RichTextProperty), PropertyType.RichText)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RollupProperty), PropertyType.Rollup)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(SelectProperty), PropertyType.Select)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(StatusProperty), PropertyType.Status)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(TitleProperty), PropertyType.Title)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(UrlProperty), PropertyType.Url)] public class Property { [JsonProperty("id")] diff --git a/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationData.cs b/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationData.cs index 87e4b10a..d129acc6 100644 --- a/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationData.cs +++ b/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationData.cs @@ -5,8 +5,8 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(SinglePropertyRelation), RelationType.Single)] - [JsonSubtypes.KnownSubType(typeof(DualPropertyRelation), RelationType.Dual)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(SinglePropertyRelation), RelationType.Single)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(DualPropertyRelation), RelationType.Dual)] public abstract class RelationData { [JsonProperty("database_id")] diff --git a/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationProperty.cs b/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationProperty.cs index 103cdc0c..382e7088 100644 --- a/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationProperty.cs +++ b/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationProperty.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; -using System.Runtime.Serialization; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Notion.Client { diff --git a/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationType.cs b/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationType.cs index 89ce1c56..a0a58a47 100644 --- a/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationType.cs +++ b/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationType.cs @@ -8,6 +8,6 @@ public enum RelationType Single, [EnumMember(Value = "dual_property")] - Dual + Dual, } } diff --git a/Src/Notion.Client/Models/Database/Properties/SelectProperty.cs b/Src/Notion.Client/Models/Database/Properties/SelectProperty.cs index 3ed99234..9af6397b 100644 --- a/Src/Notion.Client/Models/Database/Properties/SelectProperty.cs +++ b/Src/Notion.Client/Models/Database/Properties/SelectProperty.cs @@ -7,6 +7,7 @@ namespace Notion.Client public class SelectProperty : Property { public override PropertyType Type => PropertyType.Select; + public OptionWrapper Select { get; set; } } @@ -19,19 +20,20 @@ public class OptionWrapper public class SelectOption { /// - /// Name of the option as it appears in Notion. + /// Name of the option as it appears in Notion. /// [JsonProperty("name")] public string Name { get; set; } /// - /// ID of the option. + /// ID of the option. /// [JsonProperty("id")] public string Id { get; set; } /// - /// Color of the option. Possible values are: "default", "gray", "brown", "red", "orange", "yellow", "green", "blue", "purple", "pink". Defaults to "default". + /// Color of the option. Possible values are: "default", "gray", "brown", "red", "orange", "yellow", "green", "blue", + /// "purple", "pink". Defaults to "default". /// [JsonProperty("color")] [JsonConverter(typeof(StringEnumConverter))] diff --git a/Src/Notion.Client/Models/Database/RichText/RichTextBase.cs b/Src/Notion.Client/Models/Database/RichText/RichTextBase.cs index 88af1acd..3f10d578 100644 --- a/Src/Notion.Client/Models/Database/RichText/RichTextBase.cs +++ b/Src/Notion.Client/Models/Database/RichText/RichTextBase.cs @@ -5,9 +5,9 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(RichTextText), RichTextType.Text)] - [JsonSubtypes.KnownSubType(typeof(RichTextEquation), RichTextType.Equation)] - [JsonSubtypes.KnownSubType(typeof(RichTextMention), RichTextType.Mention)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RichTextText), RichTextType.Text)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RichTextEquation), RichTextType.Equation)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RichTextMention), RichTextType.Mention)] public class RichTextBase { [JsonProperty("plain_text")] diff --git a/Src/Notion.Client/Models/Database/RichText/RichTextType.cs b/Src/Notion.Client/Models/Database/RichText/RichTextType.cs index 59bc414f..58406612 100644 --- a/Src/Notion.Client/Models/Database/RichText/RichTextType.cs +++ b/Src/Notion.Client/Models/Database/RichText/RichTextType.cs @@ -14,6 +14,6 @@ public enum RichTextType Mention, [EnumMember(Value = "equation")] - Equation + Equation, } } diff --git a/Src/Notion.Client/Models/EmojiObject.cs b/Src/Notion.Client/Models/EmojiObject.cs index 95c67b61..9b5c64df 100644 --- a/Src/Notion.Client/Models/EmojiObject.cs +++ b/Src/Notion.Client/Models/EmojiObject.cs @@ -4,10 +4,10 @@ namespace Notion.Client { public class EmojiObject : IPageIcon { - [JsonProperty("type")] - public string Type { get; set; } - [JsonProperty("emoji")] public string Emoji { get; set; } + + [JsonProperty("type")] + public string Type { get; set; } } } diff --git a/Src/Notion.Client/Models/File/FileObject.cs b/Src/Notion.Client/Models/File/FileObject.cs index ce4d02f0..9ed206de 100644 --- a/Src/Notion.Client/Models/File/FileObject.cs +++ b/Src/Notion.Client/Models/File/FileObject.cs @@ -5,14 +5,14 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(UploadedFile), "file")] - [JsonSubtypes.KnownSubType(typeof(ExternalFile), "external")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(UploadedFile), "file")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ExternalFile), "external")] public abstract class FileObject : IPageIcon { - [JsonProperty("type")] - public virtual string Type { get; set; } - [JsonProperty("caption")] public IEnumerable Caption { get; set; } + + [JsonProperty("type")] + public virtual string Type { get; set; } } } diff --git a/Src/Notion.Client/Models/File/FileObjectWithName.cs b/Src/Notion.Client/Models/File/FileObjectWithName.cs index a7381929..855a5e0f 100644 --- a/Src/Notion.Client/Models/File/FileObjectWithName.cs +++ b/Src/Notion.Client/Models/File/FileObjectWithName.cs @@ -4,8 +4,8 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(UploadedFileWithName), "file")] - [JsonSubtypes.KnownSubType(typeof(ExternalFileWithName), "external")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(UploadedFileWithName), "file")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ExternalFileWithName), "external")] public abstract class FileObjectWithName { [JsonProperty("type")] diff --git a/Src/Notion.Client/Models/Filters/CheckboxFilter.cs b/Src/Notion.Client/Models/Filters/CheckboxFilter.cs index da144aec..53343e35 100644 --- a/Src/Notion.Client/Models/Filters/CheckboxFilter.cs +++ b/Src/Notion.Client/Models/Filters/CheckboxFilter.cs @@ -1,35 +1,34 @@ -using System; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Notion.Client { public class CheckboxFilter : SinglePropertyFilter, IRollupSubPropertyFilter { - [JsonProperty("checkbox")] - public Condition Checkbox { get; set; } - public CheckboxFilter( string propertyName, bool? equal = null, bool? doesNotEqual = null) { Property = propertyName; - Checkbox = new Condition(equal: equal, doesNotEqual: doesNotEqual); + Checkbox = new Condition(equal, doesNotEqual); } + [JsonProperty("checkbox")] + public Condition Checkbox { get; set; } + public class Condition { + public Condition(bool? equal = null, bool? doesNotEqual = null) + { + Equal = equal; + DoesNotEqual = doesNotEqual; + } + [JsonProperty("equals")] public bool? Equal { get; set; } [JsonProperty("does_not_equal")] public bool? DoesNotEqual { get; set; } - - public Condition(Nullable equal = null, Nullable doesNotEqual = null) - { - Equal = equal; - DoesNotEqual = doesNotEqual; - } } } } diff --git a/Src/Notion.Client/Models/Filters/DateFilter.cs b/Src/Notion.Client/Models/Filters/DateFilter.cs index 51b38dc2..dde7ad47 100644 --- a/Src/Notion.Client/Models/Filters/DateFilter.cs +++ b/Src/Notion.Client/Models/Filters/DateFilter.cs @@ -7,9 +7,6 @@ namespace Notion.Client { public class DateFilter : SinglePropertyFilter, IRollupSubPropertyFilter { - [JsonProperty("date")] - public Condition Date { get; set; } - public DateFilter( string propertyName, DateTime? equal = null, @@ -27,25 +24,59 @@ public DateFilter( bool? isNotEmpty = null) { Property = propertyName; + Date = new Condition( - equal: equal, - before: before, - after: after, - onOrBefore: onOrBefore, - onOrAfter: onOrAfter, - pastWeek: pastWeek, - pastMonth: pastMonth, - pastYear: pastYear, - nextWeek: nextWeek, - nextMonth: nextMonth, - nextYear: nextYear, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + before, + after, + onOrBefore, + onOrAfter, + pastWeek, + pastMonth, + pastYear, + nextWeek, + nextMonth, + nextYear, + isEmpty, + isNotEmpty ); } + [JsonProperty("date")] + public Condition Date { get; set; } + public class Condition { + public Condition( + DateTime? equal = null, + DateTime? before = null, + DateTime? after = null, + DateTime? onOrBefore = null, + DateTime? onOrAfter = null, + Dictionary pastWeek = null, + Dictionary pastMonth = null, + Dictionary pastYear = null, + Dictionary nextWeek = null, + Dictionary nextMonth = null, + Dictionary nextYear = null, + bool? isEmpty = null, + bool? isNotEmpty = null) + { + Equal = equal; + Before = before; + After = after; + OnOrBefore = onOrBefore; + OnOrAfter = onOrAfter; + PastWeek = pastWeek; + PastMonth = pastMonth; + PastYear = pastYear; + NextWeek = nextWeek; + NextMonth = nextMonth; + NextYear = nextYear; + IsEmpty = isEmpty; + IsNotEmpty = isNotEmpty; + } + [JsonProperty("equals")] [JsonConverter(typeof(IsoDateTimeConverter))] public DateTime? Equal { get; set; } @@ -89,36 +120,6 @@ public class Condition [JsonProperty("is_not_empty")] public bool? IsNotEmpty { get; set; } - - public Condition( - DateTime? equal = null, - DateTime? before = null, - DateTime? after = null, - DateTime? onOrBefore = null, - DateTime? onOrAfter = null, - Dictionary pastWeek = null, - Dictionary pastMonth = null, - Dictionary pastYear = null, - Dictionary nextWeek = null, - Dictionary nextMonth = null, - Dictionary nextYear = null, - bool? isEmpty = null, - bool? isNotEmpty = null) - { - Equal = equal; - Before = before; - After = after; - OnOrBefore = onOrBefore; - OnOrAfter = onOrAfter; - PastWeek = pastWeek; - PastMonth = pastMonth; - PastYear = pastYear; - NextWeek = nextWeek; - NextMonth = nextMonth; - NextYear = nextYear; - IsEmpty = isEmpty; - IsNotEmpty = isNotEmpty; - } } } } diff --git a/Src/Notion.Client/Models/Filters/EmailFilter.cs b/Src/Notion.Client/Models/Filters/EmailFilter.cs index ff5feda9..36bc3dde 100644 --- a/Src/Notion.Client/Models/Filters/EmailFilter.cs +++ b/Src/Notion.Client/Models/Filters/EmailFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class EmailFilter : SinglePropertyFilter { - [JsonProperty("email")] - public TextFilter.Condition Email { get; set; } - public EmailFilter( string propertyName, string equal = null, @@ -19,16 +16,20 @@ public EmailFilter( bool? isNotEmpty = null) { Property = propertyName; + Email = new TextFilter.Condition( - equal: equal, - doesNotEqual: doesNotEqual, - contains: contains, - doesNotContain: doesNotContain, - startsWith: startsWith, - endsWith: endsWith, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + doesNotEqual, + contains, + doesNotContain, + startsWith, + endsWith, + isEmpty, + isNotEmpty ); } + + [JsonProperty("email")] + public TextFilter.Condition Email { get; set; } } } diff --git a/Src/Notion.Client/Models/Filters/FilesFilter.cs b/Src/Notion.Client/Models/Filters/FilesFilter.cs index a32d4d7b..6c4b23c6 100644 --- a/Src/Notion.Client/Models/Filters/FilesFilter.cs +++ b/Src/Notion.Client/Models/Filters/FilesFilter.cs @@ -4,26 +4,20 @@ namespace Notion.Client { public class FilesFilter : SinglePropertyFilter, IRollupSubPropertyFilter { - [JsonProperty("files")] - public Condition Files { get; set; } - public FilesFilter( string propertyName, bool? isEmpty = null, bool? isNotEmpty = null) { Property = propertyName; - Files = new Condition(isEmpty: isEmpty, isNotEmpty: isNotEmpty); + Files = new Condition(isEmpty, isNotEmpty); } + [JsonProperty("files")] + public Condition Files { get; set; } + public class Condition { - [JsonProperty("is_empty")] - public bool? IsEmpty { get; set; } - - [JsonProperty("is_not_empty")] - public bool? IsNotEmpty { get; set; } - public Condition( bool? isEmpty = null, bool? isNotEmpty = null) @@ -31,6 +25,12 @@ public Condition( IsEmpty = isEmpty; IsNotEmpty = isNotEmpty; } + + [JsonProperty("is_empty")] + public bool? IsEmpty { get; set; } + + [JsonProperty("is_not_empty")] + public bool? IsNotEmpty { get; set; } } } } diff --git a/Src/Notion.Client/Models/Filters/Filter.cs b/Src/Notion.Client/Models/Filters/Filter.cs index 61f81f7e..47eced53 100644 --- a/Src/Notion.Client/Models/Filters/Filter.cs +++ b/Src/Notion.Client/Models/Filters/Filter.cs @@ -5,7 +5,6 @@ namespace Notion.Client { public class Filter { - } public class SinglePropertyFilter : Filter @@ -16,16 +15,16 @@ public class SinglePropertyFilter : Filter public class CompoundFilter : Filter { - [JsonProperty("or")] - public List Or { get; set; } - - [JsonProperty("and")] - public List And { get; set; } - public CompoundFilter(List or = null, List and = null) { Or = or; And = and; } + + [JsonProperty("or")] + public List Or { get; set; } + + [JsonProperty("and")] + public List And { get; set; } } } diff --git a/Src/Notion.Client/Models/Filters/FormulaFilter.cs b/Src/Notion.Client/Models/Filters/FormulaFilter.cs index eee9fc52..5aec5e00 100644 --- a/Src/Notion.Client/Models/Filters/FormulaFilter.cs +++ b/Src/Notion.Client/Models/Filters/FormulaFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class FormulaFilter : SinglePropertyFilter { - [JsonProperty("formula")] - public Condition Formula { get; set; } - public FormulaFilter( string propertyName, TextFilter.Condition @string = null, @@ -15,28 +12,20 @@ public FormulaFilter( DateFilter.Condition date = null) { Property = propertyName; + Formula = new Condition( - @string: @string, - checkbox: checkbox, - number: number, - date: date + @string, + checkbox, + number, + date ); } + [JsonProperty("formula")] + public Condition Formula { get; set; } + public class Condition { - [JsonProperty("string")] - public TextFilter.Condition String { get; set; } - - [JsonProperty("checkbox")] - public CheckboxFilter.Condition Checkbox { get; set; } - - [JsonProperty("number")] - public NumberFilter.Condition Number { get; set; } - - [JsonProperty("date")] - public DateFilter.Condition Date { get; set; } - public Condition( TextFilter.Condition @string = null, CheckboxFilter.Condition checkbox = null, @@ -48,6 +37,18 @@ public Condition( Number = number; Date = date; } + + [JsonProperty("string")] + public TextFilter.Condition String { get; set; } + + [JsonProperty("checkbox")] + public CheckboxFilter.Condition Checkbox { get; set; } + + [JsonProperty("number")] + public NumberFilter.Condition Number { get; set; } + + [JsonProperty("date")] + public DateFilter.Condition Date { get; set; } } } } diff --git a/Src/Notion.Client/Models/Filters/MultiSelectFilter.cs b/Src/Notion.Client/Models/Filters/MultiSelectFilter.cs index 14aec6d5..011a127e 100644 --- a/Src/Notion.Client/Models/Filters/MultiSelectFilter.cs +++ b/Src/Notion.Client/Models/Filters/MultiSelectFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class MultiSelectFilter : SinglePropertyFilter, IRollupSubPropertyFilter { - [JsonProperty("multi_select")] - public Condition MultiSelect { get; set; } - public MultiSelectFilter( string propertyName, string contains = null, @@ -15,29 +12,20 @@ public MultiSelectFilter( bool? isNotEmpty = null) { Property = propertyName; + MultiSelect = new Condition( - contains: contains, - doesNotContain: doesNotContain, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + contains, + doesNotContain, + isEmpty, + isNotEmpty ); } + [JsonProperty("multi_select")] + public Condition MultiSelect { get; set; } public class Condition { - [JsonProperty("contains")] - public string Contains { get; set; } - - [JsonProperty("does_not_contain")] - public string DoesNotContain { get; set; } - - [JsonProperty("is_empty")] - public bool? IsEmpty { get; set; } - - [JsonProperty("is_not_empty")] - public bool? IsNotEmpty { get; set; } - public Condition( string contains = null, string doesNotContain = null, @@ -49,7 +37,18 @@ public Condition( IsEmpty = isEmpty; IsNotEmpty = isNotEmpty; } - } + [JsonProperty("contains")] + public string Contains { get; set; } + + [JsonProperty("does_not_contain")] + public string DoesNotContain { get; set; } + + [JsonProperty("is_empty")] + public bool? IsEmpty { get; set; } + + [JsonProperty("is_not_empty")] + public bool? IsNotEmpty { get; set; } + } } } diff --git a/Src/Notion.Client/Models/Filters/NumberFilter.cs b/Src/Notion.Client/Models/Filters/NumberFilter.cs index 4895d3e8..1a2f6879 100644 --- a/Src/Notion.Client/Models/Filters/NumberFilter.cs +++ b/Src/Notion.Client/Models/Filters/NumberFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class NumberFilter : SinglePropertyFilter, IRollupSubPropertyFilter { - [JsonProperty("number")] - public Condition Number { get; set; } - public NumberFilter( string propertyName, double? equal = null, @@ -19,20 +16,44 @@ public NumberFilter( bool? isNotEmpty = null) { Property = propertyName; + Number = new Condition( - equal: equal, - doesNotEqual: doesNotEqual, - greaterThan: greaterThan, - lessThan: lessThan, - greaterThanOrEqualTo: greaterThanOrEqualTo, - lessThanOrEqualTo: lessThanOrEqualTo, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + doesNotEqual, + greaterThan, + lessThan, + greaterThanOrEqualTo, + lessThanOrEqualTo, + isEmpty, + isNotEmpty ); } + [JsonProperty("number")] + public Condition Number { get; set; } + public class Condition { + public Condition( + double? equal = null, + double? doesNotEqual = null, + double? greaterThan = null, + double? lessThan = null, + double? greaterThanOrEqualTo = null, + double? lessThanOrEqualTo = null, + bool? isEmpty = null, + bool? isNotEmpty = null) + { + Equal = equal; + DoesNotEqual = doesNotEqual; + GreaterThan = greaterThan; + LessThan = lessThan; + GreaterThanOrEqualTo = greaterThanOrEqualTo; + LessThanOrEqualTo = lessThanOrEqualTo; + IsEmpty = isEmpty; + IsNotEmpty = isNotEmpty; + } + [JsonProperty("equals")] public double? Equal { get; set; } @@ -56,27 +77,6 @@ public class Condition [JsonProperty("is_not_empty")] public bool? IsNotEmpty { get; set; } - - public Condition( - double? equal = null, - double? doesNotEqual = null, - double? greaterThan = null, - double? lessThan = null, - double? greaterThanOrEqualTo = null, - double? lessThanOrEqualTo = null, - bool? isEmpty = null, - bool? isNotEmpty = null) - { - Equal = equal; - DoesNotEqual = doesNotEqual; - GreaterThan = greaterThan; - LessThan = lessThan; - GreaterThanOrEqualTo = greaterThanOrEqualTo; - LessThanOrEqualTo = lessThanOrEqualTo; - IsEmpty = isEmpty; - IsNotEmpty = isNotEmpty; - } } - } } diff --git a/Src/Notion.Client/Models/Filters/PeopleFilter.cs b/Src/Notion.Client/Models/Filters/PeopleFilter.cs index af1067c4..6b83dda4 100644 --- a/Src/Notion.Client/Models/Filters/PeopleFilter.cs +++ b/Src/Notion.Client/Models/Filters/PeopleFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class PeopleFilter : SinglePropertyFilter, IRollupSubPropertyFilter { - [JsonProperty("people")] - public Condition People { get; set; } - public PeopleFilter( string propertyName, string contains = null, @@ -15,28 +12,20 @@ public PeopleFilter( bool? isNotEmpty = null) { Property = propertyName; + People = new Condition( - contains: contains, - doesNotContain: doesNotContain, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + contains, + doesNotContain, + isEmpty, + isNotEmpty ); } + [JsonProperty("people")] + public Condition People { get; set; } + public class Condition { - [JsonProperty("contains")] - public string Contains { get; set; } - - [JsonProperty("does_not_contain")] - public string DoesNotContain { get; set; } - - [JsonProperty("is_empty")] - public bool? IsEmpty { get; set; } - - [JsonProperty("is_not_empty")] - public bool? IsNotEmpty { get; set; } - public Condition( string contains = null, string doesNotContain = null, @@ -48,6 +37,18 @@ public Condition( IsEmpty = isEmpty; IsNotEmpty = isNotEmpty; } + + [JsonProperty("contains")] + public string Contains { get; set; } + + [JsonProperty("does_not_contain")] + public string DoesNotContain { get; set; } + + [JsonProperty("is_empty")] + public bool? IsEmpty { get; set; } + + [JsonProperty("is_not_empty")] + public bool? IsNotEmpty { get; set; } } } } diff --git a/Src/Notion.Client/Models/Filters/PhoneNumberFilter.cs b/Src/Notion.Client/Models/Filters/PhoneNumberFilter.cs index 758a65db..9ea9cf68 100644 --- a/Src/Notion.Client/Models/Filters/PhoneNumberFilter.cs +++ b/Src/Notion.Client/Models/Filters/PhoneNumberFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class PhoneNumberFilter : SinglePropertyFilter { - [JsonProperty("phone_number")] - public TextFilter.Condition Text { get; set; } - public PhoneNumberFilter( string propertyName, string equal = null, @@ -19,16 +16,20 @@ public PhoneNumberFilter( bool? isNotEmpty = null) { Property = propertyName; + Text = new TextFilter.Condition( - equal: equal, - doesNotEqual: doesNotEqual, - contains: contains, - doesNotContain: doesNotContain, - startsWith: startsWith, - endsWith: endsWith, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + doesNotEqual, + contains, + doesNotContain, + startsWith, + endsWith, + isEmpty, + isNotEmpty ); } + + [JsonProperty("phone_number")] + public TextFilter.Condition Text { get; set; } } } diff --git a/Src/Notion.Client/Models/Filters/RelationFilter.cs b/Src/Notion.Client/Models/Filters/RelationFilter.cs index b7e2924d..bff5f498 100644 --- a/Src/Notion.Client/Models/Filters/RelationFilter.cs +++ b/Src/Notion.Client/Models/Filters/RelationFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class RelationFilter : SinglePropertyFilter, IRollupSubPropertyFilter { - [JsonProperty("relation")] - public Condition Relation { get; set; } - public RelationFilter( string propertyName, string contains = null, @@ -15,28 +12,20 @@ public RelationFilter( bool? isNotEmpty = null) { Property = propertyName; + Relation = new Condition( - contains: contains, - doesNotContain: doesNotContain, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + contains, + doesNotContain, + isEmpty, + isNotEmpty ); } + [JsonProperty("relation")] + public Condition Relation { get; set; } + public class Condition { - [JsonProperty("contains")] - public string Contains { get; set; } - - [JsonProperty("does_not_contain")] - public string DoesNotContain { get; set; } - - [JsonProperty("is_empty")] - public bool? IsEmpty { get; set; } - - [JsonProperty("is_not_empty")] - public bool? IsNotEmpty { get; set; } - public Condition( string contains = null, string doesNotContain = null, @@ -48,6 +37,18 @@ public Condition( IsEmpty = isEmpty; IsNotEmpty = isNotEmpty; } + + [JsonProperty("contains")] + public string Contains { get; set; } + + [JsonProperty("does_not_contain")] + public string DoesNotContain { get; set; } + + [JsonProperty("is_empty")] + public bool? IsEmpty { get; set; } + + [JsonProperty("is_not_empty")] + public bool? IsNotEmpty { get; set; } } } } diff --git a/Src/Notion.Client/Models/Filters/RichTextFilter.cs b/Src/Notion.Client/Models/Filters/RichTextFilter.cs index 90bae02e..733b93ba 100644 --- a/Src/Notion.Client/Models/Filters/RichTextFilter.cs +++ b/Src/Notion.Client/Models/Filters/RichTextFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class RichTextFilter : SinglePropertyFilter, IRollupSubPropertyFilter { - [JsonProperty("rich_text")] - public TextFilter.Condition RichText { get; set; } - public RichTextFilter( string propertyName, string equal = null, @@ -19,23 +16,47 @@ public RichTextFilter( bool? isNotEmpty = null) { Property = propertyName; + RichText = new TextFilter.Condition( - equal: equal, - doesNotEqual: doesNotEqual, - contains: contains, - doesNotContain: doesNotContain, - startsWith: startsWith, - endsWith: endsWith, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + doesNotEqual, + contains, + doesNotContain, + startsWith, + endsWith, + isEmpty, + isNotEmpty ); } + + [JsonProperty("rich_text")] + public TextFilter.Condition RichText { get; set; } } public static class TextFilter { public class Condition { + public Condition( + string equal = null, + string doesNotEqual = null, + string contains = null, + string doesNotContain = null, + string startsWith = null, + string endsWith = null, + bool? isEmpty = null, + bool? isNotEmpty = null) + { + Equal = equal; + DoesNotEqual = doesNotEqual; + Contains = contains; + DoesNotContain = doesNotContain; + StartsWith = startsWith; + EndsWith = endsWith; + IsEmpty = isEmpty; + IsNotEmpty = isNotEmpty; + } + [JsonProperty("equals")] public string Equal { get; set; } @@ -59,26 +80,6 @@ public class Condition [JsonProperty("is_not_empty")] public bool? IsNotEmpty { get; set; } - - public Condition( - string equal = null, - string doesNotEqual = null, - string contains = null, - string doesNotContain = null, - string startsWith = null, - string endsWith = null, - bool? isEmpty = null, - bool? isNotEmpty = null) - { - Equal = equal; - DoesNotEqual = doesNotEqual; - Contains = contains; - DoesNotContain = doesNotContain; - StartsWith = startsWith; - EndsWith = endsWith; - IsEmpty = isEmpty; - IsNotEmpty = isNotEmpty; - } } } } diff --git a/Src/Notion.Client/Models/Filters/Rollup/RollupFilter.cs b/Src/Notion.Client/Models/Filters/Rollup/RollupFilter.cs index 41cb759e..df641729 100644 --- a/Src/Notion.Client/Models/Filters/Rollup/RollupFilter.cs +++ b/Src/Notion.Client/Models/Filters/Rollup/RollupFilter.cs @@ -4,18 +4,16 @@ namespace Notion.Client { public class RollupFilter : SinglePropertyFilter { - [JsonProperty("rollup")] - public Condition Rollup { get; set; } - public RollupFilter( - string propertyName - , IRollupSubPropertyFilter any = null - , IRollupSubPropertyFilter none = null - , IRollupSubPropertyFilter every = null - , DateFilter.Condition date = null - , NumberFilter.Condition number = null) + string propertyName, + IRollupSubPropertyFilter any = null, + IRollupSubPropertyFilter none = null, + IRollupSubPropertyFilter every = null, + DateFilter.Condition date = null, + NumberFilter.Condition number = null) { Property = propertyName; + Rollup = new Condition( any, none, @@ -25,14 +23,17 @@ string propertyName ); } + [JsonProperty("rollup")] + public Condition Rollup { get; set; } + public class Condition { public Condition( - IRollupSubPropertyFilter any = null - , IRollupSubPropertyFilter none = null - , IRollupSubPropertyFilter every = null - , DateFilter.Condition date = null - , NumberFilter.Condition number = null) + IRollupSubPropertyFilter any = null, + IRollupSubPropertyFilter none = null, + IRollupSubPropertyFilter every = null, + DateFilter.Condition date = null, + NumberFilter.Condition number = null) { Any = any; None = none; diff --git a/Src/Notion.Client/Models/Filters/SelectFilter.cs b/Src/Notion.Client/Models/Filters/SelectFilter.cs index 6f0887a4..064334f1 100644 --- a/Src/Notion.Client/Models/Filters/SelectFilter.cs +++ b/Src/Notion.Client/Models/Filters/SelectFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class SelectFilter : SinglePropertyFilter, IRollupSubPropertyFilter { - [JsonProperty("select")] - public Condition Select { get; set; } - public SelectFilter( string propertyName, string equal = null, @@ -15,28 +12,20 @@ public SelectFilter( bool? isNotEmpty = null) { Property = propertyName; + Select = new Condition( - equal: equal, - doesNotEqual: doesNotEqual, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + doesNotEqual, + isEmpty, + isNotEmpty ); } + [JsonProperty("select")] + public Condition Select { get; set; } + public class Condition { - [JsonProperty("equals")] - public string Equal { get; set; } - - [JsonProperty("does_not_equal")] - public string DoesNotEqual { get; set; } - - [JsonProperty("is_empty")] - public bool? IsEmpty { get; set; } - - [JsonProperty("is_not_empty")] - public bool? IsNotEmpty { get; set; } - public Condition( string equal = null, string doesNotEqual = null, @@ -48,6 +37,18 @@ public Condition( IsEmpty = isEmpty; IsNotEmpty = isNotEmpty; } + + [JsonProperty("equals")] + public string Equal { get; set; } + + [JsonProperty("does_not_equal")] + public string DoesNotEqual { get; set; } + + [JsonProperty("is_empty")] + public bool? IsEmpty { get; set; } + + [JsonProperty("is_not_empty")] + public bool? IsNotEmpty { get; set; } } } } diff --git a/Src/Notion.Client/Models/Filters/StatusFilter.cs b/Src/Notion.Client/Models/Filters/StatusFilter.cs index 7ed9b23f..0af0a22c 100644 --- a/Src/Notion.Client/Models/Filters/StatusFilter.cs +++ b/Src/Notion.Client/Models/Filters/StatusFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class StatusFilter : SinglePropertyFilter, IRollupSubPropertyFilter { - [JsonProperty("status")] - public Condition Status { get; set; } - public StatusFilter( string propertyName, string equal = null, @@ -15,28 +12,20 @@ public StatusFilter( bool? isNotEmpty = null) { Property = propertyName; + Status = new Condition( - equal: equal, - doesNotEqual: doesNotEqual, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + doesNotEqual, + isEmpty, + isNotEmpty ); } + [JsonProperty("status")] + public Condition Status { get; set; } + public class Condition { - [JsonProperty("equals")] - public string Equal { get; set; } - - [JsonProperty("does_not_equal")] - public string DoesNotEqual { get; set; } - - [JsonProperty("is_empty")] - public bool? IsEmpty { get; set; } - - [JsonProperty("is_not_empty")] - public bool? IsNotEmpty { get; set; } - public Condition( string equal = null, string doesNotEqual = null, @@ -48,6 +37,18 @@ public Condition( IsEmpty = isEmpty; IsNotEmpty = isNotEmpty; } + + [JsonProperty("equals")] + public string Equal { get; set; } + + [JsonProperty("does_not_equal")] + public string DoesNotEqual { get; set; } + + [JsonProperty("is_empty")] + public bool? IsEmpty { get; set; } + + [JsonProperty("is_not_empty")] + public bool? IsNotEmpty { get; set; } } } } diff --git a/Src/Notion.Client/Models/Filters/TimestampCreatedTimeFilter.cs b/Src/Notion.Client/Models/Filters/TimestampCreatedTimeFilter.cs index ac8f2244..d550817e 100644 --- a/Src/Notion.Client/Models/Filters/TimestampCreatedTimeFilter.cs +++ b/Src/Notion.Client/Models/Filters/TimestampCreatedTimeFilter.cs @@ -9,9 +9,6 @@ public class TimestampCreatedTimeFilter : Filter [JsonProperty("timestamp")] public string Timestamp = "created_time"; - [JsonProperty("created_time")] - public DateFilter.Condition CreatedTime { get; set; } - public TimestampCreatedTimeFilter( DateTime? equal = null, DateTime? before = null, @@ -28,20 +25,23 @@ public TimestampCreatedTimeFilter( bool? isNotEmpty = null) { CreatedTime = new DateFilter.Condition( - equal: equal, - before: before, - after: after, - onOrBefore: onOrBefore, - onOrAfter: onOrAfter, - pastWeek: pastWeek, - pastMonth: pastMonth, - pastYear: pastYear, - nextWeek: nextWeek, - nextMonth: nextMonth, - nextYear: nextYear, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + before, + after, + onOrBefore, + onOrAfter, + pastWeek, + pastMonth, + pastYear, + nextWeek, + nextMonth, + nextYear, + isEmpty, + isNotEmpty ); } + + [JsonProperty("created_time")] + public DateFilter.Condition CreatedTime { get; set; } } } diff --git a/Src/Notion.Client/Models/Filters/TimestampLastEditedTimeFilter.cs b/Src/Notion.Client/Models/Filters/TimestampLastEditedTimeFilter.cs index 1d6acb7f..51a6e39f 100644 --- a/Src/Notion.Client/Models/Filters/TimestampLastEditedTimeFilter.cs +++ b/Src/Notion.Client/Models/Filters/TimestampLastEditedTimeFilter.cs @@ -9,9 +9,6 @@ public class TimestampLastEditedTimeFilter : Filter [JsonProperty("timestamp")] public string Timestamp = "last_modified_time"; - [JsonProperty("last_edited_time")] - public DateFilter.Condition LastEditedTime { get; set; } - public TimestampLastEditedTimeFilter( DateTime? equal = null, DateTime? before = null, @@ -28,20 +25,23 @@ public TimestampLastEditedTimeFilter( bool? isNotEmpty = null) { LastEditedTime = new DateFilter.Condition( - equal: equal, - before: before, - after: after, - onOrBefore: onOrBefore, - onOrAfter: onOrAfter, - pastWeek: pastWeek, - pastMonth: pastMonth, - pastYear: pastYear, - nextWeek: nextWeek, - nextMonth: nextMonth, - nextYear: nextYear, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + before, + after, + onOrBefore, + onOrAfter, + pastWeek, + pastMonth, + pastYear, + nextWeek, + nextMonth, + nextYear, + isEmpty, + isNotEmpty ); } + + [JsonProperty("last_edited_time")] + public DateFilter.Condition LastEditedTime { get; set; } } } diff --git a/Src/Notion.Client/Models/Filters/TitleFilter.cs b/Src/Notion.Client/Models/Filters/TitleFilter.cs index 7c21bb33..1e0d4303 100644 --- a/Src/Notion.Client/Models/Filters/TitleFilter.cs +++ b/Src/Notion.Client/Models/Filters/TitleFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class TitleFilter : SinglePropertyFilter { - [JsonProperty("title")] - public TextFilter.Condition Title { get; set; } - public TitleFilter( string propertyName, string equal = null, @@ -19,16 +16,20 @@ public TitleFilter( bool? isNotEmpty = null) { Property = propertyName; + Title = new TextFilter.Condition( - equal: equal, - doesNotEqual: doesNotEqual, - contains: contains, - doesNotContain: doesNotContain, - startsWith: startsWith, - endsWith: endsWith, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + doesNotEqual, + contains, + doesNotContain, + startsWith, + endsWith, + isEmpty, + isNotEmpty ); } + + [JsonProperty("title")] + public TextFilter.Condition Title { get; set; } } } diff --git a/Src/Notion.Client/Models/Filters/URLFilter.cs b/Src/Notion.Client/Models/Filters/URLFilter.cs index b6a1fe6b..b2d4c611 100644 --- a/Src/Notion.Client/Models/Filters/URLFilter.cs +++ b/Src/Notion.Client/Models/Filters/URLFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class URLFilter : SinglePropertyFilter { - [JsonProperty("url")] - public TextFilter.Condition URL { get; set; } - public URLFilter( string propertyName, string equal = null, @@ -19,16 +16,20 @@ public URLFilter( bool? isNotEmpty = null) { Property = propertyName; + URL = new TextFilter.Condition( - equal: equal, - doesNotEqual: doesNotEqual, - contains: contains, - doesNotContain: doesNotContain, - startsWith: startsWith, - endsWith: endsWith, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + doesNotEqual, + contains, + doesNotContain, + startsWith, + endsWith, + isEmpty, + isNotEmpty ); } + + [JsonProperty("url")] + public TextFilter.Condition URL { get; set; } } } diff --git a/Src/Notion.Client/Models/IObject.cs b/Src/Notion.Client/Models/IObject.cs index 2f72f929..b8ab1108 100644 --- a/Src/Notion.Client/Models/IObject.cs +++ b/Src/Notion.Client/Models/IObject.cs @@ -5,10 +5,10 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "object")] - [JsonSubtypes.KnownSubType(typeof(Page), ObjectType.Page)] - [JsonSubtypes.KnownSubType(typeof(Database), ObjectType.Database)] - [JsonSubtypes.KnownSubType(typeof(IBlock), ObjectType.Block)] - [JsonSubtypes.KnownSubType(typeof(User), ObjectType.User)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(Page), ObjectType.Page)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(Database), ObjectType.Database)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(IBlock), ObjectType.Block)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(User), ObjectType.User)] public interface IObject { [JsonProperty("id")] diff --git a/Src/Notion.Client/Models/Page/IPageIcon.cs b/Src/Notion.Client/Models/Page/IPageIcon.cs index a89184fe..b9ebea56 100644 --- a/Src/Notion.Client/Models/Page/IPageIcon.cs +++ b/Src/Notion.Client/Models/Page/IPageIcon.cs @@ -4,9 +4,9 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(EmojiObject), "emoji")] - [JsonSubtypes.KnownSubType(typeof(FileObject), "file")] - [JsonSubtypes.KnownSubType(typeof(FileObject), "external")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(EmojiObject), "emoji")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(FileObject), "file")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(FileObject), "external")] public interface IPageIcon { [JsonProperty("type")] diff --git a/Src/Notion.Client/Models/Page/IPageParent.cs b/Src/Notion.Client/Models/Page/IPageParent.cs index 439b1a3f..b9111d91 100644 --- a/Src/Notion.Client/Models/Page/IPageParent.cs +++ b/Src/Notion.Client/Models/Page/IPageParent.cs @@ -4,10 +4,10 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(DatabaseParent), ParentType.DatabaseId)] - [JsonSubtypes.KnownSubType(typeof(PageParent), ParentType.PageId)] - [JsonSubtypes.KnownSubType(typeof(WorkspaceParent), ParentType.Workspace)] - [JsonSubtypes.KnownSubType(typeof(BlockParent), ParentType.BlockId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(DatabaseParent), ParentType.DatabaseId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PageParent), ParentType.PageId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(WorkspaceParent), ParentType.Workspace)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(BlockParent), ParentType.BlockId)] public interface IPageParent : IParent { } diff --git a/Src/Notion.Client/Models/Page/Page.cs b/Src/Notion.Client/Models/Page/Page.cs index d96fef8a..996bdd46 100644 --- a/Src/Notion.Client/Models/Page/Page.cs +++ b/Src/Notion.Client/Models/Page/Page.cs @@ -7,63 +7,63 @@ namespace Notion.Client public class Page : IObject, IObjectModificationData { /// - /// Object type - /// - public ObjectType Object => ObjectType.Page; - - /// - /// Unique identifier of the page. - /// - public string Id { get; set; } - - /// - /// The parent of this page. Can be a database, page, or workspace. + /// The parent of this page. Can be a database, page, or workspace. /// [JsonProperty("parent")] public IPageParent Parent { get; set; } /// - /// Date and time when this page was created. - /// - [JsonProperty("created_time")] - public DateTime CreatedTime { get; set; } - - /// - /// Date and time when this page was updated. - /// - [JsonProperty("last_edited_time")] - public DateTime LastEditedTime { get; set; } - - /// - /// The archived status of the page. + /// The archived status of the page. /// [JsonProperty("archived")] public bool IsArchived { get; set; } /// - /// Property values of this page. + /// Property values of this page. /// [JsonProperty("properties")] public IDictionary Properties { get; set; } /// - /// The URL of the Notion page. + /// The URL of the Notion page. /// [JsonProperty("url")] public string Url { get; set; } /// - /// Page icon. + /// Page icon. /// [JsonProperty("icon")] public IPageIcon Icon { get; set; } /// - /// Page cover image. + /// Page cover image. /// [JsonProperty("cover")] public FileObject Cover { get; set; } + /// + /// Object type + /// + public ObjectType Object => ObjectType.Page; + + /// + /// Unique identifier of the page. + /// + public string Id { get; set; } + + /// + /// Date and time when this page was created. + /// + [JsonProperty("created_time")] + public DateTime CreatedTime { get; set; } + + /// + /// Date and time when this page was updated. + /// + [JsonProperty("last_edited_time")] + public DateTime LastEditedTime { get; set; } + public PartialUser CreatedBy { get; set; } public PartialUser LastEditedBy { get; set; } diff --git a/Src/Notion.Client/Models/Parents/BlockParent.cs b/Src/Notion.Client/Models/Parents/BlockParent.cs index 1ac1fd51..e3fd7749 100644 --- a/Src/Notion.Client/Models/Parents/BlockParent.cs +++ b/Src/Notion.Client/Models/Parents/BlockParent.cs @@ -5,14 +5,14 @@ namespace Notion.Client public class BlockParent : IPageParent, IDatabaseParent, IBlockParent, ICommentParent { /// - /// Always has a value "block_id" + /// The ID of the block that the element belongs to. /// - public ParentType Type { get; set; } + [JsonProperty("block_id")] + public string BlockId { get; set; } /// - /// The ID of the block that the element belongs to. + /// Always has a value "block_id" /// - [JsonProperty("block_id")] - public string BlockId { get; set; } + public ParentType Type { get; set; } } } diff --git a/Src/Notion.Client/Models/Parents/DatabaseParent.cs b/Src/Notion.Client/Models/Parents/DatabaseParent.cs index 2e680655..878dbe89 100644 --- a/Src/Notion.Client/Models/Parents/DatabaseParent.cs +++ b/Src/Notion.Client/Models/Parents/DatabaseParent.cs @@ -5,14 +5,14 @@ namespace Notion.Client public class DatabaseParent : IPageParent, IBlockParent { /// - /// Always "database_id" + /// The ID of the database that this page belongs to. /// - public ParentType Type { get; set; } + [JsonProperty("database_id")] + public string DatabaseId { get; set; } /// - /// The ID of the database that this page belongs to. + /// Always "database_id" /// - [JsonProperty("database_id")] - public string DatabaseId { get; set; } + public ParentType Type { get; set; } } } diff --git a/Src/Notion.Client/Models/Parents/PageParent.cs b/Src/Notion.Client/Models/Parents/PageParent.cs index 13b1c95a..565f7ccc 100644 --- a/Src/Notion.Client/Models/Parents/PageParent.cs +++ b/Src/Notion.Client/Models/Parents/PageParent.cs @@ -5,14 +5,14 @@ namespace Notion.Client public class PageParent : IPageParent, IDatabaseParent, IBlockParent, ICommentParent { /// - /// Always "page_id". + /// The ID of the page that this page belongs to. /// - public ParentType Type { get; set; } + [JsonProperty("page_id")] + public string PageId { get; set; } /// - /// The ID of the page that this page belongs to. + /// Always "page_id". /// - [JsonProperty("page_id")] - public string PageId { get; set; } + public ParentType Type { get; set; } } } diff --git a/Src/Notion.Client/Models/Parents/WorkspaceParent.cs b/Src/Notion.Client/Models/Parents/WorkspaceParent.cs index 86c60a54..a0b5e1c4 100644 --- a/Src/Notion.Client/Models/Parents/WorkspaceParent.cs +++ b/Src/Notion.Client/Models/Parents/WorkspaceParent.cs @@ -3,7 +3,7 @@ public class WorkspaceParent : IPageParent, IDatabaseParent, IBlockParent { /// - /// Always "workspace". + /// Always "workspace". /// public ParentType Type { get; set; } } diff --git a/Src/Notion.Client/Models/PropertyItems/IPropertyItemObject.cs b/Src/Notion.Client/Models/PropertyItems/IPropertyItemObject.cs index 5ebc7730..58db1a7d 100644 --- a/Src/Notion.Client/Models/PropertyItems/IPropertyItemObject.cs +++ b/Src/Notion.Client/Models/PropertyItems/IPropertyItemObject.cs @@ -4,8 +4,8 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "object")] - [JsonSubtypes.KnownSubType(typeof(SimplePropertyItem), "property_item")] - [JsonSubtypes.KnownSubType(typeof(ListPropertyItem), "list")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(SimplePropertyItem), "property_item")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ListPropertyItem), "list")] public interface IPropertyItemObject { [JsonProperty("object")] @@ -18,7 +18,8 @@ public interface IPropertyItemObject string Id { get; } /// - /// Only present in paginated property values with another page of results. If present, the url the user can request to get the next page of results. + /// Only present in paginated property values with another page of results. If present, the url the user can request to + /// get the next page of results. /// [JsonProperty("next_url")] string NextURL { get; } diff --git a/Src/Notion.Client/Models/PropertyItems/ListPropertyItem.cs b/Src/Notion.Client/Models/PropertyItems/ListPropertyItem.cs index f539fcd6..5e35159c 100644 --- a/Src/Notion.Client/Models/PropertyItems/ListPropertyItem.cs +++ b/Src/Notion.Client/Models/PropertyItems/ListPropertyItem.cs @@ -1,19 +1,10 @@ using System.Collections.Generic; -using JsonSubTypes; using Newtonsoft.Json; namespace Notion.Client { public class ListPropertyItem : IPropertyItemObject { - public string Object => "list"; - - public virtual string Type { get; set; } - - public string Id { get; set; } - - public string NextURL { get; set; } - [JsonProperty("results")] public IEnumerable Results { get; set; } @@ -25,5 +16,13 @@ public class ListPropertyItem : IPropertyItemObject [JsonProperty("property_item")] public SimplePropertyItem PropertyItem { get; set; } + + public string Object => "list"; + + public virtual string Type { get; set; } + + public string Id { get; set; } + + public string NextURL { get; set; } } } diff --git a/Src/Notion.Client/Models/PropertyItems/RollupPropertyItem.cs b/Src/Notion.Client/Models/PropertyItems/RollupPropertyItem.cs index 3df75fd7..04d7da7b 100644 --- a/Src/Notion.Client/Models/PropertyItems/RollupPropertyItem.cs +++ b/Src/Notion.Client/Models/PropertyItems/RollupPropertyItem.cs @@ -7,23 +7,31 @@ public class RollupPropertyItem : SimplePropertyItem { public override string Type => "rollup"; - [JsonProperty("rollup")] public Data Rollup { get; set; } + [JsonProperty("rollup")] + public Data Rollup { get; set; } public class Data { - [JsonProperty("type")] public string Type { get; set; } + [JsonProperty("type")] + public string Type { get; set; } - [JsonProperty("function")] public string Function { get; set; } + [JsonProperty("function")] + public string Function { get; set; } - [JsonProperty("number")] public double? Number { get; set; } + [JsonProperty("number")] + public double? Number { get; set; } - [JsonProperty("date")] public Date Date { get; set; } + [JsonProperty("date")] + public Date Date { get; set; } - [JsonProperty("array")] public IEnumerable> Array { get; set; } + [JsonProperty("array")] + public IEnumerable> Array { get; set; } - [JsonProperty("unsupported")] public Dictionary Unsupported { get; set; } + [JsonProperty("unsupported")] + public Dictionary Unsupported { get; set; } - [JsonProperty("incomplete")] public Dictionary Incomplete { get; set; } + [JsonProperty("incomplete")] + public Dictionary Incomplete { get; set; } } } } diff --git a/Src/Notion.Client/Models/PropertyItems/SimplePropertyItem.cs b/Src/Notion.Client/Models/PropertyItems/SimplePropertyItem.cs index 50d95184..ed3bef38 100644 --- a/Src/Notion.Client/Models/PropertyItems/SimplePropertyItem.cs +++ b/Src/Notion.Client/Models/PropertyItems/SimplePropertyItem.cs @@ -4,26 +4,26 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(NumberPropertyItem), "number")] - [JsonSubtypes.KnownSubType(typeof(UrlPropertyItem), "url")] - [JsonSubtypes.KnownSubType(typeof(SelectPropertyItem), "select")] - [JsonSubtypes.KnownSubType(typeof(MultiSelectPropertyItem), "multi_select")] - [JsonSubtypes.KnownSubType(typeof(StatusPropertyItem), "status")] - [JsonSubtypes.KnownSubType(typeof(DatePropertyItem), "date")] - [JsonSubtypes.KnownSubType(typeof(EmailPropertyItem), "email")] - [JsonSubtypes.KnownSubType(typeof(PhoneNumberPropertyItem), "phone_number")] - [JsonSubtypes.KnownSubType(typeof(CheckboxPropertyItem), "checkbox")] - [JsonSubtypes.KnownSubType(typeof(FilesPropertyItem), "files")] - [JsonSubtypes.KnownSubType(typeof(CreatedByPropertyItem), "created_by")] - [JsonSubtypes.KnownSubType(typeof(CreatedTimePropertyItem), "created_time")] - [JsonSubtypes.KnownSubType(typeof(LastEditedByPropertyItem), "last_edited_by")] - [JsonSubtypes.KnownSubType(typeof(LastEditedTimePropertyItem), "last_edited_time")] - [JsonSubtypes.KnownSubType(typeof(FormulaPropertyItem), "formula")] - [JsonSubtypes.KnownSubType(typeof(TitlePropertyItem), "title")] - [JsonSubtypes.KnownSubType(typeof(RichTextPropertyItem), "rich_text")] - [JsonSubtypes.KnownSubType(typeof(PeoplePropertyItem), "people")] - [JsonSubtypes.KnownSubType(typeof(RelationPropertyItem), "relation")] - [JsonSubtypes.KnownSubType(typeof(RollupPropertyItem), "rollup")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(NumberPropertyItem), "number")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(UrlPropertyItem), "url")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(SelectPropertyItem), "select")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(MultiSelectPropertyItem), "multi_select")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(StatusPropertyItem), "status")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(DatePropertyItem), "date")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(EmailPropertyItem), "email")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PhoneNumberPropertyItem), "phone_number")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CheckboxPropertyItem), "checkbox")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(FilesPropertyItem), "files")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CreatedByPropertyItem), "created_by")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CreatedTimePropertyItem), "created_time")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(LastEditedByPropertyItem), "last_edited_by")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(LastEditedTimePropertyItem), "last_edited_time")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(FormulaPropertyItem), "formula")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(TitlePropertyItem), "title")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RichTextPropertyItem), "rich_text")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PeoplePropertyItem), "people")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RelationPropertyItem), "relation")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RollupPropertyItem), "rollup")] public abstract class SimplePropertyItem : IPropertyItemObject { public string Object => "property_item"; diff --git a/Src/Notion.Client/Models/PropertyItems/StatusPropertyItem.cs b/Src/Notion.Client/Models/PropertyItems/StatusPropertyItem.cs index 46e70108..6b6b863c 100644 --- a/Src/Notion.Client/Models/PropertyItems/StatusPropertyItem.cs +++ b/Src/Notion.Client/Models/PropertyItems/StatusPropertyItem.cs @@ -6,6 +6,7 @@ public class StatusPropertyItem : SimplePropertyItem { public override string Type => "status"; - [JsonProperty("status")] public SelectOption Status { get; set; } + [JsonProperty("status")] + public SelectOption Status { get; set; } } } diff --git a/Src/Notion.Client/Models/PropertyValue/CheckboxPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/CheckboxPropertyValue.cs index 1f3fec50..422eb9b7 100644 --- a/Src/Notion.Client/Models/PropertyValue/CheckboxPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/CheckboxPropertyValue.cs @@ -3,7 +3,7 @@ namespace Notion.Client { /// - /// Checkbox property value objects contain a boolean within the checkbox property. + /// Checkbox property value objects contain a boolean within the checkbox property. /// public class CheckboxPropertyValue : PropertyValue { diff --git a/Src/Notion.Client/Models/PropertyValue/CreatedByPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/CreatedByPropertyValue.cs index 17fa4ef4..31cf5f5b 100644 --- a/Src/Notion.Client/Models/PropertyValue/CreatedByPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/CreatedByPropertyValue.cs @@ -3,14 +3,14 @@ namespace Notion.Client { /// - /// Created by property value object + /// Created by property value object /// public class CreatedByPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.CreatedBy; /// - /// Describes the user who created this page. + /// Describes the user who created this page. /// [JsonProperty("created_by")] public User CreatedBy { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/CreatedTimePropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/CreatedTimePropertyValue.cs index 0b20b2dc..e0550d13 100644 --- a/Src/Notion.Client/Models/PropertyValue/CreatedTimePropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/CreatedTimePropertyValue.cs @@ -3,14 +3,14 @@ namespace Notion.Client { /// - /// Created time property value object. + /// Created time property value object. /// public class CreatedTimePropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.CreatedTime; /// - /// The date and time when this page was created. + /// The date and time when this page was created. /// [JsonProperty("created_time")] public string CreatedTime { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs index aeb3cd8e..22715b2e 100644 --- a/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs @@ -4,38 +4,39 @@ namespace Notion.Client { /// - /// Date property value object. + /// Date property value object. /// public class DatePropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.Date; /// - /// Date + /// Date /// [JsonProperty("date", NullValueHandling = NullValueHandling.Include)] public Date Date { get; set; } } /// - /// Date value object. + /// Date value object. /// public class Date { /// - /// Start date with optional time. + /// Start date with optional time. /// [JsonProperty("start")] public DateTime? Start { get; set; } /// - /// End date with optional time. + /// End date with optional time. /// [JsonProperty("end")] public DateTime? End { get; set; } /// - /// Optional time zone information for start and end. Possible values are extracted from the IANA database and they are based on the time zones from Moment.js. + /// Optional time zone information for start and end. Possible values are extracted from the IANA database and they are + /// based on the time zones from Moment.js. /// [JsonProperty("time_zone")] public string TimeZone { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/EmailPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/EmailPropertyValue.cs index 1869fc85..5a8e2c7a 100644 --- a/Src/Notion.Client/Models/PropertyValue/EmailPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/EmailPropertyValue.cs @@ -3,14 +3,14 @@ namespace Notion.Client { /// - /// Email property value object. + /// Email property value object. /// public class EmailPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.Email; /// - /// Describes an email address. + /// Describes an email address. /// [JsonProperty("email")] public string Email { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/FilesPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/FilesPropertyValue.cs index 41580fdb..67bc864a 100644 --- a/Src/Notion.Client/Models/PropertyValue/FilesPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/FilesPropertyValue.cs @@ -4,14 +4,14 @@ namespace Notion.Client { /// - /// File property value object. + /// File property value object. /// public class FilesPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.Files; /// - /// Array of File Object with name. + /// Array of File Object with name. /// [JsonProperty("files")] public List Files { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/FormulaPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/FormulaPropertyValue.cs index e85fd5bd..a1242f47 100644 --- a/Src/Notion.Client/Models/PropertyValue/FormulaPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/FormulaPropertyValue.cs @@ -3,50 +3,50 @@ namespace Notion.Client { /// - /// Formula property value object. + /// Formula property value object. /// public class FormulaPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.Formula; /// - /// A formula described in the database's properties. + /// A formula described in the database's properties. /// [JsonProperty("formula")] public FormulaValue Formula { get; set; } } /// - /// Formula value object. + /// Formula value object. /// public class FormulaValue { /// - /// Formula value type + /// Formula value type /// [JsonProperty("type")] public string Type { get; set; } /// - /// String formula value. + /// String formula value. /// [JsonProperty("string")] public string String { get; set; } /// - /// Number formula value. + /// Number formula value. /// [JsonProperty("number")] public double? Number { get; set; } /// - /// Boolean formula value. + /// Boolean formula value. /// [JsonProperty("boolean")] public bool? Boolean { get; set; } /// - /// Date formula value + /// Date formula value /// [JsonProperty("date")] public Date Date { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/LastEditedByPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/LastEditedByPropertyValue.cs index b5e26efc..a536ad60 100644 --- a/Src/Notion.Client/Models/PropertyValue/LastEditedByPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/LastEditedByPropertyValue.cs @@ -3,14 +3,14 @@ namespace Notion.Client { /// - /// Last edited by property value object. + /// Last edited by property value object. /// public class LastEditedByPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.LastEditedBy; /// - /// Describes the user who last updated this page. + /// Describes the user who last updated this page. /// [JsonProperty("last_edited_by")] public User LastEditedBy { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/LastEditedTimePropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/LastEditedTimePropertyValue.cs index 785ac3bc..25d3100d 100644 --- a/Src/Notion.Client/Models/PropertyValue/LastEditedTimePropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/LastEditedTimePropertyValue.cs @@ -3,14 +3,14 @@ namespace Notion.Client { /// - /// Last edited time property value object. + /// Last edited time property value object. /// public class LastEditedTimePropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.LastEditedTime; /// - /// The date and time when this page was last updated. + /// The date and time when this page was last updated. /// [JsonProperty("last_edited_time")] public string LastEditedTime { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/MultiSelectPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/MultiSelectPropertyValue.cs index a5ee4f0a..ff820527 100644 --- a/Src/Notion.Client/Models/PropertyValue/MultiSelectPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/MultiSelectPropertyValue.cs @@ -4,14 +4,14 @@ namespace Notion.Client { /// - /// Multi-select property value object. + /// Multi-select property value object. /// public class MultiSelectPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.MultiSelect; /// - /// An array of multi-select option values. + /// An array of multi-select option values. /// [JsonProperty("multi_select")] public List MultiSelect { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/NumberPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/NumberPropertyValue.cs index a98a34d4..15f9c768 100644 --- a/Src/Notion.Client/Models/PropertyValue/NumberPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/NumberPropertyValue.cs @@ -3,14 +3,14 @@ namespace Notion.Client { /// - /// Number formula property value object. + /// Number formula property value object. /// public class NumberPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.Number; /// - /// Value of number + /// Value of number /// [JsonProperty("number")] public double? Number { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/PeoplePropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/PeoplePropertyValue.cs index 047d33ee..62557560 100644 --- a/Src/Notion.Client/Models/PropertyValue/PeoplePropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/PeoplePropertyValue.cs @@ -4,14 +4,14 @@ namespace Notion.Client { /// - /// People property value object. + /// People property value object. /// public class PeoplePropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.People; /// - /// List of users. + /// List of users. /// [JsonProperty("people")] public List People { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/PhoneNumberPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/PhoneNumberPropertyValue.cs index be5e482e..79a24dac 100644 --- a/Src/Notion.Client/Models/PropertyValue/PhoneNumberPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/PhoneNumberPropertyValue.cs @@ -3,14 +3,14 @@ namespace Notion.Client { /// - /// Phone number property value object. + /// Phone number property value object. /// public class PhoneNumberPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.PhoneNumber; /// - /// Phone number value + /// Phone number value /// [JsonProperty("phone_number")] public string PhoneNumber { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs index 8437b4f8..f893e47a 100644 --- a/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs @@ -5,33 +5,33 @@ namespace Notion.Client { /// - /// An object describing the identifier, type, and value of a page property. + /// An object describing the identifier, type, and value of a page property. /// [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(CheckboxPropertyValue), PropertyValueType.Checkbox)] - [JsonSubtypes.KnownSubType(typeof(CreatedByPropertyValue), PropertyValueType.CreatedBy)] - [JsonSubtypes.KnownSubType(typeof(CreatedTimePropertyValue), PropertyValueType.CreatedTime)] - [JsonSubtypes.KnownSubType(typeof(DatePropertyValue), PropertyValueType.Date)] - [JsonSubtypes.KnownSubType(typeof(EmailPropertyValue), PropertyValueType.Email)] - [JsonSubtypes.KnownSubType(typeof(FilesPropertyValue), PropertyValueType.Files)] - [JsonSubtypes.KnownSubType(typeof(FormulaPropertyValue), PropertyValueType.Formula)] - [JsonSubtypes.KnownSubType(typeof(LastEditedByPropertyValue), PropertyValueType.LastEditedBy)] - [JsonSubtypes.KnownSubType(typeof(LastEditedTimePropertyValue), PropertyValueType.LastEditedTime)] - [JsonSubtypes.KnownSubType(typeof(MultiSelectPropertyValue), PropertyValueType.MultiSelect)] - [JsonSubtypes.KnownSubType(typeof(NumberPropertyValue), PropertyValueType.Number)] - [JsonSubtypes.KnownSubType(typeof(PeoplePropertyValue), PropertyValueType.People)] - [JsonSubtypes.KnownSubType(typeof(PhoneNumberPropertyValue), PropertyValueType.PhoneNumber)] - [JsonSubtypes.KnownSubType(typeof(RelationPropertyValue), PropertyValueType.Relation)] - [JsonSubtypes.KnownSubType(typeof(RichTextPropertyValue), PropertyValueType.RichText)] - [JsonSubtypes.KnownSubType(typeof(RollupPropertyValue), PropertyValueType.Rollup)] - [JsonSubtypes.KnownSubType(typeof(SelectPropertyValue), PropertyValueType.Select)] - [JsonSubtypes.KnownSubType(typeof(StatusPropertyValue), PropertyValueType.Status)] - [JsonSubtypes.KnownSubType(typeof(TitlePropertyValue), PropertyValueType.Title)] - [JsonSubtypes.KnownSubType(typeof(UrlPropertyValue), PropertyValueType.Url)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CheckboxPropertyValue), PropertyValueType.Checkbox)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CreatedByPropertyValue), PropertyValueType.CreatedBy)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CreatedTimePropertyValue), PropertyValueType.CreatedTime)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(DatePropertyValue), PropertyValueType.Date)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(EmailPropertyValue), PropertyValueType.Email)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(FilesPropertyValue), PropertyValueType.Files)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(FormulaPropertyValue), PropertyValueType.Formula)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(LastEditedByPropertyValue), PropertyValueType.LastEditedBy)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(LastEditedTimePropertyValue), PropertyValueType.LastEditedTime)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(MultiSelectPropertyValue), PropertyValueType.MultiSelect)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(NumberPropertyValue), PropertyValueType.Number)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PeoplePropertyValue), PropertyValueType.People)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PhoneNumberPropertyValue), PropertyValueType.PhoneNumber)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RelationPropertyValue), PropertyValueType.Relation)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RichTextPropertyValue), PropertyValueType.RichText)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RollupPropertyValue), PropertyValueType.Rollup)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(SelectPropertyValue), PropertyValueType.Select)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(StatusPropertyValue), PropertyValueType.Status)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(TitlePropertyValue), PropertyValueType.Title)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(UrlPropertyValue), PropertyValueType.Url)] public class PropertyValue { /// - /// Underlying identifier of the property. + /// Underlying identifier of the property. /// [JsonProperty("id")] public string Id { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs b/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs index fcbeae61..93a8d63e 100644 --- a/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs +++ b/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs @@ -3,7 +3,7 @@ namespace Notion.Client { /// - /// Types of Property Value + /// Types of Property Value /// public enum PropertyValueType { diff --git a/Src/Notion.Client/Models/PropertyValue/RelationPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/RelationPropertyValue.cs index 3d11a096..6f9e0ec8 100644 --- a/Src/Notion.Client/Models/PropertyValue/RelationPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/RelationPropertyValue.cs @@ -4,14 +4,14 @@ namespace Notion.Client { /// - /// Relation property value object. + /// Relation property value object. /// public class RelationPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.Relation; /// - /// Array of page references + /// Array of page references /// [JsonProperty("relation")] public List Relation { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/RichTextPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/RichTextPropertyValue.cs index 028ed046..90e8d0be 100644 --- a/Src/Notion.Client/Models/PropertyValue/RichTextPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/RichTextPropertyValue.cs @@ -4,14 +4,14 @@ namespace Notion.Client { /// - /// Rich Text property value object. + /// Rich Text property value object. /// public class RichTextPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.RichText; /// - /// List of rich text objects + /// List of rich text objects /// [JsonProperty("rich_text")] public List RichText { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/RollupPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/RollupPropertyValue.cs index 7c573081..2eb104fb 100644 --- a/Src/Notion.Client/Models/PropertyValue/RollupPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/RollupPropertyValue.cs @@ -4,7 +4,7 @@ namespace Notion.Client { /// - /// Rollup property value object. + /// Rollup property value object. /// public class RollupPropertyValue : PropertyValue { @@ -15,31 +15,31 @@ public class RollupPropertyValue : PropertyValue } /// - /// Object containing rollup type-specific data. + /// Object containing rollup type-specific data. /// public class RollupValue { /// - /// The type of rollup. Possible values are "number", "date", and "array". + /// The type of rollup. Possible values are "number", "date", and "array". /// [JsonProperty("type")] public string Type { get; set; } /// - /// Number rollup property values contain a number + /// Number rollup property values contain a number /// [JsonProperty("number")] public double? Number { get; set; } /// - /// Date rollup property values contain a date property value. + /// Date rollup property values contain a date property value. /// [JsonProperty("date")] public DatePropertyValue Date { get; set; } /// - /// Array rollup property values contain an array of element objects. - /// Array containing the property value object will not contain value for Id field + /// Array rollup property values contain an array of element objects. + /// Array containing the property value object will not contain value for Id field /// [JsonProperty("array")] public List Array { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/SelectPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/SelectPropertyValue.cs index 07b2a346..74c94c82 100644 --- a/Src/Notion.Client/Models/PropertyValue/SelectPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/SelectPropertyValue.cs @@ -3,7 +3,7 @@ namespace Notion.Client { /// - /// Select property value object. + /// Select property value object. /// public class SelectPropertyValue : PropertyValue { diff --git a/Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs index 497e4c18..f4a82e48 100644 --- a/Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs @@ -5,37 +5,10 @@ namespace Notion.Client { /// - /// Status property value objects contain page status + /// Status property value objects contain page status /// public class StatusPropertyValue : PropertyValue { - public override PropertyValueType Type => PropertyValueType.Status; - - [JsonProperty("status")] - public Data Status { get; set; } - - public class Data - { - /// - /// ID of the option. - /// - [JsonProperty("id")] - public string Id { get; set; } - - /// - /// Name of the option as it appears in Notion. - /// - [JsonProperty("name")] - public string Name { get; set; } - - /// - /// Color of the option. - /// - [JsonProperty("color")] - [JsonConverter(typeof(StringEnumConverter))] - public Color? Color { get; set; } - } - public enum Color { [EnumMember(Value = "default")] @@ -68,5 +41,32 @@ public enum Color [EnumMember(Value = "red")] Red, } + + public override PropertyValueType Type => PropertyValueType.Status; + + [JsonProperty("status")] + public Data Status { get; set; } + + public class Data + { + /// + /// ID of the option. + /// + [JsonProperty("id")] + public string Id { get; set; } + + /// + /// Name of the option as it appears in Notion. + /// + [JsonProperty("name")] + public string Name { get; set; } + + /// + /// Color of the option. + /// + [JsonProperty("color")] + [JsonConverter(typeof(StringEnumConverter))] + public Color? Color { get; set; } + } } } diff --git a/Src/Notion.Client/Models/PropertyValue/TitlePropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/TitlePropertyValue.cs index 58b7842d..e72a2a08 100644 --- a/Src/Notion.Client/Models/PropertyValue/TitlePropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/TitlePropertyValue.cs @@ -4,14 +4,14 @@ namespace Notion.Client { /// - /// Title property value object. + /// Title property value object. /// public class TitlePropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.Title; /// - /// An array of rich text objects + /// An array of rich text objects /// [JsonProperty("title")] public List Title { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/UrlPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/UrlPropertyValue.cs index 08b800e6..5fc8f8bb 100644 --- a/Src/Notion.Client/Models/PropertyValue/UrlPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/UrlPropertyValue.cs @@ -3,14 +3,14 @@ namespace Notion.Client { /// - /// URL property value object. + /// URL property value object. /// public class UrlPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.Url; /// - /// Describes a web address + /// Describes a web address /// [JsonProperty("url")] public string Url { get; set; } diff --git a/Src/Notion.Client/Models/User/BotOwner/IBotOwner.cs b/Src/Notion.Client/Models/User/BotOwner/IBotOwner.cs index 61a7a887..062d75c0 100644 --- a/Src/Notion.Client/Models/User/BotOwner/IBotOwner.cs +++ b/Src/Notion.Client/Models/User/BotOwner/IBotOwner.cs @@ -4,8 +4,8 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(UserOwner), "user")] - [JsonSubtypes.KnownSubType(typeof(WorkspaceIntegrationOwner), "workspace")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(UserOwner), "user")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(WorkspaceIntegrationOwner), "workspace")] public interface IBotOwner { [JsonProperty("type")] diff --git a/Src/Notion.Client/Models/User/BotOwner/UserOwner.cs b/Src/Notion.Client/Models/User/BotOwner/UserOwner.cs index 40d69867..e60a4fab 100644 --- a/Src/Notion.Client/Models/User/BotOwner/UserOwner.cs +++ b/Src/Notion.Client/Models/User/BotOwner/UserOwner.cs @@ -4,9 +4,9 @@ namespace Notion.Client { public class UserOwner : IBotOwner { - public string Type { get; set; } - [JsonProperty("user")] public User User { get; set; } + + public string Type { get; set; } } } diff --git a/Src/Notion.Client/Models/User/BotOwner/WorkspaceIntegrationOwner.cs b/Src/Notion.Client/Models/User/BotOwner/WorkspaceIntegrationOwner.cs index 78a84f6f..b5304157 100644 --- a/Src/Notion.Client/Models/User/BotOwner/WorkspaceIntegrationOwner.cs +++ b/Src/Notion.Client/Models/User/BotOwner/WorkspaceIntegrationOwner.cs @@ -4,9 +4,9 @@ namespace Notion.Client { public class WorkspaceIntegrationOwner : IBotOwner { - public string Type { get; set; } - [JsonProperty("workspace")] public bool Workspace { get; set; } + + public string Type { get; set; } } } diff --git a/Src/Notion.Client/Models/User/User.cs b/Src/Notion.Client/Models/User/User.cs index 7f336929..6ae9efef 100644 --- a/Src/Notion.Client/Models/User/User.cs +++ b/Src/Notion.Client/Models/User/User.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class User : IObject { - public ObjectType Object => ObjectType.User; - public string Id { get; set; } - [JsonProperty("type")] public string Type { get; set; } @@ -21,5 +18,9 @@ public class User : IObject [JsonProperty("bot")] public Bot Bot { get; set; } + + public ObjectType Object => ObjectType.User; + + public string Id { get; set; } } } diff --git a/Src/Notion.Client/NotionApiErrorResponse.cs b/Src/Notion.Client/NotionApiErrorResponse.cs index f27288fb..44a225b2 100644 --- a/Src/Notion.Client/NotionApiErrorResponse.cs +++ b/Src/Notion.Client/NotionApiErrorResponse.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - class NotionApiErrorResponse + internal class NotionApiErrorResponse { [JsonProperty("code")] public NotionAPIErrorCode ErrorCode { get; set; } diff --git a/Src/Notion.Client/NotionApiException.cs b/Src/Notion.Client/NotionApiException.cs index 358db384..c7c9d7d4 100644 --- a/Src/Notion.Client/NotionApiException.cs +++ b/Src/Notion.Client/NotionApiException.cs @@ -29,6 +29,7 @@ public NotionApiException( } public NotionAPIErrorCode? NotionAPIErrorCode { get; } + public HttpStatusCode StatusCode { get; } } } diff --git a/Src/Notion.Client/NotionClient.cs b/Src/Notion.Client/NotionClient.cs index f1650b29..f752413a 100644 --- a/Src/Notion.Client/NotionClient.cs +++ b/Src/Notion.Client/NotionClient.cs @@ -3,11 +3,17 @@ public interface INotionClient { IUsersClient Users { get; } + IDatabasesClient Databases { get; } + IPagesClient Pages { get; } + ISearchClient Search { get; } + IBlocksClient Blocks { get; } + ICommentsClient Comments { get; } + IRestClient RestClient { get; } } @@ -32,11 +38,17 @@ public NotionClient( } public IUsersClient Users { get; } + public IDatabasesClient Databases { get; } + public IPagesClient Pages { get; } + public ISearchClient Search { get; } + public IBlocksClient Blocks { get; } + public ICommentsClient Comments { get; } + public IRestClient RestClient { get; } } } diff --git a/Src/Notion.Client/NotionClientFactory.cs b/Src/Notion.Client/NotionClientFactory.cs index 0a02eb3c..e82ba2de 100644 --- a/Src/Notion.Client/NotionClientFactory.cs +++ b/Src/Notion.Client/NotionClientFactory.cs @@ -7,11 +7,11 @@ public static NotionClient Create(ClientOptions options) var restClient = new RestClient(options); return new NotionClient( - restClient: restClient - , users: new UsersClient(restClient) - , databases: new DatabasesClient(restClient) - , pages: new PagesClient(restClient) - , search: new SearchClient(restClient) + restClient + , new UsersClient(restClient) + , new DatabasesClient(restClient) + , new PagesClient(restClient) + , new SearchClient(restClient) , blocks: new BlocksClient(restClient) , comments: new CommentsClient(restClient) ); diff --git a/Src/Notion.Client/RestClient/ClientOptions.cs b/Src/Notion.Client/RestClient/ClientOptions.cs index 3c6be1bc..d0015767 100644 --- a/Src/Notion.Client/RestClient/ClientOptions.cs +++ b/Src/Notion.Client/RestClient/ClientOptions.cs @@ -3,7 +3,9 @@ public class ClientOptions { public string BaseUrl { get; set; } + public string NotionVersion { get; set; } + public string AuthToken { get; set; } } } diff --git a/Src/Notion.Client/RestClient/LoggingHandler.cs b/Src/Notion.Client/RestClient/LoggingHandler.cs index 8655bb97..a6001d10 100644 --- a/Src/Notion.Client/RestClient/LoggingHandler.cs +++ b/Src/Notion.Client/RestClient/LoggingHandler.cs @@ -7,7 +7,9 @@ namespace Notion.Client { public class LoggingHandler : DelegatingHandler { - protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) + protected override async Task SendAsync( + HttpRequestMessage request, + CancellationToken cancellationToken) { Log.Trace("Request: {request}", request); @@ -22,6 +24,7 @@ protected override async Task SendAsync(HttpRequestMessage catch (Exception ex) { Log.Error(ex, "Failed to get response: {exception}", ex); + throw; } } diff --git a/Src/Notion.Client/RestClient/RestClient.cs b/Src/Notion.Client/RestClient/RestClient.cs index bba3a866..5da38f61 100644 --- a/Src/Notion.Client/RestClient/RestClient.cs +++ b/Src/Notion.Client/RestClient/RestClient.cs @@ -14,50 +14,98 @@ namespace Notion.Client { public class RestClient : IRestClient { - private HttpClient _httpClient; private readonly ClientOptions _options; - protected readonly JsonSerializerSettings defaultSerializerSettings = new JsonSerializerSettings + protected readonly JsonSerializerSettings defaultSerializerSettings = new() { NullValueHandling = NullValueHandling.Ignore, - ContractResolver = new DefaultContractResolver - { - NamingStrategy = new CamelCaseNamingStrategy() - } + ContractResolver = new DefaultContractResolver {NamingStrategy = new CamelCaseNamingStrategy()}, }; + private HttpClient _httpClient; + public RestClient(ClientOptions options) { _options = MergeOptions(options); } - private static ClientOptions MergeOptions(ClientOptions options) + public async Task GetAsync( + string uri, + IDictionary queryParams = null, + IDictionary headers = null, + JsonSerializerSettings serializerSettings = null, + CancellationToken cancellationToken = default) { - return new ClientOptions - { - AuthToken = options.AuthToken, - BaseUrl = options.BaseUrl ?? Constants.BASE_URL, - NotionVersion = options.NotionVersion ?? Constants.DEFAULT_NOTION_VERSION - }; + var response = await SendAsync(uri, HttpMethod.Get, queryParams, headers, + cancellationToken: cancellationToken); + + return await response.ParseStreamAsync(serializerSettings); } - public async Task GetAsync( + public async Task PostAsync( string uri, + object body, IDictionary queryParams = null, IDictionary headers = null, JsonSerializerSettings serializerSettings = null, CancellationToken cancellationToken = default) { - var response = await SendAsync(uri, HttpMethod.Get, queryParams, headers, cancellationToken: cancellationToken); + void AttachContent(HttpRequestMessage httpRequest) => + httpRequest.Content = new StringContent(JsonConvert.SerializeObject(body, defaultSerializerSettings), + Encoding.UTF8, "application/json"); + + var response = await SendAsync(uri, HttpMethod.Post, queryParams, headers, AttachContent, + cancellationToken); return await response.ParseStreamAsync(serializerSettings); } + public async Task PatchAsync( + string uri, + object body, + IDictionary queryParams = null, + IDictionary headers = null, + JsonSerializerSettings serializerSettings = null, + CancellationToken cancellationToken = default) + { + void AttachContent(HttpRequestMessage httpRequest) + { + var serializedBody = JsonConvert.SerializeObject(body, defaultSerializerSettings); + httpRequest.Content = new StringContent(serializedBody, Encoding.UTF8, "application/json"); + } + + var response = await SendAsync(uri, new HttpMethod("PATCH"), queryParams, headers, AttachContent, + cancellationToken); + + return await response.ParseStreamAsync(serializerSettings); + } + + public async Task DeleteAsync( + string uri, + IDictionary queryParams = null, + IDictionary headers = null, + JsonSerializerSettings serializerSettings = null, + CancellationToken cancellationToken = default) + { + await SendAsync(uri, HttpMethod.Delete, queryParams, headers, null, cancellationToken); + } + + private static ClientOptions MergeOptions(ClientOptions options) + { + return new ClientOptions + { + AuthToken = options.AuthToken, + BaseUrl = options.BaseUrl ?? Constants.BASE_URL, + NotionVersion = options.NotionVersion ?? Constants.DEFAULT_NOTION_VERSION, + }; + } + private static async Task BuildException(HttpResponseMessage response) { var errorBody = await response.Content.ReadAsStringAsync(); NotionApiErrorResponse errorResponse = null; + if (!string.IsNullOrWhiteSpace(errorBody)) { try @@ -114,47 +162,11 @@ private static void AddHeaders(HttpRequestMessage request, IDictionary PostAsync( - string uri, - object body, - IDictionary queryParams = null, - IDictionary headers = null, - JsonSerializerSettings serializerSettings = null, - CancellationToken cancellationToken = default) - { - void AttachContent(HttpRequestMessage httpRequest) - { - httpRequest.Content = new StringContent(JsonConvert.SerializeObject(body, defaultSerializerSettings), Encoding.UTF8, "application/json"); - } - - var response = await SendAsync(uri, HttpMethod.Post, queryParams, headers, AttachContent, cancellationToken: cancellationToken); - - return await response.ParseStreamAsync(serializerSettings); - } - - public async Task PatchAsync(string uri, object body, IDictionary queryParams = null, IDictionary headers = null, JsonSerializerSettings serializerSettings = null, CancellationToken cancellationToken = default) - { - void AttachContent(HttpRequestMessage httpRequest) - { - var serializedBody = JsonConvert.SerializeObject(body, defaultSerializerSettings); - httpRequest.Content = new StringContent(serializedBody, Encoding.UTF8, "application/json"); - } - - var response = await SendAsync(uri, new HttpMethod("PATCH"), queryParams, headers, AttachContent, cancellationToken: cancellationToken); - - return await response.ParseStreamAsync(serializerSettings); - } - - public async Task DeleteAsync(string uri, IDictionary queryParams = null, IDictionary headers = null, JsonSerializerSettings serializerSettings = null, CancellationToken cancellationToken = default) - { - await SendAsync(uri, HttpMethod.Delete, queryParams, headers, null, cancellationToken); - } - private HttpClient EnsureHttpClient() { if (_httpClient == null) { - var pipeline = new LoggingHandler() { InnerHandler = new HttpClientHandler() }; + var pipeline = new LoggingHandler {InnerHandler = new HttpClientHandler()}; _httpClient = new HttpClient(pipeline); _httpClient.BaseAddress = new Uri(_options.BaseUrl); } diff --git a/Src/Notion.Client/http/QueryHelpers.cs b/Src/Notion.Client/http/QueryHelpers.cs index 783ae20e..86a2f0fb 100644 --- a/Src/Notion.Client/http/QueryHelpers.cs +++ b/Src/Notion.Client/http/QueryHelpers.cs @@ -25,7 +25,7 @@ public static string AddQueryString(string uri, string name, string value) throw new ArgumentNullException(nameof(value)); } - return AddQueryString(uri, new[] { new KeyValuePair(name, value) }); + return AddQueryString(uri, new[] {new KeyValuePair(name, value)}); } public static string AddQueryString(string uri, IDictionary queryParams) @@ -74,6 +74,7 @@ private static string AddQueryString( var sb = new StringBuilder(); sb.Append(uriToBeAppended); + foreach (var parameter in queryParams) { sb.Append(hasQuery ? '&' : '?'); @@ -84,13 +85,14 @@ private static string AddQueryString( } sb.Append(anchorText); + return sb.ToString(); } - private static IEnumerable> RemoveEmptyValueQueryParams(IEnumerable> queryParams) + private static IEnumerable> RemoveEmptyValueQueryParams( + IEnumerable> queryParams) { return queryParams.Where(x => !string.IsNullOrWhiteSpace(x.Value)); } - } } diff --git a/Test/Notion.IntegrationTests/CommentsClientTests.cs b/Test/Notion.IntegrationTests/CommentsClientTests.cs index 2ac7219d..32d887eb 100644 --- a/Test/Notion.IntegrationTests/CommentsClientTests.cs +++ b/Test/Notion.IntegrationTests/CommentsClientTests.cs @@ -5,130 +5,95 @@ using Notion.Client; using Xunit; -namespace Notion.IntegrationTests +namespace Notion.IntegrationTests; + +public class CommentsClientTests : IDisposable { - public class CommentsClientTests : IDisposable + private readonly INotionClient _client; + private readonly Page _page; + private readonly string _pageParentId; + + public CommentsClientTests() + { + var options = new ClientOptions {AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN")}; + + _client = NotionClientFactory.Create(options); + + _pageParentId = Environment.GetEnvironmentVariable("NOTION_PAGE_PARENT_ID") ?? + throw new ArgumentNullException("Page parent id is required."); + + _page = _client.Pages.CreateAsync( + PagesCreateParametersBuilder.Create( + new ParentPageInput {PageId = _pageParentId} + ).Build() + ).Result; + } + + public void Dispose() + { + _client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters {Archived = true}).Wait(); + } + + [Fact] + public async Task ShouldCreatePageComment() { - private readonly INotionClient _client; - private readonly string _pageParentId; - private readonly Page _page; - - public CommentsClientTests() - { - var options = new ClientOptions - { - AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN") - }; - - _client = NotionClientFactory.Create(options); - _pageParentId = Environment.GetEnvironmentVariable("NOTION_PAGE_PARENT_ID") ?? throw new ArgumentNullException("Page parent id is required."); - - _page = _client.Pages.CreateAsync( - PagesCreateParametersBuilder.Create( - new ParentPageInput() - { - PageId = _pageParentId - } - ).Build() - ).Result; - } - - [Fact] - public async Task ShouldCreatePageComment() - { - // Arrange - var parameters = CreateCommentParameters.CreatePageComment( - new ParentPageInput + // Arrange + var parameters = CreateCommentParameters.CreatePageComment( + new ParentPageInput {PageId = _page.Id}, + new List {new RichTextTextInput {Text = new Text {Content = "This is a comment"}}} + ); + + // Act + var response = await _client.Comments.Create(parameters); + + // Arrange + + Assert.NotNull(response.Parent); + Assert.NotNull(response.Id); + Assert.NotNull(response.DiscussionId); + + Assert.NotNull(response.RichText); + Assert.Single(response.RichText); + var richText = Assert.IsType(response.RichText.First()); + Assert.Equal("This is a comment", richText.Text.Content); + + var pageParent = Assert.IsType(response.Parent); + Assert.Equal(_page.Id, pageParent.PageId); + } + + [Fact] + public async Task ShouldCreateADiscussionComment() + { + // Arrange + var comment = await _client.Comments.Create( + CreateCommentParameters.CreatePageComment( + new ParentPageInput {PageId = _page.Id}, + new List {new RichTextTextInput {Text = new Text {Content = "This is a comment"}}} + ) + ); + + // Act + var response = await _client.Comments.Create( + CreateCommentParameters.CreateDiscussionComment( + comment.DiscussionId, + new List { - PageId = _page.Id - }, - new List { - new RichTextTextInput - { - Text = new Text - { - Content = "This is a comment" - } - } + new RichTextTextInput {Text = new Text {Content = "This is a sub comment"}}, } - ); - - // Act - var response = await _client.Comments.Create(parameters); - - // Arrange - - Assert.NotNull(response.Parent); - Assert.NotNull(response.Id); - Assert.NotNull(response.DiscussionId); - - Assert.NotNull(response.RichText); - Assert.Single(response.RichText); - var richText = Assert.IsType(response.RichText.First()); - Assert.Equal("This is a comment", richText.Text.Content); - - var pageParent = Assert.IsType(response.Parent); - Assert.Equal(_page.Id, pageParent.PageId); - } - - [Fact] - public async Task ShouldCreateADiscussionComment() - { - // Arrange - var comment = await _client.Comments.Create( - CreateCommentParameters.CreatePageComment( - new ParentPageInput - { - PageId = _page.Id - }, - new List { - new RichTextTextInput - { - Text = new Text - { - Content = "This is a comment" - } - } - } - ) - ); - - // Act - var response = await _client.Comments.Create( - CreateCommentParameters.CreateDiscussionComment( - comment.DiscussionId, - new List { - new RichTextTextInput - { - Text = new Text - { - Content = "This is a sub comment" - } - } - } - ) - ); - - // Arrange - Assert.Null(response.Parent); - Assert.NotNull(response.Id); - Assert.Equal(comment.DiscussionId, response.DiscussionId); - - Assert.NotNull(response.RichText); - Assert.Single(response.RichText); - var richText = Assert.IsType(response.RichText.First()); - Assert.Equal("This is a sub comment", richText.Text.Content); - - var pageParent = Assert.IsType(response.Parent); - Assert.Equal(_page.Id, pageParent.PageId); - } - - public void Dispose() - { - _client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters - { - Archived = true, - }).Wait(); - } + ) + ); + + // Arrange + Assert.Null(response.Parent); + Assert.NotNull(response.Id); + Assert.Equal(comment.DiscussionId, response.DiscussionId); + + Assert.NotNull(response.RichText); + Assert.Single(response.RichText); + var richText = Assert.IsType(response.RichText.First()); + Assert.Equal("This is a sub comment", richText.Text.Content); + + var pageParent = Assert.IsType(response.Parent); + Assert.Equal(_page.Id, pageParent.PageId); } } diff --git a/Test/Notion.IntegrationTests/IBlocksClientTests.cs b/Test/Notion.IntegrationTests/IBlocksClientTests.cs index eabef5b4..1aaa2726 100644 --- a/Test/Notion.IntegrationTests/IBlocksClientTests.cs +++ b/Test/Notion.IntegrationTests/IBlocksClientTests.cs @@ -6,537 +6,430 @@ using Notion.Client; using Xunit; -namespace Notion.IntegrationTests +namespace Notion.IntegrationTests; + +public class IBlocksClientTests { - public class IBlocksClientTests + private readonly INotionClient _client; + + public IBlocksClientTests() { - private readonly INotionClient _client; + var options = new ClientOptions {AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN")}; - public IBlocksClientTests() - { - var options = new ClientOptions - { - AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN") - }; + _client = NotionClientFactory.Create(options); + } - _client = NotionClientFactory.Create(options); - } + [Fact] + public async Task AppendChildrenAsync_AppendsBlocksGivenBlocks() + { + var pageParentId = "3c357473a28149a488c010d2b245a589"; - [Fact] - public async Task AppendChildrenAsync_AppendsBlocksGivenBlocks() - { - var pageParentId = "3c357473a28149a488c010d2b245a589"; + var page = await _client.Pages.CreateAsync( + PagesCreateParametersBuilder.Create( + new ParentPageInput {PageId = pageParentId} + ).Build() + ); - var page = await _client.Pages.CreateAsync( - PagesCreateParametersBuilder.Create( - new ParentPageInput() - { - PageId = pageParentId - } - ).Build() - ); - - var blocks = await _client.Blocks.AppendChildrenAsync( - page.Id, - new BlocksAppendChildrenParameters + var blocks = await _client.Blocks.AppendChildrenAsync( + page.Id, + new BlocksAppendChildrenParameters + { + Children = new List { - Children = new List() + new BreadcrumbBlock {Breadcrumb = new BreadcrumbBlock.Data()}, + new DividerBlock {Divider = new DividerBlock.Data()}, + new TableOfContentsBlock {TableOfContents = new TableOfContentsBlock.Data()}, + new CalloutBlock { - new BreadcrumbBlock - { - Breadcrumb = new BreadcrumbBlock.Data() - }, - new DividerBlock - { - Divider = new DividerBlock.Data() - }, - new TableOfContentsBlock - { - TableOfContents = new TableOfContentsBlock.Data() - }, - new CalloutBlock + Callout = new CalloutBlock.Info { - Callout = new CalloutBlock.Info + RichText = new List { - RichText = new List { - new RichTextTextInput - { - Text = new Text - { - Content = "Test" - } - } - } - } - } - } - } - ); - - blocks.Results.Should().HaveCount(4); - - // cleanup - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters - { - Archived = true - }); - } + new RichTextTextInput {Text = new Text {Content = "Test"}}, + }, + }, + }, + }, + } + ); - [Fact] - public async Task UpdateBlockAsync_UpdatesGivenBlock() - { - var pageParentId = "3c357473a28149a488c010d2b245a589"; + blocks.Results.Should().HaveCount(4); - var page = await _client.Pages.CreateAsync( - PagesCreateParametersBuilder.Create( - new ParentPageInput() - { - PageId = pageParentId - } - ).Build() - ); - - var blocks = await _client.Blocks.AppendChildrenAsync( - page.Id, - new BlocksAppendChildrenParameters - { - Children = new List() - { - new BreadcrumbBlock - { - Breadcrumb = new BreadcrumbBlock.Data() - } - } - } - ); + // cleanup + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + } - var blockId = blocks.Results.First().Id; - await _client.Blocks.UpdateAsync(blockId, new BreadcrumbUpdateBlock()); + [Fact] + public async Task UpdateBlockAsync_UpdatesGivenBlock() + { + var pageParentId = "3c357473a28149a488c010d2b245a589"; - blocks = await _client.Blocks.RetrieveChildrenAsync(page.Id); - blocks.Results.Should().HaveCount(1); + var page = await _client.Pages.CreateAsync( + PagesCreateParametersBuilder.Create( + new ParentPageInput {PageId = pageParentId} + ).Build() + ); - // cleanup - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters + var blocks = await _client.Blocks.AppendChildrenAsync( + page.Id, + new BlocksAppendChildrenParameters { - Archived = true - }); - } + Children = new List {new BreadcrumbBlock {Breadcrumb = new BreadcrumbBlock.Data()}}, + } + ); - [Fact] - public async Task DeleteAsync_DeleteBlockWithGivenId() - { - var pageParentId = "3c357473a28149a488c010d2b245a589"; + var blockId = blocks.Results.First().Id; + await _client.Blocks.UpdateAsync(blockId, new BreadcrumbUpdateBlock()); - var page = await _client.Pages.CreateAsync( - PagesCreateParametersBuilder.Create( - new ParentPageInput() - { - PageId = pageParentId - } - ).Build() - ); - - var blocks = await _client.Blocks.AppendChildrenAsync( - page.Id, - new BlocksAppendChildrenParameters - { - Children = new List() - { - new DividerBlock - { - Divider = new DividerBlock.Data() - }, - new TableOfContentsBlock - { - TableOfContents = new TableOfContentsBlock.Data() - }, - } - } - ); + blocks = await _client.Blocks.RetrieveChildrenAsync(page.Id); + blocks.Results.Should().HaveCount(1); - blocks.Results.Should().HaveCount(2); + // cleanup + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + } - // cleanup - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters - { - Archived = true - }); - } + [Fact] + public async Task DeleteAsync_DeleteBlockWithGivenId() + { + var pageParentId = "3c357473a28149a488c010d2b245a589"; - [Theory] - [MemberData(nameof(BlockData))] - public async Task UpdateAsync_UpdatesGivenBlock(IBlock block, IUpdateBlock updateBlock, Action assert) - { - var pageParentId = "3c357473a28149a488c010d2b245a589"; + var page = await _client.Pages.CreateAsync( + PagesCreateParametersBuilder.Create( + new ParentPageInput {PageId = pageParentId} + ).Build() + ); - var page = await _client.Pages.CreateAsync( - PagesCreateParametersBuilder.Create( - new ParentPageInput - { - PageId = pageParentId - } - ).Build() - ); - - var blocks = await _client.Blocks.AppendChildrenAsync( - page.Id, - new BlocksAppendChildrenParameters + var blocks = await _client.Blocks.AppendChildrenAsync( + page.Id, + new BlocksAppendChildrenParameters + { + Children = new List { - Children = new List() - { - block - } - } - ); + new DividerBlock {Divider = new DividerBlock.Data()}, + new TableOfContentsBlock {TableOfContents = new TableOfContentsBlock.Data()}, + }, + } + ); + + blocks.Results.Should().HaveCount(2); - var blockId = blocks.Results.First().Id; - await _client.Blocks.UpdateAsync(blockId, updateBlock); + // cleanup + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + } - blocks = await _client.Blocks.RetrieveChildrenAsync(page.Id); - blocks.Results.Should().HaveCount(1); + [Theory] + [MemberData(nameof(BlockData))] + public async Task UpdateAsync_UpdatesGivenBlock(IBlock block, IUpdateBlock updateBlock, Action assert) + { + var pageParentId = "3c357473a28149a488c010d2b245a589"; - var updatedBlock = blocks.Results.First(); + var page = await _client.Pages.CreateAsync( + PagesCreateParametersBuilder.Create( + new ParentPageInput {PageId = pageParentId} + ).Build() + ); - assert.Invoke(updatedBlock); + var blocks = await _client.Blocks.AppendChildrenAsync( + page.Id, + new BlocksAppendChildrenParameters {Children = new List {block}} + ); - // cleanup - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters - { - Archived = true - }); - } + var blockId = blocks.Results.First().Id; + await _client.Blocks.UpdateAsync(blockId, updateBlock); + + blocks = await _client.Blocks.RetrieveChildrenAsync(page.Id); + blocks.Results.Should().HaveCount(1); + + var updatedBlock = blocks.Results.First(); + + assert.Invoke(updatedBlock); + + // cleanup + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + } - private static IEnumerable BlockData() + private static IEnumerable BlockData() + { + return new List { - return new List + new object[] { - new object[] { - new BookmarkBlock + new BookmarkBlock + { + Bookmark = new BookmarkBlock.Info { - Bookmark = new BookmarkBlock.Info - { - Url = "https://developers.notion.com/reference/rich-text", - Caption = new List - { - new RichTextTextInput - { - Text = new Text - { - Content = "Notion API" - } - } - } - } - }, - new BookmarkUpdateBlock { - Bookmark = new BookmarkUpdateBlock.Info + Url = "https://developers.notion.com/reference/rich-text", + Caption = new List { - Url = "https://github.com/notion-dotnet/notion-sdk-net", - Caption = new List - { - new RichTextTextInput - { - Text = new Text - { - Content = "Github" - } - } - } - } + new RichTextTextInput {Text = new Text {Content = "Notion API"}}, + }, }, - new Action((block) => { - var updatedBlock = (BookmarkBlock)block; - Assert.Equal("https://github.com/notion-dotnet/notion-sdk-net", updatedBlock.Bookmark.Url); - Assert.Equal("Github", updatedBlock.Bookmark.Caption.OfType().First().Text.Content); - }) }, - new object[] { - new EquationBlock + new BookmarkUpdateBlock + { + Bookmark = new BookmarkUpdateBlock.Info { - Equation = new EquationBlock.Info + Url = "https://github.com/notion-dotnet/notion-sdk-net", + Caption = new List { - Expression = "e=mc^3" - } - }, - new EquationUpdateBlock { - Equation = new EquationUpdateBlock.Info - { - Expression = "e=mc^2" - } - }, - new Action((block) => { - var updatedBlock = (EquationBlock)block; - Assert.Equal("e=mc^2", updatedBlock.Equation.Expression); - }) - }, - new object[] { - new DividerBlock { - Divider = new DividerBlock.Data() - }, - new DividerUpdateBlock(), - new Action((block) => { - Assert.NotNull(block); - Assert.IsType(block); - }) - }, - new object[] { - new AudioBlock { - Audio = new ExternalFile { - External = new ExternalFile.Info { - Url = "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3" - } - } - }, - new AudioUpdateBlock { - Audio = new ExternalFileInput { - External = new ExternalFileInput.Data { - Url = "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3" - } - } + new RichTextTextInput {Text = new Text {Content = "Github"}}, + }, }, - new Action((block) => { - block.Should().NotBeNull(); - - block.Should().BeOfType().Subject - .Audio.Should().BeOfType().Subject - .External.Url.Should().Be("https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3"); - }) }, - new object[] + new Action(block => { - new TableOfContentsBlock { - TableOfContents = new TableOfContentsBlock.Data() - }, - new TableOfContentsUpdateBlock(), - new Action((block) => + var updatedBlock = (BookmarkBlock)block; + Assert.Equal("https://github.com/notion-dotnet/notion-sdk-net", updatedBlock.Bookmark.Url); + Assert.Equal("Github", updatedBlock.Bookmark.Caption.OfType().First().Text.Content); + }), + }, + new object[] + { + new EquationBlock {Equation = new EquationBlock.Info {Expression = "e=mc^3"}}, + new EquationUpdateBlock {Equation = new EquationUpdateBlock.Info {Expression = "e=mc^2"}}, + new Action(block => + { + var updatedBlock = (EquationBlock)block; + Assert.Equal("e=mc^2", updatedBlock.Equation.Expression); + }), + }, + new object[] + { + new DividerBlock {Divider = new DividerBlock.Data()}, new DividerUpdateBlock(), new Action( + block => { Assert.NotNull(block); - Assert.IsType(block); - }) - }, - new object[] + Assert.IsType(block); + }), + }, + new object[] + { + new AudioBlock { - new CalloutBlock + Audio = new ExternalFile { - Callout = new CalloutBlock.Info + External = new ExternalFile.Info { - RichText = new List - { - new RichTextTextInput - { - Text = new Text - { - Content = "Test" - } - } - } - } + Url = "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3", + }, }, - new CalloutUpdateBlock() + }, + new AudioUpdateBlock + { + Audio = new ExternalFileInput { - Callout = new CalloutUpdateBlock.Info + External = new ExternalFileInput.Data { - RichText = new List - { - new RichTextTextInput - { - Text = new Text - { - Content = "Test 2" - } - } - } - } + Url = "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3", + }, }, - new Action((block) => - { - Assert.NotNull(block); - var calloutBlock = Assert.IsType(block); - - Assert.Equal("Test 2", calloutBlock.Callout.RichText.OfType().First().Text.Content); - }) }, - new object[] + new Action(block => { - new QuoteBlock + block.Should().NotBeNull(); + + block.Should().BeOfType().Subject + .Audio.Should().BeOfType().Subject + .External.Url.Should().Be("https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3"); + }), + }, + new object[] + { + new TableOfContentsBlock {TableOfContents = new TableOfContentsBlock.Data()}, + new TableOfContentsUpdateBlock(), new Action(block => + { + Assert.NotNull(block); + Assert.IsType(block); + }), + }, + new object[] + { + new CalloutBlock + { + Callout = new CalloutBlock.Info { - Quote = new QuoteBlock.Info + RichText = new List { - RichText = new List - { - new RichTextTextInput - { - Text = new Text - { - Content = "Test" - } - } - } - } + new RichTextTextInput {Text = new Text {Content = "Test"}}, + }, }, - new QuoteUpdateBlock() + }, + new CalloutUpdateBlock + { + Callout = new CalloutUpdateBlock.Info { - Quote = new QuoteUpdateBlock.Info + RichText = new List { - RichText = new List - { - new RichTextTextInput - { - Text = new Text - { - Content = "Test 2" - } - } - } - } + new RichTextTextInput {Text = new Text {Content = "Test 2"}}, + }, }, - new Action((block) => - { - Assert.NotNull(block); - var quoteBlock = Assert.IsType(block); - - Assert.Equal("Test 2", quoteBlock.Quote.RichText.OfType().First().Text.Content); - }) }, - new object[] + new Action(block => { - new ImageBlock() { - Image = new ExternalFile + Assert.NotNull(block); + var calloutBlock = Assert.IsType(block); + + Assert.Equal("Test 2", calloutBlock.Callout.RichText.OfType().First().Text.Content); + }), + }, + new object[] + { + new QuoteBlock + { + Quote = new QuoteBlock.Info + { + RichText = new List { - External = new ExternalFile.Info - { - Url = "https://zephoria.com/wp-content/uploads/2014/08/online-community.jpg" - } - } + new RichTextTextInput {Text = new Text {Content = "Test"}}, + }, }, - new ImageUpdateBlock() + }, + new QuoteUpdateBlock + { + Quote = new QuoteUpdateBlock.Info { - Image = new ExternalFileInput + RichText = new List { - External = new ExternalFileInput.Data - { - Url = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg" - } - } + new RichTextTextInput {Text = new Text {Content = "Test 2"}}, + }, }, - new Action (block => - { - Assert.NotNull(block); - var imageBlock = Assert.IsType(block); - var imageFile = Assert.IsType(imageBlock.Image); - - Assert.Equal("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", imageFile.External.Url); - }) }, - new object[] + new Action(block => + { + Assert.NotNull(block); + var quoteBlock = Assert.IsType(block); + + Assert.Equal("Test 2", quoteBlock.Quote.RichText.OfType().First().Text.Content); + }), + }, + new object[] + { + new ImageBlock { - new EmbedBlock() + Image = new ExternalFile { - Embed = new EmbedBlock.Info + External = new ExternalFile.Info { - Url = "https://zephoria.com/wp-content/uploads/2014/08/online-community.jpg" - } + Url = "https://zephoria.com/wp-content/uploads/2014/08/online-community.jpg", + }, }, - new EmbedUpdateBlock() + }, + new ImageUpdateBlock + { + Image = new ExternalFileInput { - Embed = new EmbedUpdateBlock.Info + External = new ExternalFileInput.Data { - Url = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg" - } + Url + = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", + }, }, - new Action (block => + }, + new Action(block => + { + Assert.NotNull(block); + var imageBlock = Assert.IsType(block); + var imageFile = Assert.IsType(imageBlock.Image); + + Assert.Equal("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", + imageFile.External.Url); + }), + }, + new object[] + { + new EmbedBlock + { + Embed = new EmbedBlock.Info { - Assert.NotNull(block); - var embedBlock = Assert.IsType(block); - - Assert.Equal("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", embedBlock.Embed.Url); - }) + Url = "https://zephoria.com/wp-content/uploads/2014/08/online-community.jpg", + }, }, - new object[] + new EmbedUpdateBlock { - new TemplateBlock() + Embed = new EmbedUpdateBlock.Info { - Template = new TemplateBlock.Data - { - RichText = new List - { - new RichTextText - { - Text = new Text - { - Content = "Test Template" - } - } - }, - Children = new List - { - new EmbedBlock() - { - Embed = new EmbedBlock.Info - { - Url = "https://zephoria.com/wp-content/uploads/2014/08/online-community.jpg" - } - } - } - } + Url = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", }, - new TemplateUpdateBlock() + }, + new Action(block => + { + Assert.NotNull(block); + var embedBlock = Assert.IsType(block); + + Assert.Equal("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", + embedBlock.Embed.Url); + }), + }, + new object[] + { + new TemplateBlock + { + Template = new TemplateBlock.Data { - Template = new TemplateUpdateBlock.Info + RichText = new List { - RichText = new List + new RichTextText {Text = new Text {Content = "Test Template"}}, + }, + Children = new List + { + new EmbedBlock { - new RichTextTextInput + Embed = new EmbedBlock.Info { - Text = new Text - { - Content = "Test Template 2" - } - } - } - } + Url + = "https://zephoria.com/wp-content/uploads/2014/08/online-community.jpg", + }, + }, + }, }, - new Action (block => - { - Assert.NotNull(block); - var templateBlock = Assert.IsType(block); - - Assert.Single(templateBlock.Template.RichText); - Assert.Null(templateBlock.Template.Children); - Assert.Equal("Test Template 2", templateBlock.Template.RichText.OfType().First().Text.Content); - }) }, - new object[] + new TemplateUpdateBlock { - new LinkToPageBlock() + Template = new TemplateUpdateBlock.Info { - LinkToPage = new PageParent + RichText = new List { - Type = ParentType.PageId, - PageId = "533578e3edf14c0a91a9da6b09bac3ee" - } + new RichTextTextInput {Text = new Text {Content = "Test Template 2"}}, + }, }, - new LinkToPageUpdateBlock() + }, + new Action(block => + { + Assert.NotNull(block); + var templateBlock = Assert.IsType(block); + + Assert.Single(templateBlock.Template.RichText); + Assert.Null(templateBlock.Template.Children); + + Assert.Equal("Test Template 2", + templateBlock.Template.RichText.OfType().First().Text.Content); + }), + }, + new object[] + { + new LinkToPageBlock + { + LinkToPage = new PageParent { - LinkToPage = new ParentPageInput - { - PageId = "3c357473a28149a488c010d2b245a589" - } + Type = ParentType.PageId, PageId = "533578e3edf14c0a91a9da6b09bac3ee", }, - new Action(block => - { - Assert.NotNull(block); - var linkToPageBlock = Assert.IsType(block); + }, + new LinkToPageUpdateBlock + { + LinkToPage = new ParentPageInput {PageId = "3c357473a28149a488c010d2b245a589"}, + }, + new Action(block => + { + Assert.NotNull(block); + var linkToPageBlock = Assert.IsType(block); - var pageParent = Assert.IsType(linkToPageBlock.LinkToPage); + var pageParent = Assert.IsType(linkToPageBlock.LinkToPage); - // TODO: Currently the api doesn't allow to update the link_to_page block type - // This will change to updated ID once api start to support - Assert.Equal(Guid.Parse("533578e3edf14c0a91a9da6b09bac3ee"), Guid.Parse(pageParent.PageId)); - }) - } - }; - } + // TODO: Currently the api doesn't allow to update the link_to_page block type + // This will change to updated ID once api start to support + Assert.Equal(Guid.Parse("533578e3edf14c0a91a9da6b09bac3ee"), Guid.Parse(pageParent.PageId)); + }), + }, + }; } } diff --git a/Test/Notion.IntegrationTests/IPageClientTests.cs b/Test/Notion.IntegrationTests/IPageClientTests.cs index dbf74a90..24f11940 100644 --- a/Test/Notion.IntegrationTests/IPageClientTests.cs +++ b/Test/Notion.IntegrationTests/IPageClientTests.cs @@ -6,297 +6,228 @@ using Notion.Client; using Xunit; -namespace Notion.IntegrationTests +namespace Notion.IntegrationTests; + +public class IPageClientTests { - public class IPageClientTests - { - private readonly INotionClient _client; - private readonly string _databaseId; + private readonly INotionClient _client; + private readonly string _databaseId; - public IPageClientTests() - { - var options = new ClientOptions - { - AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN") - }; + public IPageClientTests() + { + var options = new ClientOptions {AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN")}; - _client = NotionClientFactory.Create(options); - _databaseId = Environment.GetEnvironmentVariable("DATABASE_ID") ?? "f86f2262-0751-40f2-8f63-e3f7a3c39fcb"; - } + _client = NotionClientFactory.Create(options); + _databaseId = Environment.GetEnvironmentVariable("DATABASE_ID") ?? "f86f2262-0751-40f2-8f63-e3f7a3c39fcb"; + } - [Fact] - public async Task CreateAsync_CreatesANewPage() - { - PagesCreateParameters pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput - { - DatabaseId = _databaseId - }) - .AddProperty("Name", new TitlePropertyValue - { - Title = new List + [Fact] + public async Task CreateAsync_CreatesANewPage() + { + var pagesCreateParameters = PagesCreateParametersBuilder + .Create(new DatabaseParentInput {DatabaseId = _databaseId}) + .AddProperty("Name", + new TitlePropertyValue { - new RichTextText - { - Text = new Text - { - Content = "Test Page Title" - } - } - } - }) + Title = new List + { + new RichTextText {Text = new Text {Content = "Test Page Title"}}, + }, + }) .Build(); - var page = await _client.Pages.CreateAsync(pagesCreateParameters); + var page = await _client.Pages.CreateAsync(pagesCreateParameters); - page.Should().NotBeNull(); - page.Parent.Should().BeOfType().Which - .DatabaseId.Should().Be(_databaseId); + page.Should().NotBeNull(); - page.Properties.Should().ContainKey("Name"); - var pageProperty = page.Properties["Name"].Should().BeOfType().Subject; + page.Parent.Should().BeOfType().Which + .DatabaseId.Should().Be(_databaseId); - var titleProperty = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters - { - PageId = page.Id, - PropertyId = pageProperty.Id - }); + page.Properties.Should().ContainKey("Name"); + var pageProperty = page.Properties["Name"].Should().BeOfType().Subject; - titleProperty.Results.First().As().Title.PlainText.Should().Be("Test Page Title"); + var titleProperty + = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItem( + new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = pageProperty.Id}); - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters - { - Archived = true - }); - } + titleProperty.Results.First().As().Title.PlainText.Should().Be("Test Page Title"); - [Fact] - public async Task Bug_unable_to_create_page_with_select_property() - { - PagesCreateParameters pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput - { - DatabaseId = _databaseId - }) - .AddProperty("Name", new TitlePropertyValue - { - Title = new List - { - new RichTextText - { - Text = new Text - { - Content = "Test Page Title" - } - } - } - }) - .AddProperty("TestSelect", new SelectPropertyValue - { - Select = new SelectOption + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + } + + [Fact] + public async Task Bug_unable_to_create_page_with_select_property() + { + var pagesCreateParameters = PagesCreateParametersBuilder + .Create(new DatabaseParentInput {DatabaseId = _databaseId}) + .AddProperty("Name", + new TitlePropertyValue { - Id = "dfbfbe65-6f67-4876-9f75-699124334d06" - } - }) + Title = new List + { + new RichTextText {Text = new Text {Content = "Test Page Title"}}, + }, + }) + .AddProperty("TestSelect", + new SelectPropertyValue {Select = new SelectOption {Id = "dfbfbe65-6f67-4876-9f75-699124334d06"}}) .Build(); - var page = await _client.Pages.CreateAsync(pagesCreateParameters); + var page = await _client.Pages.CreateAsync(pagesCreateParameters); - page.Should().NotBeNull(); - page.Parent.Should().BeOfType().Which - .DatabaseId.Should().Be(_databaseId); + page.Should().NotBeNull(); - page.Properties.Should().ContainKey("Name"); - var pageProperty = page.Properties["Name"].Should().BeOfType().Subject; + page.Parent.Should().BeOfType().Which + .DatabaseId.Should().Be(_databaseId); - var titleProperty = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters - { - PageId = page.Id, - PropertyId = pageProperty.Id - }); + page.Properties.Should().ContainKey("Name"); + var pageProperty = page.Properties["Name"].Should().BeOfType().Subject; - titleProperty.Results.First().As().Title.PlainText.Should().Be("Test Page Title"); + var titleProperty + = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItem( + new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = pageProperty.Id}); - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters - { - Archived = true - }); - } + titleProperty.Results.First().As().Title.PlainText.Should().Be("Test Page Title"); - [Fact] - public async Task Test_RetrievePagePropertyItemAsync() - { - PagesCreateParameters pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput - { - DatabaseId = _databaseId - }) - .AddProperty("Name", new TitlePropertyValue - { - Title = new List + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + } + + [Fact] + public async Task Test_RetrievePagePropertyItemAsync() + { + var pagesCreateParameters = PagesCreateParametersBuilder + .Create(new DatabaseParentInput {DatabaseId = _databaseId}) + .AddProperty("Name", + new TitlePropertyValue { - new RichTextText + Title = new List { - Text = new Text - { - Content = "Test Page Title" - } - } - } - }) + new RichTextText {Text = new Text {Content = "Test Page Title"}}, + }, + }) .Build(); - var page = await _client.Pages.CreateAsync(pagesCreateParameters); + var page = await _client.Pages.CreateAsync(pagesCreateParameters); - var property = await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters - { - PageId = page.Id, - PropertyId = "title" - }); + var property = await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters + { + PageId = page.Id, PropertyId = "title", + }); - property.Should().NotBeNull(); - property.Should().BeOfType(); + property.Should().NotBeNull(); + property.Should().BeOfType(); - var listProperty = (ListPropertyItem)property; + var listProperty = (ListPropertyItem)property; - listProperty.Type.Should().NotBeNull(); - listProperty.Results.Should().SatisfyRespectively(p => - { - p.Should().BeOfType(); - var titleProperty = (TitlePropertyItem)p; + listProperty.Type.Should().NotBeNull(); - titleProperty.Title.PlainText.Should().Be("Test Page Title"); - }); + listProperty.Results.Should().SatisfyRespectively(p => + { + p.Should().BeOfType(); + var titleProperty = (TitlePropertyItem)p; - // cleanup - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters - { - Archived = true - }); - } + titleProperty.Title.PlainText.Should().Be("Test Page Title"); + }); - [Fact] - public async Task Test_UpdatePageProperty_with_date_as_null() - { - // setup - add property to db and create a page with the property having a date + // cleanup + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + } - string datePropertyName = "Test Date Property"; - var updateDatabaseParameters = new DatabasesUpdateParameters(); - updateDatabaseParameters.Properties = new Dictionary - { - { "Name", new TitleUpdatePropertySchema { Title = new Dictionary() } }, - { "Test Date Property", new DateUpdatePropertySchema{ Date = new Dictionary() } } - }; + [Fact] + public async Task Test_UpdatePageProperty_with_date_as_null() + { + // setup - add property to db and create a page with the property having a date - PagesCreateParameters pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput - { - DatabaseId = _databaseId - }) - .AddProperty("Name", new TitlePropertyValue - { - Title = new List - { - new RichTextText - { - Text = new Text - { - Content = "Test Page Title" - } - } - } - }) - .AddProperty(datePropertyName, new DatePropertyValue - { - Date = new Date() + var datePropertyName = "Test Date Property"; + var updateDatabaseParameters = new DatabasesUpdateParameters(); + + updateDatabaseParameters.Properties = new Dictionary + { + {"Name", new TitleUpdatePropertySchema {Title = new Dictionary()}}, + {"Test Date Property", new DateUpdatePropertySchema {Date = new Dictionary()}}, + }; + + var pagesCreateParameters = PagesCreateParametersBuilder + .Create(new DatabaseParentInput {DatabaseId = _databaseId}) + .AddProperty("Name", + new TitlePropertyValue + { + Title = new List + { + new RichTextText {Text = new Text {Content = "Test Page Title"}}, + }, + }) + .AddProperty(datePropertyName, + new DatePropertyValue { - Start = Convert.ToDateTime("2020-12-08T12:00:00Z"), - End = Convert.ToDateTime("2025-12-08T12:00:00Z") - } - }) + Date = new Date + { + Start = Convert.ToDateTime("2020-12-08T12:00:00Z"), + End = Convert.ToDateTime("2025-12-08T12:00:00Z"), + }, + }) .Build(); - var updatedDb = await _client.Databases.UpdateAsync(_databaseId, updateDatabaseParameters); + var updatedDb = await _client.Databases.UpdateAsync(_databaseId, updateDatabaseParameters); - var page = await _client.Pages.CreateAsync(pagesCreateParameters); + var page = await _client.Pages.CreateAsync(pagesCreateParameters); - var setDate = (DatePropertyItem)await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters - { - PageId = page.Id, - PropertyId = page.Properties[datePropertyName].Id - }); + var setDate = (DatePropertyItem)await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters + { + PageId = page.Id, PropertyId = page.Properties[datePropertyName].Id, + }); - setDate?.Date?.Start.Should().Be(Convert.ToDateTime("2020-12-08T12:00:00Z")); + setDate?.Date?.Start.Should().Be(Convert.ToDateTime("2020-12-08T12:00:00Z")); - // verify - IDictionary testProps = new Dictionary(); - testProps.Add(datePropertyName, new DatePropertyValue() { Date = null }); + // verify + IDictionary testProps = new Dictionary(); + testProps.Add(datePropertyName, new DatePropertyValue {Date = null}); - var updatedPage = await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters - { - Properties = testProps - }); + var updatedPage = await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Properties = testProps}); - var verifyDate = (DatePropertyItem)await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters + var verifyDate = (DatePropertyItem)await _client.Pages.RetrievePagePropertyItem( + new RetrievePropertyItemParameters { - PageId = page.Id, - PropertyId = updatedPage.Properties[datePropertyName].Id + PageId = page.Id, PropertyId = updatedPage.Properties[datePropertyName].Id, }); - verifyDate?.Date.Should().BeNull(); + verifyDate?.Date.Should().BeNull(); - //cleanup - await _client.Blocks.DeleteAsync(page.Id); - } + //cleanup + await _client.Blocks.DeleteAsync(page.Id); + } - [Fact] - public async Task Bug_Unable_To_Parse_NumberPropertyItem() - { - // Arrange - var pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput - { - DatabaseId = _databaseId - }).AddProperty("Name", new TitlePropertyValue - { - Title = new List + [Fact] + public async Task Bug_Unable_To_Parse_NumberPropertyItem() + { + // Arrange + var pagesCreateParameters = PagesCreateParametersBuilder + .Create(new DatabaseParentInput {DatabaseId = _databaseId}).AddProperty("Name", + new TitlePropertyValue + { + Title = new List { - new RichTextText - { - Text = new Text - { - Content = "Test Page Title" - } - } - } - }).AddProperty("Number", new NumberPropertyValue - { - Number = 200.00 - }).Build(); + new RichTextText {Text = new Text {Content = "Test Page Title"}}, + }, + }).AddProperty("Number", new NumberPropertyValue {Number = 200.00}).Build(); - // Act - var page = await _client.Pages.CreateAsync(pagesCreateParameters); + // Act + var page = await _client.Pages.CreateAsync(pagesCreateParameters); - // Assert - Assert.NotNull(page); - var pageParent = Assert.IsType(page.Parent); - Assert.Equal(_databaseId, pageParent.DatabaseId); + // Assert + Assert.NotNull(page); + var pageParent = Assert.IsType(page.Parent); + Assert.Equal(_databaseId, pageParent.DatabaseId); - var titleProperty = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters - { - PageId = page.Id, - PropertyId = page.Properties["Name"].Id - }); + var titleProperty = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItem( + new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = page.Properties["Name"].Id}); - Assert.Equal("Test Page Title", titleProperty.Results.First().As().Title.PlainText); + Assert.Equal("Test Page Title", titleProperty.Results.First().As().Title.PlainText); - var numberProperty = (NumberPropertyItem)await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters - { - PageId = page.Id, - PropertyId = page.Properties["Number"].Id - }); + var numberProperty = (NumberPropertyItem)await _client.Pages.RetrievePagePropertyItem( + new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = page.Properties["Number"].Id}); - Assert.Equal(200.00, numberProperty.Number); + Assert.Equal(200.00, numberProperty.Number); - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters - { - Archived = true - }); - } + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); } } diff --git a/Test/Notion.UnitTests/ApiTestBase.cs b/Test/Notion.UnitTests/ApiTestBase.cs index e593a47c..ceb415d2 100644 --- a/Test/Notion.UnitTests/ApiTestBase.cs +++ b/Test/Notion.UnitTests/ApiTestBase.cs @@ -7,64 +7,55 @@ using WireMock.RequestBuilders; using WireMock.Server; -namespace Notion.UnitTests +namespace Notion.UnitTests; + +public class ApiTestBase : IDisposable { - public class ApiTestBase : IDisposable + protected static readonly JsonSerializerSettings JsonSerializerSettings = new() { - protected readonly WireMockServer Server; - - protected static readonly JsonSerializerSettings JsonSerializerSettings = new JsonSerializerSettings() - { - Formatting = Newtonsoft.Json.Formatting.Indented, - ContractResolver = new DefaultContractResolver - { - NamingStrategy = new CamelCaseNamingStrategy() - } - }; + Formatting = Formatting.Indented, + ContractResolver = new DefaultContractResolver {NamingStrategy = new CamelCaseNamingStrategy()}, + }; - protected readonly ClientOptions ClientOptions; + protected readonly ClientOptions ClientOptions; + protected readonly WireMockServer Server; - protected ApiTestBase() - { - Server = WireMockServer.Start(); - ClientOptions = new ClientOptions() - { - BaseUrl = Server.Urls.First(), - AuthToken = "" - }; - } + protected ApiTestBase() + { + Server = WireMockServer.Start(); + ClientOptions = new ClientOptions {BaseUrl = Server.Urls.First(), AuthToken = ""}; + } - public void Dispose() - { - Server.Stop(); - Server.Dispose(); - } + public void Dispose() + { + Server.Stop(); + Server.Dispose(); + } - protected IRequestBuilder CreateGetRequestBuilder(string path) - { - return Request.Create() - .WithPath(path) - .UsingGet() - .WithHeader("Authorization", $"Bearer {ClientOptions.AuthToken}", MatchBehaviour.AcceptOnMatch) - .WithHeader("Notion-Version", Constants.DEFAULT_NOTION_VERSION, MatchBehaviour.AcceptOnMatch); - } + protected IRequestBuilder CreateGetRequestBuilder(string path) + { + return Request.Create() + .WithPath(path) + .UsingGet() + .WithHeader("Authorization", $"Bearer {ClientOptions.AuthToken}", MatchBehaviour.AcceptOnMatch) + .WithHeader("Notion-Version", Constants.DEFAULT_NOTION_VERSION, MatchBehaviour.AcceptOnMatch); + } - protected IRequestBuilder CreatePostRequestBuilder(string path) - { - return Request.Create() - .WithPath(path) - .UsingPost() - .WithHeader("Authorization", $"Bearer {ClientOptions.AuthToken}", MatchBehaviour.AcceptOnMatch) - .WithHeader("Notion-Version", Constants.DEFAULT_NOTION_VERSION, MatchBehaviour.AcceptOnMatch); - } + protected IRequestBuilder CreatePostRequestBuilder(string path) + { + return Request.Create() + .WithPath(path) + .UsingPost() + .WithHeader("Authorization", $"Bearer {ClientOptions.AuthToken}", MatchBehaviour.AcceptOnMatch) + .WithHeader("Notion-Version", Constants.DEFAULT_NOTION_VERSION, MatchBehaviour.AcceptOnMatch); + } - protected IRequestBuilder CreatePatchRequestBuilder(string path) - { - return Request.Create() - .WithPath(path) - .UsingPatch() - .WithHeader("Authorization", $"Bearer {ClientOptions.AuthToken}", MatchBehaviour.AcceptOnMatch) - .WithHeader("Notion-Version", Constants.DEFAULT_NOTION_VERSION, MatchBehaviour.AcceptOnMatch); - } + protected IRequestBuilder CreatePatchRequestBuilder(string path) + { + return Request.Create() + .WithPath(path) + .UsingPatch() + .WithHeader("Authorization", $"Bearer {ClientOptions.AuthToken}", MatchBehaviour.AcceptOnMatch) + .WithHeader("Notion-Version", Constants.DEFAULT_NOTION_VERSION, MatchBehaviour.AcceptOnMatch); } } diff --git a/Test/Notion.UnitTests/BlocksClientTests.cs b/Test/Notion.UnitTests/BlocksClientTests.cs index 753e5464..8a568a13 100644 --- a/Test/Notion.UnitTests/BlocksClientTests.cs +++ b/Test/Notion.UnitTests/BlocksClientTests.cs @@ -7,191 +7,184 @@ using WireMock.ResponseBuilders; using Xunit; -namespace Notion.UnitTests +namespace Notion.UnitTests; + +public class BlocksClientTests : ApiTestBase { - public class BlocksClientTests : ApiTestBase - { - private readonly IBlocksClient _client; + private readonly IBlocksClient _client; - public BlocksClientTests() - { - _client = new BlocksClient(new RestClient(ClientOptions)); - } + public BlocksClientTests() + { + _client = new BlocksClient(new RestClient(ClientOptions)); + } - [Fact] - public async Task RetrieveBlockChildren() - { - // Arrange - string blockId = "3c357473-a281-49a4-88c0-10d2b245a589"; - var path = ApiEndpoints.BlocksApiUrls.RetrieveChildren(blockId); - var jsonData = await File.ReadAllTextAsync("data/blocks/RetrieveBlockChildrenResponse.json"); + [Fact] + public async Task RetrieveBlockChildren() + { + // Arrange + var blockId = "3c357473-a281-49a4-88c0-10d2b245a589"; + var path = ApiEndpoints.BlocksApiUrls.RetrieveChildren(blockId); + var jsonData = await File.ReadAllTextAsync("data/blocks/RetrieveBlockChildrenResponse.json"); - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - // Act - var childrenResult = await _client.RetrieveChildrenAsync(blockId, new BlocksRetrieveChildrenParameters()); + // Act + var childrenResult = await _client.RetrieveChildrenAsync(blockId, new BlocksRetrieveChildrenParameters()); - // Assert - var children = childrenResult.Results; - children.Should().HaveCount(8); - } + // Assert + var children = childrenResult.Results; + children.Should().HaveCount(8); + } - [Fact] - public async Task AppendBlockChildren() - { - // Arrange - string blockId = "7face6fd-3ef4-4b38-b1dc-c5044988eec0"; - var path = ApiEndpoints.BlocksApiUrls.AppendChildren(blockId); + [Fact] + public async Task AppendBlockChildren() + { + // Arrange + var blockId = "7face6fd-3ef4-4b38-b1dc-c5044988eec0"; + var path = ApiEndpoints.BlocksApiUrls.AppendChildren(blockId); - var jsonData = await File.ReadAllTextAsync("data/blocks/AppendBlockChildrenResponse.json"); + var jsonData = await File.ReadAllTextAsync("data/blocks/AppendBlockChildrenResponse.json"); - Server.Given(CreatePatchRequestBuilder(path)) - .RespondWith( + Server.Given(CreatePatchRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var parameters = new BlocksAppendChildrenParameters() + var parameters = new BlocksAppendChildrenParameters + { + Children = new List { - Children = new List + new HeadingTwoBlock { - new HeadingTwoBlock() + Heading_2 = new HeadingTwoBlock.Info { - Heading_2 = new HeadingTwoBlock.Info + RichText = new List { - RichText = new List - { - new RichTextText - { - Text = new Text - { - Content = "Lacinato kale" - } - } - } - } + new RichTextText {Text = new Text {Content = "Lacinato kale"}}, + }, }, - new ParagraphBlock() + }, + new ParagraphBlock + { + Paragraph = new ParagraphBlock.Info { - Paragraph = new ParagraphBlock.Info + RichText = new List { - RichText = new List + new RichTextText { - new RichTextText + Text = new Text { - Text = new Text + Content + = "Lacinato kale is a variety of kale with a long tradition in Italian cuisine, especially that of Tuscany. It is also known as Tuscan kale, Italian kale, dinosaur kale, kale, flat back kale, palm tree kale, or black Tuscan palm.", + Link = new Link { - Content = "Lacinato kale is a variety of kale with a long tradition in Italian cuisine, especially that of Tuscany. It is also known as Tuscan kale, Italian kale, dinosaur kale, kale, flat back kale, palm tree kale, or black Tuscan palm.", - Link = new Link - { - Url = "https://en.wikipedia.org/wiki/Lacinato_kale" - } - } - } - } - } - } - } - }; - - // Act - var blocksResult = await _client.AppendChildrenAsync(blockId, parameters); - - // Assert - var blocks = blocksResult.Results; - blocks.Should().SatisfyRespectively( - block => - { - block.Type.Should().Be(BlockType.Heading_2); - var headingBlock = (HeadingTwoBlock)block; - var text = headingBlock.Heading_2.RichText.OfType().FirstOrDefault(); - text.Text.Content.Should().Be("Lacinato kale"); + Url + = "https://en.wikipedia.org/wiki/Lacinato_kale", + }, + }, + }, + }, + }, }, - block => - { - block.Type.Should().Be(BlockType.Paragraph); - var paragraphBlock = (ParagraphBlock)block; - var text = paragraphBlock.Paragraph.RichText.OfType().LastOrDefault(); - text.Text.Content.Should().Be("Lacinato kale is a variety of kale with a long tradition in Italian cuisine, especially that of Tuscany. It is also known as Tuscan kale, Italian kale, dinosaur kale, kale, flat back kale, palm tree kale, or black Tuscan palm."); - text.Text.Link.Url.Should().Be("https://en.wikipedia.org/wiki/Lacinato_kale"); - } - ); - } + }, + }; - [Fact] - public async Task RetrieveAsync() - { - string blockId = "9bc30ad4-9373-46a5-84ab-0a7845ee52e6"; - var path = ApiEndpoints.BlocksApiUrls.Retrieve(blockId); - var jsonData = await File.ReadAllTextAsync("data/blocks/RetrieveBlockResponse.json"); + // Act + var blocksResult = await _client.AppendChildrenAsync(blockId, parameters); + + // Assert + var blocks = blocksResult.Results; + + blocks.Should().SatisfyRespectively( + block => + { + block.Type.Should().Be(BlockType.Heading_2); + var headingBlock = (HeadingTwoBlock)block; + var text = headingBlock.Heading_2.RichText.OfType().FirstOrDefault(); + text.Text.Content.Should().Be("Lacinato kale"); + }, + block => + { + block.Type.Should().Be(BlockType.Paragraph); + var paragraphBlock = (ParagraphBlock)block; + var text = paragraphBlock.Paragraph.RichText.OfType().LastOrDefault(); + + text.Text.Content.Should().Be( + "Lacinato kale is a variety of kale with a long tradition in Italian cuisine, especially that of Tuscany. It is also known as Tuscan kale, Italian kale, dinosaur kale, kale, flat back kale, palm tree kale, or black Tuscan palm."); + + text.Text.Link.Url.Should().Be("https://en.wikipedia.org/wiki/Lacinato_kale"); + } + ); + } + + [Fact] + public async Task RetrieveAsync() + { + var blockId = "9bc30ad4-9373-46a5-84ab-0a7845ee52e6"; + var path = ApiEndpoints.BlocksApiUrls.Retrieve(blockId); + var jsonData = await File.ReadAllTextAsync("data/blocks/RetrieveBlockResponse.json"); - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var block = await _client.RetrieveAsync(blockId); + var block = await _client.RetrieveAsync(blockId); - block.Id.Should().Be(blockId); - block.HasChildren.Should().BeFalse(); - block.Type.Should().Be(BlockType.ToDo); + block.Id.Should().Be(blockId); + block.HasChildren.Should().BeFalse(); + block.Type.Should().Be(BlockType.ToDo); - var todoBlock = ((ToDoBlock)block); - todoBlock.ToDo.RichText.Should().ContainSingle(); - todoBlock.ToDo.RichText.First().Should().BeAssignableTo(); - ((RichTextText)todoBlock.ToDo.RichText.First()).Text.Content.Should().Be("Lacinato kale"); - } + var todoBlock = (ToDoBlock)block; + todoBlock.ToDo.RichText.Should().ContainSingle(); + todoBlock.ToDo.RichText.First().Should().BeAssignableTo(); + ((RichTextText)todoBlock.ToDo.RichText.First()).Text.Content.Should().Be("Lacinato kale"); + } - [Fact] - public async Task UpdateAsync() - { - string blockId = "9bc30ad4-9373-46a5-84ab-0a7845ee52e6"; - var path = ApiEndpoints.BlocksApiUrls.Update(blockId); - var jsonData = await File.ReadAllTextAsync("data/blocks/UpdateBlockResponse.json"); + [Fact] + public async Task UpdateAsync() + { + var blockId = "9bc30ad4-9373-46a5-84ab-0a7845ee52e6"; + var path = ApiEndpoints.BlocksApiUrls.Update(blockId); + var jsonData = await File.ReadAllTextAsync("data/blocks/UpdateBlockResponse.json"); - Server.Given(CreatePatchRequestBuilder(path)) - .RespondWith( + Server.Given(CreatePatchRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var updateBlock = new ToDoUpdateBlock + var updateBlock = new ToDoUpdateBlock + { + ToDo = new ToDoUpdateBlock.Info { - ToDo = new ToDoUpdateBlock.Info + RichText = new List { - RichText = new List() - { - new RichTextTextInput - { - Text = new Text - { - Content = "Lacinato kale" - }, - } - }, - IsChecked = true - } - }; + new RichTextTextInput {Text = new Text {Content = "Lacinato kale"}}, + }, + IsChecked = true, + }, + }; - var block = await _client.UpdateAsync(blockId, updateBlock); + var block = await _client.UpdateAsync(blockId, updateBlock); - block.Id.Should().Be(blockId); - block.HasChildren.Should().BeFalse(); - block.Type.Should().Be(BlockType.ToDo); + block.Id.Should().Be(blockId); + block.HasChildren.Should().BeFalse(); + block.Type.Should().Be(BlockType.ToDo); - var todoBlock = ((ToDoBlock)block); - todoBlock.ToDo.RichText.Should().ContainSingle(); - todoBlock.ToDo.RichText.First().Should().BeAssignableTo(); - ((RichTextText)todoBlock.ToDo.RichText.First()).Text.Content.Should().Be("Lacinato kale"); - } + var todoBlock = (ToDoBlock)block; + todoBlock.ToDo.RichText.Should().ContainSingle(); + todoBlock.ToDo.RichText.First().Should().BeAssignableTo(); + ((RichTextText)todoBlock.ToDo.RichText.First()).Text.Content.Should().Be("Lacinato kale"); } } diff --git a/Test/Notion.UnitTests/DatabasesClientTests.cs b/Test/Notion.UnitTests/DatabasesClientTests.cs index cc4c2396..e78d0e68 100644 --- a/Test/Notion.UnitTests/DatabasesClientTests.cs +++ b/Test/Notion.UnitTests/DatabasesClientTests.cs @@ -7,483 +7,437 @@ using WireMock.ResponseBuilders; using Xunit; -namespace Notion.UnitTests +namespace Notion.UnitTests; + +public class DatabasesClientTests : ApiTestBase { - public class DatabasesClientTests : ApiTestBase + private readonly IDatabasesClient _client; + private readonly IPagesClient _pagesClient; + + public DatabasesClientTests() { - private readonly IDatabasesClient _client; - private readonly IPagesClient _pagesClient; - public DatabasesClientTests() - { - _client = new DatabasesClient(new RestClient(ClientOptions)); - _pagesClient = new PagesClient(new RestClient(ClientOptions)); - } + _client = new DatabasesClient(new RestClient(ClientOptions)); + _pagesClient = new PagesClient(new RestClient(ClientOptions)); + } - [Fact] - public async Task QueryAsync() - { - var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1"; - var path = ApiEndpoints.DatabasesApiUrls.Query(databaseId); - var jsonData = await File.ReadAllTextAsync("data/databases/DatabasesQueryResponse.json"); + [Fact] + public async Task QueryAsync() + { + var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1"; + var path = ApiEndpoints.DatabasesApiUrls.Query(databaseId); + var jsonData = await File.ReadAllTextAsync("data/databases/DatabasesQueryResponse.json"); - Server.Given(CreatePostRequestBuilder(path)) - .RespondWith( + Server.Given(CreatePostRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var databasesQueryParams = new DatabasesQueryParameters + var databasesQueryParams = new DatabasesQueryParameters + { + Filter = new CompoundFilter { - Filter = new CompoundFilter + Or = new List { - Or = new List { - new CheckboxFilter( - "In stock", - true - ), - new NumberFilter( - "Cost of next trip", - greaterThanOrEqualTo: 2 - ) - }, + new CheckboxFilter( + "In stock", + true + ), + new NumberFilter( + "Cost of next trip", + greaterThanOrEqualTo: 2 + ), }, - Sorts = new List - { - new Sort - { - Property = "Last ordered", - Direction = Direction.Ascending - } - } - }; + }, + Sorts = new List {new() {Property = "Last ordered", Direction = Direction.Ascending}}, + }; - var pagesPaginatedList = await _client.QueryAsync(databaseId, databasesQueryParams); + var pagesPaginatedList = await _client.QueryAsync(databaseId, databasesQueryParams); - pagesPaginatedList.Results.Should().ContainSingle(); + pagesPaginatedList.Results.Should().ContainSingle(); - foreach (var page in pagesPaginatedList.Results) - { - page.Parent.Should().BeAssignableTo(); - page.Object.Should().Be(ObjectType.Page); - } + foreach (var page in pagesPaginatedList.Results) + { + page.Parent.Should().BeAssignableTo(); + page.Object.Should().Be(ObjectType.Page); } + } - [Fact] - public async Task RetrieveDatabaseAsync() - { - var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1"; - var path = ApiEndpoints.DatabasesApiUrls.Retrieve(databaseId); - var jsonData = await File.ReadAllTextAsync("data/databases/DatabaseRetrieveResponse.json"); + [Fact] + public async Task RetrieveDatabaseAsync() + { + var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1"; + var path = ApiEndpoints.DatabasesApiUrls.Retrieve(databaseId); + var jsonData = await File.ReadAllTextAsync("data/databases/DatabaseRetrieveResponse.json"); - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var database = await _client.RetrieveAsync(databaseId); + var database = await _client.RetrieveAsync(databaseId); - database.Parent.Type.Should().Be(ParentType.PageId); - database.Parent.Should().BeOfType(); - ((PageParent)database.Parent).PageId.Should().Be("649089db-8984-4051-98fb-a03593b852d8"); - foreach (var property in database.Properties) - { - property.Key.Should().Be(property.Value.Name); - } + database.Parent.Type.Should().Be(ParentType.PageId); + database.Parent.Should().BeOfType(); + ((PageParent)database.Parent).PageId.Should().Be("649089db-8984-4051-98fb-a03593b852d8"); - HelperAsserts.IPageIconAsserts(database.Icon); - HelperAsserts.FileObjectAsserts(database.Cover); + foreach (var property in database.Properties) + { + property.Key.Should().Be(property.Value.Name); } - [Fact] - public async Task DatabasePropertyObjectContainNameProperty() - { - var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1"; - var path = ApiEndpoints.DatabasesApiUrls.Retrieve(databaseId); - var jsonData = await File.ReadAllTextAsync("data/databases/DatabasePropertyObjectContainNameProperty.json"); + HelperAsserts.IPageIconAsserts(database.Icon); + HelperAsserts.FileObjectAsserts(database.Cover); + } - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( + [Fact] + public async Task DatabasePropertyObjectContainNameProperty() + { + var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1"; + var path = ApiEndpoints.DatabasesApiUrls.Retrieve(databaseId); + var jsonData = await File.ReadAllTextAsync("data/databases/DatabasePropertyObjectContainNameProperty.json"); + + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var database = await _client.RetrieveAsync(databaseId); + var database = await _client.RetrieveAsync(databaseId); - foreach (var property in database.Properties) - { - property.Key.Should().Be(property.Value.Name); - } + foreach (var property in database.Properties) + { + property.Key.Should().Be(property.Value.Name); } + } - [Fact] - public async Task DatabasePropertyObjectContainRelationProperty() - { - var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1"; - var path = ApiEndpoints.DatabasesApiUrls.Retrieve(databaseId); - var jsonData = await File.ReadAllTextAsync("data/databases/DatabasePropertyObjectContainRelation.json"); + [Fact] + public async Task DatabasePropertyObjectContainRelationProperty() + { + var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1"; + var path = ApiEndpoints.DatabasesApiUrls.Retrieve(databaseId); + var jsonData = await File.ReadAllTextAsync("data/databases/DatabasePropertyObjectContainRelation.json"); - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var database = await _client.RetrieveAsync(databaseId); + var database = await _client.RetrieveAsync(databaseId); - database.Properties.Should().ContainKey("Property").WhichValue.Should().BeEquivalentTo( - new RelationProperty() + database.Properties.Should().ContainKey("Property").WhichValue.Should().BeEquivalentTo( + new RelationProperty + { + Id = "zDGa", + Name = "Property", + Relation = new DualPropertyRelation + { + DatabaseId = "f86f2262-0751-40f2-8f63-e3f7a3c39fcb", + DualProperty = new DualPropertyRelation.Data { - Id = "zDGa", - Name = "Property", - Relation = new DualPropertyRelation() - { - DatabaseId = "f86f2262-0751-40f2-8f63-e3f7a3c39fcb", - DualProperty = new DualPropertyRelation.Data - { - SyncedPropertyName = "Related to sample table (Property)", - SyncedPropertyId = "VQ}{" - } - } - }); - } + SyncedPropertyName = "Related to sample table (Property)", + SyncedPropertyId = "VQ}{", + }, + }, + }); + } - [Fact] - public async Task DatabasePropertyObjectContainParentProperty() - { - var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1"; - var path = ApiEndpoints.DatabasesApiUrls.Retrieve(databaseId); - var jsonData = await File.ReadAllTextAsync("data/databases/DatabasePropertyObjectContainParentProperty.json"); + [Fact] + public async Task DatabasePropertyObjectContainParentProperty() + { + var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1"; + var path = ApiEndpoints.DatabasesApiUrls.Retrieve(databaseId); + var jsonData = await File.ReadAllTextAsync("data/databases/DatabasePropertyObjectContainParentProperty.json"); - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var database = await _client.RetrieveAsync(databaseId); + var database = await _client.RetrieveAsync(databaseId); - database.Parent.Type.Should().Be(ParentType.PageId); - database.Parent.Should().BeOfType(); - ((PageParent)database.Parent).PageId.Should().Be("649089db-8984-4051-98fb-a03593b852d8"); - } + database.Parent.Type.Should().Be(ParentType.PageId); + database.Parent.Should().BeOfType(); + ((PageParent)database.Parent).PageId.Should().Be("649089db-8984-4051-98fb-a03593b852d8"); + } - [Fact] - public async Task CreateDatabaseAsync() - { - var pageId = "533578e3-edf1-4c0a-91a9-da6b09bac3ee"; - var path = ApiEndpoints.DatabasesApiUrls.Create; - var jsonData = await File.ReadAllTextAsync("data/databases/CreateDatabaseResponse.json"); + [Fact] + public async Task CreateDatabaseAsync() + { + var pageId = "533578e3-edf1-4c0a-91a9-da6b09bac3ee"; + var path = ApiEndpoints.DatabasesApiUrls.Create; + var jsonData = await File.ReadAllTextAsync("data/databases/CreateDatabaseResponse.json"); - Server.Given(CreatePostRequestBuilder(path)) - .RespondWith( + Server.Given(CreatePostRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var createDatabaseParameters = new DatabasesCreateParameters(); + var createDatabaseParameters = new DatabasesCreateParameters(); - createDatabaseParameters.Parent = new ParentPageInput - { - PageId = pageId - }; + createDatabaseParameters.Parent = new ParentPageInput {PageId = pageId}; + + createDatabaseParameters.Title = new List + { + new RichTextTextInput {Text = new Text {Content = "Grocery List", Link = null}}, + }; - createDatabaseParameters.Title = new List + createDatabaseParameters.Properties = new Dictionary + { + {"Name", new TitlePropertySchema {Title = new Dictionary()}}, + {"Price", new NumberPropertySchema {Number = new Number {Format = "dollar"}}}, { - new RichTextTextInput + "Food group", + new SelectPropertySchema { - Text = new Text + Select = new OptionWrapper { - Content = "Grocery List", - Link = null - } + Options = new List + { + new() {Color = Color.Green, Name = "🥦Vegetable"}, + new() {Color = Color.Red, Name = "🍎Fruit"}, + new() {Color = Color.Yellow, Name = "💪Protein"}, + }, + }, } - }; + }, + {"Last ordered", new DatePropertySchema {Date = new Dictionary()}}, + }; - createDatabaseParameters.Properties = new Dictionary - { - { "Name", new TitlePropertySchema { Title = new Dictionary() } }, - { "Price", new NumberPropertySchema { Number = new Number { Format = "dollar" } } }, - { "Food group", new SelectPropertySchema - { - Select = new OptionWrapper - { - Options = new List - { - new SelectOptionSchema - { - Color = Color.Green, - Name = "🥦Vegetable" - }, - new SelectOptionSchema - { - Color = Color.Red, - Name = "🍎Fruit" - }, - new SelectOptionSchema - { - Color = Color.Yellow, - Name = "💪Protein" - } - } - } - } - }, - { "Last ordered", new DatePropertySchema{ Date = new Dictionary() } } - }; + var database = await _client.CreateAsync(createDatabaseParameters); - var database = await _client.CreateAsync(createDatabaseParameters); + database.Parent.Type.Should().Be(ParentType.PageId); + database.Parent.Should().BeOfType(); + ((PageParent)database.Parent).PageId.Should().Be(pageId); - database.Parent.Type.Should().Be(ParentType.PageId); - database.Parent.Should().BeOfType(); - ((PageParent)database.Parent).PageId.Should().Be(pageId); + database.Properties.Should().HaveCount(4); - database.Properties.Should().HaveCount(4); + var selectOptions = (SelectProperty)database.Properties["Food group"]; + selectOptions.Name.Should().Be("Food group"); - var selectOptions = (SelectProperty)database.Properties["Food group"]; - selectOptions.Name.Should().Be("Food group"); - selectOptions.Select.Options.Should().SatisfyRespectively( - option => - { - option.Name.Should().Be("🥦Vegetable"); - option.Color.Should().Be(Color.Green); - }, - option => - { - option.Name.Should().Be("🍎Fruit"); - option.Color.Should().Be(Color.Red); - }, - option => - { - option.Name.Should().Be("💪Protein"); - option.Color.Should().Be(Color.Yellow); - } - ); - } + selectOptions.Select.Options.Should().SatisfyRespectively( + option => + { + option.Name.Should().Be("🥦Vegetable"); + option.Color.Should().Be(Color.Green); + }, + option => + { + option.Name.Should().Be("🍎Fruit"); + option.Color.Should().Be(Color.Red); + }, + option => + { + option.Name.Should().Be("💪Protein"); + option.Color.Should().Be(Color.Yellow); + } + ); + } - [Fact] - public async Task UpdateDatabaseAsync() - { - var databaseId = "1e9eee34-9c5c-4fe6-a4e1-8244eb141ed8"; - var path = ApiEndpoints.DatabasesApiUrls.Update(databaseId); - var jsonData = await File.ReadAllTextAsync("data/databases/UpdateDatabaseResponse.json"); + [Fact] + public async Task UpdateDatabaseAsync() + { + var databaseId = "1e9eee34-9c5c-4fe6-a4e1-8244eb141ed8"; + var path = ApiEndpoints.DatabasesApiUrls.Update(databaseId); + var jsonData = await File.ReadAllTextAsync("data/databases/UpdateDatabaseResponse.json"); - Server.Given(CreatePatchRequestBuilder(path)) - .RespondWith( + Server.Given(CreatePatchRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var updateDatabaseParameters = new DatabasesUpdateParameters(); + var updateDatabaseParameters = new DatabasesUpdateParameters(); + + updateDatabaseParameters.Title = new List + { + new RichTextTextInput {Text = new Text {Content = "Grocery List New", Link = null}}, + }; - updateDatabaseParameters.Title = new List + updateDatabaseParameters.Properties = new Dictionary + { + {"Name", new TitleUpdatePropertySchema {Title = new Dictionary()}}, + {"Price", new NumberUpdatePropertySchema {Number = new Number {Format = "yen"}}}, { - new RichTextTextInput + "Food group", + new SelectUpdatePropertySchema { - Text = new Text + Select = new OptionWrapper { - Content = "Grocery List New", - Link = null - } + Options = new List + { + new() {Color = Color.Green, Name = "🥦Vegetables"}, + new() {Color = Color.Red, Name = "🍎Fruit"}, + new() {Color = Color.Yellow, Name = "💪Protein"}, + }, + }, } - }; + }, + {"Last ordered", new DateUpdatePropertySchema {Date = new Dictionary()}}, + }; - updateDatabaseParameters.Properties = new Dictionary - { - { "Name", new TitleUpdatePropertySchema { Title = new Dictionary() } }, - { "Price", new NumberUpdatePropertySchema { Number = new Number { Format = "yen" } } }, - { "Food group", new SelectUpdatePropertySchema - { - Select = new OptionWrapper - { - Options = new List - { - new SelectOption - { - Color = Color.Green, - Name = "🥦Vegetables" - }, - new SelectOption - { - Color = Color.Red, - Name = "🍎Fruit" - }, - new SelectOption - { - Color = Color.Yellow, - Name = "💪Protein" - } - } - } - } - }, - { "Last ordered", new DateUpdatePropertySchema{ Date = new Dictionary() } } - }; + var database = await _client.UpdateAsync(databaseId, updateDatabaseParameters); - var database = await _client.UpdateAsync(databaseId, updateDatabaseParameters); + database.Parent.Type.Should().Be(ParentType.PageId); + database.Parent.Should().BeOfType(); + ((PageParent)database.Parent).PageId.Should().Be("533578e3-edf1-4c0a-91a9-da6b09bac3ee"); - database.Parent.Type.Should().Be(ParentType.PageId); - database.Parent.Should().BeOfType(); - ((PageParent)database.Parent).PageId.Should().Be("533578e3-edf1-4c0a-91a9-da6b09bac3ee"); + database.Properties.Should().HaveCount(4); - database.Properties.Should().HaveCount(4); + database.Title.Should().ContainSingle(); - database.Title.Should().ContainSingle(); - database.Title.Should().SatisfyRespectively( - title => - { - title.Should().BeAssignableTo(); - ((RichTextText)title).Text.Content.Should().Be("Grocery List New"); - } - ); + database.Title.Should().SatisfyRespectively( + title => + { + title.Should().BeAssignableTo(); + ((RichTextText)title).Text.Content.Should().Be("Grocery List New"); + } + ); - var selectOptions = (SelectProperty)database.Properties["Food group"]; - selectOptions.Name.Should().Be("Food group"); - selectOptions.Select.Options.Should().SatisfyRespectively( - option => - { - option.Name.Should().Be("🥦Vegetables"); - option.Color.Should().Be(Color.Green); - }, - option => - { - option.Name.Should().Be("🍎Fruit"); - option.Color.Should().Be(Color.Red); - }, - option => - { - option.Name.Should().Be("💪Protein"); - option.Color.Should().Be(Color.Yellow); - } - ); + var selectOptions = (SelectProperty)database.Properties["Food group"]; + selectOptions.Name.Should().Be("Food group"); - var price = (NumberProperty)database.Properties["Price"]; - price.Number.Format.Should().Be("yen"); - } + selectOptions.Select.Options.Should().SatisfyRespectively( + option => + { + option.Name.Should().Be("🥦Vegetables"); + option.Color.Should().Be(Color.Green); + }, + option => + { + option.Name.Should().Be("🍎Fruit"); + option.Color.Should().Be(Color.Red); + }, + option => + { + option.Name.Should().Be("💪Protein"); + option.Color.Should().Be(Color.Yellow); + } + ); - [Fact] - public async Task FormulaPropertyCanBeSetWhenCreatingDatabase() - { - var pageId = "98ad959b-2b6a-4774-80ee-00246fb0ea9b"; - var path = ApiEndpoints.DatabasesApiUrls.Create; - var jsonData = await File.ReadAllTextAsync("data/databases/FormulaPropertyCanBeSetWhenCreatingDatabaseResponse.json"); + var price = (NumberProperty)database.Properties["Price"]; + price.Number.Format.Should().Be("yen"); + } - Server.Given(CreatePostRequestBuilder(path)) - .RespondWith( + [Fact] + public async Task FormulaPropertyCanBeSetWhenCreatingDatabase() + { + var pageId = "98ad959b-2b6a-4774-80ee-00246fb0ea9b"; + var path = ApiEndpoints.DatabasesApiUrls.Create; + + var jsonData + = await File.ReadAllTextAsync("data/databases/FormulaPropertyCanBeSetWhenCreatingDatabaseResponse.json"); + + Server.Given(CreatePostRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var createDatabaseParameters = new DatabasesCreateParameters(); + var createDatabaseParameters = new DatabasesCreateParameters(); - createDatabaseParameters.Parent = new ParentPageInput - { - PageId = pageId - }; + createDatabaseParameters.Parent = new ParentPageInput {PageId = pageId}; - createDatabaseParameters.Title = new List + createDatabaseParameters.Title = new List + { + new RichTextTextInput {Text = new Text {Content = "Grocery List", Link = null}}, + }; + + createDatabaseParameters.Properties = new Dictionary + { { - new RichTextTextInput + "Cost of next trip", + new FormulaPropertySchema { - Text = new Text - { - Content = "Grocery List", - Link = null - } + Formula = new Formula {Expression = "if(prop(\"In stock\"), 0, prop(\"Price\"))"}, } - }; + }, + {"Price", new NumberPropertySchema {Number = new Number {Format = "dollar"}}}, + }; - createDatabaseParameters.Properties = new Dictionary - { - { "Cost of next trip", new FormulaPropertySchema { Formula = new Formula { Expression = "if(prop(\"In stock\"), 0, prop(\"Price\"))" } } }, - { "Price", new NumberPropertySchema { Number = new Number { Format = "dollar" } } } - }; + var database = await _client.CreateAsync(createDatabaseParameters); - var database = await _client.CreateAsync(createDatabaseParameters); + database.Parent.Type.Should().Be(ParentType.PageId); + database.Parent.Should().BeOfType(); + ((PageParent)database.Parent).PageId.Should().Be(pageId); - database.Parent.Type.Should().Be(ParentType.PageId); - database.Parent.Should().BeOfType(); - ((PageParent)database.Parent).PageId.Should().Be(pageId); + database.Properties.Should().HaveCount(2); - database.Properties.Should().HaveCount(2); + var formulaProperty = (FormulaProperty)database.Properties["Cost of next trip"]; + formulaProperty.Formula.Expression.Should().Be("if(prop(\"In stock\"), 0, prop(\"Price\"))"); + } - var formulaProperty = (FormulaProperty)database.Properties["Cost of next trip"]; - formulaProperty.Formula.Expression.Should().Be("if(prop(\"In stock\"), 0, prop(\"Price\"))"); - } + [Fact] + public async Task Fix123_QueryAsync_DateFormulaValue_Returns_Null() + { + var databaseId = "f86f2262-0751-40f2-8f63-e3f7a3c39fcb"; + var path = ApiEndpoints.DatabasesApiUrls.Query(databaseId); - [Fact] - public async Task Fix123_QueryAsync_DateFormulaValue_Returns_Null() - { - var databaseId = "f86f2262-0751-40f2-8f63-e3f7a3c39fcb"; - var path = ApiEndpoints.DatabasesApiUrls.Query(databaseId); - var jsonData = await File.ReadAllTextAsync("data/databases/Fix123QueryAsyncDateFormulaValueReturnsNullResponse.json"); + var jsonData + = await File.ReadAllTextAsync("data/databases/Fix123QueryAsyncDateFormulaValueReturnsNullResponse.json"); - Server.Given(CreatePostRequestBuilder(path)) - .RespondWith( + Server.Given(CreatePostRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var databasesQueryParams = new DatabasesQueryParameters + var databasesQueryParams = new DatabasesQueryParameters + { + Filter = new CompoundFilter { - Filter = new CompoundFilter + Or = new List { - Or = new List { - new CheckboxFilter( - "In stock", - true - ), - new NumberFilter( - "Cost of next trip", - greaterThanOrEqualTo: 2 - ) - }, + new CheckboxFilter( + "In stock", + true + ), + new NumberFilter( + "Cost of next trip", + greaterThanOrEqualTo: 2 + ), }, - Sorts = new List - { - new Sort - { - Property = "Last ordered", - Direction = Direction.Ascending - } - } - }; + }, + Sorts = new List {new() {Property = "Last ordered", Direction = Direction.Ascending}}, + }; - var pagesPaginatedList = await _client.QueryAsync(databaseId, databasesQueryParams); + var pagesPaginatedList = await _client.QueryAsync(databaseId, databasesQueryParams); - pagesPaginatedList.Results.Should().ContainSingle(); + pagesPaginatedList.Results.Should().ContainSingle(); - foreach (var page in pagesPaginatedList.Results) - { - page.Parent.Should().BeAssignableTo(); - page.Object.Should().Be(ObjectType.Page); + foreach (var page in pagesPaginatedList.Results) + { + page.Parent.Should().BeAssignableTo(); + page.Object.Should().Be(ObjectType.Page); - Server.Given(CreateGetRequestBuilder(ApiEndpoints.PagesApiUrls.RetrievePropertyItem(page.Id, page.Properties["FormulaProp"].Id))) + Server.Given(CreateGetRequestBuilder( + ApiEndpoints.PagesApiUrls.RetrievePropertyItem(page.Id, page.Properties["FormulaProp"].Id))) .RespondWith( Response.Create() - .WithStatusCode(200) - .WithBody("{\"object\":\"property_item\",\"id\":\"JwY^\",\"type\":\"formula\",\"formula\":{\"type\":\"date\",\"date\":{\"start\":\"2021-06-28\",\"end\":null}}}") + .WithStatusCode(200) + .WithBody( + "{\"object\":\"property_item\",\"id\":\"JwY^\",\"type\":\"formula\",\"formula\":{\"type\":\"date\",\"date\":{\"start\":\"2021-06-28\",\"end\":null}}}") ); - var formulaPropertyValue = (FormulaPropertyItem)await _pagesClient.RetrievePagePropertyItem(new RetrievePropertyItemParameters - { - PageId = page.Id, - PropertyId = page.Properties["FormulaProp"].Id - }); + var formulaPropertyValue = (FormulaPropertyItem)await _pagesClient.RetrievePagePropertyItem( + new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = page.Properties["FormulaProp"].Id}); - //var formulaPropertyValue = (FormulaPropertyValue)page.Properties["FormulaProp"]; - formulaPropertyValue.Formula.Date.Start.Should().Be(DateTime.Parse("2021-06-28")); - formulaPropertyValue.Formula.Date.End.Should().BeNull(); - } + //var formulaPropertyValue = (FormulaPropertyValue)page.Properties["FormulaProp"]; + formulaPropertyValue.Formula.Date.Start.Should().Be(DateTime.Parse("2021-06-28")); + formulaPropertyValue.Formula.Date.End.Should().BeNull(); } } } diff --git a/Test/Notion.UnitTests/FilterTests.cs b/Test/Notion.UnitTests/FilterTests.cs index 5b4650a5..b31a6530 100644 --- a/Test/Notion.UnitTests/FilterTests.cs +++ b/Test/Notion.UnitTests/FilterTests.cs @@ -4,131 +4,138 @@ using Notion.Client; using Xunit; -namespace Notion.UnitTests +namespace Notion.UnitTests; + +public class SerializerSettingsSource : RestClient +{ + public SerializerSettingsSource(ClientOptions options) : base(options) + { + } + + public JsonSerializerSettings GetSerializerSettings() + { + return defaultSerializerSettings; + } +} + +public class FilterTests { - public class SerializerSettingsSource : RestClient + private readonly SerializerSettingsSource _settingsSource = new(new ClientOptions()); + + private string SerializeFilter(Filter filter) + { + return JsonConvert.SerializeObject(filter, _settingsSource.GetSerializerSettings()); + } + + [Fact] + public void CompoundFilterTest() + { + var selectFilter = new SelectFilter("A select", "Option"); + var relationFilter = new RelationFilter("Link", "subtask#1"); + var dateFilter = new DateFilter("Due", pastMonth: new Dictionary()); + + var filterGroup = new List {relationFilter, selectFilter}; + + var complexFiler = new CompoundFilter( + and: new List {dateFilter, new CompoundFilter(filterGroup)} + ); + + Assert.Equal( + "{\"and\":[{\"date\":{\"past_month\":{}},\"property\":\"Due\"}," + + "{\"or\":[{\"relation\":{\"contains\":\"subtask#1\"},\"property\":\"Link\"}," + + "{\"select\":{\"equals\":\"Option\"},\"property\":\"A select\"}]}]}", + SerializeFilter(complexFiler) + ); + } + + [Fact] + public void CheckboxFilterTest() + { + var filter = new CheckboxFilter("Property name", false); + + Assert.Equal( + "{\"checkbox\":{\"equals\":false},\"property\":\"Property name\"}", + SerializeFilter(filter) + ); + } + + [Fact] + public void DateFilterTest() { - public SerializerSettingsSource(ClientOptions options) : base(options) - { + var filter = new DateFilter("When", onOrAfter: new DateTime(2042, 11, 29)); - } + Assert.Equal( + "{\"date\":{\"on_or_after\":\"2042-11-29T00:00:00\"},\"property\":\"When\"}", + SerializeFilter(filter) + ); + } + + [Fact] + public void FilesFilterTest() + { + var filter = new FilesFilter("Attachments", isNotEmpty: false); + + Assert.Equal( + "{\"files\":{\"is_not_empty\":false},\"property\":\"Attachments\"}", + SerializeFilter(filter) + ); + } - public JsonSerializerSettings GetSerializerSettings() - { - return defaultSerializerSettings; - } + [Fact] + public void FormulaFilterTest() + { + var filter = new FormulaFilter( + "Some", + number: new NumberFilter.Condition(isEmpty: true) + ); + + Assert.Equal( + "{\"formula\":{\"number\":{\"is_empty\":true}},\"property\":\"Some\"}", + SerializeFilter(filter) + ); + } + [Fact] + public void MultiSelectFilterTest() + { + var filter = new MultiSelectFilter("category 1", doesNotContain: "tag"); + + Assert.Equal( + "{\"multi_select\":{\"does_not_contain\":\"tag\"},\"property\":\"category 1\"}", + SerializeFilter(filter) + ); } - public class FilterTests + + [Fact(Skip = "Not sure if integer should be serialized as a number with decimals")] + public void NumberFilterTest() { - private readonly SerializerSettingsSource _settingsSource = new SerializerSettingsSource(new ClientOptions()); - - private string SerializeFilter(Filter filter) - { - return JsonConvert.SerializeObject(filter, _settingsSource.GetSerializerSettings()); - } - - [Fact] - public void CompoundFilterTest() - { - var selectFilter = new SelectFilter("A select", equal: "Option"); - var relationFilter = new RelationFilter("Link", contains: "subtask#1"); - var dateFilter = new DateFilter("Due", pastMonth: new Dictionary()); - - var filterGroup = new List { relationFilter, selectFilter }; - var complexFiler = new CompoundFilter( - and: new List { dateFilter, new CompoundFilter(or: filterGroup) } - ); - - Assert.Equal( - "{\"and\":[{\"date\":{\"past_month\":{}},\"property\":\"Due\"}," - + "{\"or\":[{\"relation\":{\"contains\":\"subtask#1\"},\"property\":\"Link\"}," + - "{\"select\":{\"equals\":\"Option\"},\"property\":\"A select\"}]}]}", - SerializeFilter(complexFiler) - ); - } - - [Fact] - public void CheckboxFilterTest() - { - var filter = new CheckboxFilter("Property name", equal: false); - Assert.Equal( - "{\"checkbox\":{\"equals\":false},\"property\":\"Property name\"}", - SerializeFilter(filter) - ); - } - - [Fact] - public void DateFilterTest() - { - var filter = new DateFilter("When", onOrAfter: new DateTime(2042, 11, 29)); - Assert.Equal( - "{\"date\":{\"on_or_after\":\"2042-11-29T00:00:00\"},\"property\":\"When\"}", - SerializeFilter(filter) - ); - } - - [Fact] - public void FilesFilterTest() - { - var filter = new FilesFilter("Attachments", isNotEmpty: false); - Assert.Equal( - "{\"files\":{\"is_not_empty\":false},\"property\":\"Attachments\"}", - SerializeFilter(filter) - ); - } - - [Fact] - public void FormulaFilterTest() - { - var filter = new FormulaFilter( - "Some", - number: new NumberFilter.Condition(isEmpty: true) - ); - Assert.Equal( - "{\"formula\":{\"number\":{\"is_empty\":true}},\"property\":\"Some\"}", - SerializeFilter(filter) - ); - } - - [Fact] - public void MultiSelectFilterTest() - { - var filter = new MultiSelectFilter("category 1", doesNotContain: "tag"); - Assert.Equal( - "{\"multi_select\":{\"does_not_contain\":\"tag\"},\"property\":\"category 1\"}", - SerializeFilter(filter) - ); - } - - [Fact(Skip = "Not sure if integer should be serialized as a number with decimals")] - public void NumberFilterTest() - { - var filter = new NumberFilter("sum", greaterThanOrEqualTo: -54); - Assert.Equal( - "{\"number\":{\"greater_than_or_equal_to\":-54.0},\"property\":\"sum\"}", - SerializeFilter(filter) - ); - } - - [Fact] - public void PeopleFilter() - { - var filter = new PeopleFilter("assignee PM", doesNotContain: "some-uuid"); - Assert.Equal( - "{\"people\":{\"does_not_contain\":\"some-uuid\"},\"property\":\"assignee PM\"}", - SerializeFilter(filter) - ); - } - - [Fact] - public void RichTextFilterTest() - { - var filter = new RichTextFilter("Some property", doesNotEqual: "Example text"); - Assert.Equal( - "{\"rich_text\":{\"does_not_equal\":\"Example text\"},\"property\":\"Some property\"}", - SerializeFilter(filter) - ); - } + var filter = new NumberFilter("sum", greaterThanOrEqualTo: -54); + + Assert.Equal( + "{\"number\":{\"greater_than_or_equal_to\":-54.0},\"property\":\"sum\"}", + SerializeFilter(filter) + ); + } + + [Fact] + public void PeopleFilter() + { + var filter = new PeopleFilter("assignee PM", doesNotContain: "some-uuid"); + + Assert.Equal( + "{\"people\":{\"does_not_contain\":\"some-uuid\"},\"property\":\"assignee PM\"}", + SerializeFilter(filter) + ); + } + + [Fact] + public void RichTextFilterTest() + { + var filter = new RichTextFilter("Some property", doesNotEqual: "Example text"); + + Assert.Equal( + "{\"rich_text\":{\"does_not_equal\":\"Example text\"},\"property\":\"Some property\"}", + SerializeFilter(filter) + ); } -} +} diff --git a/Test/Notion.UnitTests/HelperAsserts.cs b/Test/Notion.UnitTests/HelperAsserts.cs index 1b07fbf5..3b1a29ec 100644 --- a/Test/Notion.UnitTests/HelperAsserts.cs +++ b/Test/Notion.UnitTests/HelperAsserts.cs @@ -1,41 +1,44 @@ using FluentAssertions; using Notion.Client; -namespace Notion.UnitTests +namespace Notion.UnitTests; + +public static class HelperAsserts { - public static class HelperAsserts + public static void IPageIconAsserts(IPageIcon icon) { - public static void IPageIconAsserts(IPageIcon icon) + icon.Should().NotBeNull(); + + switch (icon) { - icon.Should().NotBeNull(); - - switch (icon) - { - case EmojiObject emoji: - emoji.Emoji.Should().NotBeNull(); - break; - case FileObject fileObject: - FileObjectAsserts(fileObject); - break; - } + case EmojiObject emoji: + emoji.Emoji.Should().NotBeNull(); + + break; + case FileObject fileObject: + FileObjectAsserts(fileObject); + + break; } + } - public static void FileObjectAsserts(FileObject fileObject) + public static void FileObjectAsserts(FileObject fileObject) + { + fileObject.Should().NotBeNull(); + + switch (fileObject) { - fileObject.Should().NotBeNull(); - - switch (fileObject) - { - case UploadedFile uploadedFile: - uploadedFile.File.Should().NotBeNull(); - uploadedFile.File.Url.Should().NotBeNull(); - uploadedFile.File.ExpiryTime.Should().NotBeSameDateAs(default); - break; - case ExternalFile externalFile: - externalFile.External.Should().NotBeNull(); - externalFile.External.Url.Should().NotBeNull(); - break; - } + case UploadedFile uploadedFile: + uploadedFile.File.Should().NotBeNull(); + uploadedFile.File.Url.Should().NotBeNull(); + uploadedFile.File.ExpiryTime.Should().NotBeSameDateAs(default); + + break; + case ExternalFile externalFile: + externalFile.External.Should().NotBeNull(); + externalFile.External.Url.Should().NotBeNull(); + + break; } } } diff --git a/Test/Notion.UnitTests/PagesClientTests.cs b/Test/Notion.UnitTests/PagesClientTests.cs index 13598b0f..3f6710a5 100644 --- a/Test/Notion.UnitTests/PagesClientTests.cs +++ b/Test/Notion.UnitTests/PagesClientTests.cs @@ -8,264 +8,246 @@ using WireMock.ResponseBuilders; using Xunit; -namespace Notion.UnitTests +namespace Notion.UnitTests; + +public class PagesClientTests : ApiTestBase { - public class PagesClientTests : ApiTestBase - { - private readonly IPagesClient _client; + private readonly IPagesClient _client; - public PagesClientTests() - { - _client = new PagesClient(new RestClient(ClientOptions)); - } + public PagesClientTests() + { + _client = new PagesClient(new RestClient(ClientOptions)); + } - [Fact] - public async Task RetrieveAsync() - { - var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; - var path = ApiEndpoints.PagesApiUrls.Retrieve(pageId); - var jsonData = await File.ReadAllTextAsync("data/pages/PageObjectShouldHaveUrlPropertyResponse.json"); + [Fact] + public async Task RetrieveAsync() + { + var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; + var path = ApiEndpoints.PagesApiUrls.Retrieve(pageId); + var jsonData = await File.ReadAllTextAsync("data/pages/PageObjectShouldHaveUrlPropertyResponse.json"); - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var page = await _client.RetrieveAsync(pageId); + var page = await _client.RetrieveAsync(pageId); - page.Url.Should().Be("https://www.notion.so/Avocado-251d2b5f268c4de2afe9c71ff92ca95c"); - page.Id.Should().Be(pageId); - page.Parent.Type.Should().Be(ParentType.DatabaseId); - ((DatabaseParent)page.Parent).DatabaseId.Should().Be("48f8fee9-cd79-4180-bc2f-ec0398253067"); - page.IsArchived.Should().BeFalse(); - } + page.Url.Should().Be("https://www.notion.so/Avocado-251d2b5f268c4de2afe9c71ff92ca95c"); + page.Id.Should().Be(pageId); + page.Parent.Type.Should().Be(ParentType.DatabaseId); + ((DatabaseParent)page.Parent).DatabaseId.Should().Be("48f8fee9-cd79-4180-bc2f-ec0398253067"); + page.IsArchived.Should().BeFalse(); + } - [Fact] - public async Task CreateAsync() - { - var path = ApiEndpoints.PagesApiUrls.Create(); + [Fact] + public async Task CreateAsync() + { + var path = ApiEndpoints.PagesApiUrls.Create(); - var jsonData = await File.ReadAllTextAsync("data/pages/CreatePageResponse.json"); + var jsonData = await File.ReadAllTextAsync("data/pages/CreatePageResponse.json"); - Server.Given(CreatePostRequestBuilder(path)) - .RespondWith( - Response.Create() + Server.Given(CreatePostRequestBuilder(path)) + .RespondWith( + Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput - { - DatabaseId = "3c357473-a281-49a4-88c0-10d2b245a589" - }).AddProperty("Name", new TitlePropertyValue() - { - Title = new List() + var pagesCreateParameters = PagesCreateParametersBuilder + .Create(new DatabaseParentInput {DatabaseId = "3c357473-a281-49a4-88c0-10d2b245a589"}).AddProperty("Name", + new TitlePropertyValue { - new RichTextText() - { - Text = new Text - { - Content = "Test" - } - } - } - }).Build(); - - var page = await _client.CreateAsync(pagesCreateParameters); - - page.Id.Should().NotBeNullOrEmpty(); - page.Url.Should().NotBeNullOrEmpty(); - page.Properties.Should().HaveCount(1); - page.Properties.First().Key.Should().Be("Name"); - page.IsArchived.Should().BeFalse(); - page.Parent.Should().NotBeNull(); - ((DatabaseParent)page.Parent).DatabaseId.Should().Be("3c357473-a281-49a4-88c0-10d2b245a589"); - } - - [Fact] - public async Task UpdatePropertiesAsync() - { - var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; - var propertyId = "{>U;"; - var path = ApiEndpoints.PagesApiUrls.UpdateProperties(pageId); + Title = new List {new RichTextText {Text = new Text {Content = "Test"}}}, + }).Build(); + + var page = await _client.CreateAsync(pagesCreateParameters); + + page.Id.Should().NotBeNullOrEmpty(); + page.Url.Should().NotBeNullOrEmpty(); + page.Properties.Should().HaveCount(1); + page.Properties.First().Key.Should().Be("Name"); + page.IsArchived.Should().BeFalse(); + page.Parent.Should().NotBeNull(); + ((DatabaseParent)page.Parent).DatabaseId.Should().Be("3c357473-a281-49a4-88c0-10d2b245a589"); + } - var jsonData = await File.ReadAllTextAsync("data/pages/UpdatePagePropertiesResponse.json"); + [Fact] + public async Task UpdatePropertiesAsync() + { + var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; + var propertyId = "{>U;"; + var path = ApiEndpoints.PagesApiUrls.UpdateProperties(pageId); + + var jsonData = await File.ReadAllTextAsync("data/pages/UpdatePagePropertiesResponse.json"); - Server.Given(CreatePatchRequestBuilder(path)) - .RespondWith( - Response.Create() + Server.Given(CreatePatchRequestBuilder(path)) + .RespondWith( + Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - Server.Given(CreateGetRequestBuilder(ApiEndpoints.PagesApiUrls.RetrievePropertyItem(pageId, propertyId))) - .RespondWith( - Response.Create().WithStatusCode(200).WithBody("{\"object\":\"property_item\",\"id\":\"{>U;\",\"type\":\"checkbox\",\"checkbox\":true}")); + Server.Given(CreateGetRequestBuilder(ApiEndpoints.PagesApiUrls.RetrievePropertyItem(pageId, propertyId))) + .RespondWith( + Response.Create().WithStatusCode(200) + .WithBody( + "{\"object\":\"property_item\",\"id\":\"{>U;\",\"type\":\"checkbox\",\"checkbox\":true}")); - var updatedProperties = new Dictionary() - { - { "In stock", new CheckboxPropertyValue() { Checkbox = true } } - }; + var updatedProperties = new Dictionary + { + {"In stock", new CheckboxPropertyValue {Checkbox = true}}, + }; - var page = await _client.UpdatePropertiesAsync(pageId, updatedProperties); + var page = await _client.UpdatePropertiesAsync(pageId, updatedProperties); - page.Id.Should().Be(pageId); - page.Properties.Should().HaveCount(2); - var updatedProperty = page.Properties.First(x => x.Key == "In stock"); + page.Id.Should().Be(pageId); + page.Properties.Should().HaveCount(2); + var updatedProperty = page.Properties.First(x => x.Key == "In stock"); - var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItem(new RetrievePropertyItemParameters - { - PageId = page.Id, - PropertyId = updatedProperty.Value.Id - }); + var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItem( + new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = updatedProperty.Value.Id}); - checkboxPropertyValue.Checkbox.Should().BeTrue(); - } + checkboxPropertyValue.Checkbox.Should().BeTrue(); + } - [Fact] - public async Task PageObjectShouldHaveUrlProperty() - { - var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; - var path = ApiEndpoints.PagesApiUrls.Retrieve(pageId); - var jsonData = await File.ReadAllTextAsync("data/pages/PageObjectShouldHaveUrlPropertyResponse.json"); + [Fact] + public async Task PageObjectShouldHaveUrlProperty() + { + var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; + var path = ApiEndpoints.PagesApiUrls.Retrieve(pageId); + var jsonData = await File.ReadAllTextAsync("data/pages/PageObjectShouldHaveUrlPropertyResponse.json"); - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var page = await _client.RetrieveAsync(pageId); + var page = await _client.RetrieveAsync(pageId); - page.Url.Should().Be("https://www.notion.so/Avocado-251d2b5f268c4de2afe9c71ff92ca95c"); - } + page.Url.Should().Be("https://www.notion.so/Avocado-251d2b5f268c4de2afe9c71ff92ca95c"); + } - [Fact] - public async Task UpdatePageAsync() - { - var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; - var propertyId = "{>U;"; - var path = ApiEndpoints.PagesApiUrls.UpdateProperties(pageId); + [Fact] + public async Task UpdatePageAsync() + { + var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; + var propertyId = "{>U;"; + var path = ApiEndpoints.PagesApiUrls.UpdateProperties(pageId); - var jsonData = await File.ReadAllTextAsync("data/pages/UpdatePagePropertiesResponse.json"); + var jsonData = await File.ReadAllTextAsync("data/pages/UpdatePagePropertiesResponse.json"); - Server.Given(CreatePatchRequestBuilder(path)) - .RespondWith( - Response.Create() + Server.Given(CreatePatchRequestBuilder(path)) + .RespondWith( + Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - Server.Given(CreateGetRequestBuilder(ApiEndpoints.PagesApiUrls.RetrievePropertyItem(pageId, propertyId))) - .RespondWith( - Response.Create().WithStatusCode(200).WithBody("{\"object\":\"property_item\",\"id\":\"{>U;\",\"type\":\"checkbox\",\"checkbox\":true}")); + Server.Given(CreateGetRequestBuilder(ApiEndpoints.PagesApiUrls.RetrievePropertyItem(pageId, propertyId))) + .RespondWith( + Response.Create().WithStatusCode(200) + .WithBody( + "{\"object\":\"property_item\",\"id\":\"{>U;\",\"type\":\"checkbox\",\"checkbox\":true}")); - var pagesUpdateParameters = new PagesUpdateParameters + var pagesUpdateParameters = new PagesUpdateParameters + { + Properties = new Dictionary { - Properties = new Dictionary() - { - { "In stock", new CheckboxPropertyValue() { Checkbox = true } } - } - }; + {"In stock", new CheckboxPropertyValue {Checkbox = true}}, + }, + }; - var page = await _client.UpdateAsync(pageId, pagesUpdateParameters); + var page = await _client.UpdateAsync(pageId, pagesUpdateParameters); - page.Id.Should().Be(pageId); - page.IsArchived.Should().BeFalse(); - page.Properties.Should().HaveCount(2); - var updatedProperty = page.Properties.First(x => x.Key == "In stock"); + page.Id.Should().Be(pageId); + page.IsArchived.Should().BeFalse(); + page.Properties.Should().HaveCount(2); + var updatedProperty = page.Properties.First(x => x.Key == "In stock"); - var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItem(new RetrievePropertyItemParameters - { - PageId = page.Id, - PropertyId = updatedProperty.Value.Id - }); + var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItem( + new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = updatedProperty.Value.Id}); - checkboxPropertyValue.Checkbox.Should().BeTrue(); - } + checkboxPropertyValue.Checkbox.Should().BeTrue(); + } - [Fact] - public async Task ArchivePageAsync() - { - var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; - var propertyId = "{>U;"; + [Fact] + public async Task ArchivePageAsync() + { + var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; + var propertyId = "{>U;"; - var path = ApiEndpoints.PagesApiUrls.UpdateProperties(pageId); + var path = ApiEndpoints.PagesApiUrls.UpdateProperties(pageId); - var jsonData = await File.ReadAllTextAsync("data/pages/ArchivePageResponse.json"); + var jsonData = await File.ReadAllTextAsync("data/pages/ArchivePageResponse.json"); - Server.Given(CreatePatchRequestBuilder(path)) - .RespondWith( - Response.Create() + Server.Given(CreatePatchRequestBuilder(path)) + .RespondWith( + Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - Server.Given(CreateGetRequestBuilder(ApiEndpoints.PagesApiUrls.RetrievePropertyItem(pageId, propertyId))) - .RespondWith( - Response.Create().WithStatusCode(200).WithBody("{\"object\":\"property_item\",\"id\":\"{>U;\",\"type\":\"checkbox\",\"checkbox\":true}")); + Server.Given(CreateGetRequestBuilder(ApiEndpoints.PagesApiUrls.RetrievePropertyItem(pageId, propertyId))) + .RespondWith( + Response.Create().WithStatusCode(200) + .WithBody( + "{\"object\":\"property_item\",\"id\":\"{>U;\",\"type\":\"checkbox\",\"checkbox\":true}")); - var pagesUpdateParameters = new PagesUpdateParameters + var pagesUpdateParameters = new PagesUpdateParameters + { + Archived = true, + Properties = new Dictionary { - Archived = true, - Properties = new Dictionary() - { - { "In stock", new CheckboxPropertyValue() { Checkbox = true } } - } - }; + {"In stock", new CheckboxPropertyValue {Checkbox = true}}, + }, + }; - var page = await _client.UpdateAsync(pageId, pagesUpdateParameters); + var page = await _client.UpdateAsync(pageId, pagesUpdateParameters); - page.Id.Should().Be(pageId); - page.IsArchived.Should().BeTrue(); - page.Properties.Should().HaveCount(2); - var updatedProperty = page.Properties.First(x => x.Key == "In stock"); + page.Id.Should().Be(pageId); + page.IsArchived.Should().BeTrue(); + page.Properties.Should().HaveCount(2); + var updatedProperty = page.Properties.First(x => x.Key == "In stock"); - var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItem(new RetrievePropertyItemParameters - { - PageId = page.Id, - PropertyId = updatedProperty.Value.Id - }); + var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItem( + new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = updatedProperty.Value.Id}); - checkboxPropertyValue.Checkbox.Should().BeTrue(); - } + checkboxPropertyValue.Checkbox.Should().BeTrue(); + } - [Fact] - public async Task CreateAsync_Throws_ArgumentNullException_When_Parameter_Is_Null() - { - Func act = async () => await _client.CreateAsync(null); + [Fact] + public async Task CreateAsync_Throws_ArgumentNullException_When_Parameter_Is_Null() + { + Func act = async () => await _client.CreateAsync(null); - (await act.Should().ThrowAsync()).And.ParamName.Should().Be("pagesCreateParameters"); - } + (await act.Should().ThrowAsync()).And.ParamName.Should().Be("pagesCreateParameters"); + } - [Fact] - public async Task CreateAsync_Throws_ArgumentNullException_When_Parent_Is_Missing() - { - var pagesCreateParameters = PagesCreateParametersBuilder.Create(null).Build(); + [Fact] + public async Task CreateAsync_Throws_ArgumentNullException_When_Parent_Is_Missing() + { + var pagesCreateParameters = PagesCreateParametersBuilder.Create(null).Build(); - Func act = async () => await _client.CreateAsync(pagesCreateParameters); + Func act = async () => await _client.CreateAsync(pagesCreateParameters); - (await act.Should().ThrowAsync()).And.ParamName.Should().Be("Parent"); - } + (await act.Should().ThrowAsync()).And.ParamName.Should().Be("Parent"); + } - [Fact] - public async Task CreateAsync_Throws_ArgumentNullException_When_Properties_Is_Missing() + [Fact] + public async Task CreateAsync_Throws_ArgumentNullException_When_Properties_Is_Missing() + { + var pagesCreateParameters = new PagesCreateParameters { - var pagesCreateParameters = new PagesCreateParameters - { - Parent = new ParentPageInput() - { - PageId = "3c357473-a281-49a4-88c0-10d2b245a589", - }, - Properties = null - }; + Parent = new ParentPageInput {PageId = "3c357473-a281-49a4-88c0-10d2b245a589"}, Properties = null, + }; - Func act = async () => await _client.CreateAsync(pagesCreateParameters); + Func act = async () => await _client.CreateAsync(pagesCreateParameters); - (await act.Should().ThrowAsync()).And.ParamName.Should().Be("Properties"); - } + (await act.Should().ThrowAsync()).And.ParamName.Should().Be("Properties"); } } diff --git a/Test/Notion.UnitTests/PropertyTests.cs b/Test/Notion.UnitTests/PropertyTests.cs index d09e4a87..c8196f15 100644 --- a/Test/Notion.UnitTests/PropertyTests.cs +++ b/Test/Notion.UnitTests/PropertyTests.cs @@ -1,67 +1,65 @@ using System; -using FluentAssertions; using Notion.Client; using Notion.Client.Extensions; using Xunit; -namespace Notion.UnitTests +namespace Notion.UnitTests; + +public class PropertyTests { - public class PropertyTests + [Theory] + [InlineData(typeof(CheckboxProperty), PropertyType.Checkbox)] + [InlineData(typeof(CreatedByProperty), PropertyType.CreatedBy)] + [InlineData(typeof(CreatedTimeProperty), PropertyType.CreatedTime)] + [InlineData(typeof(DateProperty), PropertyType.Date)] + [InlineData(typeof(EmailProperty), PropertyType.Email)] + [InlineData(typeof(FilesProperty), PropertyType.Files)] + [InlineData(typeof(FormulaProperty), PropertyType.Formula)] + [InlineData(typeof(LastEditedByProperty), PropertyType.LastEditedBy)] + [InlineData(typeof(LastEditedTimeProperty), PropertyType.LastEditedTime)] + [InlineData(typeof(NumberProperty), PropertyType.Number)] + [InlineData(typeof(PeopleProperty), PropertyType.People)] + [InlineData(typeof(PhoneNumberProperty), PropertyType.PhoneNumber)] + [InlineData(typeof(RelationProperty), PropertyType.Relation)] + [InlineData(typeof(RichTextProperty), PropertyType.RichText)] + [InlineData(typeof(RollupProperty), PropertyType.Rollup)] + [InlineData(typeof(SelectProperty), PropertyType.Select)] + [InlineData(typeof(TitleProperty), PropertyType.Title)] + [InlineData(typeof(UrlProperty), PropertyType.Url)] + public void TestPropertyType(Type type, PropertyType expectedPropertyType) { - [Theory] - [InlineData(typeof(CheckboxProperty), PropertyType.Checkbox)] - [InlineData(typeof(CreatedByProperty), PropertyType.CreatedBy)] - [InlineData(typeof(CreatedTimeProperty), PropertyType.CreatedTime)] - [InlineData(typeof(DateProperty), PropertyType.Date)] - [InlineData(typeof(EmailProperty), PropertyType.Email)] - [InlineData(typeof(FilesProperty), PropertyType.Files)] - [InlineData(typeof(FormulaProperty), PropertyType.Formula)] - [InlineData(typeof(LastEditedByProperty), PropertyType.LastEditedBy)] - [InlineData(typeof(LastEditedTimeProperty), PropertyType.LastEditedTime)] - [InlineData(typeof(NumberProperty), PropertyType.Number)] - [InlineData(typeof(PeopleProperty), PropertyType.People)] - [InlineData(typeof(PhoneNumberProperty), PropertyType.PhoneNumber)] - [InlineData(typeof(RelationProperty), PropertyType.Relation)] - [InlineData(typeof(RichTextProperty), PropertyType.RichText)] - [InlineData(typeof(RollupProperty), PropertyType.Rollup)] - [InlineData(typeof(SelectProperty), PropertyType.Select)] - [InlineData(typeof(TitleProperty), PropertyType.Title)] - [InlineData(typeof(UrlProperty), PropertyType.Url)] - public void TestPropertyType(Type type, PropertyType expectedPropertyType) - { - var typeInstance = (Property)Activator.CreateInstance(type); + var typeInstance = (Property)Activator.CreateInstance(type); - var actualPropertyType = typeInstance.Type; + var actualPropertyType = typeInstance.Type; - Assert.Equal(expectedPropertyType, actualPropertyType); - } + Assert.Equal(expectedPropertyType, actualPropertyType); + } - [Theory] - [InlineData(typeof(CheckboxProperty), "checkbox")] - [InlineData(typeof(CreatedByProperty), "created_by")] - [InlineData(typeof(CreatedTimeProperty), "created_time")] - [InlineData(typeof(DateProperty), "date")] - [InlineData(typeof(EmailProperty), "email")] - [InlineData(typeof(FilesProperty), "files")] - [InlineData(typeof(FormulaProperty), "formula")] - [InlineData(typeof(LastEditedByProperty), "last_edited_by")] - [InlineData(typeof(LastEditedTimeProperty), "last_edited_time")] - [InlineData(typeof(NumberProperty), "number")] - [InlineData(typeof(PeopleProperty), "people")] - [InlineData(typeof(PhoneNumberProperty), "phone_number")] - [InlineData(typeof(RelationProperty), "relation")] - [InlineData(typeof(RichTextProperty), "rich_text")] - [InlineData(typeof(RollupProperty), "rollup")] - [InlineData(typeof(SelectProperty), "select")] - [InlineData(typeof(TitleProperty), "title")] - [InlineData(typeof(UrlProperty), "url")] - public void TestPropertyTypeText(Type type, string expectedPropertyType) - { - var typeInstance = (Property)Activator.CreateInstance(type); + [Theory] + [InlineData(typeof(CheckboxProperty), "checkbox")] + [InlineData(typeof(CreatedByProperty), "created_by")] + [InlineData(typeof(CreatedTimeProperty), "created_time")] + [InlineData(typeof(DateProperty), "date")] + [InlineData(typeof(EmailProperty), "email")] + [InlineData(typeof(FilesProperty), "files")] + [InlineData(typeof(FormulaProperty), "formula")] + [InlineData(typeof(LastEditedByProperty), "last_edited_by")] + [InlineData(typeof(LastEditedTimeProperty), "last_edited_time")] + [InlineData(typeof(NumberProperty), "number")] + [InlineData(typeof(PeopleProperty), "people")] + [InlineData(typeof(PhoneNumberProperty), "phone_number")] + [InlineData(typeof(RelationProperty), "relation")] + [InlineData(typeof(RichTextProperty), "rich_text")] + [InlineData(typeof(RollupProperty), "rollup")] + [InlineData(typeof(SelectProperty), "select")] + [InlineData(typeof(TitleProperty), "title")] + [InlineData(typeof(UrlProperty), "url")] + public void TestPropertyTypeText(Type type, string expectedPropertyType) + { + var typeInstance = (Property)Activator.CreateInstance(type); - var actualPropertyType = typeInstance.Type.GetEnumMemberValue(); + var actualPropertyType = typeInstance.Type.GetEnumMemberValue(); - Assert.Equal(expectedPropertyType, actualPropertyType); - } + Assert.Equal(expectedPropertyType, actualPropertyType); } } diff --git a/Test/Notion.UnitTests/SearchClientTest.cs b/Test/Notion.UnitTests/SearchClientTest.cs index aa506572..3ca7dd27 100644 --- a/Test/Notion.UnitTests/SearchClientTest.cs +++ b/Test/Notion.UnitTests/SearchClientTest.cs @@ -1,71 +1,65 @@ -using System; -using System.IO; +using System.IO; using System.Threading.Tasks; using FluentAssertions; using Notion.Client; using WireMock.ResponseBuilders; using Xunit; -namespace Notion.UnitTests +namespace Notion.UnitTests; + +public class SearchClientTest : ApiTestBase { - public class SearchClientTest : ApiTestBase - { - private readonly SearchClient _client; + private readonly SearchClient _client; - public SearchClientTest() - { - _client = new SearchClient(new RestClient(ClientOptions)); - } + public SearchClientTest() + { + _client = new SearchClient(new RestClient(ClientOptions)); + } - [Fact] - public async Task Search() - { - // Arrange - var path = ApiEndpoints.SearchApiUrls.Search(); - var jsonData = await File.ReadAllTextAsync("data/search/SearchResponse.json"); + [Fact] + public async Task Search() + { + // Arrange + var path = ApiEndpoints.SearchApiUrls.Search(); + var jsonData = await File.ReadAllTextAsync("data/search/SearchResponse.json"); - Server.Given(CreatePostRequestBuilder(path)) - .RespondWith( + Server.Given(CreatePostRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - SearchParameters searchParameters = new SearchParameters() - { - Query = "External tasks", - Sort = new SearchSort - { - Direction = SearchDirection.Ascending, - Timestamp = "last_edited_time" - } - }; + var searchParameters = new SearchParameters + { + Query = "External tasks", + Sort = new SearchSort {Direction = SearchDirection.Ascending, Timestamp = "last_edited_time"}, + }; - // Act - var searchResult = await _client.SearchAsync(searchParameters); + // Act + var searchResult = await _client.SearchAsync(searchParameters); - // Assert - var results = searchResult.Results; + // Assert + var results = searchResult.Results; - results.Should().SatisfyRespectively( - obj => - { - obj.Object.Should().Be(ObjectType.Database); + results.Should().SatisfyRespectively( + obj => + { + obj.Object.Should().Be(ObjectType.Database); - var database = (Database)obj; - database.Properties.Should().HaveCount(2); - }, - obj => - { - obj.Object.Should().Be(ObjectType.Page); + var database = (Database)obj; + database.Properties.Should().HaveCount(2); + }, + obj => + { + obj.Object.Should().Be(ObjectType.Page); - var page = (Page)obj; - page.IsArchived.Should().BeFalse(); - page.Properties.Should().HaveCount(1); - page.Parent.Should().BeAssignableTo(); - ((DatabaseParent)page.Parent).DatabaseId.Should().Be("e6c6f8ff-c70e-4970-91ba-98f03e0d7fc6"); - } - ); - } + var page = (Page)obj; + page.IsArchived.Should().BeFalse(); + page.Properties.Should().HaveCount(1); + page.Parent.Should().BeAssignableTo(); + ((DatabaseParent)page.Parent).DatabaseId.Should().Be("e6c6f8ff-c70e-4970-91ba-98f03e0d7fc6"); + } + ); } } diff --git a/Test/Notion.UnitTests/UserClientTest.cs b/Test/Notion.UnitTests/UserClientTest.cs index d9b27984..6e93decc 100644 --- a/Test/Notion.UnitTests/UserClientTest.cs +++ b/Test/Notion.UnitTests/UserClientTest.cs @@ -5,145 +5,144 @@ using WireMock.ResponseBuilders; using Xunit; -namespace Notion.UnitTests +namespace Notion.UnitTests; + +public class UserClientTest : ApiTestBase { - public class UserClientTest : ApiTestBase + private readonly IUsersClient _client; + + public UserClientTest() + { + _client = new UsersClient(new RestClient(ClientOptions)); + } + + [Fact] + public async Task ListUsers() + { + // Arrange + var jsonData = await File.ReadAllTextAsync("data/users/ListUsersResponse.json"); + var path = ApiEndpoints.UsersApiUrls.List(); + + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( + Response.Create() + .WithStatusCode(200) + .WithBody(jsonData) + ); + + // Act + var users = await _client.ListAsync(); + + // Assert + users.Results.Should().SatisfyRespectively( + user => + { + user.Id.Should().Be("5e37c1b4-630f-4e81-bd6b-296af31e345f"); + user.Name.Should().Be("Vedant Koditkar"); + user.Type.Should().Be("person"); + user.Person.Email.Should().Be("vedkoditkar@gmail.com"); + user.Bot.Should().BeNull(); + }, + user => + { + user.Id.Should().Be("590693f3-797f-4970-98ff-7284106393e5"); + user.Name.Should().Be("Test"); + user.Type.Should().Be("bot"); + user.Person.Should().BeNull(); + } + ); + } + + [Fact] + public async Task RetrieveUser() { - private readonly IUsersClient _client; - - public UserClientTest() - { - _client = new UsersClient(new RestClient(ClientOptions)); - } - - [Fact] - public async Task ListUsers() - { - // Arrange - var jsonData = await File.ReadAllTextAsync("data/users/ListUsersResponse.json"); - var path = ApiEndpoints.UsersApiUrls.List(); - - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( + // Arrange + var jsonData = await File.ReadAllTextAsync("data/users/RetrieveUserResponse.json"); + var userId = "5e37c1b4-630f-4e81-bd6b-296af31e345f"; + var path = ApiEndpoints.UsersApiUrls.Retrieve(userId); + + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - // Act - var users = await _client.ListAsync(); - - // Assert - users.Results.Should().SatisfyRespectively( - user => - { - user.Id.Should().Be("5e37c1b4-630f-4e81-bd6b-296af31e345f"); - user.Name.Should().Be("Vedant Koditkar"); - user.Type.Should().Be("person"); - user.Person.Email.Should().Be("vedkoditkar@gmail.com"); - user.Bot.Should().BeNull(); - }, - user => - { - user.Id.Should().Be("590693f3-797f-4970-98ff-7284106393e5"); - user.Name.Should().Be("Test"); - user.Type.Should().Be("bot"); - user.Person.Should().BeNull(); - } + // Act + var user = await _client.RetrieveAsync(userId); + + // Assert + user.Id.Should().Be("5e37c1b4-630f-4e81-bd6b-296af31e345f"); + user.Name.Should().Be("Vedant Koditkar"); + user.Type.Should().Be("person"); + user.Person.Email.Should().Be("vedkoditkar@gmail.com"); + user.Bot.Should().BeNull(); + } + + [Fact] + public async Task RetrieveTokenUser_WorkspaceInternalToken() + { + // Arrange + var jsonData = await File.ReadAllTextAsync("data/users/MeResponse.json"); + + var path = ApiEndpoints.UsersApiUrls.Me(); + + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( + Response.Create() + .WithStatusCode(200) + .WithBody(jsonData) ); - } - - [Fact] - public async Task RetrieveUser() - { - // Arrange - var jsonData = await File.ReadAllTextAsync("data/users/RetrieveUserResponse.json"); - var userId = "5e37c1b4-630f-4e81-bd6b-296af31e345f"; - var path = ApiEndpoints.UsersApiUrls.Retrieve(userId); - - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( + + // Act + var user = await _client.MeAsync(); + + // Assert + user.Id.Should().Be("590693f3-797f-4970-98ff-7284106393e5"); + user.Name.Should().Be("Test"); + user.AvatarUrl.Should().BeNull(); + user.Type.Should().Be("bot"); + user.Person.Should().BeNull(); + user.Bot.Should().NotBeNull(); + user.Bot.Owner.Should().BeOfType(); + + var owner = (WorkspaceIntegrationOwner)user.Bot.Owner; + owner.Workspace.Should().BeTrue(); + } + + [Fact] + public async Task RetrieveTokenUser_UserLevelToken() + { + // Arrange + var jsonData = await File.ReadAllTextAsync("data/users/MeUserLevelResponse.json"); + + var path = ApiEndpoints.UsersApiUrls.Me(); + + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - // Act - var user = await _client.RetrieveAsync(userId); - - // Assert - user.Id.Should().Be("5e37c1b4-630f-4e81-bd6b-296af31e345f"); - user.Name.Should().Be("Vedant Koditkar"); - user.Type.Should().Be("person"); - user.Person.Email.Should().Be("vedkoditkar@gmail.com"); - user.Bot.Should().BeNull(); - } - - [Fact] - public async Task RetrieveTokenUser_WorkspaceInternalToken() - { - // Arrange - var jsonData = await File.ReadAllTextAsync("data/users/MeResponse.json"); - - var path = ApiEndpoints.UsersApiUrls.Me(); - - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( - Response.Create() - .WithStatusCode(200) - .WithBody(jsonData) - ); - - // Act - var user = await _client.MeAsync(); - - // Assert - user.Id.Should().Be("590693f3-797f-4970-98ff-7284106393e5"); - user.Name.Should().Be("Test"); - user.AvatarUrl.Should().BeNull(); - user.Type.Should().Be("bot"); - user.Person.Should().BeNull(); - user.Bot.Should().NotBeNull(); - user.Bot.Owner.Should().BeOfType(); - - var owner = (WorkspaceIntegrationOwner)user.Bot.Owner; - owner.Workspace.Should().BeTrue(); - } - - [Fact] - public async Task RetrieveTokenUser_UserLevelToken() - { - // Arrange - var jsonData = await File.ReadAllTextAsync("data/users/MeUserLevelResponse.json"); - - var path = ApiEndpoints.UsersApiUrls.Me(); - - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( - Response.Create() - .WithStatusCode(200) - .WithBody(jsonData) - ); - - // Act - var user = await _client.MeAsync(); - - // Assert - user.Id.Should().Be("16d84278-ab0e-484c-9bdd-b35da3bd8905"); - user.Name.Should().Be("pied piper"); - user.AvatarUrl.Should().BeNull(); - user.Type.Should().Be("bot"); - user.Person.Should().BeNull(); - user.Bot.Should().NotBeNull(); - user.Bot.Owner.Should().BeOfType(); - - var owner = (UserOwner)user.Bot.Owner; - owner.User.Id.Should().Be("5389a034-eb5c-47b5-8a9e-f79c99ef166c"); - owner.User.Name.Should().Be("christine makenotion"); - owner.User.AvatarUrl.Should().BeNull(); - owner.User.Type.Should().Be("person"); - owner.User.Person.Email.Should().Be("christine@makenotion.com"); - owner.User.Bot.Should().BeNull(); - } + // Act + var user = await _client.MeAsync(); + + // Assert + user.Id.Should().Be("16d84278-ab0e-484c-9bdd-b35da3bd8905"); + user.Name.Should().Be("pied piper"); + user.AvatarUrl.Should().BeNull(); + user.Type.Should().Be("bot"); + user.Person.Should().BeNull(); + user.Bot.Should().NotBeNull(); + user.Bot.Owner.Should().BeOfType(); + + var owner = (UserOwner)user.Bot.Owner; + owner.User.Id.Should().Be("5389a034-eb5c-47b5-8a9e-f79c99ef166c"); + owner.User.Name.Should().Be("christine makenotion"); + owner.User.AvatarUrl.Should().BeNull(); + owner.User.Type.Should().Be("person"); + owner.User.Person.Email.Should().Be("christine@makenotion.com"); + owner.User.Bot.Should().BeNull(); } } From 3e482b11ff79f4c12e635b4471a00aac75445e25 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Wed, 5 Oct 2022 21:09:10 +0530 Subject: [PATCH 107/216] =?UTF-8?q?Add=20jetbrains.resharper.globaltools?= =?UTF-8?q?=20=E2=9E=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .config/dotnet-tools.json | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .config/dotnet-tools.json diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json new file mode 100644 index 00000000..92211a4f --- /dev/null +++ b/.config/dotnet-tools.json @@ -0,0 +1,12 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "jetbrains.resharper.globaltools": { + "version": "2022.2.3", + "commands": [ + "jb" + ] + } + } +} \ No newline at end of file From f012d884f8bdf63f61b3baf7ec786473eadbf098 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Wed, 5 Oct 2022 22:06:45 +0530 Subject: [PATCH 108/216] Updated editorconfig file --- .editorconfig | 291 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 273 insertions(+), 18 deletions(-) diff --git a/.editorconfig b/.editorconfig index f8d20ed2..7e8f258c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,11 +1,261 @@ +root = true # EditorConfig is awesome: https://EditorConfig.org # top-most EditorConfig file -root = true # Don't use tabs for indentation. [*] indent_style = space + +[*.cs] +# Microsoft .NET properties +csharp_preferred_modifier_order = public, private, protected, internal, new, static, abstract, virtual, sealed, readonly, override, extern, unsafe, volatile, async:suggestion +csharp_style_var_elsewhere = true:suggestion +csharp_style_var_for_built_in_types = true:suggestion +csharp_style_var_when_type_is_apparent = true:suggestion +dotnet_naming_rule.constants_rule.import_to_resharper = as_predefined +dotnet_naming_rule.constants_rule.resharper_style = AaBb, _ + aaBb +dotnet_naming_rule.constants_rule.severity = suggestion +dotnet_naming_rule.constants_rule.style = upper_camel_case_style +dotnet_naming_rule.constants_rule.symbols = constants_symbols +dotnet_naming_rule.constants_should_be_pascal_case_rule.import_to_resharper = True +dotnet_naming_rule.constants_should_be_pascal_case_rule.resharper_description = constants_should_be_pascal_case +dotnet_naming_rule.constants_should_be_pascal_case_rule.resharper_guid = a0135172-b297-46cb-bb0f-b1f267109d7b +dotnet_naming_rule.constants_should_be_pascal_case_rule.severity = suggestion +dotnet_naming_rule.constants_should_be_pascal_case_rule.style = upper_camel_case_style +dotnet_naming_rule.constants_should_be_pascal_case_rule.symbols = constants_should_be_pascal_case_symbols +dotnet_naming_rule.constants_should_be_pascal_case_rule_1.import_to_resharper = False +dotnet_naming_rule.constants_should_be_pascal_case_rule_1.severity = suggestion +dotnet_naming_rule.constants_should_be_pascal_case_rule_1.style = upper_camel_case_style +dotnet_naming_rule.constants_should_be_pascal_case_rule_1.symbols = constants_should_be_pascal_case_symbols_1 +dotnet_naming_rule.instance_fields_should_be_camel_case_rule.import_to_resharper = True +dotnet_naming_rule.instance_fields_should_be_camel_case_rule.resharper_description = instance_fields_should_be_camel_case +dotnet_naming_rule.instance_fields_should_be_camel_case_rule.resharper_guid = ed8be1d2-8aa4-45a9-a0fe-964e144ccec7 +dotnet_naming_rule.instance_fields_should_be_camel_case_rule.severity = suggestion +dotnet_naming_rule.instance_fields_should_be_camel_case_rule.style = lower_camel_case_style +dotnet_naming_rule.instance_fields_should_be_camel_case_rule.symbols = instance_fields_should_be_camel_case_symbols +dotnet_naming_rule.interfaces_rule.import_to_resharper = as_predefined +dotnet_naming_rule.interfaces_rule.severity = suggestion +dotnet_naming_rule.interfaces_rule.style = upper_camel_case_style +dotnet_naming_rule.interfaces_rule.symbols = interfaces_symbols +dotnet_naming_rule.locals_should_be_camel_case_rule.import_to_resharper = True +dotnet_naming_rule.locals_should_be_camel_case_rule.resharper_description = locals_should_be_camel_case +dotnet_naming_rule.locals_should_be_camel_case_rule.resharper_guid = dd900f14-6d42-4a58-8277-056e5dab89e7 +dotnet_naming_rule.locals_should_be_camel_case_rule.severity = suggestion +dotnet_naming_rule.locals_should_be_camel_case_rule.style = lower_camel_case_style_1 +dotnet_naming_rule.locals_should_be_camel_case_rule.symbols = locals_should_be_camel_case_symbols +dotnet_naming_rule.local_constants_rule.import_to_resharper = as_predefined +dotnet_naming_rule.local_constants_rule.resharper_style = AaBb, aaBb +dotnet_naming_rule.local_constants_rule.severity = suggestion +dotnet_naming_rule.local_constants_rule.style = upper_camel_case_style +dotnet_naming_rule.local_constants_rule.symbols = local_constants_symbols +dotnet_naming_rule.local_functions_should_be_pascal_case_rule.import_to_resharper = True +dotnet_naming_rule.local_functions_should_be_pascal_case_rule.resharper_description = local_functions_should_be_pascal_case +dotnet_naming_rule.local_functions_should_be_pascal_case_rule.resharper_guid = 67e7ac04-3277-4549-b0bb-98cbfad21765 +dotnet_naming_rule.local_functions_should_be_pascal_case_rule.severity = suggestion +dotnet_naming_rule.local_functions_should_be_pascal_case_rule.style = upper_camel_case_style +dotnet_naming_rule.local_functions_should_be_pascal_case_rule.symbols = local_functions_should_be_pascal_case_symbols +dotnet_naming_rule.members_should_be_pascal_case_rule.import_to_resharper = True +dotnet_naming_rule.members_should_be_pascal_case_rule.resharper_description = members_should_be_pascal_case +dotnet_naming_rule.members_should_be_pascal_case_rule.resharper_guid = 605fba47-8912-494e-9e4c-98aeb57fd884 +dotnet_naming_rule.members_should_be_pascal_case_rule.severity = suggestion +dotnet_naming_rule.members_should_be_pascal_case_rule.style = upper_camel_case_style +dotnet_naming_rule.members_should_be_pascal_case_rule.symbols = members_should_be_pascal_case_symbols +dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case_rule.import_to_resharper = True +dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case_rule.resharper_description = non_private_readonly_fields_should_be_pascal_case +dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case_rule.resharper_guid = e8e1b724-94dd-4cbe-9385-85343fea2b41 +dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case_rule.severity = suggestion +dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case_rule.style = upper_camel_case_style +dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case_rule.symbols = non_private_readonly_fields_should_be_pascal_case_symbols +dotnet_naming_rule.non_private_static_fields_should_be_pascal_case_rule.import_to_resharper = True +dotnet_naming_rule.non_private_static_fields_should_be_pascal_case_rule.resharper_description = non_private_static_fields_should_be_pascal_case +dotnet_naming_rule.non_private_static_fields_should_be_pascal_case_rule.resharper_guid = 51051115-1f5e-4eea-aa9d-2eac02e9b082 +dotnet_naming_rule.non_private_static_fields_should_be_pascal_case_rule.severity = suggestion +dotnet_naming_rule.non_private_static_fields_should_be_pascal_case_rule.style = upper_camel_case_style +dotnet_naming_rule.non_private_static_fields_should_be_pascal_case_rule.symbols = non_private_static_fields_should_be_pascal_case_symbols +dotnet_naming_rule.private_constants_rule.import_to_resharper = as_predefined +dotnet_naming_rule.private_constants_rule.resharper_style = AaBb, _ + aaBb +dotnet_naming_rule.private_constants_rule.severity = suggestion +dotnet_naming_rule.private_constants_rule.style = upper_camel_case_style +dotnet_naming_rule.private_constants_rule.symbols = private_constants_symbols +dotnet_naming_rule.private_static_fields_rule.import_to_resharper = as_predefined +dotnet_naming_rule.private_static_fields_rule.severity = suggestion +dotnet_naming_rule.private_static_fields_rule.style = s_lower_camel_case_style +dotnet_naming_rule.private_static_fields_rule.symbols = private_static_fields_symbols +dotnet_naming_rule.private_static_readonly_rule.import_to_resharper = as_predefined +dotnet_naming_rule.private_static_readonly_rule.severity = suggestion +dotnet_naming_rule.private_static_readonly_rule.style = s_lower_camel_case_style +dotnet_naming_rule.private_static_readonly_rule.symbols = private_static_readonly_symbols +dotnet_naming_rule.public_fields_rule.import_to_resharper = as_predefined +dotnet_naming_rule.public_fields_rule.severity = suggestion +dotnet_naming_rule.public_fields_rule.style = lower_camel_case_style +dotnet_naming_rule.public_fields_rule.symbols = public_fields_symbols +dotnet_naming_rule.static_fields_should_be_camel_case_rule.import_to_resharper = True +dotnet_naming_rule.static_fields_should_be_camel_case_rule.resharper_description = static_fields_should_be_camel_case +dotnet_naming_rule.static_fields_should_be_camel_case_rule.resharper_guid = f286ec29-34ab-4806-9c8a-586f11eedd52 +dotnet_naming_rule.static_fields_should_be_camel_case_rule.severity = suggestion +dotnet_naming_rule.static_fields_should_be_camel_case_rule.style = s_lower_camel_case_style +dotnet_naming_rule.static_fields_should_be_camel_case_rule.symbols = static_fields_should_be_camel_case_symbols +dotnet_naming_rule.static_readonly_rule.import_to_resharper = as_predefined +dotnet_naming_rule.static_readonly_rule.resharper_style = AaBb, s_ + aaBb +dotnet_naming_rule.static_readonly_rule.severity = suggestion +dotnet_naming_rule.static_readonly_rule.style = upper_camel_case_style +dotnet_naming_rule.static_readonly_rule.symbols = static_readonly_symbols +dotnet_naming_rule.type_parameters_rule.import_to_resharper = as_predefined +dotnet_naming_rule.type_parameters_rule.severity = suggestion +dotnet_naming_rule.type_parameters_rule.style = upper_camel_case_style +dotnet_naming_rule.type_parameters_rule.symbols = type_parameters_symbols +dotnet_naming_style.lower_camel_case_style.capitalization = camel_case +dotnet_naming_style.lower_camel_case_style.required_prefix = _ +dotnet_naming_style.lower_camel_case_style_1.capitalization = camel_case +dotnet_naming_style.s_lower_camel_case_style.capitalization = camel_case +dotnet_naming_style.s_lower_camel_case_style.required_prefix = s_ +dotnet_naming_style.upper_camel_case_style.capitalization = pascal_case +dotnet_naming_symbols.constants_should_be_pascal_case_symbols.applicable_accessibilities = local,public,internal,private,protected,protected_internal,private_protected +dotnet_naming_symbols.constants_should_be_pascal_case_symbols.applicable_kinds = local +dotnet_naming_symbols.constants_should_be_pascal_case_symbols.required_modifiers = const +dotnet_naming_symbols.constants_should_be_pascal_case_symbols.resharper_applicable_kinds = constant_field,local_constant +dotnet_naming_symbols.constants_should_be_pascal_case_symbols.resharper_required_modifiers = any +dotnet_naming_symbols.constants_should_be_pascal_case_symbols_1.applicable_accessibilities = local,public,internal,private,protected,protected_internal,private_protected +dotnet_naming_symbols.constants_should_be_pascal_case_symbols_1.applicable_kinds = field +dotnet_naming_symbols.constants_should_be_pascal_case_symbols_1.required_modifiers = const +dotnet_naming_symbols.constants_symbols.applicable_accessibilities = public,internal,protected,protected_internal,private_protected +dotnet_naming_symbols.constants_symbols.applicable_kinds = field +dotnet_naming_symbols.constants_symbols.required_modifiers = const +dotnet_naming_symbols.instance_fields_should_be_camel_case_symbols.applicable_accessibilities = local,public,internal,private,protected,protected_internal,private_protected +dotnet_naming_symbols.instance_fields_should_be_camel_case_symbols.applicable_kinds = field +dotnet_naming_symbols.instance_fields_should_be_camel_case_symbols.resharper_applicable_kinds = any_field +dotnet_naming_symbols.instance_fields_should_be_camel_case_symbols.resharper_required_modifiers = any +dotnet_naming_symbols.interfaces_symbols.applicable_accessibilities = * +dotnet_naming_symbols.interfaces_symbols.applicable_kinds = interface +dotnet_naming_symbols.locals_should_be_camel_case_symbols.applicable_accessibilities = local,public,internal,private,protected,protected_internal,private_protected +dotnet_naming_symbols.locals_should_be_camel_case_symbols.applicable_kinds = parameter,local +dotnet_naming_symbols.locals_should_be_camel_case_symbols.resharper_applicable_kinds = parameter,local +dotnet_naming_symbols.locals_should_be_camel_case_symbols.resharper_required_modifiers = any +dotnet_naming_symbols.local_constants_symbols.applicable_accessibilities = * +dotnet_naming_symbols.local_constants_symbols.applicable_kinds = local +dotnet_naming_symbols.local_constants_symbols.required_modifiers = const +dotnet_naming_symbols.local_functions_should_be_pascal_case_symbols.applicable_accessibilities = local,public,internal,private,protected,protected_internal,private_protected +dotnet_naming_symbols.local_functions_should_be_pascal_case_symbols.applicable_kinds = local_function +dotnet_naming_symbols.local_functions_should_be_pascal_case_symbols.resharper_applicable_kinds = local_function +dotnet_naming_symbols.local_functions_should_be_pascal_case_symbols.resharper_required_modifiers = any +dotnet_naming_symbols.members_should_be_pascal_case_symbols.applicable_accessibilities = local,public,internal,private,protected,protected_internal,private_protected +dotnet_naming_symbols.members_should_be_pascal_case_symbols.applicable_kinds = namespace,class,struct,interface,enum,property,method,field,event,delegate,parameter,type_parameter,local,local_function +dotnet_naming_symbols.members_should_be_pascal_case_symbols.resharper_applicable_kinds = namespace,class,struct,interface,enum,property,method,any_field,event,delegate,parameter,type_parameter,local,local_function +dotnet_naming_symbols.members_should_be_pascal_case_symbols.resharper_required_modifiers = any +dotnet_naming_symbols.non_private_readonly_fields_should_be_pascal_case_symbols.applicable_accessibilities = local,public,internal,protected,protected_internal,private_protected +dotnet_naming_symbols.non_private_readonly_fields_should_be_pascal_case_symbols.applicable_kinds = field +dotnet_naming_symbols.non_private_readonly_fields_should_be_pascal_case_symbols.required_modifiers = readonly +dotnet_naming_symbols.non_private_readonly_fields_should_be_pascal_case_symbols.resharper_applicable_kinds = readonly_field +dotnet_naming_symbols.non_private_readonly_fields_should_be_pascal_case_symbols.resharper_required_modifiers = any +dotnet_naming_symbols.non_private_static_fields_should_be_pascal_case_symbols.applicable_accessibilities = local,public,internal,protected,protected_internal,private_protected +dotnet_naming_symbols.non_private_static_fields_should_be_pascal_case_symbols.applicable_kinds = field +dotnet_naming_symbols.non_private_static_fields_should_be_pascal_case_symbols.required_modifiers = static +dotnet_naming_symbols.non_private_static_fields_should_be_pascal_case_symbols.resharper_applicable_kinds = any_field +dotnet_naming_symbols.non_private_static_fields_should_be_pascal_case_symbols.resharper_required_modifiers = static +dotnet_naming_symbols.private_constants_symbols.applicable_accessibilities = private +dotnet_naming_symbols.private_constants_symbols.applicable_kinds = field +dotnet_naming_symbols.private_constants_symbols.required_modifiers = const +dotnet_naming_symbols.private_static_fields_symbols.applicable_accessibilities = private +dotnet_naming_symbols.private_static_fields_symbols.applicable_kinds = field +dotnet_naming_symbols.private_static_fields_symbols.required_modifiers = static +dotnet_naming_symbols.private_static_readonly_symbols.applicable_accessibilities = private +dotnet_naming_symbols.private_static_readonly_symbols.applicable_kinds = field +dotnet_naming_symbols.private_static_readonly_symbols.required_modifiers = static,readonly +dotnet_naming_symbols.public_fields_symbols.applicable_accessibilities = public,internal,protected,protected_internal,private_protected +dotnet_naming_symbols.public_fields_symbols.applicable_kinds = field +dotnet_naming_symbols.static_fields_should_be_camel_case_symbols.applicable_accessibilities = local,public,internal,private,protected,protected_internal,private_protected +dotnet_naming_symbols.static_fields_should_be_camel_case_symbols.applicable_kinds = field +dotnet_naming_symbols.static_fields_should_be_camel_case_symbols.required_modifiers = static +dotnet_naming_symbols.static_fields_should_be_camel_case_symbols.resharper_applicable_kinds = any_field +dotnet_naming_symbols.static_fields_should_be_camel_case_symbols.resharper_required_modifiers = static +dotnet_naming_symbols.static_readonly_symbols.applicable_accessibilities = public,internal,protected,protected_internal,private_protected +dotnet_naming_symbols.static_readonly_symbols.applicable_kinds = field +dotnet_naming_symbols.static_readonly_symbols.required_modifiers = static,readonly +dotnet_naming_symbols.type_parameters_symbols.applicable_accessibilities = * +dotnet_naming_symbols.type_parameters_symbols.applicable_kinds = type_parameter +dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary:none +dotnet_style_parentheses_in_other_binary_operators = never_if_unnecessary:none +dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary:none +dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion +dotnet_style_predefined_type_for_member_access = true:suggestion +dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion + +# ReSharper properties +# resharper_arguments_anonymous_function = named +# resharper_arguments_literal = named +# resharper_arguments_named = named +# resharper_arguments_other = named +# resharper_arguments_string_literal = named +resharper_blank_lines_after_control_transfer_statements = 1 +resharper_blank_lines_after_multiline_statements = 1 +resharper_blank_lines_around_single_line_auto_property = 1 +resharper_blank_lines_around_single_line_local_method = 1 +resharper_blank_lines_around_single_line_property = 1 +resharper_blank_lines_before_block_statements = 1 +resharper_blank_lines_before_control_transfer_statements = 1 +resharper_blank_lines_before_multiline_statements = 1 +resharper_blank_lines_before_single_line_comment = 1 +resharper_braces_for_for = required +resharper_braces_for_foreach = required +resharper_braces_for_ifelse = required +resharper_braces_for_while = required +resharper_braces_redundant = false +resharper_case_block_braces = next_line_shifted_2 +resharper_csharp_blank_lines_around_single_line_invocable = 1 +resharper_csharp_keep_blank_lines_in_code = 1 +resharper_csharp_keep_blank_lines_in_declarations = 1 +resharper_csharp_wrap_after_declaration_lpar = true +resharper_csharp_wrap_extends_list_style = chop_if_long +resharper_csharp_wrap_parameters_style = chop_if_long +resharper_indent_nested_fixed_stmt = true +resharper_indent_nested_foreach_stmt = true +resharper_indent_nested_for_stmt = true +resharper_indent_nested_lock_stmt = true +resharper_indent_nested_usings_stmt = true +resharper_indent_nested_while_stmt = true +resharper_keep_existing_declaration_block_arrangement = true +resharper_keep_existing_declaration_parens_arrangement = false +resharper_keep_existing_embedded_block_arrangement = true +resharper_keep_existing_enum_arrangement = true +resharper_keep_existing_expr_member_arrangement = false +resharper_keep_existing_initializer_arrangement = false +resharper_local_function_body = expression_body +resharper_max_enum_members_on_line = 1 +resharper_max_formal_parameters_on_line = 4 +resharper_place_field_attribute_on_same_line = if_owner_is_single_line +resharper_space_within_single_line_array_initializer_braces = false +resharper_trailing_comma_in_multiline_lists = true +resharper_use_heuristics_for_body_style = false +resharper_use_indent_from_vs = false +resharper_wrap_before_eq = true +resharper_wrap_before_first_type_parameter_constraint = true + +# ReSharper inspection severities +resharper_arrange_accessor_owner_body_highlighting = none +resharper_arrange_local_function_body_highlighting = suggestion +resharper_arrange_namespace_body_highlighting = suggestion +resharper_arrange_redundant_parentheses_highlighting = hint +resharper_arrange_this_qualifier_highlighting = none +resharper_arrange_type_member_modifiers_highlighting = hint +resharper_arrange_type_modifiers_highlighting = hint +resharper_built_in_type_reference_style_for_member_access_highlighting = suggestion +resharper_built_in_type_reference_style_highlighting = suggestion +resharper_inconsistent_naming_highlighting = suggestion +resharper_redundant_base_qualifier_highlighting = none +resharper_suggest_var_or_type_built_in_types_highlighting = suggestion +resharper_suggest_var_or_type_elsewhere_highlighting = suggestion +resharper_suggest_var_or_type_simple_types_highlighting = suggestion + +resharper_csharp_force_attribute_style=separate +resharper_csharp_method_or_operator_body=expression_body +resharper_csharp_max_enum_members_on_line=1 +resharper_csharp_place_attribute_on_same_line=false +resharper_csharp_wrap_object_and_collection_initializer_style=chop_always +resharper_csharp_use_heuristics_for_body_style=true + +# Standard properties +insert_final_newline = true # (Please don't specify an indent_size here; that has too many unintended consequences.) # Code files @@ -39,7 +289,7 @@ indent_size = 2 [*.{cs,vb}] # IDE0055: Fix formatting -dotnet_diagnostic.IDE0055.severity = warning +dotnet_diagnostic.ide0055.severity = warning # Sort using and Import directives with System.* appearing first dotnet_sort_system_directives_first = true @@ -143,23 +393,23 @@ dotnet_naming_symbols.all_members.applicable_kinds = * dotnet_naming_style.pascal_case_style.capitalization = pascal_case # error RS2008: Enable analyzer release tracking for the analyzer project containing rule '{0}' -dotnet_diagnostic.RS2008.severity = none +dotnet_diagnostic.rs2008.severity = none # IDE0073: File header # dotnet_diagnostic.IDE0073.severity = warning # file_header_template = # IDE0035: Remove unreachable code -dotnet_diagnostic.IDE0035.severity = warning +dotnet_diagnostic.ide0035.severity = warning # IDE0036: Order modifiers -dotnet_diagnostic.IDE0036.severity = warning +dotnet_diagnostic.ide0036.severity = warning # IDE0043: Format string contains invalid placeholder -dotnet_diagnostic.IDE0043.severity = warning +dotnet_diagnostic.ide0043.severity = warning # IDE0044: Make field readonly -dotnet_diagnostic.IDE0044.severity = warning +dotnet_diagnostic.ide0044.severity = warning # RS0016: Only enable if API files are present dotnet_public_api_analyzer.require_api_files = true @@ -236,39 +486,39 @@ csharp_preserve_single_line_statements = true [src/CodeStyle/**.{cs,vb}] # warning RS0005: Do not use generic CodeAction.Create to create CodeAction -dotnet_diagnostic.RS0005.severity = none +dotnet_diagnostic.rs0005.severity = none [src/{Analyzers,CodeStyle,Features,Workspaces,EditorFeatures,VisualStudio}/**/*.{cs,vb}] # IDE0011: Add braces csharp_prefer_braces = when_multiline:warning # NOTE: We need the below severity entry for Add Braces due to https://github.com/dotnet/roslyn/issues/44201 -dotnet_diagnostic.IDE0011.severity = warning +dotnet_diagnostic.ide0011.severity = warning # IDE0040: Add accessibility modifiers -dotnet_diagnostic.IDE0040.severity = warning +dotnet_diagnostic.ide0040.severity = warning # CONSIDER: Are IDE0051 and IDE0052 too noisy to be warnings for IDE editing scenarios? Should they be made build-only warnings? # IDE0051: Remove unused private member -dotnet_diagnostic.IDE0051.severity = warning +dotnet_diagnostic.ide0051.severity = warning # IDE0052: Remove unread private member -dotnet_diagnostic.IDE0052.severity = warning +dotnet_diagnostic.ide0052.severity = warning # IDE0059: Unnecessary assignment to a value -dotnet_diagnostic.IDE0059.severity = warning +dotnet_diagnostic.ide0059.severity = warning # IDE0060: Remove unused parameter -dotnet_diagnostic.IDE0060.severity = warning +dotnet_diagnostic.ide0060.severity = warning # CA1012: Abstract types should not have public constructors -dotnet_diagnostic.CA1012.severity = warning +dotnet_diagnostic.ca1012.severity = warning # CA1822: Make member static -dotnet_diagnostic.CA1822.severity = warning +dotnet_diagnostic.ca1822.severity = warning # Prefer "var" everywhere -dotnet_diagnostic.IDE0007.severity = warning +dotnet_diagnostic.ide0007.severity = warning csharp_style_var_for_built_in_types = true:warning csharp_style_var_when_type_is_apparent = true:warning csharp_style_var_elsewhere = true:warning @@ -277,4 +527,9 @@ csharp_style_var_elsewhere = true:warning # CA1822: Make member static # Not enforced as a build 'warning' for 'VisualStudio' layer due to large number of false positives from https://github.com/dotnet/roslyn-analyzers/issues/3857 and https://github.com/dotnet/roslyn-analyzers/issues/3858 # Additionally, there is a risk of accidentally breaking an internal API that partners rely on though IVT. -dotnet_diagnostic.CA1822.severity = suggestion \ No newline at end of file +dotnet_diagnostic.ca1822.severity = suggestion + +[*.{appxmanifest,asax,ascx,aspx,axaml,axml,build,config,cs,cshtml,csproj,css,dbml,discomap,dtd,htm,html,js,json,jsproj,jsx,lsproj,master,njsproj,nuspec,paml,proj,props,proto,razor,resjson,resw,resx,skin,StyleCop,targets,tasks,ts,tsx,vb,vbproj,xaml,xamlx,xml,xoml,xsd}] +indent_style = space +indent_size = 4 +tab_width = 4 From 311dcde9e9d52a028959df2b3fe2d01c1116da40 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Wed, 5 Oct 2022 22:08:51 +0530 Subject: [PATCH 109/216] =?UTF-8?q?Run=20solution=20wide=20linter=20?= =?UTF-8?q?=F0=9F=9A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Notion.Client/Api/ApiEndpoints.cs | 124 ++- Src/Notion.Client/Api/Blocks/BlocksClient.cs | 14 +- Src/Notion.Client/Api/Blocks/IBlocksClient.cs | 16 +- .../BlocksRetrieveChildrenParameters.cs | 1 + .../UpdateBlocks/AudioUpdateBlock.cs | 3 +- .../UpdateBlocks/BookmarkUpdateBlock.cs | 4 +- .../UpdateBlocks/BreadcrumbUpdateBlock.cs | 12 +- .../UpdateBlocks/DividerUpdateBlock.cs | 12 +- .../TableOfContentsUpdateBlock.cs | 12 +- .../Create/Request/CreateCommentParameters.cs | 22 +- .../Api/Comments/ICommentsClient.cs | 6 +- .../Api/Comments/Retrieve/CommentsClient.cs | 6 +- .../Request/RetrieveCommentsParameters.cs | 2 + .../Api/Comments/Retrieve/Response/Comment.cs | 8 +- .../Retrieve/Response/ICommentParent.cs | 4 +- .../Api/Databases/DatabasesClient.cs | 4 +- .../Api/Databases/IDatabasesClient.cs | 28 +- .../DatabasesCreateParameters.cs | 12 +- .../RequestParams/DatabasesListParameters.cs | 1 + .../RequestParams/DatabasesQueryParameters.cs | 3 + .../DatabasesUpdateParameters.cs | 1 - .../Api/Databases/RequestParams/Direction.cs | 2 +- .../Api/Databases/RequestParams/Timestamp.cs | 2 +- Src/Notion.Client/Api/Pages/IPagesClient.cs | 49 +- Src/Notion.Client/Api/Pages/PagesClient.cs | 23 +- .../PagesCreateParameters.cs | 4 + .../PagesCreateParametersBuilder.cs | 17 +- .../RequestParams/PagesUpdateParameters.cs | 12 +- Src/Notion.Client/Api/Search/ISearchClient.cs | 9 +- .../Api/Search/Parameters/SearchDirection.cs | 2 +- .../Api/Search/Parameters/SearchFilter.cs | 1 + .../Api/Search/Parameters/SearchObjectType.cs | 2 +- .../Api/Search/Parameters/SearchParameters.cs | 4 + Src/Notion.Client/Api/Users/IUsersClient.cs | 22 +- Src/Notion.Client/Api/Users/UsersClient.cs | 7 +- Src/Notion.Client/Constants.cs | 1 + .../DI/ServiceCollectionExtensions.cs | 4 +- .../Extensions/EnumExtensions.cs | 9 +- .../HttpResponseMessageExtensions.cs | 8 +- Src/Notion.Client/Models/Blocks/AudioBlock.cs | 4 +- Src/Notion.Client/Models/Blocks/Block.cs | 2 +- Src/Notion.Client/Models/Blocks/BlockType.cs | 2 +- .../Models/Blocks/BookmarkBlock.cs | 4 +- .../Models/Blocks/BreadcrumbBlock.cs | 4 +- .../Models/Blocks/BulletedListItemBlock.cs | 4 +- .../Models/Blocks/CalloutBlock.cs | 4 +- .../Models/Blocks/ChildDatabaseBlock.cs | 4 +- .../Models/Blocks/ChildPageBlock.cs | 4 +- Src/Notion.Client/Models/Blocks/CodeBlock.cs | 4 +- .../Models/Blocks/ColumnListBlock.cs | 4 +- .../Models/Blocks/DividerBlock.cs | 4 +- Src/Notion.Client/Models/Blocks/EmbedBlock.cs | 5 +- .../Models/Blocks/EquationBlock.cs | 4 +- Src/Notion.Client/Models/Blocks/FileBlock.cs | 4 +- .../Models/Blocks/HeadingOneBlock.cs | 4 +- .../Models/Blocks/HeadingThreeeBlock.cs | 4 +- .../Models/Blocks/HeadingTwoBlock.cs | 4 +- Src/Notion.Client/Models/Blocks/IBlock.cs | 64 +- .../Models/Blocks/IBlockParent.cs | 8 +- Src/Notion.Client/Models/Blocks/ImageBlock.cs | 4 +- .../Models/Blocks/LinkPreviewBlock.cs | 8 +- .../Models/Blocks/LinkToPageBlock.cs | 4 +- .../Models/Blocks/NumberedListItemBlock.cs | 4 +- Src/Notion.Client/Models/Blocks/PDFBlock.cs | 4 +- .../Models/Blocks/ParagraphBlock.cs | 4 +- Src/Notion.Client/Models/Blocks/QuoteBlock.cs | 4 +- .../Models/Blocks/SyncedBlockBlock.cs | 4 +- Src/Notion.Client/Models/Blocks/TableBlock.cs | 4 +- .../Models/Blocks/TableOfContentsBlock.cs | 4 +- .../Models/Blocks/TableRowBlock.cs | 4 +- .../Models/Blocks/TemplateBlock.cs | 4 +- Src/Notion.Client/Models/Blocks/ToDoBlock.cs | 4 +- .../Models/Blocks/ToggleBlock.cs | 4 +- Src/Notion.Client/Models/Blocks/VideoBlock.cs | 4 +- .../Models/Common/IObjectModificationData.cs | 8 +- Src/Notion.Client/Models/Database/Database.cs | 32 +- .../Models/Database/IDatabaseParent.cs | 6 +- .../Models/Database/Properties/Property.cs | 40 +- .../RelationProperty/RelationData.cs | 4 +- .../RelationProperty/RelationProperty.cs | 4 +- .../RelationProperty/RelationType.cs | 2 +- .../Database/Properties/SelectProperty.cs | 8 +- .../Models/Database/RichText/RichTextBase.cs | 6 +- .../Models/Database/RichText/RichTextType.cs | 2 +- Src/Notion.Client/Models/EmojiObject.cs | 6 +- Src/Notion.Client/Models/File/FileObject.cs | 10 +- .../Models/File/FileObjectWithName.cs | 4 +- .../Models/Filters/CheckboxFilter.cs | 23 +- .../Models/Filters/DateFilter.cs | 93 +-- .../Models/Filters/EmailFilter.cs | 23 +- .../Models/Filters/FilesFilter.cs | 20 +- Src/Notion.Client/Models/Filters/Filter.cs | 13 +- .../Models/Filters/FormulaFilter.cs | 39 +- .../Models/Filters/MultiSelectFilter.cs | 39 +- .../Models/Filters/NumberFilter.cs | 64 +- .../Models/Filters/PeopleFilter.cs | 39 +- .../Models/Filters/PhoneNumberFilter.cs | 23 +- .../Models/Filters/RelationFilter.cs | 39 +- .../Models/Filters/RichTextFilter.cs | 63 +- .../Models/Filters/Rollup/RollupFilter.cs | 29 +- .../Models/Filters/SelectFilter.cs | 39 +- .../Models/Filters/StatusFilter.cs | 39 +- .../Filters/TimestampCreatedTimeFilter.cs | 32 +- .../Filters/TimestampLastEditedTimeFilter.cs | 32 +- .../Models/Filters/TitleFilter.cs | 23 +- Src/Notion.Client/Models/Filters/URLFilter.cs | 23 +- Src/Notion.Client/Models/IObject.cs | 8 +- Src/Notion.Client/Models/Page/IPageIcon.cs | 6 +- Src/Notion.Client/Models/Page/IPageParent.cs | 8 +- Src/Notion.Client/Models/Page/Page.cs | 56 +- .../Models/Parents/BlockParent.cs | 10 +- .../Models/Parents/DatabaseParent.cs | 10 +- .../Models/Parents/PageParent.cs | 10 +- .../Models/Parents/WorkspaceParent.cs | 2 +- .../PropertyItems/IPropertyItemObject.cs | 7 +- .../Models/PropertyItems/ListPropertyItem.cs | 17 +- .../PropertyItems/RollupPropertyItem.cs | 24 +- .../PropertyItems/SimplePropertyItem.cs | 40 +- .../PropertyItems/StatusPropertyItem.cs | 3 +- .../PropertyValue/CheckboxPropertyValue.cs | 2 +- .../PropertyValue/CreatedByPropertyValue.cs | 4 +- .../PropertyValue/CreatedTimePropertyValue.cs | 4 +- .../Models/PropertyValue/DatePropertyValue.cs | 13 +- .../PropertyValue/EmailPropertyValue.cs | 4 +- .../PropertyValue/FilesPropertyValue.cs | 4 +- .../PropertyValue/FormulaPropertyValue.cs | 16 +- .../LastEditedByPropertyValue.cs | 4 +- .../LastEditedTimePropertyValue.cs | 4 +- .../PropertyValue/MultiSelectPropertyValue.cs | 4 +- .../PropertyValue/NumberPropertyValue.cs | 4 +- .../PropertyValue/PeoplePropertyValue.cs | 4 +- .../PropertyValue/PhoneNumberPropertyValue.cs | 4 +- .../Models/PropertyValue/PropertyValue.cs | 44 +- .../Models/PropertyValue/PropertyValueType.cs | 2 +- .../PropertyValue/RelationPropertyValue.cs | 4 +- .../PropertyValue/RichTextPropertyValue.cs | 4 +- .../PropertyValue/RollupPropertyValue.cs | 14 +- .../PropertyValue/SelectPropertyValue.cs | 2 +- .../PropertyValue/StatusPropertyValue.cs | 56 +- .../PropertyValue/TitlePropertyValue.cs | 4 +- .../Models/PropertyValue/UrlPropertyValue.cs | 4 +- .../Models/User/BotOwner/IBotOwner.cs | 4 +- .../Models/User/BotOwner/UserOwner.cs | 4 +- .../BotOwner/WorkspaceIntegrationOwner.cs | 4 +- Src/Notion.Client/Models/User/User.cs | 7 +- Src/Notion.Client/NotionApiErrorResponse.cs | 2 +- Src/Notion.Client/NotionApiException.cs | 1 + Src/Notion.Client/NotionClient.cs | 12 + Src/Notion.Client/NotionClientFactory.cs | 10 +- Src/Notion.Client/RestClient/ClientOptions.cs | 2 + .../RestClient/LoggingHandler.cs | 5 +- Src/Notion.Client/RestClient/RestClient.cs | 116 +-- Src/Notion.Client/http/QueryHelpers.cs | 8 +- .../CommentsClientTests.cs | 207 ++--- .../IBlocksClientTests.cs | 775 ++++++++---------- .../IPageClientTests.cs | 401 ++++----- Test/Notion.UnitTests/ApiTestBase.cs | 93 +-- Test/Notion.UnitTests/BlocksClientTests.cs | 265 +++--- Test/Notion.UnitTests/DatabasesClientTests.cs | 658 +++++++-------- Test/Notion.UnitTests/FilterTests.cs | 247 +++--- Test/Notion.UnitTests/HelperAsserts.cs | 61 +- Test/Notion.UnitTests/PagesClientTests.cs | 354 ++++---- Test/Notion.UnitTests/PropertyTests.cs | 104 ++- Test/Notion.UnitTests/SearchClientTest.cs | 92 +-- Test/Notion.UnitTests/UserClientTest.cs | 253 +++--- 165 files changed, 2744 insertions(+), 2852 deletions(-) diff --git a/Src/Notion.Client/Api/ApiEndpoints.cs b/Src/Notion.Client/Api/ApiEndpoints.cs index ec6f5b1a..51dbe7fd 100644 --- a/Src/Notion.Client/Api/ApiEndpoints.cs +++ b/Src/Notion.Client/Api/ApiEndpoints.cs @@ -1,72 +1,140 @@ -using System; - -namespace Notion.Client +namespace Notion.Client { public static class ApiEndpoints { public static class DatabasesApiUrls { - public static string Retrieve(string databaseId) => $"/v1/databases/{databaseId}"; - public static string List() => "/v1/databases"; - public static string Query(string databaseId) => $"/v1/databases/{databaseId}/query"; public static string Create => "/v1/databases"; - public static string Update(string databaseId) => $"/v1/databases/{databaseId}"; + + public static string Retrieve(string databaseId) + { + return $"/v1/databases/{databaseId}"; + } + + public static string List() + { + return "/v1/databases"; + } + + public static string Query(string databaseId) + { + return $"/v1/databases/{databaseId}/query"; + } + + public static string Update(string databaseId) + { + return $"/v1/databases/{databaseId}"; + } } public static class UsersApiUrls { - public static string Retrieve(string userId) => $"/v1/users/{userId}"; - public static string List() => "/v1/users"; + public static string Retrieve(string userId) + { + return $"/v1/users/{userId}"; + } + + public static string List() + { + return "/v1/users"; + } /// - /// Get the for retrieve your token's bot user. + /// Get the for retrieve your token's bot user. /// - /// Returns a retrieve your token's bot user. - public static string Me() => "/v1/users/me"; + /// Returns a retrieve your token's bot user. + public static string Me() + { + return "/v1/users/me"; + } } public static class BlocksApiUrls { - public static string Retrieve(string blockId) => $"/v1/blocks/{blockId}"; - public static string Update(string blockId) => $"/v1/blocks/{blockId}"; + public static string Retrieve(string blockId) + { + return $"/v1/blocks/{blockId}"; + } + + public static string Update(string blockId) + { + return $"/v1/blocks/{blockId}"; + } /// - /// Get the for deleting a block. + /// Get the for deleting a block. /// /// Identifier for a Notion block - /// Returns a for deleting a block. - public static string Delete(string blockId) => $"/v1/blocks/{blockId}"; + /// Returns a for deleting a block. + public static string Delete(string blockId) + { + return $"/v1/blocks/{blockId}"; + } + + public static string RetrieveChildren(string blockId) + { + return $"/v1/blocks/{blockId}/children"; + } - public static string RetrieveChildren(string blockId) => $"/v1/blocks/{blockId}/children"; - public static string AppendChildren(string blockId) => $"/v1/blocks/{blockId}/children"; + public static string AppendChildren(string blockId) + { + return $"/v1/blocks/{blockId}/children"; + } } public static class PagesApiUrls { - public static string Create() => $"/v1/pages"; - public static string Retrieve(string pageId) => $"/v1/pages/{pageId}"; - public static string Update(string pageId) => $"/v1/pages/{pageId}"; - public static string UpdateProperties(string pageId) => $"/v1/pages/{pageId}"; + public static string Create() + { + return "/v1/pages"; + } + + public static string Retrieve(string pageId) + { + return $"/v1/pages/{pageId}"; + } + + public static string Update(string pageId) + { + return $"/v1/pages/{pageId}"; + } + + public static string UpdateProperties(string pageId) + { + return $"/v1/pages/{pageId}"; + } /// - /// Get the for retrieve page property item + /// Get the for retrieve page property item /// /// Identifier for a Notion Page /// Identifier for a Notion Property /// - public static string RetrievePropertyItem(string pageId, string propertyId) => $"/v1/pages/{pageId}/properties/{propertyId}"; + public static string RetrievePropertyItem(string pageId, string propertyId) + { + return $"/v1/pages/{pageId}/properties/{propertyId}"; + } } public static class SearchApiUrls { - public static string Search() => "/v1/search"; + public static string Search() + { + return "/v1/search"; + } } public static class CommentsApiUrls { - public static string Retrieve() => "/v1/comments"; + public static string Retrieve() + { + return "/v1/comments"; + } - public static string Create() => "/v1/comments"; + public static string Create() + { + return "/v1/comments"; + } } } } diff --git a/Src/Notion.Client/Api/Blocks/BlocksClient.cs b/Src/Notion.Client/Api/Blocks/BlocksClient.cs index cc06642e..8fbdcd26 100644 --- a/Src/Notion.Client/Api/Blocks/BlocksClient.cs +++ b/Src/Notion.Client/Api/Blocks/BlocksClient.cs @@ -14,7 +14,9 @@ public BlocksClient(IRestClient client) _client = client; } - public async Task> RetrieveChildrenAsync(string blockId, BlocksRetrieveChildrenParameters parameters = null) + public async Task> RetrieveChildrenAsync( + string blockId, + BlocksRetrieveChildrenParameters parameters = null) { if (string.IsNullOrWhiteSpace(blockId)) { @@ -25,16 +27,18 @@ public async Task> RetrieveChildrenAsync(string blockId, B var queryParameters = (IBlocksRetrieveChildrenQueryParameters)parameters; - var queryParams = new Dictionary() + var queryParams = new Dictionary { - { "start_cursor", queryParameters?.StartCursor?.ToString() }, - { "page_size", queryParameters?.PageSize?.ToString() } + {"start_cursor", queryParameters?.StartCursor}, + {"page_size", queryParameters?.PageSize?.ToString()}, }; return await _client.GetAsync>(url, queryParams); } - public async Task> AppendChildrenAsync(string blockId, BlocksAppendChildrenParameters parameters = null) + public async Task> AppendChildrenAsync( + string blockId, + BlocksAppendChildrenParameters parameters = null) { if (string.IsNullOrWhiteSpace(blockId)) { diff --git a/Src/Notion.Client/Api/Blocks/IBlocksClient.cs b/Src/Notion.Client/Api/Blocks/IBlocksClient.cs index 90ebf073..f45611b7 100644 --- a/Src/Notion.Client/Api/Blocks/IBlocksClient.cs +++ b/Src/Notion.Client/Api/Blocks/IBlocksClient.cs @@ -5,32 +5,36 @@ namespace Notion.Client public interface IBlocksClient { /// - /// Retrieves a Block object using the ID specified. + /// Retrieves a Block object using the ID specified. /// /// /// Block Task RetrieveAsync(string blockId); /// - /// Updates the content for the specified block_id based on the block type. + /// Updates the content for the specified block_id based on the block type. /// /// /// /// Block Task UpdateAsync(string blockId, IUpdateBlock updateBlock); - Task> RetrieveChildrenAsync(string blockId, BlocksRetrieveChildrenParameters parameters = null); + Task> RetrieveChildrenAsync( + string blockId, + BlocksRetrieveChildrenParameters parameters = null); /// - /// Creates and appends new children blocks to the parent block_id specified. + /// Creates and appends new children blocks to the parent block_id specified. /// /// Identifier for a block /// /// A paginated list of newly created first level children block objects. - Task> AppendChildrenAsync(string blockId, BlocksAppendChildrenParameters parameters = null); + Task> AppendChildrenAsync( + string blockId, + BlocksAppendChildrenParameters parameters = null); /// - /// Sets a Block object, including page blocks, to archived: true using the ID specified. + /// Sets a Block object, including page blocks, to archived: true using the ID specified. /// /// Identifier for a Notion block Task DeleteAsync(string blockId); diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksRetrieveChildrenParameters.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksRetrieveChildrenParameters.cs index ddc73a91..30f9c17d 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksRetrieveChildrenParameters.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksRetrieveChildrenParameters.cs @@ -3,6 +3,7 @@ public class BlocksRetrieveChildrenParameters : IBlocksRetrieveChildrenQueryParameters { public string StartCursor { get; set; } + public int? PageSize { get; set; } } } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/AudioUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/AudioUpdateBlock.cs index 8747ad63..f341e441 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/AudioUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/AudioUpdateBlock.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Notion.Client { diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BookmarkUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BookmarkUpdateBlock.cs index c3333737..612b6dda 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BookmarkUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BookmarkUpdateBlock.cs @@ -5,11 +5,11 @@ namespace Notion.Client { public class BookmarkUpdateBlock : IUpdateBlock { - public bool Archived { get; set; } - [JsonProperty("bookmark")] public Info Bookmark { get; set; } + public bool Archived { get; set; } + public class Info { [JsonProperty("url")] diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BreadcrumbUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BreadcrumbUpdateBlock.cs index 2bb8be38..a90f6966 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BreadcrumbUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BreadcrumbUpdateBlock.cs @@ -4,18 +4,18 @@ namespace Notion.Client { public class BreadcrumbUpdateBlock : IUpdateBlock { - public bool Archived { get; set; } + public BreadcrumbUpdateBlock() + { + Breadcrumb = new Info(); + } [JsonProperty("breadcrumb")] public Info Breadcrumb { get; set; } - public class Info - { - } + public bool Archived { get; set; } - public BreadcrumbUpdateBlock() + public class Info { - Breadcrumb = new Info(); } } } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/DividerUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/DividerUpdateBlock.cs index 6c5b447c..79f332f0 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/DividerUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/DividerUpdateBlock.cs @@ -4,18 +4,18 @@ namespace Notion.Client { public class DividerUpdateBlock : IUpdateBlock { - public bool Archived { get; set; } + public DividerUpdateBlock() + { + Divider = new Info(); + } [JsonProperty("divider")] public Info Divider { get; set; } - public class Info - { - } + public bool Archived { get; set; } - public DividerUpdateBlock() + public class Info { - Divider = new Info(); } } } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableOfContentsUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableOfContentsUpdateBlock.cs index 36eee182..bef1f278 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableOfContentsUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableOfContentsUpdateBlock.cs @@ -4,18 +4,18 @@ namespace Notion.Client { public class TableOfContentsUpdateBlock : IUpdateBlock { - public bool Archived { get; set; } + public TableOfContentsUpdateBlock() + { + TableOfContents = new Info(); + } [JsonProperty("table_of_contents")] public Info TableOfContents { get; set; } - public class Info - { - } + public bool Archived { get; set; } - public TableOfContentsUpdateBlock() + public class Info { - TableOfContents = new Info(); } } } diff --git a/Src/Notion.Client/Api/Comments/Create/Request/CreateCommentParameters.cs b/Src/Notion.Client/Api/Comments/Create/Request/CreateCommentParameters.cs index aadaf1f1..3b676133 100644 --- a/Src/Notion.Client/Api/Comments/Create/Request/CreateCommentParameters.cs +++ b/Src/Notion.Client/Api/Comments/Create/Request/CreateCommentParameters.cs @@ -24,25 +24,23 @@ public interface ICreatePageCommentBodyParameters : ICreateCommentsBodyParameter public class CreateCommentParameters : ICreateDiscussionCommentBodyParameters, ICreatePageCommentBodyParameters { public string DiscussionId { get; set; } + public IEnumerable RichText { get; set; } + public ParentPageInput Parent { get; set; } - public static CreateCommentParameters CreatePageComment(ParentPageInput parent, IEnumerable richText) + public static CreateCommentParameters CreatePageComment( + ParentPageInput parent, + IEnumerable richText) { - return new CreateCommentParameters - { - Parent = parent, - RichText = richText - }; + return new CreateCommentParameters {Parent = parent, RichText = richText}; } - public static CreateCommentParameters CreateDiscussionComment(string discussionId, IEnumerable richText) + public static CreateCommentParameters CreateDiscussionComment( + string discussionId, + IEnumerable richText) { - return new CreateCommentParameters - { - DiscussionId = discussionId, - RichText = richText - }; + return new CreateCommentParameters {DiscussionId = discussionId, RichText = richText}; } } } diff --git a/Src/Notion.Client/Api/Comments/ICommentsClient.cs b/Src/Notion.Client/Api/Comments/ICommentsClient.cs index d936203c..871319da 100644 --- a/Src/Notion.Client/Api/Comments/ICommentsClient.cs +++ b/Src/Notion.Client/Api/Comments/ICommentsClient.cs @@ -5,10 +5,12 @@ namespace Notion.Client public interface ICommentsClient { /// - /// Retrieves a list of un-resolved Comment objects from a page or block. + /// Retrieves a list of un-resolved Comment objects from a page or block. /// /// Retrieve comments parameters - /// + /// + /// + /// Task Retrieve(RetrieveCommentsParameters retrieveCommentsParameters); Task Create(CreateCommentParameters createCommentParameters); diff --git a/Src/Notion.Client/Api/Comments/Retrieve/CommentsClient.cs b/Src/Notion.Client/Api/Comments/Retrieve/CommentsClient.cs index d228200c..b979086f 100644 --- a/Src/Notion.Client/Api/Comments/Retrieve/CommentsClient.cs +++ b/Src/Notion.Client/Api/Comments/Retrieve/CommentsClient.cs @@ -9,11 +9,9 @@ public async Task Retrieve(RetrieveCommentsParameters { var qp = (IRetrieveCommentsQueryParameters)parameters; - var queryParams = new Dictionary() + var queryParams = new Dictionary { - { "block_id", qp.BlockId }, - { "start_cursor", qp.StartCursor }, - { "page_size", qp.PageSize.ToString() }, + {"block_id", qp.BlockId}, {"start_cursor", qp.StartCursor}, {"page_size", qp.PageSize.ToString()}, }; return await _client.GetAsync( diff --git a/Src/Notion.Client/Api/Comments/Retrieve/Request/RetrieveCommentsParameters.cs b/Src/Notion.Client/Api/Comments/Retrieve/Request/RetrieveCommentsParameters.cs index e78c4cad..d42ec9e7 100644 --- a/Src/Notion.Client/Api/Comments/Retrieve/Request/RetrieveCommentsParameters.cs +++ b/Src/Notion.Client/Api/Comments/Retrieve/Request/RetrieveCommentsParameters.cs @@ -3,7 +3,9 @@ public class RetrieveCommentsParameters : IRetrieveCommentsQueryParameters { public string BlockId { get; set; } + public string StartCursor { get; set; } + public int? PageSize { get; set; } } } diff --git a/Src/Notion.Client/Api/Comments/Retrieve/Response/Comment.cs b/Src/Notion.Client/Api/Comments/Retrieve/Response/Comment.cs index 531fb43c..9b9ef2ae 100644 --- a/Src/Notion.Client/Api/Comments/Retrieve/Response/Comment.cs +++ b/Src/Notion.Client/Api/Comments/Retrieve/Response/Comment.cs @@ -6,10 +6,6 @@ namespace Notion.Client { public class Comment : IObject { - public string Id { get; set; } - - public ObjectType Object => ObjectType.Comment; - [JsonProperty("parent")] public ICommentParent Parent { get; set; } @@ -27,5 +23,9 @@ public class Comment : IObject [JsonProperty("last_edited_time")] public DateTime LastEditedTime { get; set; } + + public string Id { get; set; } + + public ObjectType Object => ObjectType.Comment; } } diff --git a/Src/Notion.Client/Api/Comments/Retrieve/Response/ICommentParent.cs b/Src/Notion.Client/Api/Comments/Retrieve/Response/ICommentParent.cs index e323c7e1..9e05d019 100644 --- a/Src/Notion.Client/Api/Comments/Retrieve/Response/ICommentParent.cs +++ b/Src/Notion.Client/Api/Comments/Retrieve/Response/ICommentParent.cs @@ -4,8 +4,8 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(PageParent), ParentType.PageId)] - [JsonSubtypes.KnownSubType(typeof(BlockParent), ParentType.BlockId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PageParent), ParentType.PageId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(BlockParent), ParentType.BlockId)] public interface ICommentParent { } diff --git a/Src/Notion.Client/Api/Databases/DatabasesClient.cs b/Src/Notion.Client/Api/Databases/DatabasesClient.cs index 2ab17a8b..5157dee9 100644 --- a/Src/Notion.Client/Api/Databases/DatabasesClient.cs +++ b/Src/Notion.Client/Api/Databases/DatabasesClient.cs @@ -17,7 +17,9 @@ public async Task RetrieveAsync(string databaseId) return await _client.GetAsync(DatabasesApiUrls.Retrieve(databaseId)); } - public async Task> QueryAsync(string databaseId, DatabasesQueryParameters databasesQueryParameters) + public async Task> QueryAsync( + string databaseId, + DatabasesQueryParameters databasesQueryParameters) { var body = (IDatabaseQueryBodyParameters)databasesQueryParameters; diff --git a/Src/Notion.Client/Api/Databases/IDatabasesClient.cs b/Src/Notion.Client/Api/Databases/IDatabasesClient.cs index 115ccfed..9c245ce3 100644 --- a/Src/Notion.Client/Api/Databases/IDatabasesClient.cs +++ b/Src/Notion.Client/Api/Databases/IDatabasesClient.cs @@ -5,35 +5,43 @@ namespace Notion.Client public interface IDatabasesClient { /// - /// Retrieves a Database object using the ID specified. + /// Retrieves a Database object using the ID specified. /// /// Identifier for a Notion database - /// + /// + /// + /// Task RetrieveAsync(string databaseId); /// - /// Gets a list of Pages contained in the database, filtered and ordered according to the - /// filter conditions and sort criteria provided in the request. The response may contain - /// fewer than page_size of results. + /// Gets a list of Pages contained in the database, filtered and ordered according to the + /// filter conditions and sort criteria provided in the request. The response may contain + /// fewer than page_size of results. /// /// /// - /// + /// + /// + /// Task> QueryAsync(string databaseId, DatabasesQueryParameters databasesQueryParameters); /// - /// Creates a database as a subpage in the specified parent page, with the specified properties schema. + /// Creates a database as a subpage in the specified parent page, with the specified properties schema. /// /// - /// + /// + /// + /// Task CreateAsync(DatabasesCreateParameters databasesCreateParameters); /// - /// Updates an existing database as specified by the parameters. + /// Updates an existing database as specified by the parameters. /// /// /// - /// + /// + /// + /// Task UpdateAsync(string databaseId, DatabasesUpdateParameters databasesUpdateParameters); } } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/DatabasesCreateParameters.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/DatabasesCreateParameters.cs index bafad0ec..9cb7086b 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/DatabasesCreateParameters.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/DatabasesCreateParameters.cs @@ -5,6 +5,12 @@ namespace Notion.Client { public class DatabasesCreateParameters : IDatabasesCreateBodyParameters, IDatabasesCreateQueryParameters { + [JsonProperty("icon")] + public IPageIcon Icon { get; set; } + + [JsonProperty("cover")] + public FileObject Cover { get; set; } + [JsonProperty("parent")] public ParentPageInput Parent { get; set; } @@ -14,12 +20,6 @@ public class DatabasesCreateParameters : IDatabasesCreateBodyParameters, IDataba [JsonProperty("title")] public List Title { get; set; } - [JsonProperty("icon")] - public IPageIcon Icon { get; set; } - - [JsonProperty("cover")] - public FileObject Cover { get; set; } - public bool? IsInline { get; set; } public List Description { get; set; } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesListParameters.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesListParameters.cs index 51136e47..922e54fc 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesListParameters.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesListParameters.cs @@ -3,6 +3,7 @@ public class DatabasesListParameters : IDatabasesListQueryParmaters { public string StartCursor { get; set; } + public int? PageSize { get; set; } } } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesQueryParameters.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesQueryParameters.cs index 454961a2..51bd8a06 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesQueryParameters.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesQueryParameters.cs @@ -5,8 +5,11 @@ namespace Notion.Client public class DatabasesQueryParameters : IDatabaseQueryBodyParameters { public Filter Filter { get; set; } + public List Sorts { get; set; } + public string StartCursor { get; set; } + public int? PageSize { get; set; } } } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs index b9cb182e..41da2d17 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using Newtonsoft.Json; namespace Notion.Client { diff --git a/Src/Notion.Client/Api/Databases/RequestParams/Direction.cs b/Src/Notion.Client/Api/Databases/RequestParams/Direction.cs index c79d501d..76b87da3 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/Direction.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/Direction.cs @@ -11,6 +11,6 @@ public enum Direction Ascending, [EnumMember(Value = "descending")] - Descending + Descending, } } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/Timestamp.cs b/Src/Notion.Client/Api/Databases/RequestParams/Timestamp.cs index 334b8c22..4eb359d4 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/Timestamp.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/Timestamp.cs @@ -11,6 +11,6 @@ public enum Timestamp CreatedTime, [EnumMember(Value = "last_edited_time")] - LastEditedTime + LastEditedTime, } } diff --git a/Src/Notion.Client/Api/Pages/IPagesClient.cs b/Src/Notion.Client/Api/Pages/IPagesClient.cs index 90eac980..f6b8f94f 100644 --- a/Src/Notion.Client/Api/Pages/IPagesClient.cs +++ b/Src/Notion.Client/Api/Pages/IPagesClient.cs @@ -6,49 +6,58 @@ namespace Notion.Client public interface IPagesClient { /// - /// Creates a new page in the specified database or as a child of an existing page. - /// - /// If the parent is a database, the property values of the new page in the properties parameter must conform to the parent database's property schema. - /// - /// If the parent is a page, the only valid property is title. + /// Creates a new page in the specified database or as a child of an existing page. + /// If the parent is a database, the + /// property values of the + /// new page in the properties parameter must conform to the parent + /// database's property schema. + /// If the parent is a page, the only valid property is title. /// /// Create page parameters - /// Created object. + /// Created object. Task CreateAsync(PagesCreateParameters pagesCreateParameters); /// - /// Retrieves a Page object using the ID specified. + /// Retrieves a Page object using the ID specified. /// /// Identifier for a Notion page - /// + /// + /// + /// Task RetrieveAsync(string pageId); /// - /// Updates page property values for the specified page. - /// Note: Properties that are not set via the properties parameter will remain unchanged. + /// Updates page property values for the specified page. + /// Note: Properties that are not set via the properties parameter will remain unchanged. /// /// Identifier for a Notion page - /// Property values to update for this page. The keys are the names or IDs of the property and the values are property values. - /// Updated object + /// + /// Property values to update for this page. The keys are the names or IDs of the property + /// and the values are property values. + /// + /// Updated object Task UpdatePropertiesAsync( string pageId, - IDictionary updatedProperties - ); + IDictionary updatedProperties); /// - /// Updates page property values for the specified page. - /// Properties that are not set via the properties parameter will remain unchanged. + /// Updates page property values for the specified page. + /// Properties that are not set via the properties parameter will remain unchanged. /// /// Identifier for a Notion page /// Update property parameters - /// Updated object + /// Updated object Task UpdateAsync(string pageId, PagesUpdateParameters pagesUpdateParameters); /// - /// Retrieves a property_item object for a given pageId and propertyId. Depending on the property type, the object returned will either be a value or a paginated list of property item values. + /// Retrieves a property_item object for a given pageId and propertyId. Depending on the property type, the object + /// returned will either be a value or a paginated list of property item values. /// /// Property body and query parameters - /// - Task RetrievePagePropertyItem(RetrievePropertyItemParameters retrievePropertyItemParameters); + /// + /// + /// + Task RetrievePagePropertyItem( + RetrievePropertyItemParameters retrievePropertyItemParameters); } } diff --git a/Src/Notion.Client/Api/Pages/PagesClient.cs b/Src/Notion.Client/Api/Pages/PagesClient.cs index 5bce1904..b71f924f 100644 --- a/Src/Notion.Client/Api/Pages/PagesClient.cs +++ b/Src/Notion.Client/Api/Pages/PagesClient.cs @@ -15,11 +15,12 @@ public PagesClient(IRestClient client) } /// - /// Creates a new page in the specified database or as a child of an existing page. - /// - /// If the parent is a database, the property values of the new page in the properties parameter must conform to the parent database's property schema. - /// - /// If the parent is a page, the only valid property is title. + /// Creates a new page in the specified database or as a child of an existing page. + /// If the parent is a database, the + /// property values of the + /// new page in the properties parameter must conform to the parent + /// database's property schema. + /// If the parent is a page, the only valid property is title. /// /// Create page parameters /// Created page. @@ -48,20 +49,22 @@ public async Task CreateAsync(PagesCreateParameters pagesCreateParameters) public async Task RetrieveAsync(string pageId) { var url = PagesApiUrls.Retrieve(pageId); + return await _client.GetAsync(url); } - public async Task RetrievePagePropertyItem(RetrievePropertyItemParameters retrievePropertyItemParameters) + public async Task RetrievePagePropertyItem( + RetrievePropertyItemParameters retrievePropertyItemParameters) { var pathParameters = (IRetrievePropertyItemPathParameters)retrievePropertyItemParameters; var queryParameters = (IRetrievePropertyQueryParameters)retrievePropertyItemParameters; var url = PagesApiUrls.RetrievePropertyItem(pathParameters.PageId, pathParameters.PropertyId); - var queryParams = new Dictionary() + var queryParams = new Dictionary { - { "start_cursor", queryParameters?.StartCursor }, - { "page_size", queryParameters?.PageSize?.ToString() } + {"start_cursor", queryParameters?.StartCursor}, + {"page_size", queryParameters?.PageSize?.ToString()}, }; return await _client.GetAsync(url, queryParams); @@ -81,7 +84,7 @@ public async Task UpdatePropertiesAsync( IDictionary updatedProperties) { var url = PagesApiUrls.UpdateProperties(pageId); - var body = new UpdatePropertiesParameters { Properties = updatedProperties }; + var body = new UpdatePropertiesParameters {Properties = updatedProperties}; return await _client.PatchAsync(url, body); } diff --git a/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParameters.cs b/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParameters.cs index 52cb0a89..08572811 100644 --- a/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParameters.cs +++ b/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParameters.cs @@ -5,9 +5,13 @@ namespace Notion.Client public class PagesCreateParameters : IPagesCreateBodyParameters, IPagesCreateQueryParameters { public IPageParentInput Parent { get; set; } + public IDictionary Properties { get; set; } + public IList Children { get; set; } + public IPageIcon Icon { get; set; } + public FileObject Cover { get; set; } } } diff --git a/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParametersBuilder.cs b/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParametersBuilder.cs index b86a207a..7df2fe4c 100644 --- a/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParametersBuilder.cs +++ b/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParametersBuilder.cs @@ -4,11 +4,11 @@ namespace Notion.Client { public class PagesCreateParametersBuilder { - private IPageParentInput parent; - private readonly Dictionary properties = new Dictionary(); private readonly IList children = new List(); - private IPageIcon icon; + private readonly Dictionary properties = new(); private FileObject cover; + private IPageIcon icon; + private IPageParentInput parent; private PagesCreateParametersBuilder() { @@ -16,33 +16,34 @@ private PagesCreateParametersBuilder() public static PagesCreateParametersBuilder Create(IPageParentInput parent) { - return new PagesCreateParametersBuilder - { - parent = parent - }; + return new PagesCreateParametersBuilder {parent = parent}; } public PagesCreateParametersBuilder AddProperty(string nameOrId, PropertyValue value) { properties[nameOrId] = value; + return this; } public PagesCreateParametersBuilder AddPageContent(IBlock block) { children.Add(block); + return this; } public PagesCreateParametersBuilder SetIcon(IPageIcon pageIcon) { icon = pageIcon; + return this; } public PagesCreateParametersBuilder SetCover(FileObject pageCover) { cover = pageCover; + return this; } @@ -54,7 +55,7 @@ public PagesCreateParameters Build() Properties = properties, Children = children, Icon = icon, - Cover = cover + Cover = cover, }; } } diff --git a/Src/Notion.Client/Api/Pages/RequestParams/PagesUpdateParameters.cs b/Src/Notion.Client/Api/Pages/RequestParams/PagesUpdateParameters.cs index 40f06b12..742ef8dd 100644 --- a/Src/Notion.Client/Api/Pages/RequestParams/PagesUpdateParameters.cs +++ b/Src/Notion.Client/Api/Pages/RequestParams/PagesUpdateParameters.cs @@ -5,16 +5,16 @@ namespace Notion.Client { public class PagesUpdateParameters : IPagesUpdateBodyParameters { - [JsonProperty("archived")] - public bool Archived { get; set; } - - [JsonProperty("properties")] - public IDictionary Properties { get; set; } - [JsonProperty("icon")] public IPageIcon Icon { get; set; } [JsonProperty("cover")] public FileObject Cover { get; set; } + + [JsonProperty("archived")] + public bool Archived { get; set; } + + [JsonProperty("properties")] + public IDictionary Properties { get; set; } } } diff --git a/Src/Notion.Client/Api/Search/ISearchClient.cs b/Src/Notion.Client/Api/Search/ISearchClient.cs index 9eb487d5..8071db6d 100644 --- a/Src/Notion.Client/Api/Search/ISearchClient.cs +++ b/Src/Notion.Client/Api/Search/ISearchClient.cs @@ -5,12 +5,13 @@ namespace Notion.Client public interface ISearchClient { /// - /// Searches all original pages, databases, and child pages/databases that are shared with the integration. - /// - /// It will not return linked databases, since these duplicate their source databases. + /// Searches all original pages, databases, and child pages/databases that are shared with the integration. + /// It will not return linked databases, since these duplicate their source databases. /// /// Search filters and body parameters - /// + /// + /// + /// Task> SearchAsync(SearchParameters parameters); } } diff --git a/Src/Notion.Client/Api/Search/Parameters/SearchDirection.cs b/Src/Notion.Client/Api/Search/Parameters/SearchDirection.cs index fdac0b59..0bde8d23 100644 --- a/Src/Notion.Client/Api/Search/Parameters/SearchDirection.cs +++ b/Src/Notion.Client/Api/Search/Parameters/SearchDirection.cs @@ -8,6 +8,6 @@ public enum SearchDirection Ascending, [EnumMember(Value = "descending")] - Descending + Descending, } } diff --git a/Src/Notion.Client/Api/Search/Parameters/SearchFilter.cs b/Src/Notion.Client/Api/Search/Parameters/SearchFilter.cs index cc84a9a3..dbd5cf5f 100644 --- a/Src/Notion.Client/Api/Search/Parameters/SearchFilter.cs +++ b/Src/Notion.Client/Api/Search/Parameters/SearchFilter.cs @@ -7,6 +7,7 @@ public class SearchFilter { [JsonConverter(typeof(StringEnumConverter))] public SearchObjectType Value { get; set; } + public string Property => "object"; } } diff --git a/Src/Notion.Client/Api/Search/Parameters/SearchObjectType.cs b/Src/Notion.Client/Api/Search/Parameters/SearchObjectType.cs index 78a012df..773ef95a 100644 --- a/Src/Notion.Client/Api/Search/Parameters/SearchObjectType.cs +++ b/Src/Notion.Client/Api/Search/Parameters/SearchObjectType.cs @@ -8,6 +8,6 @@ public enum SearchObjectType Page, [EnumMember(Value = "database")] - Database + Database, } } diff --git a/Src/Notion.Client/Api/Search/Parameters/SearchParameters.cs b/Src/Notion.Client/Api/Search/Parameters/SearchParameters.cs index ae02c0f4..e1c8ced8 100644 --- a/Src/Notion.Client/Api/Search/Parameters/SearchParameters.cs +++ b/Src/Notion.Client/Api/Search/Parameters/SearchParameters.cs @@ -3,9 +3,13 @@ public class SearchParameters : ISearchBodyParameters { public string Query { get; set; } + public SearchSort Sort { get; set; } + public SearchFilter Filter { get; set; } + public string StartCursor { get; set; } + public int? PageSize { get; set; } } } diff --git a/Src/Notion.Client/Api/Users/IUsersClient.cs b/Src/Notion.Client/Api/Users/IUsersClient.cs index 41443678..69981022 100644 --- a/Src/Notion.Client/Api/Users/IUsersClient.cs +++ b/Src/Notion.Client/Api/Users/IUsersClient.cs @@ -5,24 +5,30 @@ namespace Notion.Client public interface IUsersClient { /// - /// Retrieves a User using the ID specified. + /// Retrieves a User using the ID specified. /// /// Identifier for a Notion user - /// + /// + /// + /// Task RetrieveAsync(string userId); /// - /// Returns a paginated list of Users for the workspace. - /// - /// The response may contain fewer than page_size of results. + /// Returns a paginated list of Users for the workspace. + /// The response may contain fewer than page_size of results. /// - /// + /// + /// + /// Task> ListAsync(); /// - /// Retrieves the bot User associated with the API token provided in the authorization header. + /// Retrieves the bot User associated with the API token provided in the authorization header. /// - /// object of type bot having an owner field with information about the person who authorized the integration. + /// + /// object of type bot having an owner field with information about the person who authorized + /// the integration. + /// Task MeAsync(); } } diff --git a/Src/Notion.Client/Api/Users/UsersClient.cs b/Src/Notion.Client/Api/Users/UsersClient.cs index 5c745f72..957ac45e 100644 --- a/Src/Notion.Client/Api/Users/UsersClient.cs +++ b/Src/Notion.Client/Api/Users/UsersClient.cs @@ -23,9 +23,12 @@ public async Task> ListAsync() } /// - /// Retrieves the bot User associated with the API token provided in the authorization header. + /// Retrieves the bot User associated with the API token provided in the authorization header. /// - /// User object of type bot having an owner field with information about the person who authorized the integration. + /// + /// User object of type bot having an owner field with information about the person who authorized the + /// integration. + /// public async Task MeAsync() { return await _client.GetAsync(UsersApiUrls.Me()); diff --git a/Src/Notion.Client/Constants.cs b/Src/Notion.Client/Constants.cs index 5034edae..072291e1 100644 --- a/Src/Notion.Client/Constants.cs +++ b/Src/Notion.Client/Constants.cs @@ -1,6 +1,7 @@ using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("Notion.UnitTests")] + namespace Notion.Client { internal class Constants diff --git a/Src/Notion.Client/DI/ServiceCollectionExtensions.cs b/Src/Notion.Client/DI/ServiceCollectionExtensions.cs index a4aed7fd..866dc92d 100644 --- a/Src/Notion.Client/DI/ServiceCollectionExtensions.cs +++ b/Src/Notion.Client/DI/ServiceCollectionExtensions.cs @@ -5,7 +5,9 @@ namespace Microsoft.Extensions.DependencyInjection { public static class ServiceCollectionExtensions { - public static IServiceCollection AddNotionClient(this IServiceCollection services, Action options) + public static IServiceCollection AddNotionClient( + this IServiceCollection services, + Action options) { services.AddSingleton(sp => { diff --git a/Src/Notion.Client/Extensions/EnumExtensions.cs b/Src/Notion.Client/Extensions/EnumExtensions.cs index 987104b8..cd60aebd 100644 --- a/Src/Notion.Client/Extensions/EnumExtensions.cs +++ b/Src/Notion.Client/Extensions/EnumExtensions.cs @@ -1,15 +1,18 @@ -using System.Linq; +using System; +using System.Linq; using System.Runtime.Serialization; namespace Notion.Client.Extensions { public static class EnumExtensions { - public static string GetEnumMemberValue(this T enumValue) where T : System.Enum + public static string GetEnumMemberValue(this T enumValue) where T : Enum { var enumType = typeof(T); var memInfo = enumType.GetMember(enumValue.ToString()); - var attr = memInfo.FirstOrDefault()?.GetCustomAttributes(false).OfType().FirstOrDefault(); + + var attr = memInfo.FirstOrDefault()?.GetCustomAttributes(false).OfType() + .FirstOrDefault(); if (attr != null) { diff --git a/Src/Notion.Client/Extensions/HttpResponseMessageExtensions.cs b/Src/Notion.Client/Extensions/HttpResponseMessageExtensions.cs index 9b01580d..b6a9396d 100644 --- a/Src/Notion.Client/Extensions/HttpResponseMessageExtensions.cs +++ b/Src/Notion.Client/Extensions/HttpResponseMessageExtensions.cs @@ -7,11 +7,13 @@ namespace Notion.Client.Extensions { internal static class HttpResponseMessageExtensions { - internal static async Task ParseStreamAsync(this HttpResponseMessage response, JsonSerializerSettings serializerSettings = null) + internal static async Task ParseStreamAsync( + this HttpResponseMessage response, + JsonSerializerSettings serializerSettings = null) { - using (Stream stream = await response.Content.ReadAsStreamAsync()) + using (var stream = await response.Content.ReadAsStreamAsync()) { - using (StreamReader streamReader = new StreamReader(stream)) + using (var streamReader = new StreamReader(stream)) { using (JsonReader jsonReader = new JsonTextReader(streamReader)) { diff --git a/Src/Notion.Client/Models/Blocks/AudioBlock.cs b/Src/Notion.Client/Models/Blocks/AudioBlock.cs index 040f346b..1ba1a4a3 100644 --- a/Src/Notion.Client/Models/Blocks/AudioBlock.cs +++ b/Src/Notion.Client/Models/Blocks/AudioBlock.cs @@ -4,9 +4,9 @@ namespace Notion.Client { public class AudioBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Audio; - [JsonProperty("audio")] public FileObject Audio { get; set; } + + public override BlockType Type => BlockType.Audio; } } diff --git a/Src/Notion.Client/Models/Blocks/Block.cs b/Src/Notion.Client/Models/Blocks/Block.cs index 81bcd6bb..883399df 100644 --- a/Src/Notion.Client/Models/Blocks/Block.cs +++ b/Src/Notion.Client/Models/Blocks/Block.cs @@ -21,7 +21,7 @@ public abstract class Block : IBlock public PartialUser LastEditedBy { get; set; } /// - /// Information about the block's parent. + /// Information about the block's parent. /// public IBlockParent Parent { get; set; } } diff --git a/Src/Notion.Client/Models/Blocks/BlockType.cs b/Src/Notion.Client/Models/Blocks/BlockType.cs index 8a2c626a..f15c3b37 100644 --- a/Src/Notion.Client/Models/Blocks/BlockType.cs +++ b/Src/Notion.Client/Models/Blocks/BlockType.cs @@ -101,6 +101,6 @@ public enum BlockType LinkPreview, [EnumMember(Value = "unsupported")] - Unsupported + Unsupported, } } diff --git a/Src/Notion.Client/Models/Blocks/BookmarkBlock.cs b/Src/Notion.Client/Models/Blocks/BookmarkBlock.cs index 735b1725..73099c82 100644 --- a/Src/Notion.Client/Models/Blocks/BookmarkBlock.cs +++ b/Src/Notion.Client/Models/Blocks/BookmarkBlock.cs @@ -5,11 +5,11 @@ namespace Notion.Client { public class BookmarkBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Bookmark; - [JsonProperty("bookmark")] public Info Bookmark { get; set; } + public override BlockType Type => BlockType.Bookmark; + public class Info { [JsonProperty("url")] diff --git a/Src/Notion.Client/Models/Blocks/BreadcrumbBlock.cs b/Src/Notion.Client/Models/Blocks/BreadcrumbBlock.cs index 73ae614d..d5585a40 100644 --- a/Src/Notion.Client/Models/Blocks/BreadcrumbBlock.cs +++ b/Src/Notion.Client/Models/Blocks/BreadcrumbBlock.cs @@ -4,11 +4,11 @@ namespace Notion.Client { public class BreadcrumbBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Breadcrumb; - [JsonProperty("breadcrumb")] public Data Breadcrumb { get; set; } + public override BlockType Type => BlockType.Breadcrumb; + public class Data { } diff --git a/Src/Notion.Client/Models/Blocks/BulletedListItemBlock.cs b/Src/Notion.Client/Models/Blocks/BulletedListItemBlock.cs index 7eca3397..c823b4bd 100644 --- a/Src/Notion.Client/Models/Blocks/BulletedListItemBlock.cs +++ b/Src/Notion.Client/Models/Blocks/BulletedListItemBlock.cs @@ -6,11 +6,11 @@ namespace Notion.Client { public class BulletedListItemBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.BulletedListItem; - [JsonProperty("bulleted_list_item")] public Info BulletedListItem { get; set; } + public override BlockType Type => BlockType.BulletedListItem; + public class Info { [JsonProperty("rich_text")] diff --git a/Src/Notion.Client/Models/Blocks/CalloutBlock.cs b/Src/Notion.Client/Models/Blocks/CalloutBlock.cs index 8cc4bb7a..d4ef61c4 100644 --- a/Src/Notion.Client/Models/Blocks/CalloutBlock.cs +++ b/Src/Notion.Client/Models/Blocks/CalloutBlock.cs @@ -6,11 +6,11 @@ namespace Notion.Client { public class CalloutBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Callout; - [JsonProperty("callout")] public Info Callout { get; set; } + public override BlockType Type => BlockType.Callout; + public class Info { [JsonProperty("rich_text")] diff --git a/Src/Notion.Client/Models/Blocks/ChildDatabaseBlock.cs b/Src/Notion.Client/Models/Blocks/ChildDatabaseBlock.cs index 273836a9..e56fcadb 100644 --- a/Src/Notion.Client/Models/Blocks/ChildDatabaseBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ChildDatabaseBlock.cs @@ -4,11 +4,11 @@ namespace Notion.Client { public class ChildDatabaseBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.ChildDatabase; - [JsonProperty("child_database")] public Info ChildDatabase { get; set; } + public override BlockType Type => BlockType.ChildDatabase; + public class Info { [JsonProperty("title")] diff --git a/Src/Notion.Client/Models/Blocks/ChildPageBlock.cs b/Src/Notion.Client/Models/Blocks/ChildPageBlock.cs index 91c8f343..216b0d82 100644 --- a/Src/Notion.Client/Models/Blocks/ChildPageBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ChildPageBlock.cs @@ -4,11 +4,11 @@ namespace Notion.Client { public class ChildPageBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.ChildPage; - [JsonProperty("child_page")] public Info ChildPage { get; set; } + public override BlockType Type => BlockType.ChildPage; + public class Info { [JsonProperty("title")] diff --git a/Src/Notion.Client/Models/Blocks/CodeBlock.cs b/Src/Notion.Client/Models/Blocks/CodeBlock.cs index 5eb1456b..9cb2c350 100644 --- a/Src/Notion.Client/Models/Blocks/CodeBlock.cs +++ b/Src/Notion.Client/Models/Blocks/CodeBlock.cs @@ -5,11 +5,11 @@ namespace Notion.Client { public class CodeBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Code; - [JsonProperty("code")] public Info Code { get; set; } + public override BlockType Type => BlockType.Code; + public class Info { [JsonProperty("rich_text")] diff --git a/Src/Notion.Client/Models/Blocks/ColumnListBlock.cs b/Src/Notion.Client/Models/Blocks/ColumnListBlock.cs index f86ecba0..59bd6245 100644 --- a/Src/Notion.Client/Models/Blocks/ColumnListBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ColumnListBlock.cs @@ -5,11 +5,11 @@ namespace Notion.Client { public class ColumnListBlock : Block, INonColumnBlock { - public override BlockType Type => BlockType.ColumnList; - [JsonProperty("column_list")] public Info ColumnList { get; set; } + public override BlockType Type => BlockType.ColumnList; + public class Info { [JsonProperty("children")] diff --git a/Src/Notion.Client/Models/Blocks/DividerBlock.cs b/Src/Notion.Client/Models/Blocks/DividerBlock.cs index 61e0301b..26c55783 100644 --- a/Src/Notion.Client/Models/Blocks/DividerBlock.cs +++ b/Src/Notion.Client/Models/Blocks/DividerBlock.cs @@ -4,11 +4,11 @@ namespace Notion.Client { public class DividerBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Divider; - [JsonProperty("divider")] public Data Divider { get; set; } + public override BlockType Type => BlockType.Divider; + public class Data { } diff --git a/Src/Notion.Client/Models/Blocks/EmbedBlock.cs b/Src/Notion.Client/Models/Blocks/EmbedBlock.cs index bbd93e10..92c1dfdd 100644 --- a/Src/Notion.Client/Models/Blocks/EmbedBlock.cs +++ b/Src/Notion.Client/Models/Blocks/EmbedBlock.cs @@ -5,11 +5,11 @@ namespace Notion.Client { public class EmbedBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Embed; - [JsonProperty("embed")] public Info Embed { get; set; } + public override BlockType Type => BlockType.Embed; + public class Info { [JsonProperty("url")] @@ -17,7 +17,6 @@ public class Info [JsonProperty("caption")] public IEnumerable Caption { get; set; } - } } } diff --git a/Src/Notion.Client/Models/Blocks/EquationBlock.cs b/Src/Notion.Client/Models/Blocks/EquationBlock.cs index 310a76df..411c4e3b 100644 --- a/Src/Notion.Client/Models/Blocks/EquationBlock.cs +++ b/Src/Notion.Client/Models/Blocks/EquationBlock.cs @@ -4,11 +4,11 @@ namespace Notion.Client { public class EquationBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Equation; - [JsonProperty("equation")] public Info Equation { get; set; } + public override BlockType Type => BlockType.Equation; + public class Info { [JsonProperty("expression")] diff --git a/Src/Notion.Client/Models/Blocks/FileBlock.cs b/Src/Notion.Client/Models/Blocks/FileBlock.cs index 5495e4bc..7749a693 100644 --- a/Src/Notion.Client/Models/Blocks/FileBlock.cs +++ b/Src/Notion.Client/Models/Blocks/FileBlock.cs @@ -4,9 +4,9 @@ namespace Notion.Client { public class FileBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.File; - [JsonProperty("file")] public FileObject File { get; set; } + + public override BlockType Type => BlockType.File; } } diff --git a/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs b/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs index 853f9ae5..aced5461 100644 --- a/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs +++ b/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs @@ -6,11 +6,11 @@ namespace Notion.Client { public class HeadingOneBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Heading_1; - [JsonProperty("heading_1")] public Info Heading_1 { get; set; } + public override BlockType Type => BlockType.Heading_1; + public override bool HasChildren => false; public class Info diff --git a/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs b/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs index 99d9b861..10999e0e 100644 --- a/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs +++ b/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs @@ -6,11 +6,11 @@ namespace Notion.Client { public class HeadingThreeeBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Heading_3; - [JsonProperty("heading_3")] public Info Heading_3 { get; set; } + public override BlockType Type => BlockType.Heading_3; + public override bool HasChildren => false; public class Info diff --git a/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs b/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs index ea074e8a..553d56f2 100644 --- a/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs +++ b/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs @@ -6,11 +6,11 @@ namespace Notion.Client { public class HeadingTwoBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Heading_2; - [JsonProperty("heading_2")] public Info Heading_2 { get; set; } + public override BlockType Type => BlockType.Heading_2; + public override bool HasChildren => false; public class Info diff --git a/Src/Notion.Client/Models/Blocks/IBlock.cs b/Src/Notion.Client/Models/Blocks/IBlock.cs index a09f923a..fcf5364d 100644 --- a/Src/Notion.Client/Models/Blocks/IBlock.cs +++ b/Src/Notion.Client/Models/Blocks/IBlock.cs @@ -5,38 +5,38 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(AudioBlock), BlockType.Audio)] - [JsonSubtypes.KnownSubType(typeof(BookmarkBlock), BlockType.Bookmark)] - [JsonSubtypes.KnownSubType(typeof(BreadcrumbBlock), BlockType.Breadcrumb)] - [JsonSubtypes.KnownSubType(typeof(BulletedListItemBlock), BlockType.BulletedListItem)] - [JsonSubtypes.KnownSubType(typeof(CalloutBlock), BlockType.Callout)] - [JsonSubtypes.KnownSubType(typeof(ChildPageBlock), BlockType.ChildPage)] - [JsonSubtypes.KnownSubType(typeof(ChildDatabaseBlock), BlockType.ChildDatabase)] - [JsonSubtypes.KnownSubType(typeof(CodeBlock), BlockType.Code)] - [JsonSubtypes.KnownSubType(typeof(ColumnBlock), BlockType.Column)] - [JsonSubtypes.KnownSubType(typeof(ColumnListBlock), BlockType.ColumnList)] - [JsonSubtypes.KnownSubType(typeof(DividerBlock), BlockType.Divider)] - [JsonSubtypes.KnownSubType(typeof(EmbedBlock), BlockType.Embed)] - [JsonSubtypes.KnownSubType(typeof(EquationBlock), BlockType.Equation)] - [JsonSubtypes.KnownSubType(typeof(FileBlock), BlockType.File)] - [JsonSubtypes.KnownSubType(typeof(HeadingOneBlock), BlockType.Heading_1)] - [JsonSubtypes.KnownSubType(typeof(HeadingTwoBlock), BlockType.Heading_2)] - [JsonSubtypes.KnownSubType(typeof(HeadingThreeeBlock), BlockType.Heading_3)] - [JsonSubtypes.KnownSubType(typeof(ImageBlock), BlockType.Image)] - [JsonSubtypes.KnownSubType(typeof(LinkPreviewBlock), BlockType.LinkPreview)] - [JsonSubtypes.KnownSubType(typeof(LinkToPageBlock), BlockType.LinkToPage)] - [JsonSubtypes.KnownSubType(typeof(NumberedListItemBlock), BlockType.NumberedListItem)] - [JsonSubtypes.KnownSubType(typeof(ParagraphBlock), BlockType.Paragraph)] - [JsonSubtypes.KnownSubType(typeof(PDFBlock), BlockType.PDF)] - [JsonSubtypes.KnownSubType(typeof(QuoteBlock), BlockType.Quote)] - [JsonSubtypes.KnownSubType(typeof(TableBlock), BlockType.Table)] - [JsonSubtypes.KnownSubType(typeof(TableRowBlock), BlockType.TableRow)] - [JsonSubtypes.KnownSubType(typeof(TableOfContentsBlock), BlockType.TableOfContents)] - [JsonSubtypes.KnownSubType(typeof(TemplateBlock), BlockType.Template)] - [JsonSubtypes.KnownSubType(typeof(ToDoBlock), BlockType.ToDo)] - [JsonSubtypes.KnownSubType(typeof(ToggleBlock), BlockType.Toggle)] - [JsonSubtypes.KnownSubType(typeof(VideoBlock), BlockType.Video)] - [JsonSubtypes.KnownSubType(typeof(UnsupportedBlock), BlockType.Unsupported)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(AudioBlock), BlockType.Audio)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(BookmarkBlock), BlockType.Bookmark)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(BreadcrumbBlock), BlockType.Breadcrumb)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(BulletedListItemBlock), BlockType.BulletedListItem)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CalloutBlock), BlockType.Callout)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ChildPageBlock), BlockType.ChildPage)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ChildDatabaseBlock), BlockType.ChildDatabase)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CodeBlock), BlockType.Code)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ColumnBlock), BlockType.Column)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ColumnListBlock), BlockType.ColumnList)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(DividerBlock), BlockType.Divider)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(EmbedBlock), BlockType.Embed)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(EquationBlock), BlockType.Equation)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(FileBlock), BlockType.File)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(HeadingOneBlock), BlockType.Heading_1)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(HeadingTwoBlock), BlockType.Heading_2)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(HeadingThreeeBlock), BlockType.Heading_3)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ImageBlock), BlockType.Image)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(LinkPreviewBlock), BlockType.LinkPreview)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(LinkToPageBlock), BlockType.LinkToPage)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(NumberedListItemBlock), BlockType.NumberedListItem)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ParagraphBlock), BlockType.Paragraph)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PDFBlock), BlockType.PDF)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(QuoteBlock), BlockType.Quote)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(TableBlock), BlockType.Table)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(TableRowBlock), BlockType.TableRow)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(TableOfContentsBlock), BlockType.TableOfContents)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(TemplateBlock), BlockType.Template)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ToDoBlock), BlockType.ToDo)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ToggleBlock), BlockType.Toggle)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(VideoBlock), BlockType.Video)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(UnsupportedBlock), BlockType.Unsupported)] public interface IBlock : IObject, IObjectModificationData { [JsonProperty("type")] diff --git a/Src/Notion.Client/Models/Blocks/IBlockParent.cs b/Src/Notion.Client/Models/Blocks/IBlockParent.cs index 73634400..b2f8783f 100644 --- a/Src/Notion.Client/Models/Blocks/IBlockParent.cs +++ b/Src/Notion.Client/Models/Blocks/IBlockParent.cs @@ -4,10 +4,10 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(DatabaseParent), ParentType.DatabaseId)] - [JsonSubtypes.KnownSubType(typeof(PageParent), ParentType.PageId)] - [JsonSubtypes.KnownSubType(typeof(WorkspaceParent), ParentType.Workspace)] - [JsonSubtypes.KnownSubType(typeof(BlockParent), ParentType.BlockId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(DatabaseParent), ParentType.DatabaseId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PageParent), ParentType.PageId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(WorkspaceParent), ParentType.Workspace)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(BlockParent), ParentType.BlockId)] public interface IBlockParent : IParent { } diff --git a/Src/Notion.Client/Models/Blocks/ImageBlock.cs b/Src/Notion.Client/Models/Blocks/ImageBlock.cs index 17aa6bae..cd6b055f 100644 --- a/Src/Notion.Client/Models/Blocks/ImageBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ImageBlock.cs @@ -4,9 +4,9 @@ namespace Notion.Client { public class ImageBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Image; - [JsonProperty("image")] public FileObject Image { get; set; } + + public override BlockType Type => BlockType.Image; } } diff --git a/Src/Notion.Client/Models/Blocks/LinkPreviewBlock.cs b/Src/Notion.Client/Models/Blocks/LinkPreviewBlock.cs index 83f138c6..72107e48 100644 --- a/Src/Notion.Client/Models/Blocks/LinkPreviewBlock.cs +++ b/Src/Notion.Client/Models/Blocks/LinkPreviewBlock.cs @@ -4,13 +4,15 @@ namespace Notion.Client { public class LinkPreviewBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.LinkPreview; + [JsonProperty("link_preview")] + public Data LinkPreview { get; set; } - [JsonProperty("link_preview")] public Data LinkPreview { get; set; } + public override BlockType Type => BlockType.LinkPreview; public class Data { - [JsonProperty("url")] public string Url { get; set; } + [JsonProperty("url")] + public string Url { get; set; } } } } diff --git a/Src/Notion.Client/Models/Blocks/LinkToPageBlock.cs b/Src/Notion.Client/Models/Blocks/LinkToPageBlock.cs index 30d3d7dd..ad688ca2 100644 --- a/Src/Notion.Client/Models/Blocks/LinkToPageBlock.cs +++ b/Src/Notion.Client/Models/Blocks/LinkToPageBlock.cs @@ -4,9 +4,9 @@ namespace Notion.Client { public class LinkToPageBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.LinkToPage; - [JsonProperty("link_to_page")] public IPageParent LinkToPage { get; set; } + + public override BlockType Type => BlockType.LinkToPage; } } diff --git a/Src/Notion.Client/Models/Blocks/NumberedListItemBlock.cs b/Src/Notion.Client/Models/Blocks/NumberedListItemBlock.cs index 3fe0d76a..f4a645e9 100644 --- a/Src/Notion.Client/Models/Blocks/NumberedListItemBlock.cs +++ b/Src/Notion.Client/Models/Blocks/NumberedListItemBlock.cs @@ -6,11 +6,11 @@ namespace Notion.Client { public class NumberedListItemBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.NumberedListItem; - [JsonProperty("numbered_list_item")] public Info NumberedListItem { get; set; } + public override BlockType Type => BlockType.NumberedListItem; + public class Info { [JsonProperty("rich_text")] diff --git a/Src/Notion.Client/Models/Blocks/PDFBlock.cs b/Src/Notion.Client/Models/Blocks/PDFBlock.cs index 85458796..55e3ce42 100644 --- a/Src/Notion.Client/Models/Blocks/PDFBlock.cs +++ b/Src/Notion.Client/Models/Blocks/PDFBlock.cs @@ -4,9 +4,9 @@ namespace Notion.Client { public class PDFBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.PDF; - [JsonProperty("pdf")] public FileObject PDF { get; set; } + + public override BlockType Type => BlockType.PDF; } } diff --git a/Src/Notion.Client/Models/Blocks/ParagraphBlock.cs b/Src/Notion.Client/Models/Blocks/ParagraphBlock.cs index 67458b3c..f3b73f36 100644 --- a/Src/Notion.Client/Models/Blocks/ParagraphBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ParagraphBlock.cs @@ -6,11 +6,11 @@ namespace Notion.Client { public class ParagraphBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Paragraph; - [JsonProperty("paragraph")] public Info Paragraph { get; set; } + public override BlockType Type => BlockType.Paragraph; + public class Info { [JsonProperty("rich_text")] diff --git a/Src/Notion.Client/Models/Blocks/QuoteBlock.cs b/Src/Notion.Client/Models/Blocks/QuoteBlock.cs index 5fdad7da..e1466be6 100644 --- a/Src/Notion.Client/Models/Blocks/QuoteBlock.cs +++ b/Src/Notion.Client/Models/Blocks/QuoteBlock.cs @@ -6,11 +6,11 @@ namespace Notion.Client { public class QuoteBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Quote; - [JsonProperty("quote")] public Info Quote { get; set; } + public override BlockType Type => BlockType.Quote; + public class Info { [JsonProperty("rich_text")] diff --git a/Src/Notion.Client/Models/Blocks/SyncedBlockBlock.cs b/Src/Notion.Client/Models/Blocks/SyncedBlockBlock.cs index 33c4dd25..98aa1d0f 100644 --- a/Src/Notion.Client/Models/Blocks/SyncedBlockBlock.cs +++ b/Src/Notion.Client/Models/Blocks/SyncedBlockBlock.cs @@ -5,11 +5,11 @@ namespace Notion.Client { public class SyncedBlockBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.SyncedBlock; - [JsonProperty("synced_block")] public Data SyncedBlock { get; set; } + public override BlockType Type => BlockType.SyncedBlock; + public class Data { [JsonProperty("synced_from")] diff --git a/Src/Notion.Client/Models/Blocks/TableBlock.cs b/Src/Notion.Client/Models/Blocks/TableBlock.cs index dd20d94b..cf41440c 100644 --- a/Src/Notion.Client/Models/Blocks/TableBlock.cs +++ b/Src/Notion.Client/Models/Blocks/TableBlock.cs @@ -4,11 +4,11 @@ namespace Notion.Client { public class TableBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Table; - [JsonProperty("table")] public TableInfo Table { get; set; } + public override BlockType Type => BlockType.Table; + public class TableInfo { [JsonProperty("table_width")] diff --git a/Src/Notion.Client/Models/Blocks/TableOfContentsBlock.cs b/Src/Notion.Client/Models/Blocks/TableOfContentsBlock.cs index 991ff903..0a6c9f26 100644 --- a/Src/Notion.Client/Models/Blocks/TableOfContentsBlock.cs +++ b/Src/Notion.Client/Models/Blocks/TableOfContentsBlock.cs @@ -5,11 +5,11 @@ namespace Notion.Client { public class TableOfContentsBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.TableOfContents; - [JsonProperty("table_of_contents")] public Data TableOfContents { get; set; } + public override BlockType Type => BlockType.TableOfContents; + public class Data { [JsonProperty("color")] diff --git a/Src/Notion.Client/Models/Blocks/TableRowBlock.cs b/Src/Notion.Client/Models/Blocks/TableRowBlock.cs index e7214e6c..be105447 100644 --- a/Src/Notion.Client/Models/Blocks/TableRowBlock.cs +++ b/Src/Notion.Client/Models/Blocks/TableRowBlock.cs @@ -5,11 +5,11 @@ namespace Notion.Client { public class TableRowBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.TableRow; - [JsonProperty("table_row")] public Info TableRow { get; set; } + public override BlockType Type => BlockType.TableRow; + public class Info { [JsonProperty("cells")] diff --git a/Src/Notion.Client/Models/Blocks/TemplateBlock.cs b/Src/Notion.Client/Models/Blocks/TemplateBlock.cs index 69a78b62..705eaac3 100644 --- a/Src/Notion.Client/Models/Blocks/TemplateBlock.cs +++ b/Src/Notion.Client/Models/Blocks/TemplateBlock.cs @@ -5,11 +5,11 @@ namespace Notion.Client { public class TemplateBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Template; - [JsonProperty("template")] public Data Template { get; set; } + public override BlockType Type => BlockType.Template; + public class Data { [JsonProperty("rich_text")] diff --git a/Src/Notion.Client/Models/Blocks/ToDoBlock.cs b/Src/Notion.Client/Models/Blocks/ToDoBlock.cs index 8b153f3b..0c52201a 100644 --- a/Src/Notion.Client/Models/Blocks/ToDoBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ToDoBlock.cs @@ -6,11 +6,11 @@ namespace Notion.Client { public class ToDoBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.ToDo; - [JsonProperty("to_do")] public Info ToDo { get; set; } + public override BlockType Type => BlockType.ToDo; + public class Info { [JsonProperty("rich_text")] diff --git a/Src/Notion.Client/Models/Blocks/ToggleBlock.cs b/Src/Notion.Client/Models/Blocks/ToggleBlock.cs index 6646e9be..f61a1368 100644 --- a/Src/Notion.Client/Models/Blocks/ToggleBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ToggleBlock.cs @@ -6,11 +6,11 @@ namespace Notion.Client { public class ToggleBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Toggle; - [JsonProperty("toggle")] public Info Toggle { get; set; } + public override BlockType Type => BlockType.Toggle; + public class Info { [JsonProperty("rich_text")] diff --git a/Src/Notion.Client/Models/Blocks/VideoBlock.cs b/Src/Notion.Client/Models/Blocks/VideoBlock.cs index 015bed96..7713ff7b 100644 --- a/Src/Notion.Client/Models/Blocks/VideoBlock.cs +++ b/Src/Notion.Client/Models/Blocks/VideoBlock.cs @@ -4,9 +4,9 @@ namespace Notion.Client { public class VideoBlock : Block, IColumnChildrenBlock, INonColumnBlock { - public override BlockType Type => BlockType.Video; - [JsonProperty("video")] public FileObject Video { get; set; } + + public override BlockType Type => BlockType.Video; } } diff --git a/Src/Notion.Client/Models/Common/IObjectModificationData.cs b/Src/Notion.Client/Models/Common/IObjectModificationData.cs index 06177ccd..0e70ffcf 100644 --- a/Src/Notion.Client/Models/Common/IObjectModificationData.cs +++ b/Src/Notion.Client/Models/Common/IObjectModificationData.cs @@ -6,25 +6,25 @@ namespace Notion.Client public interface IObjectModificationData { /// - /// Date and time when this object was created. + /// Date and time when this object was created. /// [JsonProperty("created_time")] DateTime CreatedTime { get; set; } /// - /// Date and time when this object was updated. + /// Date and time when this object was updated. /// [JsonProperty("last_edited_time")] DateTime LastEditedTime { get; set; } /// - /// User who created the object. + /// User who created the object. /// [JsonProperty("created_by")] PartialUser CreatedBy { get; set; } /// - /// User who last modified the object. + /// User who last modified the object. /// [JsonProperty("last_edited_by")] PartialUser LastEditedBy { get; set; } diff --git a/Src/Notion.Client/Models/Database/Database.cs b/Src/Notion.Client/Models/Database/Database.cs index 502d8a5a..33da29b7 100644 --- a/Src/Notion.Client/Models/Database/Database.cs +++ b/Src/Notion.Client/Models/Database/Database.cs @@ -6,16 +6,6 @@ namespace Notion.Client { public class Database : IObject, IObjectModificationData { - public ObjectType Object => ObjectType.Database; - - public string Id { get; set; } - - [JsonProperty("created_time")] - public DateTime CreatedTime { get; set; } - - [JsonProperty("last_edited_time")] - public DateTime LastEditedTime { get; set; } - [JsonProperty("title")] public List Title { get; set; } @@ -32,25 +22,35 @@ public class Database : IObject, IObjectModificationData public FileObject Cover { get; set; } /// - /// The URL of the Notion database. + /// The URL of the Notion database. /// [JsonProperty("url")] public string Url { get; set; } /// - /// The archived status of the database. + /// The archived status of the database. /// [JsonProperty("archived")] public bool Archived { get; set; } - public PartialUser CreatedBy { get; set; } - - public PartialUser LastEditedBy { get; set; } - [JsonProperty("is_inline")] public bool IsInline { get; set; } [JsonProperty("description")] public IEnumerable Description { get; set; } + + public ObjectType Object => ObjectType.Database; + + public string Id { get; set; } + + [JsonProperty("created_time")] + public DateTime CreatedTime { get; set; } + + [JsonProperty("last_edited_time")] + public DateTime LastEditedTime { get; set; } + + public PartialUser CreatedBy { get; set; } + + public PartialUser LastEditedBy { get; set; } } } diff --git a/Src/Notion.Client/Models/Database/IDatabaseParent.cs b/Src/Notion.Client/Models/Database/IDatabaseParent.cs index 59233c38..768f815b 100644 --- a/Src/Notion.Client/Models/Database/IDatabaseParent.cs +++ b/Src/Notion.Client/Models/Database/IDatabaseParent.cs @@ -4,9 +4,9 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(PageParent), ParentType.PageId)] - [JsonSubtypes.KnownSubType(typeof(WorkspaceParent), ParentType.Workspace)] - [JsonSubtypes.KnownSubType(typeof(BlockParent), ParentType.BlockId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PageParent), ParentType.PageId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(WorkspaceParent), ParentType.Workspace)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(BlockParent), ParentType.BlockId)] public interface IDatabaseParent : IParent { } diff --git a/Src/Notion.Client/Models/Database/Properties/Property.cs b/Src/Notion.Client/Models/Database/Properties/Property.cs index 1f61b0dc..163b7ef0 100644 --- a/Src/Notion.Client/Models/Database/Properties/Property.cs +++ b/Src/Notion.Client/Models/Database/Properties/Property.cs @@ -5,26 +5,26 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(CheckboxProperty), PropertyType.Checkbox)] - [JsonSubtypes.KnownSubType(typeof(CreatedByProperty), PropertyType.CreatedBy)] - [JsonSubtypes.KnownSubType(typeof(CreatedTimeProperty), PropertyType.CreatedTime)] - [JsonSubtypes.KnownSubType(typeof(DateProperty), PropertyType.Date)] - [JsonSubtypes.KnownSubType(typeof(EmailProperty), PropertyType.Email)] - [JsonSubtypes.KnownSubType(typeof(FilesProperty), PropertyType.Files)] - [JsonSubtypes.KnownSubType(typeof(FormulaProperty), PropertyType.Formula)] - [JsonSubtypes.KnownSubType(typeof(LastEditedByProperty), PropertyType.LastEditedBy)] - [JsonSubtypes.KnownSubType(typeof(LastEditedTimeProperty), PropertyType.LastEditedTime)] - [JsonSubtypes.KnownSubType(typeof(MultiSelectProperty), PropertyType.MultiSelect)] - [JsonSubtypes.KnownSubType(typeof(NumberProperty), PropertyType.Number)] - [JsonSubtypes.KnownSubType(typeof(PeopleProperty), PropertyType.People)] - [JsonSubtypes.KnownSubType(typeof(PhoneNumberProperty), PropertyType.PhoneNumber)] - [JsonSubtypes.KnownSubType(typeof(RelationProperty), PropertyType.Relation)] - [JsonSubtypes.KnownSubType(typeof(RichTextProperty), PropertyType.RichText)] - [JsonSubtypes.KnownSubType(typeof(RollupProperty), PropertyType.Rollup)] - [JsonSubtypes.KnownSubType(typeof(SelectProperty), PropertyType.Select)] - [JsonSubtypes.KnownSubType(typeof(StatusProperty), PropertyType.Status)] - [JsonSubtypes.KnownSubType(typeof(TitleProperty), PropertyType.Title)] - [JsonSubtypes.KnownSubType(typeof(UrlProperty), PropertyType.Url)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CheckboxProperty), PropertyType.Checkbox)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CreatedByProperty), PropertyType.CreatedBy)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CreatedTimeProperty), PropertyType.CreatedTime)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(DateProperty), PropertyType.Date)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(EmailProperty), PropertyType.Email)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(FilesProperty), PropertyType.Files)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(FormulaProperty), PropertyType.Formula)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(LastEditedByProperty), PropertyType.LastEditedBy)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(LastEditedTimeProperty), PropertyType.LastEditedTime)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(MultiSelectProperty), PropertyType.MultiSelect)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(NumberProperty), PropertyType.Number)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PeopleProperty), PropertyType.People)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PhoneNumberProperty), PropertyType.PhoneNumber)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RelationProperty), PropertyType.Relation)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RichTextProperty), PropertyType.RichText)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RollupProperty), PropertyType.Rollup)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(SelectProperty), PropertyType.Select)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(StatusProperty), PropertyType.Status)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(TitleProperty), PropertyType.Title)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(UrlProperty), PropertyType.Url)] public class Property { [JsonProperty("id")] diff --git a/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationData.cs b/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationData.cs index 87e4b10a..d129acc6 100644 --- a/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationData.cs +++ b/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationData.cs @@ -5,8 +5,8 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(SinglePropertyRelation), RelationType.Single)] - [JsonSubtypes.KnownSubType(typeof(DualPropertyRelation), RelationType.Dual)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(SinglePropertyRelation), RelationType.Single)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(DualPropertyRelation), RelationType.Dual)] public abstract class RelationData { [JsonProperty("database_id")] diff --git a/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationProperty.cs b/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationProperty.cs index 103cdc0c..382e7088 100644 --- a/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationProperty.cs +++ b/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationProperty.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; -using System.Runtime.Serialization; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Notion.Client { diff --git a/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationType.cs b/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationType.cs index 89ce1c56..a0a58a47 100644 --- a/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationType.cs +++ b/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationType.cs @@ -8,6 +8,6 @@ public enum RelationType Single, [EnumMember(Value = "dual_property")] - Dual + Dual, } } diff --git a/Src/Notion.Client/Models/Database/Properties/SelectProperty.cs b/Src/Notion.Client/Models/Database/Properties/SelectProperty.cs index 3ed99234..9af6397b 100644 --- a/Src/Notion.Client/Models/Database/Properties/SelectProperty.cs +++ b/Src/Notion.Client/Models/Database/Properties/SelectProperty.cs @@ -7,6 +7,7 @@ namespace Notion.Client public class SelectProperty : Property { public override PropertyType Type => PropertyType.Select; + public OptionWrapper Select { get; set; } } @@ -19,19 +20,20 @@ public class OptionWrapper public class SelectOption { /// - /// Name of the option as it appears in Notion. + /// Name of the option as it appears in Notion. /// [JsonProperty("name")] public string Name { get; set; } /// - /// ID of the option. + /// ID of the option. /// [JsonProperty("id")] public string Id { get; set; } /// - /// Color of the option. Possible values are: "default", "gray", "brown", "red", "orange", "yellow", "green", "blue", "purple", "pink". Defaults to "default". + /// Color of the option. Possible values are: "default", "gray", "brown", "red", "orange", "yellow", "green", "blue", + /// "purple", "pink". Defaults to "default". /// [JsonProperty("color")] [JsonConverter(typeof(StringEnumConverter))] diff --git a/Src/Notion.Client/Models/Database/RichText/RichTextBase.cs b/Src/Notion.Client/Models/Database/RichText/RichTextBase.cs index 88af1acd..3f10d578 100644 --- a/Src/Notion.Client/Models/Database/RichText/RichTextBase.cs +++ b/Src/Notion.Client/Models/Database/RichText/RichTextBase.cs @@ -5,9 +5,9 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(RichTextText), RichTextType.Text)] - [JsonSubtypes.KnownSubType(typeof(RichTextEquation), RichTextType.Equation)] - [JsonSubtypes.KnownSubType(typeof(RichTextMention), RichTextType.Mention)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RichTextText), RichTextType.Text)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RichTextEquation), RichTextType.Equation)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RichTextMention), RichTextType.Mention)] public class RichTextBase { [JsonProperty("plain_text")] diff --git a/Src/Notion.Client/Models/Database/RichText/RichTextType.cs b/Src/Notion.Client/Models/Database/RichText/RichTextType.cs index 59bc414f..58406612 100644 --- a/Src/Notion.Client/Models/Database/RichText/RichTextType.cs +++ b/Src/Notion.Client/Models/Database/RichText/RichTextType.cs @@ -14,6 +14,6 @@ public enum RichTextType Mention, [EnumMember(Value = "equation")] - Equation + Equation, } } diff --git a/Src/Notion.Client/Models/EmojiObject.cs b/Src/Notion.Client/Models/EmojiObject.cs index 95c67b61..9b5c64df 100644 --- a/Src/Notion.Client/Models/EmojiObject.cs +++ b/Src/Notion.Client/Models/EmojiObject.cs @@ -4,10 +4,10 @@ namespace Notion.Client { public class EmojiObject : IPageIcon { - [JsonProperty("type")] - public string Type { get; set; } - [JsonProperty("emoji")] public string Emoji { get; set; } + + [JsonProperty("type")] + public string Type { get; set; } } } diff --git a/Src/Notion.Client/Models/File/FileObject.cs b/Src/Notion.Client/Models/File/FileObject.cs index ce4d02f0..9ed206de 100644 --- a/Src/Notion.Client/Models/File/FileObject.cs +++ b/Src/Notion.Client/Models/File/FileObject.cs @@ -5,14 +5,14 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(UploadedFile), "file")] - [JsonSubtypes.KnownSubType(typeof(ExternalFile), "external")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(UploadedFile), "file")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ExternalFile), "external")] public abstract class FileObject : IPageIcon { - [JsonProperty("type")] - public virtual string Type { get; set; } - [JsonProperty("caption")] public IEnumerable Caption { get; set; } + + [JsonProperty("type")] + public virtual string Type { get; set; } } } diff --git a/Src/Notion.Client/Models/File/FileObjectWithName.cs b/Src/Notion.Client/Models/File/FileObjectWithName.cs index a7381929..855a5e0f 100644 --- a/Src/Notion.Client/Models/File/FileObjectWithName.cs +++ b/Src/Notion.Client/Models/File/FileObjectWithName.cs @@ -4,8 +4,8 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(UploadedFileWithName), "file")] - [JsonSubtypes.KnownSubType(typeof(ExternalFileWithName), "external")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(UploadedFileWithName), "file")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ExternalFileWithName), "external")] public abstract class FileObjectWithName { [JsonProperty("type")] diff --git a/Src/Notion.Client/Models/Filters/CheckboxFilter.cs b/Src/Notion.Client/Models/Filters/CheckboxFilter.cs index da144aec..53343e35 100644 --- a/Src/Notion.Client/Models/Filters/CheckboxFilter.cs +++ b/Src/Notion.Client/Models/Filters/CheckboxFilter.cs @@ -1,35 +1,34 @@ -using System; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Notion.Client { public class CheckboxFilter : SinglePropertyFilter, IRollupSubPropertyFilter { - [JsonProperty("checkbox")] - public Condition Checkbox { get; set; } - public CheckboxFilter( string propertyName, bool? equal = null, bool? doesNotEqual = null) { Property = propertyName; - Checkbox = new Condition(equal: equal, doesNotEqual: doesNotEqual); + Checkbox = new Condition(equal, doesNotEqual); } + [JsonProperty("checkbox")] + public Condition Checkbox { get; set; } + public class Condition { + public Condition(bool? equal = null, bool? doesNotEqual = null) + { + Equal = equal; + DoesNotEqual = doesNotEqual; + } + [JsonProperty("equals")] public bool? Equal { get; set; } [JsonProperty("does_not_equal")] public bool? DoesNotEqual { get; set; } - - public Condition(Nullable equal = null, Nullable doesNotEqual = null) - { - Equal = equal; - DoesNotEqual = doesNotEqual; - } } } } diff --git a/Src/Notion.Client/Models/Filters/DateFilter.cs b/Src/Notion.Client/Models/Filters/DateFilter.cs index 51b38dc2..dde7ad47 100644 --- a/Src/Notion.Client/Models/Filters/DateFilter.cs +++ b/Src/Notion.Client/Models/Filters/DateFilter.cs @@ -7,9 +7,6 @@ namespace Notion.Client { public class DateFilter : SinglePropertyFilter, IRollupSubPropertyFilter { - [JsonProperty("date")] - public Condition Date { get; set; } - public DateFilter( string propertyName, DateTime? equal = null, @@ -27,25 +24,59 @@ public DateFilter( bool? isNotEmpty = null) { Property = propertyName; + Date = new Condition( - equal: equal, - before: before, - after: after, - onOrBefore: onOrBefore, - onOrAfter: onOrAfter, - pastWeek: pastWeek, - pastMonth: pastMonth, - pastYear: pastYear, - nextWeek: nextWeek, - nextMonth: nextMonth, - nextYear: nextYear, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + before, + after, + onOrBefore, + onOrAfter, + pastWeek, + pastMonth, + pastYear, + nextWeek, + nextMonth, + nextYear, + isEmpty, + isNotEmpty ); } + [JsonProperty("date")] + public Condition Date { get; set; } + public class Condition { + public Condition( + DateTime? equal = null, + DateTime? before = null, + DateTime? after = null, + DateTime? onOrBefore = null, + DateTime? onOrAfter = null, + Dictionary pastWeek = null, + Dictionary pastMonth = null, + Dictionary pastYear = null, + Dictionary nextWeek = null, + Dictionary nextMonth = null, + Dictionary nextYear = null, + bool? isEmpty = null, + bool? isNotEmpty = null) + { + Equal = equal; + Before = before; + After = after; + OnOrBefore = onOrBefore; + OnOrAfter = onOrAfter; + PastWeek = pastWeek; + PastMonth = pastMonth; + PastYear = pastYear; + NextWeek = nextWeek; + NextMonth = nextMonth; + NextYear = nextYear; + IsEmpty = isEmpty; + IsNotEmpty = isNotEmpty; + } + [JsonProperty("equals")] [JsonConverter(typeof(IsoDateTimeConverter))] public DateTime? Equal { get; set; } @@ -89,36 +120,6 @@ public class Condition [JsonProperty("is_not_empty")] public bool? IsNotEmpty { get; set; } - - public Condition( - DateTime? equal = null, - DateTime? before = null, - DateTime? after = null, - DateTime? onOrBefore = null, - DateTime? onOrAfter = null, - Dictionary pastWeek = null, - Dictionary pastMonth = null, - Dictionary pastYear = null, - Dictionary nextWeek = null, - Dictionary nextMonth = null, - Dictionary nextYear = null, - bool? isEmpty = null, - bool? isNotEmpty = null) - { - Equal = equal; - Before = before; - After = after; - OnOrBefore = onOrBefore; - OnOrAfter = onOrAfter; - PastWeek = pastWeek; - PastMonth = pastMonth; - PastYear = pastYear; - NextWeek = nextWeek; - NextMonth = nextMonth; - NextYear = nextYear; - IsEmpty = isEmpty; - IsNotEmpty = isNotEmpty; - } } } } diff --git a/Src/Notion.Client/Models/Filters/EmailFilter.cs b/Src/Notion.Client/Models/Filters/EmailFilter.cs index ff5feda9..36bc3dde 100644 --- a/Src/Notion.Client/Models/Filters/EmailFilter.cs +++ b/Src/Notion.Client/Models/Filters/EmailFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class EmailFilter : SinglePropertyFilter { - [JsonProperty("email")] - public TextFilter.Condition Email { get; set; } - public EmailFilter( string propertyName, string equal = null, @@ -19,16 +16,20 @@ public EmailFilter( bool? isNotEmpty = null) { Property = propertyName; + Email = new TextFilter.Condition( - equal: equal, - doesNotEqual: doesNotEqual, - contains: contains, - doesNotContain: doesNotContain, - startsWith: startsWith, - endsWith: endsWith, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + doesNotEqual, + contains, + doesNotContain, + startsWith, + endsWith, + isEmpty, + isNotEmpty ); } + + [JsonProperty("email")] + public TextFilter.Condition Email { get; set; } } } diff --git a/Src/Notion.Client/Models/Filters/FilesFilter.cs b/Src/Notion.Client/Models/Filters/FilesFilter.cs index a32d4d7b..6c4b23c6 100644 --- a/Src/Notion.Client/Models/Filters/FilesFilter.cs +++ b/Src/Notion.Client/Models/Filters/FilesFilter.cs @@ -4,26 +4,20 @@ namespace Notion.Client { public class FilesFilter : SinglePropertyFilter, IRollupSubPropertyFilter { - [JsonProperty("files")] - public Condition Files { get; set; } - public FilesFilter( string propertyName, bool? isEmpty = null, bool? isNotEmpty = null) { Property = propertyName; - Files = new Condition(isEmpty: isEmpty, isNotEmpty: isNotEmpty); + Files = new Condition(isEmpty, isNotEmpty); } + [JsonProperty("files")] + public Condition Files { get; set; } + public class Condition { - [JsonProperty("is_empty")] - public bool? IsEmpty { get; set; } - - [JsonProperty("is_not_empty")] - public bool? IsNotEmpty { get; set; } - public Condition( bool? isEmpty = null, bool? isNotEmpty = null) @@ -31,6 +25,12 @@ public Condition( IsEmpty = isEmpty; IsNotEmpty = isNotEmpty; } + + [JsonProperty("is_empty")] + public bool? IsEmpty { get; set; } + + [JsonProperty("is_not_empty")] + public bool? IsNotEmpty { get; set; } } } } diff --git a/Src/Notion.Client/Models/Filters/Filter.cs b/Src/Notion.Client/Models/Filters/Filter.cs index 61f81f7e..47eced53 100644 --- a/Src/Notion.Client/Models/Filters/Filter.cs +++ b/Src/Notion.Client/Models/Filters/Filter.cs @@ -5,7 +5,6 @@ namespace Notion.Client { public class Filter { - } public class SinglePropertyFilter : Filter @@ -16,16 +15,16 @@ public class SinglePropertyFilter : Filter public class CompoundFilter : Filter { - [JsonProperty("or")] - public List Or { get; set; } - - [JsonProperty("and")] - public List And { get; set; } - public CompoundFilter(List or = null, List and = null) { Or = or; And = and; } + + [JsonProperty("or")] + public List Or { get; set; } + + [JsonProperty("and")] + public List And { get; set; } } } diff --git a/Src/Notion.Client/Models/Filters/FormulaFilter.cs b/Src/Notion.Client/Models/Filters/FormulaFilter.cs index eee9fc52..5aec5e00 100644 --- a/Src/Notion.Client/Models/Filters/FormulaFilter.cs +++ b/Src/Notion.Client/Models/Filters/FormulaFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class FormulaFilter : SinglePropertyFilter { - [JsonProperty("formula")] - public Condition Formula { get; set; } - public FormulaFilter( string propertyName, TextFilter.Condition @string = null, @@ -15,28 +12,20 @@ public FormulaFilter( DateFilter.Condition date = null) { Property = propertyName; + Formula = new Condition( - @string: @string, - checkbox: checkbox, - number: number, - date: date + @string, + checkbox, + number, + date ); } + [JsonProperty("formula")] + public Condition Formula { get; set; } + public class Condition { - [JsonProperty("string")] - public TextFilter.Condition String { get; set; } - - [JsonProperty("checkbox")] - public CheckboxFilter.Condition Checkbox { get; set; } - - [JsonProperty("number")] - public NumberFilter.Condition Number { get; set; } - - [JsonProperty("date")] - public DateFilter.Condition Date { get; set; } - public Condition( TextFilter.Condition @string = null, CheckboxFilter.Condition checkbox = null, @@ -48,6 +37,18 @@ public Condition( Number = number; Date = date; } + + [JsonProperty("string")] + public TextFilter.Condition String { get; set; } + + [JsonProperty("checkbox")] + public CheckboxFilter.Condition Checkbox { get; set; } + + [JsonProperty("number")] + public NumberFilter.Condition Number { get; set; } + + [JsonProperty("date")] + public DateFilter.Condition Date { get; set; } } } } diff --git a/Src/Notion.Client/Models/Filters/MultiSelectFilter.cs b/Src/Notion.Client/Models/Filters/MultiSelectFilter.cs index 14aec6d5..011a127e 100644 --- a/Src/Notion.Client/Models/Filters/MultiSelectFilter.cs +++ b/Src/Notion.Client/Models/Filters/MultiSelectFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class MultiSelectFilter : SinglePropertyFilter, IRollupSubPropertyFilter { - [JsonProperty("multi_select")] - public Condition MultiSelect { get; set; } - public MultiSelectFilter( string propertyName, string contains = null, @@ -15,29 +12,20 @@ public MultiSelectFilter( bool? isNotEmpty = null) { Property = propertyName; + MultiSelect = new Condition( - contains: contains, - doesNotContain: doesNotContain, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + contains, + doesNotContain, + isEmpty, + isNotEmpty ); } + [JsonProperty("multi_select")] + public Condition MultiSelect { get; set; } public class Condition { - [JsonProperty("contains")] - public string Contains { get; set; } - - [JsonProperty("does_not_contain")] - public string DoesNotContain { get; set; } - - [JsonProperty("is_empty")] - public bool? IsEmpty { get; set; } - - [JsonProperty("is_not_empty")] - public bool? IsNotEmpty { get; set; } - public Condition( string contains = null, string doesNotContain = null, @@ -49,7 +37,18 @@ public Condition( IsEmpty = isEmpty; IsNotEmpty = isNotEmpty; } - } + [JsonProperty("contains")] + public string Contains { get; set; } + + [JsonProperty("does_not_contain")] + public string DoesNotContain { get; set; } + + [JsonProperty("is_empty")] + public bool? IsEmpty { get; set; } + + [JsonProperty("is_not_empty")] + public bool? IsNotEmpty { get; set; } + } } } diff --git a/Src/Notion.Client/Models/Filters/NumberFilter.cs b/Src/Notion.Client/Models/Filters/NumberFilter.cs index 4895d3e8..1a2f6879 100644 --- a/Src/Notion.Client/Models/Filters/NumberFilter.cs +++ b/Src/Notion.Client/Models/Filters/NumberFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class NumberFilter : SinglePropertyFilter, IRollupSubPropertyFilter { - [JsonProperty("number")] - public Condition Number { get; set; } - public NumberFilter( string propertyName, double? equal = null, @@ -19,20 +16,44 @@ public NumberFilter( bool? isNotEmpty = null) { Property = propertyName; + Number = new Condition( - equal: equal, - doesNotEqual: doesNotEqual, - greaterThan: greaterThan, - lessThan: lessThan, - greaterThanOrEqualTo: greaterThanOrEqualTo, - lessThanOrEqualTo: lessThanOrEqualTo, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + doesNotEqual, + greaterThan, + lessThan, + greaterThanOrEqualTo, + lessThanOrEqualTo, + isEmpty, + isNotEmpty ); } + [JsonProperty("number")] + public Condition Number { get; set; } + public class Condition { + public Condition( + double? equal = null, + double? doesNotEqual = null, + double? greaterThan = null, + double? lessThan = null, + double? greaterThanOrEqualTo = null, + double? lessThanOrEqualTo = null, + bool? isEmpty = null, + bool? isNotEmpty = null) + { + Equal = equal; + DoesNotEqual = doesNotEqual; + GreaterThan = greaterThan; + LessThan = lessThan; + GreaterThanOrEqualTo = greaterThanOrEqualTo; + LessThanOrEqualTo = lessThanOrEqualTo; + IsEmpty = isEmpty; + IsNotEmpty = isNotEmpty; + } + [JsonProperty("equals")] public double? Equal { get; set; } @@ -56,27 +77,6 @@ public class Condition [JsonProperty("is_not_empty")] public bool? IsNotEmpty { get; set; } - - public Condition( - double? equal = null, - double? doesNotEqual = null, - double? greaterThan = null, - double? lessThan = null, - double? greaterThanOrEqualTo = null, - double? lessThanOrEqualTo = null, - bool? isEmpty = null, - bool? isNotEmpty = null) - { - Equal = equal; - DoesNotEqual = doesNotEqual; - GreaterThan = greaterThan; - LessThan = lessThan; - GreaterThanOrEqualTo = greaterThanOrEqualTo; - LessThanOrEqualTo = lessThanOrEqualTo; - IsEmpty = isEmpty; - IsNotEmpty = isNotEmpty; - } } - } } diff --git a/Src/Notion.Client/Models/Filters/PeopleFilter.cs b/Src/Notion.Client/Models/Filters/PeopleFilter.cs index af1067c4..6b83dda4 100644 --- a/Src/Notion.Client/Models/Filters/PeopleFilter.cs +++ b/Src/Notion.Client/Models/Filters/PeopleFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class PeopleFilter : SinglePropertyFilter, IRollupSubPropertyFilter { - [JsonProperty("people")] - public Condition People { get; set; } - public PeopleFilter( string propertyName, string contains = null, @@ -15,28 +12,20 @@ public PeopleFilter( bool? isNotEmpty = null) { Property = propertyName; + People = new Condition( - contains: contains, - doesNotContain: doesNotContain, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + contains, + doesNotContain, + isEmpty, + isNotEmpty ); } + [JsonProperty("people")] + public Condition People { get; set; } + public class Condition { - [JsonProperty("contains")] - public string Contains { get; set; } - - [JsonProperty("does_not_contain")] - public string DoesNotContain { get; set; } - - [JsonProperty("is_empty")] - public bool? IsEmpty { get; set; } - - [JsonProperty("is_not_empty")] - public bool? IsNotEmpty { get; set; } - public Condition( string contains = null, string doesNotContain = null, @@ -48,6 +37,18 @@ public Condition( IsEmpty = isEmpty; IsNotEmpty = isNotEmpty; } + + [JsonProperty("contains")] + public string Contains { get; set; } + + [JsonProperty("does_not_contain")] + public string DoesNotContain { get; set; } + + [JsonProperty("is_empty")] + public bool? IsEmpty { get; set; } + + [JsonProperty("is_not_empty")] + public bool? IsNotEmpty { get; set; } } } } diff --git a/Src/Notion.Client/Models/Filters/PhoneNumberFilter.cs b/Src/Notion.Client/Models/Filters/PhoneNumberFilter.cs index 758a65db..9ea9cf68 100644 --- a/Src/Notion.Client/Models/Filters/PhoneNumberFilter.cs +++ b/Src/Notion.Client/Models/Filters/PhoneNumberFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class PhoneNumberFilter : SinglePropertyFilter { - [JsonProperty("phone_number")] - public TextFilter.Condition Text { get; set; } - public PhoneNumberFilter( string propertyName, string equal = null, @@ -19,16 +16,20 @@ public PhoneNumberFilter( bool? isNotEmpty = null) { Property = propertyName; + Text = new TextFilter.Condition( - equal: equal, - doesNotEqual: doesNotEqual, - contains: contains, - doesNotContain: doesNotContain, - startsWith: startsWith, - endsWith: endsWith, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + doesNotEqual, + contains, + doesNotContain, + startsWith, + endsWith, + isEmpty, + isNotEmpty ); } + + [JsonProperty("phone_number")] + public TextFilter.Condition Text { get; set; } } } diff --git a/Src/Notion.Client/Models/Filters/RelationFilter.cs b/Src/Notion.Client/Models/Filters/RelationFilter.cs index b7e2924d..bff5f498 100644 --- a/Src/Notion.Client/Models/Filters/RelationFilter.cs +++ b/Src/Notion.Client/Models/Filters/RelationFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class RelationFilter : SinglePropertyFilter, IRollupSubPropertyFilter { - [JsonProperty("relation")] - public Condition Relation { get; set; } - public RelationFilter( string propertyName, string contains = null, @@ -15,28 +12,20 @@ public RelationFilter( bool? isNotEmpty = null) { Property = propertyName; + Relation = new Condition( - contains: contains, - doesNotContain: doesNotContain, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + contains, + doesNotContain, + isEmpty, + isNotEmpty ); } + [JsonProperty("relation")] + public Condition Relation { get; set; } + public class Condition { - [JsonProperty("contains")] - public string Contains { get; set; } - - [JsonProperty("does_not_contain")] - public string DoesNotContain { get; set; } - - [JsonProperty("is_empty")] - public bool? IsEmpty { get; set; } - - [JsonProperty("is_not_empty")] - public bool? IsNotEmpty { get; set; } - public Condition( string contains = null, string doesNotContain = null, @@ -48,6 +37,18 @@ public Condition( IsEmpty = isEmpty; IsNotEmpty = isNotEmpty; } + + [JsonProperty("contains")] + public string Contains { get; set; } + + [JsonProperty("does_not_contain")] + public string DoesNotContain { get; set; } + + [JsonProperty("is_empty")] + public bool? IsEmpty { get; set; } + + [JsonProperty("is_not_empty")] + public bool? IsNotEmpty { get; set; } } } } diff --git a/Src/Notion.Client/Models/Filters/RichTextFilter.cs b/Src/Notion.Client/Models/Filters/RichTextFilter.cs index 90bae02e..733b93ba 100644 --- a/Src/Notion.Client/Models/Filters/RichTextFilter.cs +++ b/Src/Notion.Client/Models/Filters/RichTextFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class RichTextFilter : SinglePropertyFilter, IRollupSubPropertyFilter { - [JsonProperty("rich_text")] - public TextFilter.Condition RichText { get; set; } - public RichTextFilter( string propertyName, string equal = null, @@ -19,23 +16,47 @@ public RichTextFilter( bool? isNotEmpty = null) { Property = propertyName; + RichText = new TextFilter.Condition( - equal: equal, - doesNotEqual: doesNotEqual, - contains: contains, - doesNotContain: doesNotContain, - startsWith: startsWith, - endsWith: endsWith, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + doesNotEqual, + contains, + doesNotContain, + startsWith, + endsWith, + isEmpty, + isNotEmpty ); } + + [JsonProperty("rich_text")] + public TextFilter.Condition RichText { get; set; } } public static class TextFilter { public class Condition { + public Condition( + string equal = null, + string doesNotEqual = null, + string contains = null, + string doesNotContain = null, + string startsWith = null, + string endsWith = null, + bool? isEmpty = null, + bool? isNotEmpty = null) + { + Equal = equal; + DoesNotEqual = doesNotEqual; + Contains = contains; + DoesNotContain = doesNotContain; + StartsWith = startsWith; + EndsWith = endsWith; + IsEmpty = isEmpty; + IsNotEmpty = isNotEmpty; + } + [JsonProperty("equals")] public string Equal { get; set; } @@ -59,26 +80,6 @@ public class Condition [JsonProperty("is_not_empty")] public bool? IsNotEmpty { get; set; } - - public Condition( - string equal = null, - string doesNotEqual = null, - string contains = null, - string doesNotContain = null, - string startsWith = null, - string endsWith = null, - bool? isEmpty = null, - bool? isNotEmpty = null) - { - Equal = equal; - DoesNotEqual = doesNotEqual; - Contains = contains; - DoesNotContain = doesNotContain; - StartsWith = startsWith; - EndsWith = endsWith; - IsEmpty = isEmpty; - IsNotEmpty = isNotEmpty; - } } } } diff --git a/Src/Notion.Client/Models/Filters/Rollup/RollupFilter.cs b/Src/Notion.Client/Models/Filters/Rollup/RollupFilter.cs index 41cb759e..df641729 100644 --- a/Src/Notion.Client/Models/Filters/Rollup/RollupFilter.cs +++ b/Src/Notion.Client/Models/Filters/Rollup/RollupFilter.cs @@ -4,18 +4,16 @@ namespace Notion.Client { public class RollupFilter : SinglePropertyFilter { - [JsonProperty("rollup")] - public Condition Rollup { get; set; } - public RollupFilter( - string propertyName - , IRollupSubPropertyFilter any = null - , IRollupSubPropertyFilter none = null - , IRollupSubPropertyFilter every = null - , DateFilter.Condition date = null - , NumberFilter.Condition number = null) + string propertyName, + IRollupSubPropertyFilter any = null, + IRollupSubPropertyFilter none = null, + IRollupSubPropertyFilter every = null, + DateFilter.Condition date = null, + NumberFilter.Condition number = null) { Property = propertyName; + Rollup = new Condition( any, none, @@ -25,14 +23,17 @@ string propertyName ); } + [JsonProperty("rollup")] + public Condition Rollup { get; set; } + public class Condition { public Condition( - IRollupSubPropertyFilter any = null - , IRollupSubPropertyFilter none = null - , IRollupSubPropertyFilter every = null - , DateFilter.Condition date = null - , NumberFilter.Condition number = null) + IRollupSubPropertyFilter any = null, + IRollupSubPropertyFilter none = null, + IRollupSubPropertyFilter every = null, + DateFilter.Condition date = null, + NumberFilter.Condition number = null) { Any = any; None = none; diff --git a/Src/Notion.Client/Models/Filters/SelectFilter.cs b/Src/Notion.Client/Models/Filters/SelectFilter.cs index 6f0887a4..064334f1 100644 --- a/Src/Notion.Client/Models/Filters/SelectFilter.cs +++ b/Src/Notion.Client/Models/Filters/SelectFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class SelectFilter : SinglePropertyFilter, IRollupSubPropertyFilter { - [JsonProperty("select")] - public Condition Select { get; set; } - public SelectFilter( string propertyName, string equal = null, @@ -15,28 +12,20 @@ public SelectFilter( bool? isNotEmpty = null) { Property = propertyName; + Select = new Condition( - equal: equal, - doesNotEqual: doesNotEqual, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + doesNotEqual, + isEmpty, + isNotEmpty ); } + [JsonProperty("select")] + public Condition Select { get; set; } + public class Condition { - [JsonProperty("equals")] - public string Equal { get; set; } - - [JsonProperty("does_not_equal")] - public string DoesNotEqual { get; set; } - - [JsonProperty("is_empty")] - public bool? IsEmpty { get; set; } - - [JsonProperty("is_not_empty")] - public bool? IsNotEmpty { get; set; } - public Condition( string equal = null, string doesNotEqual = null, @@ -48,6 +37,18 @@ public Condition( IsEmpty = isEmpty; IsNotEmpty = isNotEmpty; } + + [JsonProperty("equals")] + public string Equal { get; set; } + + [JsonProperty("does_not_equal")] + public string DoesNotEqual { get; set; } + + [JsonProperty("is_empty")] + public bool? IsEmpty { get; set; } + + [JsonProperty("is_not_empty")] + public bool? IsNotEmpty { get; set; } } } } diff --git a/Src/Notion.Client/Models/Filters/StatusFilter.cs b/Src/Notion.Client/Models/Filters/StatusFilter.cs index 7ed9b23f..0af0a22c 100644 --- a/Src/Notion.Client/Models/Filters/StatusFilter.cs +++ b/Src/Notion.Client/Models/Filters/StatusFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class StatusFilter : SinglePropertyFilter, IRollupSubPropertyFilter { - [JsonProperty("status")] - public Condition Status { get; set; } - public StatusFilter( string propertyName, string equal = null, @@ -15,28 +12,20 @@ public StatusFilter( bool? isNotEmpty = null) { Property = propertyName; + Status = new Condition( - equal: equal, - doesNotEqual: doesNotEqual, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + doesNotEqual, + isEmpty, + isNotEmpty ); } + [JsonProperty("status")] + public Condition Status { get; set; } + public class Condition { - [JsonProperty("equals")] - public string Equal { get; set; } - - [JsonProperty("does_not_equal")] - public string DoesNotEqual { get; set; } - - [JsonProperty("is_empty")] - public bool? IsEmpty { get; set; } - - [JsonProperty("is_not_empty")] - public bool? IsNotEmpty { get; set; } - public Condition( string equal = null, string doesNotEqual = null, @@ -48,6 +37,18 @@ public Condition( IsEmpty = isEmpty; IsNotEmpty = isNotEmpty; } + + [JsonProperty("equals")] + public string Equal { get; set; } + + [JsonProperty("does_not_equal")] + public string DoesNotEqual { get; set; } + + [JsonProperty("is_empty")] + public bool? IsEmpty { get; set; } + + [JsonProperty("is_not_empty")] + public bool? IsNotEmpty { get; set; } } } } diff --git a/Src/Notion.Client/Models/Filters/TimestampCreatedTimeFilter.cs b/Src/Notion.Client/Models/Filters/TimestampCreatedTimeFilter.cs index ac8f2244..d550817e 100644 --- a/Src/Notion.Client/Models/Filters/TimestampCreatedTimeFilter.cs +++ b/Src/Notion.Client/Models/Filters/TimestampCreatedTimeFilter.cs @@ -9,9 +9,6 @@ public class TimestampCreatedTimeFilter : Filter [JsonProperty("timestamp")] public string Timestamp = "created_time"; - [JsonProperty("created_time")] - public DateFilter.Condition CreatedTime { get; set; } - public TimestampCreatedTimeFilter( DateTime? equal = null, DateTime? before = null, @@ -28,20 +25,23 @@ public TimestampCreatedTimeFilter( bool? isNotEmpty = null) { CreatedTime = new DateFilter.Condition( - equal: equal, - before: before, - after: after, - onOrBefore: onOrBefore, - onOrAfter: onOrAfter, - pastWeek: pastWeek, - pastMonth: pastMonth, - pastYear: pastYear, - nextWeek: nextWeek, - nextMonth: nextMonth, - nextYear: nextYear, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + before, + after, + onOrBefore, + onOrAfter, + pastWeek, + pastMonth, + pastYear, + nextWeek, + nextMonth, + nextYear, + isEmpty, + isNotEmpty ); } + + [JsonProperty("created_time")] + public DateFilter.Condition CreatedTime { get; set; } } } diff --git a/Src/Notion.Client/Models/Filters/TimestampLastEditedTimeFilter.cs b/Src/Notion.Client/Models/Filters/TimestampLastEditedTimeFilter.cs index 1d6acb7f..51a6e39f 100644 --- a/Src/Notion.Client/Models/Filters/TimestampLastEditedTimeFilter.cs +++ b/Src/Notion.Client/Models/Filters/TimestampLastEditedTimeFilter.cs @@ -9,9 +9,6 @@ public class TimestampLastEditedTimeFilter : Filter [JsonProperty("timestamp")] public string Timestamp = "last_modified_time"; - [JsonProperty("last_edited_time")] - public DateFilter.Condition LastEditedTime { get; set; } - public TimestampLastEditedTimeFilter( DateTime? equal = null, DateTime? before = null, @@ -28,20 +25,23 @@ public TimestampLastEditedTimeFilter( bool? isNotEmpty = null) { LastEditedTime = new DateFilter.Condition( - equal: equal, - before: before, - after: after, - onOrBefore: onOrBefore, - onOrAfter: onOrAfter, - pastWeek: pastWeek, - pastMonth: pastMonth, - pastYear: pastYear, - nextWeek: nextWeek, - nextMonth: nextMonth, - nextYear: nextYear, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + before, + after, + onOrBefore, + onOrAfter, + pastWeek, + pastMonth, + pastYear, + nextWeek, + nextMonth, + nextYear, + isEmpty, + isNotEmpty ); } + + [JsonProperty("last_edited_time")] + public DateFilter.Condition LastEditedTime { get; set; } } } diff --git a/Src/Notion.Client/Models/Filters/TitleFilter.cs b/Src/Notion.Client/Models/Filters/TitleFilter.cs index 7c21bb33..1e0d4303 100644 --- a/Src/Notion.Client/Models/Filters/TitleFilter.cs +++ b/Src/Notion.Client/Models/Filters/TitleFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class TitleFilter : SinglePropertyFilter { - [JsonProperty("title")] - public TextFilter.Condition Title { get; set; } - public TitleFilter( string propertyName, string equal = null, @@ -19,16 +16,20 @@ public TitleFilter( bool? isNotEmpty = null) { Property = propertyName; + Title = new TextFilter.Condition( - equal: equal, - doesNotEqual: doesNotEqual, - contains: contains, - doesNotContain: doesNotContain, - startsWith: startsWith, - endsWith: endsWith, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + doesNotEqual, + contains, + doesNotContain, + startsWith, + endsWith, + isEmpty, + isNotEmpty ); } + + [JsonProperty("title")] + public TextFilter.Condition Title { get; set; } } } diff --git a/Src/Notion.Client/Models/Filters/URLFilter.cs b/Src/Notion.Client/Models/Filters/URLFilter.cs index b6a1fe6b..b2d4c611 100644 --- a/Src/Notion.Client/Models/Filters/URLFilter.cs +++ b/Src/Notion.Client/Models/Filters/URLFilter.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class URLFilter : SinglePropertyFilter { - [JsonProperty("url")] - public TextFilter.Condition URL { get; set; } - public URLFilter( string propertyName, string equal = null, @@ -19,16 +16,20 @@ public URLFilter( bool? isNotEmpty = null) { Property = propertyName; + URL = new TextFilter.Condition( - equal: equal, - doesNotEqual: doesNotEqual, - contains: contains, - doesNotContain: doesNotContain, - startsWith: startsWith, - endsWith: endsWith, - isEmpty: isEmpty, - isNotEmpty: isNotEmpty + equal, + doesNotEqual, + contains, + doesNotContain, + startsWith, + endsWith, + isEmpty, + isNotEmpty ); } + + [JsonProperty("url")] + public TextFilter.Condition URL { get; set; } } } diff --git a/Src/Notion.Client/Models/IObject.cs b/Src/Notion.Client/Models/IObject.cs index 2f72f929..b8ab1108 100644 --- a/Src/Notion.Client/Models/IObject.cs +++ b/Src/Notion.Client/Models/IObject.cs @@ -5,10 +5,10 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "object")] - [JsonSubtypes.KnownSubType(typeof(Page), ObjectType.Page)] - [JsonSubtypes.KnownSubType(typeof(Database), ObjectType.Database)] - [JsonSubtypes.KnownSubType(typeof(IBlock), ObjectType.Block)] - [JsonSubtypes.KnownSubType(typeof(User), ObjectType.User)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(Page), ObjectType.Page)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(Database), ObjectType.Database)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(IBlock), ObjectType.Block)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(User), ObjectType.User)] public interface IObject { [JsonProperty("id")] diff --git a/Src/Notion.Client/Models/Page/IPageIcon.cs b/Src/Notion.Client/Models/Page/IPageIcon.cs index a89184fe..b9ebea56 100644 --- a/Src/Notion.Client/Models/Page/IPageIcon.cs +++ b/Src/Notion.Client/Models/Page/IPageIcon.cs @@ -4,9 +4,9 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(EmojiObject), "emoji")] - [JsonSubtypes.KnownSubType(typeof(FileObject), "file")] - [JsonSubtypes.KnownSubType(typeof(FileObject), "external")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(EmojiObject), "emoji")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(FileObject), "file")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(FileObject), "external")] public interface IPageIcon { [JsonProperty("type")] diff --git a/Src/Notion.Client/Models/Page/IPageParent.cs b/Src/Notion.Client/Models/Page/IPageParent.cs index 439b1a3f..b9111d91 100644 --- a/Src/Notion.Client/Models/Page/IPageParent.cs +++ b/Src/Notion.Client/Models/Page/IPageParent.cs @@ -4,10 +4,10 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(DatabaseParent), ParentType.DatabaseId)] - [JsonSubtypes.KnownSubType(typeof(PageParent), ParentType.PageId)] - [JsonSubtypes.KnownSubType(typeof(WorkspaceParent), ParentType.Workspace)] - [JsonSubtypes.KnownSubType(typeof(BlockParent), ParentType.BlockId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(DatabaseParent), ParentType.DatabaseId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PageParent), ParentType.PageId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(WorkspaceParent), ParentType.Workspace)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(BlockParent), ParentType.BlockId)] public interface IPageParent : IParent { } diff --git a/Src/Notion.Client/Models/Page/Page.cs b/Src/Notion.Client/Models/Page/Page.cs index d96fef8a..996bdd46 100644 --- a/Src/Notion.Client/Models/Page/Page.cs +++ b/Src/Notion.Client/Models/Page/Page.cs @@ -7,63 +7,63 @@ namespace Notion.Client public class Page : IObject, IObjectModificationData { /// - /// Object type - /// - public ObjectType Object => ObjectType.Page; - - /// - /// Unique identifier of the page. - /// - public string Id { get; set; } - - /// - /// The parent of this page. Can be a database, page, or workspace. + /// The parent of this page. Can be a database, page, or workspace. /// [JsonProperty("parent")] public IPageParent Parent { get; set; } /// - /// Date and time when this page was created. - /// - [JsonProperty("created_time")] - public DateTime CreatedTime { get; set; } - - /// - /// Date and time when this page was updated. - /// - [JsonProperty("last_edited_time")] - public DateTime LastEditedTime { get; set; } - - /// - /// The archived status of the page. + /// The archived status of the page. /// [JsonProperty("archived")] public bool IsArchived { get; set; } /// - /// Property values of this page. + /// Property values of this page. /// [JsonProperty("properties")] public IDictionary Properties { get; set; } /// - /// The URL of the Notion page. + /// The URL of the Notion page. /// [JsonProperty("url")] public string Url { get; set; } /// - /// Page icon. + /// Page icon. /// [JsonProperty("icon")] public IPageIcon Icon { get; set; } /// - /// Page cover image. + /// Page cover image. /// [JsonProperty("cover")] public FileObject Cover { get; set; } + /// + /// Object type + /// + public ObjectType Object => ObjectType.Page; + + /// + /// Unique identifier of the page. + /// + public string Id { get; set; } + + /// + /// Date and time when this page was created. + /// + [JsonProperty("created_time")] + public DateTime CreatedTime { get; set; } + + /// + /// Date and time when this page was updated. + /// + [JsonProperty("last_edited_time")] + public DateTime LastEditedTime { get; set; } + public PartialUser CreatedBy { get; set; } public PartialUser LastEditedBy { get; set; } diff --git a/Src/Notion.Client/Models/Parents/BlockParent.cs b/Src/Notion.Client/Models/Parents/BlockParent.cs index 1ac1fd51..e3fd7749 100644 --- a/Src/Notion.Client/Models/Parents/BlockParent.cs +++ b/Src/Notion.Client/Models/Parents/BlockParent.cs @@ -5,14 +5,14 @@ namespace Notion.Client public class BlockParent : IPageParent, IDatabaseParent, IBlockParent, ICommentParent { /// - /// Always has a value "block_id" + /// The ID of the block that the element belongs to. /// - public ParentType Type { get; set; } + [JsonProperty("block_id")] + public string BlockId { get; set; } /// - /// The ID of the block that the element belongs to. + /// Always has a value "block_id" /// - [JsonProperty("block_id")] - public string BlockId { get; set; } + public ParentType Type { get; set; } } } diff --git a/Src/Notion.Client/Models/Parents/DatabaseParent.cs b/Src/Notion.Client/Models/Parents/DatabaseParent.cs index 2e680655..878dbe89 100644 --- a/Src/Notion.Client/Models/Parents/DatabaseParent.cs +++ b/Src/Notion.Client/Models/Parents/DatabaseParent.cs @@ -5,14 +5,14 @@ namespace Notion.Client public class DatabaseParent : IPageParent, IBlockParent { /// - /// Always "database_id" + /// The ID of the database that this page belongs to. /// - public ParentType Type { get; set; } + [JsonProperty("database_id")] + public string DatabaseId { get; set; } /// - /// The ID of the database that this page belongs to. + /// Always "database_id" /// - [JsonProperty("database_id")] - public string DatabaseId { get; set; } + public ParentType Type { get; set; } } } diff --git a/Src/Notion.Client/Models/Parents/PageParent.cs b/Src/Notion.Client/Models/Parents/PageParent.cs index 13b1c95a..565f7ccc 100644 --- a/Src/Notion.Client/Models/Parents/PageParent.cs +++ b/Src/Notion.Client/Models/Parents/PageParent.cs @@ -5,14 +5,14 @@ namespace Notion.Client public class PageParent : IPageParent, IDatabaseParent, IBlockParent, ICommentParent { /// - /// Always "page_id". + /// The ID of the page that this page belongs to. /// - public ParentType Type { get; set; } + [JsonProperty("page_id")] + public string PageId { get; set; } /// - /// The ID of the page that this page belongs to. + /// Always "page_id". /// - [JsonProperty("page_id")] - public string PageId { get; set; } + public ParentType Type { get; set; } } } diff --git a/Src/Notion.Client/Models/Parents/WorkspaceParent.cs b/Src/Notion.Client/Models/Parents/WorkspaceParent.cs index 86c60a54..a0b5e1c4 100644 --- a/Src/Notion.Client/Models/Parents/WorkspaceParent.cs +++ b/Src/Notion.Client/Models/Parents/WorkspaceParent.cs @@ -3,7 +3,7 @@ public class WorkspaceParent : IPageParent, IDatabaseParent, IBlockParent { /// - /// Always "workspace". + /// Always "workspace". /// public ParentType Type { get; set; } } diff --git a/Src/Notion.Client/Models/PropertyItems/IPropertyItemObject.cs b/Src/Notion.Client/Models/PropertyItems/IPropertyItemObject.cs index 5ebc7730..58db1a7d 100644 --- a/Src/Notion.Client/Models/PropertyItems/IPropertyItemObject.cs +++ b/Src/Notion.Client/Models/PropertyItems/IPropertyItemObject.cs @@ -4,8 +4,8 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "object")] - [JsonSubtypes.KnownSubType(typeof(SimplePropertyItem), "property_item")] - [JsonSubtypes.KnownSubType(typeof(ListPropertyItem), "list")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(SimplePropertyItem), "property_item")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ListPropertyItem), "list")] public interface IPropertyItemObject { [JsonProperty("object")] @@ -18,7 +18,8 @@ public interface IPropertyItemObject string Id { get; } /// - /// Only present in paginated property values with another page of results. If present, the url the user can request to get the next page of results. + /// Only present in paginated property values with another page of results. If present, the url the user can request to + /// get the next page of results. /// [JsonProperty("next_url")] string NextURL { get; } diff --git a/Src/Notion.Client/Models/PropertyItems/ListPropertyItem.cs b/Src/Notion.Client/Models/PropertyItems/ListPropertyItem.cs index f539fcd6..5e35159c 100644 --- a/Src/Notion.Client/Models/PropertyItems/ListPropertyItem.cs +++ b/Src/Notion.Client/Models/PropertyItems/ListPropertyItem.cs @@ -1,19 +1,10 @@ using System.Collections.Generic; -using JsonSubTypes; using Newtonsoft.Json; namespace Notion.Client { public class ListPropertyItem : IPropertyItemObject { - public string Object => "list"; - - public virtual string Type { get; set; } - - public string Id { get; set; } - - public string NextURL { get; set; } - [JsonProperty("results")] public IEnumerable Results { get; set; } @@ -25,5 +16,13 @@ public class ListPropertyItem : IPropertyItemObject [JsonProperty("property_item")] public SimplePropertyItem PropertyItem { get; set; } + + public string Object => "list"; + + public virtual string Type { get; set; } + + public string Id { get; set; } + + public string NextURL { get; set; } } } diff --git a/Src/Notion.Client/Models/PropertyItems/RollupPropertyItem.cs b/Src/Notion.Client/Models/PropertyItems/RollupPropertyItem.cs index 3df75fd7..04d7da7b 100644 --- a/Src/Notion.Client/Models/PropertyItems/RollupPropertyItem.cs +++ b/Src/Notion.Client/Models/PropertyItems/RollupPropertyItem.cs @@ -7,23 +7,31 @@ public class RollupPropertyItem : SimplePropertyItem { public override string Type => "rollup"; - [JsonProperty("rollup")] public Data Rollup { get; set; } + [JsonProperty("rollup")] + public Data Rollup { get; set; } public class Data { - [JsonProperty("type")] public string Type { get; set; } + [JsonProperty("type")] + public string Type { get; set; } - [JsonProperty("function")] public string Function { get; set; } + [JsonProperty("function")] + public string Function { get; set; } - [JsonProperty("number")] public double? Number { get; set; } + [JsonProperty("number")] + public double? Number { get; set; } - [JsonProperty("date")] public Date Date { get; set; } + [JsonProperty("date")] + public Date Date { get; set; } - [JsonProperty("array")] public IEnumerable> Array { get; set; } + [JsonProperty("array")] + public IEnumerable> Array { get; set; } - [JsonProperty("unsupported")] public Dictionary Unsupported { get; set; } + [JsonProperty("unsupported")] + public Dictionary Unsupported { get; set; } - [JsonProperty("incomplete")] public Dictionary Incomplete { get; set; } + [JsonProperty("incomplete")] + public Dictionary Incomplete { get; set; } } } } diff --git a/Src/Notion.Client/Models/PropertyItems/SimplePropertyItem.cs b/Src/Notion.Client/Models/PropertyItems/SimplePropertyItem.cs index 50d95184..ed3bef38 100644 --- a/Src/Notion.Client/Models/PropertyItems/SimplePropertyItem.cs +++ b/Src/Notion.Client/Models/PropertyItems/SimplePropertyItem.cs @@ -4,26 +4,26 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(NumberPropertyItem), "number")] - [JsonSubtypes.KnownSubType(typeof(UrlPropertyItem), "url")] - [JsonSubtypes.KnownSubType(typeof(SelectPropertyItem), "select")] - [JsonSubtypes.KnownSubType(typeof(MultiSelectPropertyItem), "multi_select")] - [JsonSubtypes.KnownSubType(typeof(StatusPropertyItem), "status")] - [JsonSubtypes.KnownSubType(typeof(DatePropertyItem), "date")] - [JsonSubtypes.KnownSubType(typeof(EmailPropertyItem), "email")] - [JsonSubtypes.KnownSubType(typeof(PhoneNumberPropertyItem), "phone_number")] - [JsonSubtypes.KnownSubType(typeof(CheckboxPropertyItem), "checkbox")] - [JsonSubtypes.KnownSubType(typeof(FilesPropertyItem), "files")] - [JsonSubtypes.KnownSubType(typeof(CreatedByPropertyItem), "created_by")] - [JsonSubtypes.KnownSubType(typeof(CreatedTimePropertyItem), "created_time")] - [JsonSubtypes.KnownSubType(typeof(LastEditedByPropertyItem), "last_edited_by")] - [JsonSubtypes.KnownSubType(typeof(LastEditedTimePropertyItem), "last_edited_time")] - [JsonSubtypes.KnownSubType(typeof(FormulaPropertyItem), "formula")] - [JsonSubtypes.KnownSubType(typeof(TitlePropertyItem), "title")] - [JsonSubtypes.KnownSubType(typeof(RichTextPropertyItem), "rich_text")] - [JsonSubtypes.KnownSubType(typeof(PeoplePropertyItem), "people")] - [JsonSubtypes.KnownSubType(typeof(RelationPropertyItem), "relation")] - [JsonSubtypes.KnownSubType(typeof(RollupPropertyItem), "rollup")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(NumberPropertyItem), "number")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(UrlPropertyItem), "url")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(SelectPropertyItem), "select")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(MultiSelectPropertyItem), "multi_select")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(StatusPropertyItem), "status")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(DatePropertyItem), "date")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(EmailPropertyItem), "email")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PhoneNumberPropertyItem), "phone_number")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CheckboxPropertyItem), "checkbox")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(FilesPropertyItem), "files")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CreatedByPropertyItem), "created_by")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CreatedTimePropertyItem), "created_time")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(LastEditedByPropertyItem), "last_edited_by")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(LastEditedTimePropertyItem), "last_edited_time")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(FormulaPropertyItem), "formula")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(TitlePropertyItem), "title")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RichTextPropertyItem), "rich_text")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PeoplePropertyItem), "people")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RelationPropertyItem), "relation")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RollupPropertyItem), "rollup")] public abstract class SimplePropertyItem : IPropertyItemObject { public string Object => "property_item"; diff --git a/Src/Notion.Client/Models/PropertyItems/StatusPropertyItem.cs b/Src/Notion.Client/Models/PropertyItems/StatusPropertyItem.cs index 46e70108..6b6b863c 100644 --- a/Src/Notion.Client/Models/PropertyItems/StatusPropertyItem.cs +++ b/Src/Notion.Client/Models/PropertyItems/StatusPropertyItem.cs @@ -6,6 +6,7 @@ public class StatusPropertyItem : SimplePropertyItem { public override string Type => "status"; - [JsonProperty("status")] public SelectOption Status { get; set; } + [JsonProperty("status")] + public SelectOption Status { get; set; } } } diff --git a/Src/Notion.Client/Models/PropertyValue/CheckboxPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/CheckboxPropertyValue.cs index 1f3fec50..422eb9b7 100644 --- a/Src/Notion.Client/Models/PropertyValue/CheckboxPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/CheckboxPropertyValue.cs @@ -3,7 +3,7 @@ namespace Notion.Client { /// - /// Checkbox property value objects contain a boolean within the checkbox property. + /// Checkbox property value objects contain a boolean within the checkbox property. /// public class CheckboxPropertyValue : PropertyValue { diff --git a/Src/Notion.Client/Models/PropertyValue/CreatedByPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/CreatedByPropertyValue.cs index 17fa4ef4..31cf5f5b 100644 --- a/Src/Notion.Client/Models/PropertyValue/CreatedByPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/CreatedByPropertyValue.cs @@ -3,14 +3,14 @@ namespace Notion.Client { /// - /// Created by property value object + /// Created by property value object /// public class CreatedByPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.CreatedBy; /// - /// Describes the user who created this page. + /// Describes the user who created this page. /// [JsonProperty("created_by")] public User CreatedBy { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/CreatedTimePropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/CreatedTimePropertyValue.cs index 0b20b2dc..e0550d13 100644 --- a/Src/Notion.Client/Models/PropertyValue/CreatedTimePropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/CreatedTimePropertyValue.cs @@ -3,14 +3,14 @@ namespace Notion.Client { /// - /// Created time property value object. + /// Created time property value object. /// public class CreatedTimePropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.CreatedTime; /// - /// The date and time when this page was created. + /// The date and time when this page was created. /// [JsonProperty("created_time")] public string CreatedTime { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs index aeb3cd8e..22715b2e 100644 --- a/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs @@ -4,38 +4,39 @@ namespace Notion.Client { /// - /// Date property value object. + /// Date property value object. /// public class DatePropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.Date; /// - /// Date + /// Date /// [JsonProperty("date", NullValueHandling = NullValueHandling.Include)] public Date Date { get; set; } } /// - /// Date value object. + /// Date value object. /// public class Date { /// - /// Start date with optional time. + /// Start date with optional time. /// [JsonProperty("start")] public DateTime? Start { get; set; } /// - /// End date with optional time. + /// End date with optional time. /// [JsonProperty("end")] public DateTime? End { get; set; } /// - /// Optional time zone information for start and end. Possible values are extracted from the IANA database and they are based on the time zones from Moment.js. + /// Optional time zone information for start and end. Possible values are extracted from the IANA database and they are + /// based on the time zones from Moment.js. /// [JsonProperty("time_zone")] public string TimeZone { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/EmailPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/EmailPropertyValue.cs index 1869fc85..5a8e2c7a 100644 --- a/Src/Notion.Client/Models/PropertyValue/EmailPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/EmailPropertyValue.cs @@ -3,14 +3,14 @@ namespace Notion.Client { /// - /// Email property value object. + /// Email property value object. /// public class EmailPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.Email; /// - /// Describes an email address. + /// Describes an email address. /// [JsonProperty("email")] public string Email { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/FilesPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/FilesPropertyValue.cs index 41580fdb..67bc864a 100644 --- a/Src/Notion.Client/Models/PropertyValue/FilesPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/FilesPropertyValue.cs @@ -4,14 +4,14 @@ namespace Notion.Client { /// - /// File property value object. + /// File property value object. /// public class FilesPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.Files; /// - /// Array of File Object with name. + /// Array of File Object with name. /// [JsonProperty("files")] public List Files { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/FormulaPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/FormulaPropertyValue.cs index e85fd5bd..a1242f47 100644 --- a/Src/Notion.Client/Models/PropertyValue/FormulaPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/FormulaPropertyValue.cs @@ -3,50 +3,50 @@ namespace Notion.Client { /// - /// Formula property value object. + /// Formula property value object. /// public class FormulaPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.Formula; /// - /// A formula described in the database's properties. + /// A formula described in the database's properties. /// [JsonProperty("formula")] public FormulaValue Formula { get; set; } } /// - /// Formula value object. + /// Formula value object. /// public class FormulaValue { /// - /// Formula value type + /// Formula value type /// [JsonProperty("type")] public string Type { get; set; } /// - /// String formula value. + /// String formula value. /// [JsonProperty("string")] public string String { get; set; } /// - /// Number formula value. + /// Number formula value. /// [JsonProperty("number")] public double? Number { get; set; } /// - /// Boolean formula value. + /// Boolean formula value. /// [JsonProperty("boolean")] public bool? Boolean { get; set; } /// - /// Date formula value + /// Date formula value /// [JsonProperty("date")] public Date Date { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/LastEditedByPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/LastEditedByPropertyValue.cs index b5e26efc..a536ad60 100644 --- a/Src/Notion.Client/Models/PropertyValue/LastEditedByPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/LastEditedByPropertyValue.cs @@ -3,14 +3,14 @@ namespace Notion.Client { /// - /// Last edited by property value object. + /// Last edited by property value object. /// public class LastEditedByPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.LastEditedBy; /// - /// Describes the user who last updated this page. + /// Describes the user who last updated this page. /// [JsonProperty("last_edited_by")] public User LastEditedBy { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/LastEditedTimePropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/LastEditedTimePropertyValue.cs index 785ac3bc..25d3100d 100644 --- a/Src/Notion.Client/Models/PropertyValue/LastEditedTimePropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/LastEditedTimePropertyValue.cs @@ -3,14 +3,14 @@ namespace Notion.Client { /// - /// Last edited time property value object. + /// Last edited time property value object. /// public class LastEditedTimePropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.LastEditedTime; /// - /// The date and time when this page was last updated. + /// The date and time when this page was last updated. /// [JsonProperty("last_edited_time")] public string LastEditedTime { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/MultiSelectPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/MultiSelectPropertyValue.cs index a5ee4f0a..ff820527 100644 --- a/Src/Notion.Client/Models/PropertyValue/MultiSelectPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/MultiSelectPropertyValue.cs @@ -4,14 +4,14 @@ namespace Notion.Client { /// - /// Multi-select property value object. + /// Multi-select property value object. /// public class MultiSelectPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.MultiSelect; /// - /// An array of multi-select option values. + /// An array of multi-select option values. /// [JsonProperty("multi_select")] public List MultiSelect { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/NumberPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/NumberPropertyValue.cs index a98a34d4..15f9c768 100644 --- a/Src/Notion.Client/Models/PropertyValue/NumberPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/NumberPropertyValue.cs @@ -3,14 +3,14 @@ namespace Notion.Client { /// - /// Number formula property value object. + /// Number formula property value object. /// public class NumberPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.Number; /// - /// Value of number + /// Value of number /// [JsonProperty("number")] public double? Number { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/PeoplePropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/PeoplePropertyValue.cs index 047d33ee..62557560 100644 --- a/Src/Notion.Client/Models/PropertyValue/PeoplePropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/PeoplePropertyValue.cs @@ -4,14 +4,14 @@ namespace Notion.Client { /// - /// People property value object. + /// People property value object. /// public class PeoplePropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.People; /// - /// List of users. + /// List of users. /// [JsonProperty("people")] public List People { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/PhoneNumberPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/PhoneNumberPropertyValue.cs index be5e482e..79a24dac 100644 --- a/Src/Notion.Client/Models/PropertyValue/PhoneNumberPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/PhoneNumberPropertyValue.cs @@ -3,14 +3,14 @@ namespace Notion.Client { /// - /// Phone number property value object. + /// Phone number property value object. /// public class PhoneNumberPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.PhoneNumber; /// - /// Phone number value + /// Phone number value /// [JsonProperty("phone_number")] public string PhoneNumber { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs index 8437b4f8..f893e47a 100644 --- a/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs @@ -5,33 +5,33 @@ namespace Notion.Client { /// - /// An object describing the identifier, type, and value of a page property. + /// An object describing the identifier, type, and value of a page property. /// [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(CheckboxPropertyValue), PropertyValueType.Checkbox)] - [JsonSubtypes.KnownSubType(typeof(CreatedByPropertyValue), PropertyValueType.CreatedBy)] - [JsonSubtypes.KnownSubType(typeof(CreatedTimePropertyValue), PropertyValueType.CreatedTime)] - [JsonSubtypes.KnownSubType(typeof(DatePropertyValue), PropertyValueType.Date)] - [JsonSubtypes.KnownSubType(typeof(EmailPropertyValue), PropertyValueType.Email)] - [JsonSubtypes.KnownSubType(typeof(FilesPropertyValue), PropertyValueType.Files)] - [JsonSubtypes.KnownSubType(typeof(FormulaPropertyValue), PropertyValueType.Formula)] - [JsonSubtypes.KnownSubType(typeof(LastEditedByPropertyValue), PropertyValueType.LastEditedBy)] - [JsonSubtypes.KnownSubType(typeof(LastEditedTimePropertyValue), PropertyValueType.LastEditedTime)] - [JsonSubtypes.KnownSubType(typeof(MultiSelectPropertyValue), PropertyValueType.MultiSelect)] - [JsonSubtypes.KnownSubType(typeof(NumberPropertyValue), PropertyValueType.Number)] - [JsonSubtypes.KnownSubType(typeof(PeoplePropertyValue), PropertyValueType.People)] - [JsonSubtypes.KnownSubType(typeof(PhoneNumberPropertyValue), PropertyValueType.PhoneNumber)] - [JsonSubtypes.KnownSubType(typeof(RelationPropertyValue), PropertyValueType.Relation)] - [JsonSubtypes.KnownSubType(typeof(RichTextPropertyValue), PropertyValueType.RichText)] - [JsonSubtypes.KnownSubType(typeof(RollupPropertyValue), PropertyValueType.Rollup)] - [JsonSubtypes.KnownSubType(typeof(SelectPropertyValue), PropertyValueType.Select)] - [JsonSubtypes.KnownSubType(typeof(StatusPropertyValue), PropertyValueType.Status)] - [JsonSubtypes.KnownSubType(typeof(TitlePropertyValue), PropertyValueType.Title)] - [JsonSubtypes.KnownSubType(typeof(UrlPropertyValue), PropertyValueType.Url)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CheckboxPropertyValue), PropertyValueType.Checkbox)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CreatedByPropertyValue), PropertyValueType.CreatedBy)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CreatedTimePropertyValue), PropertyValueType.CreatedTime)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(DatePropertyValue), PropertyValueType.Date)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(EmailPropertyValue), PropertyValueType.Email)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(FilesPropertyValue), PropertyValueType.Files)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(FormulaPropertyValue), PropertyValueType.Formula)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(LastEditedByPropertyValue), PropertyValueType.LastEditedBy)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(LastEditedTimePropertyValue), PropertyValueType.LastEditedTime)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(MultiSelectPropertyValue), PropertyValueType.MultiSelect)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(NumberPropertyValue), PropertyValueType.Number)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PeoplePropertyValue), PropertyValueType.People)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(PhoneNumberPropertyValue), PropertyValueType.PhoneNumber)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RelationPropertyValue), PropertyValueType.Relation)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RichTextPropertyValue), PropertyValueType.RichText)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(RollupPropertyValue), PropertyValueType.Rollup)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(SelectPropertyValue), PropertyValueType.Select)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(StatusPropertyValue), PropertyValueType.Status)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(TitlePropertyValue), PropertyValueType.Title)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(UrlPropertyValue), PropertyValueType.Url)] public class PropertyValue { /// - /// Underlying identifier of the property. + /// Underlying identifier of the property. /// [JsonProperty("id")] public string Id { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs b/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs index fcbeae61..93a8d63e 100644 --- a/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs +++ b/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs @@ -3,7 +3,7 @@ namespace Notion.Client { /// - /// Types of Property Value + /// Types of Property Value /// public enum PropertyValueType { diff --git a/Src/Notion.Client/Models/PropertyValue/RelationPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/RelationPropertyValue.cs index 3d11a096..6f9e0ec8 100644 --- a/Src/Notion.Client/Models/PropertyValue/RelationPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/RelationPropertyValue.cs @@ -4,14 +4,14 @@ namespace Notion.Client { /// - /// Relation property value object. + /// Relation property value object. /// public class RelationPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.Relation; /// - /// Array of page references + /// Array of page references /// [JsonProperty("relation")] public List Relation { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/RichTextPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/RichTextPropertyValue.cs index 028ed046..90e8d0be 100644 --- a/Src/Notion.Client/Models/PropertyValue/RichTextPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/RichTextPropertyValue.cs @@ -4,14 +4,14 @@ namespace Notion.Client { /// - /// Rich Text property value object. + /// Rich Text property value object. /// public class RichTextPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.RichText; /// - /// List of rich text objects + /// List of rich text objects /// [JsonProperty("rich_text")] public List RichText { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/RollupPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/RollupPropertyValue.cs index 7c573081..2eb104fb 100644 --- a/Src/Notion.Client/Models/PropertyValue/RollupPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/RollupPropertyValue.cs @@ -4,7 +4,7 @@ namespace Notion.Client { /// - /// Rollup property value object. + /// Rollup property value object. /// public class RollupPropertyValue : PropertyValue { @@ -15,31 +15,31 @@ public class RollupPropertyValue : PropertyValue } /// - /// Object containing rollup type-specific data. + /// Object containing rollup type-specific data. /// public class RollupValue { /// - /// The type of rollup. Possible values are "number", "date", and "array". + /// The type of rollup. Possible values are "number", "date", and "array". /// [JsonProperty("type")] public string Type { get; set; } /// - /// Number rollup property values contain a number + /// Number rollup property values contain a number /// [JsonProperty("number")] public double? Number { get; set; } /// - /// Date rollup property values contain a date property value. + /// Date rollup property values contain a date property value. /// [JsonProperty("date")] public DatePropertyValue Date { get; set; } /// - /// Array rollup property values contain an array of element objects. - /// Array containing the property value object will not contain value for Id field + /// Array rollup property values contain an array of element objects. + /// Array containing the property value object will not contain value for Id field /// [JsonProperty("array")] public List Array { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/SelectPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/SelectPropertyValue.cs index 07b2a346..74c94c82 100644 --- a/Src/Notion.Client/Models/PropertyValue/SelectPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/SelectPropertyValue.cs @@ -3,7 +3,7 @@ namespace Notion.Client { /// - /// Select property value object. + /// Select property value object. /// public class SelectPropertyValue : PropertyValue { diff --git a/Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs index 497e4c18..f4a82e48 100644 --- a/Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs @@ -5,37 +5,10 @@ namespace Notion.Client { /// - /// Status property value objects contain page status + /// Status property value objects contain page status /// public class StatusPropertyValue : PropertyValue { - public override PropertyValueType Type => PropertyValueType.Status; - - [JsonProperty("status")] - public Data Status { get; set; } - - public class Data - { - /// - /// ID of the option. - /// - [JsonProperty("id")] - public string Id { get; set; } - - /// - /// Name of the option as it appears in Notion. - /// - [JsonProperty("name")] - public string Name { get; set; } - - /// - /// Color of the option. - /// - [JsonProperty("color")] - [JsonConverter(typeof(StringEnumConverter))] - public Color? Color { get; set; } - } - public enum Color { [EnumMember(Value = "default")] @@ -68,5 +41,32 @@ public enum Color [EnumMember(Value = "red")] Red, } + + public override PropertyValueType Type => PropertyValueType.Status; + + [JsonProperty("status")] + public Data Status { get; set; } + + public class Data + { + /// + /// ID of the option. + /// + [JsonProperty("id")] + public string Id { get; set; } + + /// + /// Name of the option as it appears in Notion. + /// + [JsonProperty("name")] + public string Name { get; set; } + + /// + /// Color of the option. + /// + [JsonProperty("color")] + [JsonConverter(typeof(StringEnumConverter))] + public Color? Color { get; set; } + } } } diff --git a/Src/Notion.Client/Models/PropertyValue/TitlePropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/TitlePropertyValue.cs index 58b7842d..e72a2a08 100644 --- a/Src/Notion.Client/Models/PropertyValue/TitlePropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/TitlePropertyValue.cs @@ -4,14 +4,14 @@ namespace Notion.Client { /// - /// Title property value object. + /// Title property value object. /// public class TitlePropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.Title; /// - /// An array of rich text objects + /// An array of rich text objects /// [JsonProperty("title")] public List Title { get; set; } diff --git a/Src/Notion.Client/Models/PropertyValue/UrlPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/UrlPropertyValue.cs index 08b800e6..5fc8f8bb 100644 --- a/Src/Notion.Client/Models/PropertyValue/UrlPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/UrlPropertyValue.cs @@ -3,14 +3,14 @@ namespace Notion.Client { /// - /// URL property value object. + /// URL property value object. /// public class UrlPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.Url; /// - /// Describes a web address + /// Describes a web address /// [JsonProperty("url")] public string Url { get; set; } diff --git a/Src/Notion.Client/Models/User/BotOwner/IBotOwner.cs b/Src/Notion.Client/Models/User/BotOwner/IBotOwner.cs index 61a7a887..062d75c0 100644 --- a/Src/Notion.Client/Models/User/BotOwner/IBotOwner.cs +++ b/Src/Notion.Client/Models/User/BotOwner/IBotOwner.cs @@ -4,8 +4,8 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] - [JsonSubtypes.KnownSubType(typeof(UserOwner), "user")] - [JsonSubtypes.KnownSubType(typeof(WorkspaceIntegrationOwner), "workspace")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(UserOwner), "user")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(WorkspaceIntegrationOwner), "workspace")] public interface IBotOwner { [JsonProperty("type")] diff --git a/Src/Notion.Client/Models/User/BotOwner/UserOwner.cs b/Src/Notion.Client/Models/User/BotOwner/UserOwner.cs index 40d69867..e60a4fab 100644 --- a/Src/Notion.Client/Models/User/BotOwner/UserOwner.cs +++ b/Src/Notion.Client/Models/User/BotOwner/UserOwner.cs @@ -4,9 +4,9 @@ namespace Notion.Client { public class UserOwner : IBotOwner { - public string Type { get; set; } - [JsonProperty("user")] public User User { get; set; } + + public string Type { get; set; } } } diff --git a/Src/Notion.Client/Models/User/BotOwner/WorkspaceIntegrationOwner.cs b/Src/Notion.Client/Models/User/BotOwner/WorkspaceIntegrationOwner.cs index 78a84f6f..b5304157 100644 --- a/Src/Notion.Client/Models/User/BotOwner/WorkspaceIntegrationOwner.cs +++ b/Src/Notion.Client/Models/User/BotOwner/WorkspaceIntegrationOwner.cs @@ -4,9 +4,9 @@ namespace Notion.Client { public class WorkspaceIntegrationOwner : IBotOwner { - public string Type { get; set; } - [JsonProperty("workspace")] public bool Workspace { get; set; } + + public string Type { get; set; } } } diff --git a/Src/Notion.Client/Models/User/User.cs b/Src/Notion.Client/Models/User/User.cs index 7f336929..6ae9efef 100644 --- a/Src/Notion.Client/Models/User/User.cs +++ b/Src/Notion.Client/Models/User/User.cs @@ -4,9 +4,6 @@ namespace Notion.Client { public class User : IObject { - public ObjectType Object => ObjectType.User; - public string Id { get; set; } - [JsonProperty("type")] public string Type { get; set; } @@ -21,5 +18,9 @@ public class User : IObject [JsonProperty("bot")] public Bot Bot { get; set; } + + public ObjectType Object => ObjectType.User; + + public string Id { get; set; } } } diff --git a/Src/Notion.Client/NotionApiErrorResponse.cs b/Src/Notion.Client/NotionApiErrorResponse.cs index f27288fb..44a225b2 100644 --- a/Src/Notion.Client/NotionApiErrorResponse.cs +++ b/Src/Notion.Client/NotionApiErrorResponse.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - class NotionApiErrorResponse + internal class NotionApiErrorResponse { [JsonProperty("code")] public NotionAPIErrorCode ErrorCode { get; set; } diff --git a/Src/Notion.Client/NotionApiException.cs b/Src/Notion.Client/NotionApiException.cs index 358db384..c7c9d7d4 100644 --- a/Src/Notion.Client/NotionApiException.cs +++ b/Src/Notion.Client/NotionApiException.cs @@ -29,6 +29,7 @@ public NotionApiException( } public NotionAPIErrorCode? NotionAPIErrorCode { get; } + public HttpStatusCode StatusCode { get; } } } diff --git a/Src/Notion.Client/NotionClient.cs b/Src/Notion.Client/NotionClient.cs index f1650b29..f752413a 100644 --- a/Src/Notion.Client/NotionClient.cs +++ b/Src/Notion.Client/NotionClient.cs @@ -3,11 +3,17 @@ public interface INotionClient { IUsersClient Users { get; } + IDatabasesClient Databases { get; } + IPagesClient Pages { get; } + ISearchClient Search { get; } + IBlocksClient Blocks { get; } + ICommentsClient Comments { get; } + IRestClient RestClient { get; } } @@ -32,11 +38,17 @@ public NotionClient( } public IUsersClient Users { get; } + public IDatabasesClient Databases { get; } + public IPagesClient Pages { get; } + public ISearchClient Search { get; } + public IBlocksClient Blocks { get; } + public ICommentsClient Comments { get; } + public IRestClient RestClient { get; } } } diff --git a/Src/Notion.Client/NotionClientFactory.cs b/Src/Notion.Client/NotionClientFactory.cs index 0a02eb3c..e82ba2de 100644 --- a/Src/Notion.Client/NotionClientFactory.cs +++ b/Src/Notion.Client/NotionClientFactory.cs @@ -7,11 +7,11 @@ public static NotionClient Create(ClientOptions options) var restClient = new RestClient(options); return new NotionClient( - restClient: restClient - , users: new UsersClient(restClient) - , databases: new DatabasesClient(restClient) - , pages: new PagesClient(restClient) - , search: new SearchClient(restClient) + restClient + , new UsersClient(restClient) + , new DatabasesClient(restClient) + , new PagesClient(restClient) + , new SearchClient(restClient) , blocks: new BlocksClient(restClient) , comments: new CommentsClient(restClient) ); diff --git a/Src/Notion.Client/RestClient/ClientOptions.cs b/Src/Notion.Client/RestClient/ClientOptions.cs index 3c6be1bc..d0015767 100644 --- a/Src/Notion.Client/RestClient/ClientOptions.cs +++ b/Src/Notion.Client/RestClient/ClientOptions.cs @@ -3,7 +3,9 @@ public class ClientOptions { public string BaseUrl { get; set; } + public string NotionVersion { get; set; } + public string AuthToken { get; set; } } } diff --git a/Src/Notion.Client/RestClient/LoggingHandler.cs b/Src/Notion.Client/RestClient/LoggingHandler.cs index 8655bb97..a6001d10 100644 --- a/Src/Notion.Client/RestClient/LoggingHandler.cs +++ b/Src/Notion.Client/RestClient/LoggingHandler.cs @@ -7,7 +7,9 @@ namespace Notion.Client { public class LoggingHandler : DelegatingHandler { - protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) + protected override async Task SendAsync( + HttpRequestMessage request, + CancellationToken cancellationToken) { Log.Trace("Request: {request}", request); @@ -22,6 +24,7 @@ protected override async Task SendAsync(HttpRequestMessage catch (Exception ex) { Log.Error(ex, "Failed to get response: {exception}", ex); + throw; } } diff --git a/Src/Notion.Client/RestClient/RestClient.cs b/Src/Notion.Client/RestClient/RestClient.cs index bba3a866..5da38f61 100644 --- a/Src/Notion.Client/RestClient/RestClient.cs +++ b/Src/Notion.Client/RestClient/RestClient.cs @@ -14,50 +14,98 @@ namespace Notion.Client { public class RestClient : IRestClient { - private HttpClient _httpClient; private readonly ClientOptions _options; - protected readonly JsonSerializerSettings defaultSerializerSettings = new JsonSerializerSettings + protected readonly JsonSerializerSettings defaultSerializerSettings = new() { NullValueHandling = NullValueHandling.Ignore, - ContractResolver = new DefaultContractResolver - { - NamingStrategy = new CamelCaseNamingStrategy() - } + ContractResolver = new DefaultContractResolver {NamingStrategy = new CamelCaseNamingStrategy()}, }; + private HttpClient _httpClient; + public RestClient(ClientOptions options) { _options = MergeOptions(options); } - private static ClientOptions MergeOptions(ClientOptions options) + public async Task GetAsync( + string uri, + IDictionary queryParams = null, + IDictionary headers = null, + JsonSerializerSettings serializerSettings = null, + CancellationToken cancellationToken = default) { - return new ClientOptions - { - AuthToken = options.AuthToken, - BaseUrl = options.BaseUrl ?? Constants.BASE_URL, - NotionVersion = options.NotionVersion ?? Constants.DEFAULT_NOTION_VERSION - }; + var response = await SendAsync(uri, HttpMethod.Get, queryParams, headers, + cancellationToken: cancellationToken); + + return await response.ParseStreamAsync(serializerSettings); } - public async Task GetAsync( + public async Task PostAsync( string uri, + object body, IDictionary queryParams = null, IDictionary headers = null, JsonSerializerSettings serializerSettings = null, CancellationToken cancellationToken = default) { - var response = await SendAsync(uri, HttpMethod.Get, queryParams, headers, cancellationToken: cancellationToken); + void AttachContent(HttpRequestMessage httpRequest) => + httpRequest.Content = new StringContent(JsonConvert.SerializeObject(body, defaultSerializerSettings), + Encoding.UTF8, "application/json"); + + var response = await SendAsync(uri, HttpMethod.Post, queryParams, headers, AttachContent, + cancellationToken); return await response.ParseStreamAsync(serializerSettings); } + public async Task PatchAsync( + string uri, + object body, + IDictionary queryParams = null, + IDictionary headers = null, + JsonSerializerSettings serializerSettings = null, + CancellationToken cancellationToken = default) + { + void AttachContent(HttpRequestMessage httpRequest) + { + var serializedBody = JsonConvert.SerializeObject(body, defaultSerializerSettings); + httpRequest.Content = new StringContent(serializedBody, Encoding.UTF8, "application/json"); + } + + var response = await SendAsync(uri, new HttpMethod("PATCH"), queryParams, headers, AttachContent, + cancellationToken); + + return await response.ParseStreamAsync(serializerSettings); + } + + public async Task DeleteAsync( + string uri, + IDictionary queryParams = null, + IDictionary headers = null, + JsonSerializerSettings serializerSettings = null, + CancellationToken cancellationToken = default) + { + await SendAsync(uri, HttpMethod.Delete, queryParams, headers, null, cancellationToken); + } + + private static ClientOptions MergeOptions(ClientOptions options) + { + return new ClientOptions + { + AuthToken = options.AuthToken, + BaseUrl = options.BaseUrl ?? Constants.BASE_URL, + NotionVersion = options.NotionVersion ?? Constants.DEFAULT_NOTION_VERSION, + }; + } + private static async Task BuildException(HttpResponseMessage response) { var errorBody = await response.Content.ReadAsStringAsync(); NotionApiErrorResponse errorResponse = null; + if (!string.IsNullOrWhiteSpace(errorBody)) { try @@ -114,47 +162,11 @@ private static void AddHeaders(HttpRequestMessage request, IDictionary PostAsync( - string uri, - object body, - IDictionary queryParams = null, - IDictionary headers = null, - JsonSerializerSettings serializerSettings = null, - CancellationToken cancellationToken = default) - { - void AttachContent(HttpRequestMessage httpRequest) - { - httpRequest.Content = new StringContent(JsonConvert.SerializeObject(body, defaultSerializerSettings), Encoding.UTF8, "application/json"); - } - - var response = await SendAsync(uri, HttpMethod.Post, queryParams, headers, AttachContent, cancellationToken: cancellationToken); - - return await response.ParseStreamAsync(serializerSettings); - } - - public async Task PatchAsync(string uri, object body, IDictionary queryParams = null, IDictionary headers = null, JsonSerializerSettings serializerSettings = null, CancellationToken cancellationToken = default) - { - void AttachContent(HttpRequestMessage httpRequest) - { - var serializedBody = JsonConvert.SerializeObject(body, defaultSerializerSettings); - httpRequest.Content = new StringContent(serializedBody, Encoding.UTF8, "application/json"); - } - - var response = await SendAsync(uri, new HttpMethod("PATCH"), queryParams, headers, AttachContent, cancellationToken: cancellationToken); - - return await response.ParseStreamAsync(serializerSettings); - } - - public async Task DeleteAsync(string uri, IDictionary queryParams = null, IDictionary headers = null, JsonSerializerSettings serializerSettings = null, CancellationToken cancellationToken = default) - { - await SendAsync(uri, HttpMethod.Delete, queryParams, headers, null, cancellationToken); - } - private HttpClient EnsureHttpClient() { if (_httpClient == null) { - var pipeline = new LoggingHandler() { InnerHandler = new HttpClientHandler() }; + var pipeline = new LoggingHandler {InnerHandler = new HttpClientHandler()}; _httpClient = new HttpClient(pipeline); _httpClient.BaseAddress = new Uri(_options.BaseUrl); } diff --git a/Src/Notion.Client/http/QueryHelpers.cs b/Src/Notion.Client/http/QueryHelpers.cs index 783ae20e..86a2f0fb 100644 --- a/Src/Notion.Client/http/QueryHelpers.cs +++ b/Src/Notion.Client/http/QueryHelpers.cs @@ -25,7 +25,7 @@ public static string AddQueryString(string uri, string name, string value) throw new ArgumentNullException(nameof(value)); } - return AddQueryString(uri, new[] { new KeyValuePair(name, value) }); + return AddQueryString(uri, new[] {new KeyValuePair(name, value)}); } public static string AddQueryString(string uri, IDictionary queryParams) @@ -74,6 +74,7 @@ private static string AddQueryString( var sb = new StringBuilder(); sb.Append(uriToBeAppended); + foreach (var parameter in queryParams) { sb.Append(hasQuery ? '&' : '?'); @@ -84,13 +85,14 @@ private static string AddQueryString( } sb.Append(anchorText); + return sb.ToString(); } - private static IEnumerable> RemoveEmptyValueQueryParams(IEnumerable> queryParams) + private static IEnumerable> RemoveEmptyValueQueryParams( + IEnumerable> queryParams) { return queryParams.Where(x => !string.IsNullOrWhiteSpace(x.Value)); } - } } diff --git a/Test/Notion.IntegrationTests/CommentsClientTests.cs b/Test/Notion.IntegrationTests/CommentsClientTests.cs index 2ac7219d..32d887eb 100644 --- a/Test/Notion.IntegrationTests/CommentsClientTests.cs +++ b/Test/Notion.IntegrationTests/CommentsClientTests.cs @@ -5,130 +5,95 @@ using Notion.Client; using Xunit; -namespace Notion.IntegrationTests +namespace Notion.IntegrationTests; + +public class CommentsClientTests : IDisposable { - public class CommentsClientTests : IDisposable + private readonly INotionClient _client; + private readonly Page _page; + private readonly string _pageParentId; + + public CommentsClientTests() + { + var options = new ClientOptions {AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN")}; + + _client = NotionClientFactory.Create(options); + + _pageParentId = Environment.GetEnvironmentVariable("NOTION_PAGE_PARENT_ID") ?? + throw new ArgumentNullException("Page parent id is required."); + + _page = _client.Pages.CreateAsync( + PagesCreateParametersBuilder.Create( + new ParentPageInput {PageId = _pageParentId} + ).Build() + ).Result; + } + + public void Dispose() + { + _client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters {Archived = true}).Wait(); + } + + [Fact] + public async Task ShouldCreatePageComment() { - private readonly INotionClient _client; - private readonly string _pageParentId; - private readonly Page _page; - - public CommentsClientTests() - { - var options = new ClientOptions - { - AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN") - }; - - _client = NotionClientFactory.Create(options); - _pageParentId = Environment.GetEnvironmentVariable("NOTION_PAGE_PARENT_ID") ?? throw new ArgumentNullException("Page parent id is required."); - - _page = _client.Pages.CreateAsync( - PagesCreateParametersBuilder.Create( - new ParentPageInput() - { - PageId = _pageParentId - } - ).Build() - ).Result; - } - - [Fact] - public async Task ShouldCreatePageComment() - { - // Arrange - var parameters = CreateCommentParameters.CreatePageComment( - new ParentPageInput + // Arrange + var parameters = CreateCommentParameters.CreatePageComment( + new ParentPageInput {PageId = _page.Id}, + new List {new RichTextTextInput {Text = new Text {Content = "This is a comment"}}} + ); + + // Act + var response = await _client.Comments.Create(parameters); + + // Arrange + + Assert.NotNull(response.Parent); + Assert.NotNull(response.Id); + Assert.NotNull(response.DiscussionId); + + Assert.NotNull(response.RichText); + Assert.Single(response.RichText); + var richText = Assert.IsType(response.RichText.First()); + Assert.Equal("This is a comment", richText.Text.Content); + + var pageParent = Assert.IsType(response.Parent); + Assert.Equal(_page.Id, pageParent.PageId); + } + + [Fact] + public async Task ShouldCreateADiscussionComment() + { + // Arrange + var comment = await _client.Comments.Create( + CreateCommentParameters.CreatePageComment( + new ParentPageInput {PageId = _page.Id}, + new List {new RichTextTextInput {Text = new Text {Content = "This is a comment"}}} + ) + ); + + // Act + var response = await _client.Comments.Create( + CreateCommentParameters.CreateDiscussionComment( + comment.DiscussionId, + new List { - PageId = _page.Id - }, - new List { - new RichTextTextInput - { - Text = new Text - { - Content = "This is a comment" - } - } + new RichTextTextInput {Text = new Text {Content = "This is a sub comment"}}, } - ); - - // Act - var response = await _client.Comments.Create(parameters); - - // Arrange - - Assert.NotNull(response.Parent); - Assert.NotNull(response.Id); - Assert.NotNull(response.DiscussionId); - - Assert.NotNull(response.RichText); - Assert.Single(response.RichText); - var richText = Assert.IsType(response.RichText.First()); - Assert.Equal("This is a comment", richText.Text.Content); - - var pageParent = Assert.IsType(response.Parent); - Assert.Equal(_page.Id, pageParent.PageId); - } - - [Fact] - public async Task ShouldCreateADiscussionComment() - { - // Arrange - var comment = await _client.Comments.Create( - CreateCommentParameters.CreatePageComment( - new ParentPageInput - { - PageId = _page.Id - }, - new List { - new RichTextTextInput - { - Text = new Text - { - Content = "This is a comment" - } - } - } - ) - ); - - // Act - var response = await _client.Comments.Create( - CreateCommentParameters.CreateDiscussionComment( - comment.DiscussionId, - new List { - new RichTextTextInput - { - Text = new Text - { - Content = "This is a sub comment" - } - } - } - ) - ); - - // Arrange - Assert.Null(response.Parent); - Assert.NotNull(response.Id); - Assert.Equal(comment.DiscussionId, response.DiscussionId); - - Assert.NotNull(response.RichText); - Assert.Single(response.RichText); - var richText = Assert.IsType(response.RichText.First()); - Assert.Equal("This is a sub comment", richText.Text.Content); - - var pageParent = Assert.IsType(response.Parent); - Assert.Equal(_page.Id, pageParent.PageId); - } - - public void Dispose() - { - _client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters - { - Archived = true, - }).Wait(); - } + ) + ); + + // Arrange + Assert.Null(response.Parent); + Assert.NotNull(response.Id); + Assert.Equal(comment.DiscussionId, response.DiscussionId); + + Assert.NotNull(response.RichText); + Assert.Single(response.RichText); + var richText = Assert.IsType(response.RichText.First()); + Assert.Equal("This is a sub comment", richText.Text.Content); + + var pageParent = Assert.IsType(response.Parent); + Assert.Equal(_page.Id, pageParent.PageId); } } diff --git a/Test/Notion.IntegrationTests/IBlocksClientTests.cs b/Test/Notion.IntegrationTests/IBlocksClientTests.cs index eabef5b4..1aaa2726 100644 --- a/Test/Notion.IntegrationTests/IBlocksClientTests.cs +++ b/Test/Notion.IntegrationTests/IBlocksClientTests.cs @@ -6,537 +6,430 @@ using Notion.Client; using Xunit; -namespace Notion.IntegrationTests +namespace Notion.IntegrationTests; + +public class IBlocksClientTests { - public class IBlocksClientTests + private readonly INotionClient _client; + + public IBlocksClientTests() { - private readonly INotionClient _client; + var options = new ClientOptions {AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN")}; - public IBlocksClientTests() - { - var options = new ClientOptions - { - AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN") - }; + _client = NotionClientFactory.Create(options); + } - _client = NotionClientFactory.Create(options); - } + [Fact] + public async Task AppendChildrenAsync_AppendsBlocksGivenBlocks() + { + var pageParentId = "3c357473a28149a488c010d2b245a589"; - [Fact] - public async Task AppendChildrenAsync_AppendsBlocksGivenBlocks() - { - var pageParentId = "3c357473a28149a488c010d2b245a589"; + var page = await _client.Pages.CreateAsync( + PagesCreateParametersBuilder.Create( + new ParentPageInput {PageId = pageParentId} + ).Build() + ); - var page = await _client.Pages.CreateAsync( - PagesCreateParametersBuilder.Create( - new ParentPageInput() - { - PageId = pageParentId - } - ).Build() - ); - - var blocks = await _client.Blocks.AppendChildrenAsync( - page.Id, - new BlocksAppendChildrenParameters + var blocks = await _client.Blocks.AppendChildrenAsync( + page.Id, + new BlocksAppendChildrenParameters + { + Children = new List { - Children = new List() + new BreadcrumbBlock {Breadcrumb = new BreadcrumbBlock.Data()}, + new DividerBlock {Divider = new DividerBlock.Data()}, + new TableOfContentsBlock {TableOfContents = new TableOfContentsBlock.Data()}, + new CalloutBlock { - new BreadcrumbBlock - { - Breadcrumb = new BreadcrumbBlock.Data() - }, - new DividerBlock - { - Divider = new DividerBlock.Data() - }, - new TableOfContentsBlock - { - TableOfContents = new TableOfContentsBlock.Data() - }, - new CalloutBlock + Callout = new CalloutBlock.Info { - Callout = new CalloutBlock.Info + RichText = new List { - RichText = new List { - new RichTextTextInput - { - Text = new Text - { - Content = "Test" - } - } - } - } - } - } - } - ); - - blocks.Results.Should().HaveCount(4); - - // cleanup - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters - { - Archived = true - }); - } + new RichTextTextInput {Text = new Text {Content = "Test"}}, + }, + }, + }, + }, + } + ); - [Fact] - public async Task UpdateBlockAsync_UpdatesGivenBlock() - { - var pageParentId = "3c357473a28149a488c010d2b245a589"; + blocks.Results.Should().HaveCount(4); - var page = await _client.Pages.CreateAsync( - PagesCreateParametersBuilder.Create( - new ParentPageInput() - { - PageId = pageParentId - } - ).Build() - ); - - var blocks = await _client.Blocks.AppendChildrenAsync( - page.Id, - new BlocksAppendChildrenParameters - { - Children = new List() - { - new BreadcrumbBlock - { - Breadcrumb = new BreadcrumbBlock.Data() - } - } - } - ); + // cleanup + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + } - var blockId = blocks.Results.First().Id; - await _client.Blocks.UpdateAsync(blockId, new BreadcrumbUpdateBlock()); + [Fact] + public async Task UpdateBlockAsync_UpdatesGivenBlock() + { + var pageParentId = "3c357473a28149a488c010d2b245a589"; - blocks = await _client.Blocks.RetrieveChildrenAsync(page.Id); - blocks.Results.Should().HaveCount(1); + var page = await _client.Pages.CreateAsync( + PagesCreateParametersBuilder.Create( + new ParentPageInput {PageId = pageParentId} + ).Build() + ); - // cleanup - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters + var blocks = await _client.Blocks.AppendChildrenAsync( + page.Id, + new BlocksAppendChildrenParameters { - Archived = true - }); - } + Children = new List {new BreadcrumbBlock {Breadcrumb = new BreadcrumbBlock.Data()}}, + } + ); - [Fact] - public async Task DeleteAsync_DeleteBlockWithGivenId() - { - var pageParentId = "3c357473a28149a488c010d2b245a589"; + var blockId = blocks.Results.First().Id; + await _client.Blocks.UpdateAsync(blockId, new BreadcrumbUpdateBlock()); - var page = await _client.Pages.CreateAsync( - PagesCreateParametersBuilder.Create( - new ParentPageInput() - { - PageId = pageParentId - } - ).Build() - ); - - var blocks = await _client.Blocks.AppendChildrenAsync( - page.Id, - new BlocksAppendChildrenParameters - { - Children = new List() - { - new DividerBlock - { - Divider = new DividerBlock.Data() - }, - new TableOfContentsBlock - { - TableOfContents = new TableOfContentsBlock.Data() - }, - } - } - ); + blocks = await _client.Blocks.RetrieveChildrenAsync(page.Id); + blocks.Results.Should().HaveCount(1); - blocks.Results.Should().HaveCount(2); + // cleanup + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + } - // cleanup - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters - { - Archived = true - }); - } + [Fact] + public async Task DeleteAsync_DeleteBlockWithGivenId() + { + var pageParentId = "3c357473a28149a488c010d2b245a589"; - [Theory] - [MemberData(nameof(BlockData))] - public async Task UpdateAsync_UpdatesGivenBlock(IBlock block, IUpdateBlock updateBlock, Action assert) - { - var pageParentId = "3c357473a28149a488c010d2b245a589"; + var page = await _client.Pages.CreateAsync( + PagesCreateParametersBuilder.Create( + new ParentPageInput {PageId = pageParentId} + ).Build() + ); - var page = await _client.Pages.CreateAsync( - PagesCreateParametersBuilder.Create( - new ParentPageInput - { - PageId = pageParentId - } - ).Build() - ); - - var blocks = await _client.Blocks.AppendChildrenAsync( - page.Id, - new BlocksAppendChildrenParameters + var blocks = await _client.Blocks.AppendChildrenAsync( + page.Id, + new BlocksAppendChildrenParameters + { + Children = new List { - Children = new List() - { - block - } - } - ); + new DividerBlock {Divider = new DividerBlock.Data()}, + new TableOfContentsBlock {TableOfContents = new TableOfContentsBlock.Data()}, + }, + } + ); + + blocks.Results.Should().HaveCount(2); - var blockId = blocks.Results.First().Id; - await _client.Blocks.UpdateAsync(blockId, updateBlock); + // cleanup + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + } - blocks = await _client.Blocks.RetrieveChildrenAsync(page.Id); - blocks.Results.Should().HaveCount(1); + [Theory] + [MemberData(nameof(BlockData))] + public async Task UpdateAsync_UpdatesGivenBlock(IBlock block, IUpdateBlock updateBlock, Action assert) + { + var pageParentId = "3c357473a28149a488c010d2b245a589"; - var updatedBlock = blocks.Results.First(); + var page = await _client.Pages.CreateAsync( + PagesCreateParametersBuilder.Create( + new ParentPageInput {PageId = pageParentId} + ).Build() + ); - assert.Invoke(updatedBlock); + var blocks = await _client.Blocks.AppendChildrenAsync( + page.Id, + new BlocksAppendChildrenParameters {Children = new List {block}} + ); - // cleanup - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters - { - Archived = true - }); - } + var blockId = blocks.Results.First().Id; + await _client.Blocks.UpdateAsync(blockId, updateBlock); + + blocks = await _client.Blocks.RetrieveChildrenAsync(page.Id); + blocks.Results.Should().HaveCount(1); + + var updatedBlock = blocks.Results.First(); + + assert.Invoke(updatedBlock); + + // cleanup + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + } - private static IEnumerable BlockData() + private static IEnumerable BlockData() + { + return new List { - return new List + new object[] { - new object[] { - new BookmarkBlock + new BookmarkBlock + { + Bookmark = new BookmarkBlock.Info { - Bookmark = new BookmarkBlock.Info - { - Url = "https://developers.notion.com/reference/rich-text", - Caption = new List - { - new RichTextTextInput - { - Text = new Text - { - Content = "Notion API" - } - } - } - } - }, - new BookmarkUpdateBlock { - Bookmark = new BookmarkUpdateBlock.Info + Url = "https://developers.notion.com/reference/rich-text", + Caption = new List { - Url = "https://github.com/notion-dotnet/notion-sdk-net", - Caption = new List - { - new RichTextTextInput - { - Text = new Text - { - Content = "Github" - } - } - } - } + new RichTextTextInput {Text = new Text {Content = "Notion API"}}, + }, }, - new Action((block) => { - var updatedBlock = (BookmarkBlock)block; - Assert.Equal("https://github.com/notion-dotnet/notion-sdk-net", updatedBlock.Bookmark.Url); - Assert.Equal("Github", updatedBlock.Bookmark.Caption.OfType().First().Text.Content); - }) }, - new object[] { - new EquationBlock + new BookmarkUpdateBlock + { + Bookmark = new BookmarkUpdateBlock.Info { - Equation = new EquationBlock.Info + Url = "https://github.com/notion-dotnet/notion-sdk-net", + Caption = new List { - Expression = "e=mc^3" - } - }, - new EquationUpdateBlock { - Equation = new EquationUpdateBlock.Info - { - Expression = "e=mc^2" - } - }, - new Action((block) => { - var updatedBlock = (EquationBlock)block; - Assert.Equal("e=mc^2", updatedBlock.Equation.Expression); - }) - }, - new object[] { - new DividerBlock { - Divider = new DividerBlock.Data() - }, - new DividerUpdateBlock(), - new Action((block) => { - Assert.NotNull(block); - Assert.IsType(block); - }) - }, - new object[] { - new AudioBlock { - Audio = new ExternalFile { - External = new ExternalFile.Info { - Url = "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3" - } - } - }, - new AudioUpdateBlock { - Audio = new ExternalFileInput { - External = new ExternalFileInput.Data { - Url = "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3" - } - } + new RichTextTextInput {Text = new Text {Content = "Github"}}, + }, }, - new Action((block) => { - block.Should().NotBeNull(); - - block.Should().BeOfType().Subject - .Audio.Should().BeOfType().Subject - .External.Url.Should().Be("https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3"); - }) }, - new object[] + new Action(block => { - new TableOfContentsBlock { - TableOfContents = new TableOfContentsBlock.Data() - }, - new TableOfContentsUpdateBlock(), - new Action((block) => + var updatedBlock = (BookmarkBlock)block; + Assert.Equal("https://github.com/notion-dotnet/notion-sdk-net", updatedBlock.Bookmark.Url); + Assert.Equal("Github", updatedBlock.Bookmark.Caption.OfType().First().Text.Content); + }), + }, + new object[] + { + new EquationBlock {Equation = new EquationBlock.Info {Expression = "e=mc^3"}}, + new EquationUpdateBlock {Equation = new EquationUpdateBlock.Info {Expression = "e=mc^2"}}, + new Action(block => + { + var updatedBlock = (EquationBlock)block; + Assert.Equal("e=mc^2", updatedBlock.Equation.Expression); + }), + }, + new object[] + { + new DividerBlock {Divider = new DividerBlock.Data()}, new DividerUpdateBlock(), new Action( + block => { Assert.NotNull(block); - Assert.IsType(block); - }) - }, - new object[] + Assert.IsType(block); + }), + }, + new object[] + { + new AudioBlock { - new CalloutBlock + Audio = new ExternalFile { - Callout = new CalloutBlock.Info + External = new ExternalFile.Info { - RichText = new List - { - new RichTextTextInput - { - Text = new Text - { - Content = "Test" - } - } - } - } + Url = "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3", + }, }, - new CalloutUpdateBlock() + }, + new AudioUpdateBlock + { + Audio = new ExternalFileInput { - Callout = new CalloutUpdateBlock.Info + External = new ExternalFileInput.Data { - RichText = new List - { - new RichTextTextInput - { - Text = new Text - { - Content = "Test 2" - } - } - } - } + Url = "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3", + }, }, - new Action((block) => - { - Assert.NotNull(block); - var calloutBlock = Assert.IsType(block); - - Assert.Equal("Test 2", calloutBlock.Callout.RichText.OfType().First().Text.Content); - }) }, - new object[] + new Action(block => { - new QuoteBlock + block.Should().NotBeNull(); + + block.Should().BeOfType().Subject + .Audio.Should().BeOfType().Subject + .External.Url.Should().Be("https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3"); + }), + }, + new object[] + { + new TableOfContentsBlock {TableOfContents = new TableOfContentsBlock.Data()}, + new TableOfContentsUpdateBlock(), new Action(block => + { + Assert.NotNull(block); + Assert.IsType(block); + }), + }, + new object[] + { + new CalloutBlock + { + Callout = new CalloutBlock.Info { - Quote = new QuoteBlock.Info + RichText = new List { - RichText = new List - { - new RichTextTextInput - { - Text = new Text - { - Content = "Test" - } - } - } - } + new RichTextTextInput {Text = new Text {Content = "Test"}}, + }, }, - new QuoteUpdateBlock() + }, + new CalloutUpdateBlock + { + Callout = new CalloutUpdateBlock.Info { - Quote = new QuoteUpdateBlock.Info + RichText = new List { - RichText = new List - { - new RichTextTextInput - { - Text = new Text - { - Content = "Test 2" - } - } - } - } + new RichTextTextInput {Text = new Text {Content = "Test 2"}}, + }, }, - new Action((block) => - { - Assert.NotNull(block); - var quoteBlock = Assert.IsType(block); - - Assert.Equal("Test 2", quoteBlock.Quote.RichText.OfType().First().Text.Content); - }) }, - new object[] + new Action(block => { - new ImageBlock() { - Image = new ExternalFile + Assert.NotNull(block); + var calloutBlock = Assert.IsType(block); + + Assert.Equal("Test 2", calloutBlock.Callout.RichText.OfType().First().Text.Content); + }), + }, + new object[] + { + new QuoteBlock + { + Quote = new QuoteBlock.Info + { + RichText = new List { - External = new ExternalFile.Info - { - Url = "https://zephoria.com/wp-content/uploads/2014/08/online-community.jpg" - } - } + new RichTextTextInput {Text = new Text {Content = "Test"}}, + }, }, - new ImageUpdateBlock() + }, + new QuoteUpdateBlock + { + Quote = new QuoteUpdateBlock.Info { - Image = new ExternalFileInput + RichText = new List { - External = new ExternalFileInput.Data - { - Url = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg" - } - } + new RichTextTextInput {Text = new Text {Content = "Test 2"}}, + }, }, - new Action (block => - { - Assert.NotNull(block); - var imageBlock = Assert.IsType(block); - var imageFile = Assert.IsType(imageBlock.Image); - - Assert.Equal("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", imageFile.External.Url); - }) }, - new object[] + new Action(block => + { + Assert.NotNull(block); + var quoteBlock = Assert.IsType(block); + + Assert.Equal("Test 2", quoteBlock.Quote.RichText.OfType().First().Text.Content); + }), + }, + new object[] + { + new ImageBlock { - new EmbedBlock() + Image = new ExternalFile { - Embed = new EmbedBlock.Info + External = new ExternalFile.Info { - Url = "https://zephoria.com/wp-content/uploads/2014/08/online-community.jpg" - } + Url = "https://zephoria.com/wp-content/uploads/2014/08/online-community.jpg", + }, }, - new EmbedUpdateBlock() + }, + new ImageUpdateBlock + { + Image = new ExternalFileInput { - Embed = new EmbedUpdateBlock.Info + External = new ExternalFileInput.Data { - Url = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg" - } + Url + = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", + }, }, - new Action (block => + }, + new Action(block => + { + Assert.NotNull(block); + var imageBlock = Assert.IsType(block); + var imageFile = Assert.IsType(imageBlock.Image); + + Assert.Equal("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", + imageFile.External.Url); + }), + }, + new object[] + { + new EmbedBlock + { + Embed = new EmbedBlock.Info { - Assert.NotNull(block); - var embedBlock = Assert.IsType(block); - - Assert.Equal("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", embedBlock.Embed.Url); - }) + Url = "https://zephoria.com/wp-content/uploads/2014/08/online-community.jpg", + }, }, - new object[] + new EmbedUpdateBlock { - new TemplateBlock() + Embed = new EmbedUpdateBlock.Info { - Template = new TemplateBlock.Data - { - RichText = new List - { - new RichTextText - { - Text = new Text - { - Content = "Test Template" - } - } - }, - Children = new List - { - new EmbedBlock() - { - Embed = new EmbedBlock.Info - { - Url = "https://zephoria.com/wp-content/uploads/2014/08/online-community.jpg" - } - } - } - } + Url = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", }, - new TemplateUpdateBlock() + }, + new Action(block => + { + Assert.NotNull(block); + var embedBlock = Assert.IsType(block); + + Assert.Equal("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", + embedBlock.Embed.Url); + }), + }, + new object[] + { + new TemplateBlock + { + Template = new TemplateBlock.Data { - Template = new TemplateUpdateBlock.Info + RichText = new List { - RichText = new List + new RichTextText {Text = new Text {Content = "Test Template"}}, + }, + Children = new List + { + new EmbedBlock { - new RichTextTextInput + Embed = new EmbedBlock.Info { - Text = new Text - { - Content = "Test Template 2" - } - } - } - } + Url + = "https://zephoria.com/wp-content/uploads/2014/08/online-community.jpg", + }, + }, + }, }, - new Action (block => - { - Assert.NotNull(block); - var templateBlock = Assert.IsType(block); - - Assert.Single(templateBlock.Template.RichText); - Assert.Null(templateBlock.Template.Children); - Assert.Equal("Test Template 2", templateBlock.Template.RichText.OfType().First().Text.Content); - }) }, - new object[] + new TemplateUpdateBlock { - new LinkToPageBlock() + Template = new TemplateUpdateBlock.Info { - LinkToPage = new PageParent + RichText = new List { - Type = ParentType.PageId, - PageId = "533578e3edf14c0a91a9da6b09bac3ee" - } + new RichTextTextInput {Text = new Text {Content = "Test Template 2"}}, + }, }, - new LinkToPageUpdateBlock() + }, + new Action(block => + { + Assert.NotNull(block); + var templateBlock = Assert.IsType(block); + + Assert.Single(templateBlock.Template.RichText); + Assert.Null(templateBlock.Template.Children); + + Assert.Equal("Test Template 2", + templateBlock.Template.RichText.OfType().First().Text.Content); + }), + }, + new object[] + { + new LinkToPageBlock + { + LinkToPage = new PageParent { - LinkToPage = new ParentPageInput - { - PageId = "3c357473a28149a488c010d2b245a589" - } + Type = ParentType.PageId, PageId = "533578e3edf14c0a91a9da6b09bac3ee", }, - new Action(block => - { - Assert.NotNull(block); - var linkToPageBlock = Assert.IsType(block); + }, + new LinkToPageUpdateBlock + { + LinkToPage = new ParentPageInput {PageId = "3c357473a28149a488c010d2b245a589"}, + }, + new Action(block => + { + Assert.NotNull(block); + var linkToPageBlock = Assert.IsType(block); - var pageParent = Assert.IsType(linkToPageBlock.LinkToPage); + var pageParent = Assert.IsType(linkToPageBlock.LinkToPage); - // TODO: Currently the api doesn't allow to update the link_to_page block type - // This will change to updated ID once api start to support - Assert.Equal(Guid.Parse("533578e3edf14c0a91a9da6b09bac3ee"), Guid.Parse(pageParent.PageId)); - }) - } - }; - } + // TODO: Currently the api doesn't allow to update the link_to_page block type + // This will change to updated ID once api start to support + Assert.Equal(Guid.Parse("533578e3edf14c0a91a9da6b09bac3ee"), Guid.Parse(pageParent.PageId)); + }), + }, + }; } } diff --git a/Test/Notion.IntegrationTests/IPageClientTests.cs b/Test/Notion.IntegrationTests/IPageClientTests.cs index dbf74a90..24f11940 100644 --- a/Test/Notion.IntegrationTests/IPageClientTests.cs +++ b/Test/Notion.IntegrationTests/IPageClientTests.cs @@ -6,297 +6,228 @@ using Notion.Client; using Xunit; -namespace Notion.IntegrationTests +namespace Notion.IntegrationTests; + +public class IPageClientTests { - public class IPageClientTests - { - private readonly INotionClient _client; - private readonly string _databaseId; + private readonly INotionClient _client; + private readonly string _databaseId; - public IPageClientTests() - { - var options = new ClientOptions - { - AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN") - }; + public IPageClientTests() + { + var options = new ClientOptions {AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN")}; - _client = NotionClientFactory.Create(options); - _databaseId = Environment.GetEnvironmentVariable("DATABASE_ID") ?? "f86f2262-0751-40f2-8f63-e3f7a3c39fcb"; - } + _client = NotionClientFactory.Create(options); + _databaseId = Environment.GetEnvironmentVariable("DATABASE_ID") ?? "f86f2262-0751-40f2-8f63-e3f7a3c39fcb"; + } - [Fact] - public async Task CreateAsync_CreatesANewPage() - { - PagesCreateParameters pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput - { - DatabaseId = _databaseId - }) - .AddProperty("Name", new TitlePropertyValue - { - Title = new List + [Fact] + public async Task CreateAsync_CreatesANewPage() + { + var pagesCreateParameters = PagesCreateParametersBuilder + .Create(new DatabaseParentInput {DatabaseId = _databaseId}) + .AddProperty("Name", + new TitlePropertyValue { - new RichTextText - { - Text = new Text - { - Content = "Test Page Title" - } - } - } - }) + Title = new List + { + new RichTextText {Text = new Text {Content = "Test Page Title"}}, + }, + }) .Build(); - var page = await _client.Pages.CreateAsync(pagesCreateParameters); + var page = await _client.Pages.CreateAsync(pagesCreateParameters); - page.Should().NotBeNull(); - page.Parent.Should().BeOfType().Which - .DatabaseId.Should().Be(_databaseId); + page.Should().NotBeNull(); - page.Properties.Should().ContainKey("Name"); - var pageProperty = page.Properties["Name"].Should().BeOfType().Subject; + page.Parent.Should().BeOfType().Which + .DatabaseId.Should().Be(_databaseId); - var titleProperty = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters - { - PageId = page.Id, - PropertyId = pageProperty.Id - }); + page.Properties.Should().ContainKey("Name"); + var pageProperty = page.Properties["Name"].Should().BeOfType().Subject; - titleProperty.Results.First().As().Title.PlainText.Should().Be("Test Page Title"); + var titleProperty + = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItem( + new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = pageProperty.Id}); - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters - { - Archived = true - }); - } + titleProperty.Results.First().As().Title.PlainText.Should().Be("Test Page Title"); - [Fact] - public async Task Bug_unable_to_create_page_with_select_property() - { - PagesCreateParameters pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput - { - DatabaseId = _databaseId - }) - .AddProperty("Name", new TitlePropertyValue - { - Title = new List - { - new RichTextText - { - Text = new Text - { - Content = "Test Page Title" - } - } - } - }) - .AddProperty("TestSelect", new SelectPropertyValue - { - Select = new SelectOption + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + } + + [Fact] + public async Task Bug_unable_to_create_page_with_select_property() + { + var pagesCreateParameters = PagesCreateParametersBuilder + .Create(new DatabaseParentInput {DatabaseId = _databaseId}) + .AddProperty("Name", + new TitlePropertyValue { - Id = "dfbfbe65-6f67-4876-9f75-699124334d06" - } - }) + Title = new List + { + new RichTextText {Text = new Text {Content = "Test Page Title"}}, + }, + }) + .AddProperty("TestSelect", + new SelectPropertyValue {Select = new SelectOption {Id = "dfbfbe65-6f67-4876-9f75-699124334d06"}}) .Build(); - var page = await _client.Pages.CreateAsync(pagesCreateParameters); + var page = await _client.Pages.CreateAsync(pagesCreateParameters); - page.Should().NotBeNull(); - page.Parent.Should().BeOfType().Which - .DatabaseId.Should().Be(_databaseId); + page.Should().NotBeNull(); - page.Properties.Should().ContainKey("Name"); - var pageProperty = page.Properties["Name"].Should().BeOfType().Subject; + page.Parent.Should().BeOfType().Which + .DatabaseId.Should().Be(_databaseId); - var titleProperty = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters - { - PageId = page.Id, - PropertyId = pageProperty.Id - }); + page.Properties.Should().ContainKey("Name"); + var pageProperty = page.Properties["Name"].Should().BeOfType().Subject; - titleProperty.Results.First().As().Title.PlainText.Should().Be("Test Page Title"); + var titleProperty + = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItem( + new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = pageProperty.Id}); - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters - { - Archived = true - }); - } + titleProperty.Results.First().As().Title.PlainText.Should().Be("Test Page Title"); - [Fact] - public async Task Test_RetrievePagePropertyItemAsync() - { - PagesCreateParameters pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput - { - DatabaseId = _databaseId - }) - .AddProperty("Name", new TitlePropertyValue - { - Title = new List + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + } + + [Fact] + public async Task Test_RetrievePagePropertyItemAsync() + { + var pagesCreateParameters = PagesCreateParametersBuilder + .Create(new DatabaseParentInput {DatabaseId = _databaseId}) + .AddProperty("Name", + new TitlePropertyValue { - new RichTextText + Title = new List { - Text = new Text - { - Content = "Test Page Title" - } - } - } - }) + new RichTextText {Text = new Text {Content = "Test Page Title"}}, + }, + }) .Build(); - var page = await _client.Pages.CreateAsync(pagesCreateParameters); + var page = await _client.Pages.CreateAsync(pagesCreateParameters); - var property = await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters - { - PageId = page.Id, - PropertyId = "title" - }); + var property = await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters + { + PageId = page.Id, PropertyId = "title", + }); - property.Should().NotBeNull(); - property.Should().BeOfType(); + property.Should().NotBeNull(); + property.Should().BeOfType(); - var listProperty = (ListPropertyItem)property; + var listProperty = (ListPropertyItem)property; - listProperty.Type.Should().NotBeNull(); - listProperty.Results.Should().SatisfyRespectively(p => - { - p.Should().BeOfType(); - var titleProperty = (TitlePropertyItem)p; + listProperty.Type.Should().NotBeNull(); - titleProperty.Title.PlainText.Should().Be("Test Page Title"); - }); + listProperty.Results.Should().SatisfyRespectively(p => + { + p.Should().BeOfType(); + var titleProperty = (TitlePropertyItem)p; - // cleanup - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters - { - Archived = true - }); - } + titleProperty.Title.PlainText.Should().Be("Test Page Title"); + }); - [Fact] - public async Task Test_UpdatePageProperty_with_date_as_null() - { - // setup - add property to db and create a page with the property having a date + // cleanup + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + } - string datePropertyName = "Test Date Property"; - var updateDatabaseParameters = new DatabasesUpdateParameters(); - updateDatabaseParameters.Properties = new Dictionary - { - { "Name", new TitleUpdatePropertySchema { Title = new Dictionary() } }, - { "Test Date Property", new DateUpdatePropertySchema{ Date = new Dictionary() } } - }; + [Fact] + public async Task Test_UpdatePageProperty_with_date_as_null() + { + // setup - add property to db and create a page with the property having a date - PagesCreateParameters pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput - { - DatabaseId = _databaseId - }) - .AddProperty("Name", new TitlePropertyValue - { - Title = new List - { - new RichTextText - { - Text = new Text - { - Content = "Test Page Title" - } - } - } - }) - .AddProperty(datePropertyName, new DatePropertyValue - { - Date = new Date() + var datePropertyName = "Test Date Property"; + var updateDatabaseParameters = new DatabasesUpdateParameters(); + + updateDatabaseParameters.Properties = new Dictionary + { + {"Name", new TitleUpdatePropertySchema {Title = new Dictionary()}}, + {"Test Date Property", new DateUpdatePropertySchema {Date = new Dictionary()}}, + }; + + var pagesCreateParameters = PagesCreateParametersBuilder + .Create(new DatabaseParentInput {DatabaseId = _databaseId}) + .AddProperty("Name", + new TitlePropertyValue + { + Title = new List + { + new RichTextText {Text = new Text {Content = "Test Page Title"}}, + }, + }) + .AddProperty(datePropertyName, + new DatePropertyValue { - Start = Convert.ToDateTime("2020-12-08T12:00:00Z"), - End = Convert.ToDateTime("2025-12-08T12:00:00Z") - } - }) + Date = new Date + { + Start = Convert.ToDateTime("2020-12-08T12:00:00Z"), + End = Convert.ToDateTime("2025-12-08T12:00:00Z"), + }, + }) .Build(); - var updatedDb = await _client.Databases.UpdateAsync(_databaseId, updateDatabaseParameters); + var updatedDb = await _client.Databases.UpdateAsync(_databaseId, updateDatabaseParameters); - var page = await _client.Pages.CreateAsync(pagesCreateParameters); + var page = await _client.Pages.CreateAsync(pagesCreateParameters); - var setDate = (DatePropertyItem)await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters - { - PageId = page.Id, - PropertyId = page.Properties[datePropertyName].Id - }); + var setDate = (DatePropertyItem)await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters + { + PageId = page.Id, PropertyId = page.Properties[datePropertyName].Id, + }); - setDate?.Date?.Start.Should().Be(Convert.ToDateTime("2020-12-08T12:00:00Z")); + setDate?.Date?.Start.Should().Be(Convert.ToDateTime("2020-12-08T12:00:00Z")); - // verify - IDictionary testProps = new Dictionary(); - testProps.Add(datePropertyName, new DatePropertyValue() { Date = null }); + // verify + IDictionary testProps = new Dictionary(); + testProps.Add(datePropertyName, new DatePropertyValue {Date = null}); - var updatedPage = await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters - { - Properties = testProps - }); + var updatedPage = await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Properties = testProps}); - var verifyDate = (DatePropertyItem)await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters + var verifyDate = (DatePropertyItem)await _client.Pages.RetrievePagePropertyItem( + new RetrievePropertyItemParameters { - PageId = page.Id, - PropertyId = updatedPage.Properties[datePropertyName].Id + PageId = page.Id, PropertyId = updatedPage.Properties[datePropertyName].Id, }); - verifyDate?.Date.Should().BeNull(); + verifyDate?.Date.Should().BeNull(); - //cleanup - await _client.Blocks.DeleteAsync(page.Id); - } + //cleanup + await _client.Blocks.DeleteAsync(page.Id); + } - [Fact] - public async Task Bug_Unable_To_Parse_NumberPropertyItem() - { - // Arrange - var pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput - { - DatabaseId = _databaseId - }).AddProperty("Name", new TitlePropertyValue - { - Title = new List + [Fact] + public async Task Bug_Unable_To_Parse_NumberPropertyItem() + { + // Arrange + var pagesCreateParameters = PagesCreateParametersBuilder + .Create(new DatabaseParentInput {DatabaseId = _databaseId}).AddProperty("Name", + new TitlePropertyValue + { + Title = new List { - new RichTextText - { - Text = new Text - { - Content = "Test Page Title" - } - } - } - }).AddProperty("Number", new NumberPropertyValue - { - Number = 200.00 - }).Build(); + new RichTextText {Text = new Text {Content = "Test Page Title"}}, + }, + }).AddProperty("Number", new NumberPropertyValue {Number = 200.00}).Build(); - // Act - var page = await _client.Pages.CreateAsync(pagesCreateParameters); + // Act + var page = await _client.Pages.CreateAsync(pagesCreateParameters); - // Assert - Assert.NotNull(page); - var pageParent = Assert.IsType(page.Parent); - Assert.Equal(_databaseId, pageParent.DatabaseId); + // Assert + Assert.NotNull(page); + var pageParent = Assert.IsType(page.Parent); + Assert.Equal(_databaseId, pageParent.DatabaseId); - var titleProperty = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters - { - PageId = page.Id, - PropertyId = page.Properties["Name"].Id - }); + var titleProperty = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItem( + new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = page.Properties["Name"].Id}); - Assert.Equal("Test Page Title", titleProperty.Results.First().As().Title.PlainText); + Assert.Equal("Test Page Title", titleProperty.Results.First().As().Title.PlainText); - var numberProperty = (NumberPropertyItem)await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters - { - PageId = page.Id, - PropertyId = page.Properties["Number"].Id - }); + var numberProperty = (NumberPropertyItem)await _client.Pages.RetrievePagePropertyItem( + new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = page.Properties["Number"].Id}); - Assert.Equal(200.00, numberProperty.Number); + Assert.Equal(200.00, numberProperty.Number); - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters - { - Archived = true - }); - } + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); } } diff --git a/Test/Notion.UnitTests/ApiTestBase.cs b/Test/Notion.UnitTests/ApiTestBase.cs index e593a47c..ceb415d2 100644 --- a/Test/Notion.UnitTests/ApiTestBase.cs +++ b/Test/Notion.UnitTests/ApiTestBase.cs @@ -7,64 +7,55 @@ using WireMock.RequestBuilders; using WireMock.Server; -namespace Notion.UnitTests +namespace Notion.UnitTests; + +public class ApiTestBase : IDisposable { - public class ApiTestBase : IDisposable + protected static readonly JsonSerializerSettings JsonSerializerSettings = new() { - protected readonly WireMockServer Server; - - protected static readonly JsonSerializerSettings JsonSerializerSettings = new JsonSerializerSettings() - { - Formatting = Newtonsoft.Json.Formatting.Indented, - ContractResolver = new DefaultContractResolver - { - NamingStrategy = new CamelCaseNamingStrategy() - } - }; + Formatting = Formatting.Indented, + ContractResolver = new DefaultContractResolver {NamingStrategy = new CamelCaseNamingStrategy()}, + }; - protected readonly ClientOptions ClientOptions; + protected readonly ClientOptions ClientOptions; + protected readonly WireMockServer Server; - protected ApiTestBase() - { - Server = WireMockServer.Start(); - ClientOptions = new ClientOptions() - { - BaseUrl = Server.Urls.First(), - AuthToken = "" - }; - } + protected ApiTestBase() + { + Server = WireMockServer.Start(); + ClientOptions = new ClientOptions {BaseUrl = Server.Urls.First(), AuthToken = ""}; + } - public void Dispose() - { - Server.Stop(); - Server.Dispose(); - } + public void Dispose() + { + Server.Stop(); + Server.Dispose(); + } - protected IRequestBuilder CreateGetRequestBuilder(string path) - { - return Request.Create() - .WithPath(path) - .UsingGet() - .WithHeader("Authorization", $"Bearer {ClientOptions.AuthToken}", MatchBehaviour.AcceptOnMatch) - .WithHeader("Notion-Version", Constants.DEFAULT_NOTION_VERSION, MatchBehaviour.AcceptOnMatch); - } + protected IRequestBuilder CreateGetRequestBuilder(string path) + { + return Request.Create() + .WithPath(path) + .UsingGet() + .WithHeader("Authorization", $"Bearer {ClientOptions.AuthToken}", MatchBehaviour.AcceptOnMatch) + .WithHeader("Notion-Version", Constants.DEFAULT_NOTION_VERSION, MatchBehaviour.AcceptOnMatch); + } - protected IRequestBuilder CreatePostRequestBuilder(string path) - { - return Request.Create() - .WithPath(path) - .UsingPost() - .WithHeader("Authorization", $"Bearer {ClientOptions.AuthToken}", MatchBehaviour.AcceptOnMatch) - .WithHeader("Notion-Version", Constants.DEFAULT_NOTION_VERSION, MatchBehaviour.AcceptOnMatch); - } + protected IRequestBuilder CreatePostRequestBuilder(string path) + { + return Request.Create() + .WithPath(path) + .UsingPost() + .WithHeader("Authorization", $"Bearer {ClientOptions.AuthToken}", MatchBehaviour.AcceptOnMatch) + .WithHeader("Notion-Version", Constants.DEFAULT_NOTION_VERSION, MatchBehaviour.AcceptOnMatch); + } - protected IRequestBuilder CreatePatchRequestBuilder(string path) - { - return Request.Create() - .WithPath(path) - .UsingPatch() - .WithHeader("Authorization", $"Bearer {ClientOptions.AuthToken}", MatchBehaviour.AcceptOnMatch) - .WithHeader("Notion-Version", Constants.DEFAULT_NOTION_VERSION, MatchBehaviour.AcceptOnMatch); - } + protected IRequestBuilder CreatePatchRequestBuilder(string path) + { + return Request.Create() + .WithPath(path) + .UsingPatch() + .WithHeader("Authorization", $"Bearer {ClientOptions.AuthToken}", MatchBehaviour.AcceptOnMatch) + .WithHeader("Notion-Version", Constants.DEFAULT_NOTION_VERSION, MatchBehaviour.AcceptOnMatch); } } diff --git a/Test/Notion.UnitTests/BlocksClientTests.cs b/Test/Notion.UnitTests/BlocksClientTests.cs index 753e5464..8a568a13 100644 --- a/Test/Notion.UnitTests/BlocksClientTests.cs +++ b/Test/Notion.UnitTests/BlocksClientTests.cs @@ -7,191 +7,184 @@ using WireMock.ResponseBuilders; using Xunit; -namespace Notion.UnitTests +namespace Notion.UnitTests; + +public class BlocksClientTests : ApiTestBase { - public class BlocksClientTests : ApiTestBase - { - private readonly IBlocksClient _client; + private readonly IBlocksClient _client; - public BlocksClientTests() - { - _client = new BlocksClient(new RestClient(ClientOptions)); - } + public BlocksClientTests() + { + _client = new BlocksClient(new RestClient(ClientOptions)); + } - [Fact] - public async Task RetrieveBlockChildren() - { - // Arrange - string blockId = "3c357473-a281-49a4-88c0-10d2b245a589"; - var path = ApiEndpoints.BlocksApiUrls.RetrieveChildren(blockId); - var jsonData = await File.ReadAllTextAsync("data/blocks/RetrieveBlockChildrenResponse.json"); + [Fact] + public async Task RetrieveBlockChildren() + { + // Arrange + var blockId = "3c357473-a281-49a4-88c0-10d2b245a589"; + var path = ApiEndpoints.BlocksApiUrls.RetrieveChildren(blockId); + var jsonData = await File.ReadAllTextAsync("data/blocks/RetrieveBlockChildrenResponse.json"); - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - // Act - var childrenResult = await _client.RetrieveChildrenAsync(blockId, new BlocksRetrieveChildrenParameters()); + // Act + var childrenResult = await _client.RetrieveChildrenAsync(blockId, new BlocksRetrieveChildrenParameters()); - // Assert - var children = childrenResult.Results; - children.Should().HaveCount(8); - } + // Assert + var children = childrenResult.Results; + children.Should().HaveCount(8); + } - [Fact] - public async Task AppendBlockChildren() - { - // Arrange - string blockId = "7face6fd-3ef4-4b38-b1dc-c5044988eec0"; - var path = ApiEndpoints.BlocksApiUrls.AppendChildren(blockId); + [Fact] + public async Task AppendBlockChildren() + { + // Arrange + var blockId = "7face6fd-3ef4-4b38-b1dc-c5044988eec0"; + var path = ApiEndpoints.BlocksApiUrls.AppendChildren(blockId); - var jsonData = await File.ReadAllTextAsync("data/blocks/AppendBlockChildrenResponse.json"); + var jsonData = await File.ReadAllTextAsync("data/blocks/AppendBlockChildrenResponse.json"); - Server.Given(CreatePatchRequestBuilder(path)) - .RespondWith( + Server.Given(CreatePatchRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var parameters = new BlocksAppendChildrenParameters() + var parameters = new BlocksAppendChildrenParameters + { + Children = new List { - Children = new List + new HeadingTwoBlock { - new HeadingTwoBlock() + Heading_2 = new HeadingTwoBlock.Info { - Heading_2 = new HeadingTwoBlock.Info + RichText = new List { - RichText = new List - { - new RichTextText - { - Text = new Text - { - Content = "Lacinato kale" - } - } - } - } + new RichTextText {Text = new Text {Content = "Lacinato kale"}}, + }, }, - new ParagraphBlock() + }, + new ParagraphBlock + { + Paragraph = new ParagraphBlock.Info { - Paragraph = new ParagraphBlock.Info + RichText = new List { - RichText = new List + new RichTextText { - new RichTextText + Text = new Text { - Text = new Text + Content + = "Lacinato kale is a variety of kale with a long tradition in Italian cuisine, especially that of Tuscany. It is also known as Tuscan kale, Italian kale, dinosaur kale, kale, flat back kale, palm tree kale, or black Tuscan palm.", + Link = new Link { - Content = "Lacinato kale is a variety of kale with a long tradition in Italian cuisine, especially that of Tuscany. It is also known as Tuscan kale, Italian kale, dinosaur kale, kale, flat back kale, palm tree kale, or black Tuscan palm.", - Link = new Link - { - Url = "https://en.wikipedia.org/wiki/Lacinato_kale" - } - } - } - } - } - } - } - }; - - // Act - var blocksResult = await _client.AppendChildrenAsync(blockId, parameters); - - // Assert - var blocks = blocksResult.Results; - blocks.Should().SatisfyRespectively( - block => - { - block.Type.Should().Be(BlockType.Heading_2); - var headingBlock = (HeadingTwoBlock)block; - var text = headingBlock.Heading_2.RichText.OfType().FirstOrDefault(); - text.Text.Content.Should().Be("Lacinato kale"); + Url + = "https://en.wikipedia.org/wiki/Lacinato_kale", + }, + }, + }, + }, + }, }, - block => - { - block.Type.Should().Be(BlockType.Paragraph); - var paragraphBlock = (ParagraphBlock)block; - var text = paragraphBlock.Paragraph.RichText.OfType().LastOrDefault(); - text.Text.Content.Should().Be("Lacinato kale is a variety of kale with a long tradition in Italian cuisine, especially that of Tuscany. It is also known as Tuscan kale, Italian kale, dinosaur kale, kale, flat back kale, palm tree kale, or black Tuscan palm."); - text.Text.Link.Url.Should().Be("https://en.wikipedia.org/wiki/Lacinato_kale"); - } - ); - } + }, + }; - [Fact] - public async Task RetrieveAsync() - { - string blockId = "9bc30ad4-9373-46a5-84ab-0a7845ee52e6"; - var path = ApiEndpoints.BlocksApiUrls.Retrieve(blockId); - var jsonData = await File.ReadAllTextAsync("data/blocks/RetrieveBlockResponse.json"); + // Act + var blocksResult = await _client.AppendChildrenAsync(blockId, parameters); + + // Assert + var blocks = blocksResult.Results; + + blocks.Should().SatisfyRespectively( + block => + { + block.Type.Should().Be(BlockType.Heading_2); + var headingBlock = (HeadingTwoBlock)block; + var text = headingBlock.Heading_2.RichText.OfType().FirstOrDefault(); + text.Text.Content.Should().Be("Lacinato kale"); + }, + block => + { + block.Type.Should().Be(BlockType.Paragraph); + var paragraphBlock = (ParagraphBlock)block; + var text = paragraphBlock.Paragraph.RichText.OfType().LastOrDefault(); + + text.Text.Content.Should().Be( + "Lacinato kale is a variety of kale with a long tradition in Italian cuisine, especially that of Tuscany. It is also known as Tuscan kale, Italian kale, dinosaur kale, kale, flat back kale, palm tree kale, or black Tuscan palm."); + + text.Text.Link.Url.Should().Be("https://en.wikipedia.org/wiki/Lacinato_kale"); + } + ); + } + + [Fact] + public async Task RetrieveAsync() + { + var blockId = "9bc30ad4-9373-46a5-84ab-0a7845ee52e6"; + var path = ApiEndpoints.BlocksApiUrls.Retrieve(blockId); + var jsonData = await File.ReadAllTextAsync("data/blocks/RetrieveBlockResponse.json"); - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var block = await _client.RetrieveAsync(blockId); + var block = await _client.RetrieveAsync(blockId); - block.Id.Should().Be(blockId); - block.HasChildren.Should().BeFalse(); - block.Type.Should().Be(BlockType.ToDo); + block.Id.Should().Be(blockId); + block.HasChildren.Should().BeFalse(); + block.Type.Should().Be(BlockType.ToDo); - var todoBlock = ((ToDoBlock)block); - todoBlock.ToDo.RichText.Should().ContainSingle(); - todoBlock.ToDo.RichText.First().Should().BeAssignableTo(); - ((RichTextText)todoBlock.ToDo.RichText.First()).Text.Content.Should().Be("Lacinato kale"); - } + var todoBlock = (ToDoBlock)block; + todoBlock.ToDo.RichText.Should().ContainSingle(); + todoBlock.ToDo.RichText.First().Should().BeAssignableTo(); + ((RichTextText)todoBlock.ToDo.RichText.First()).Text.Content.Should().Be("Lacinato kale"); + } - [Fact] - public async Task UpdateAsync() - { - string blockId = "9bc30ad4-9373-46a5-84ab-0a7845ee52e6"; - var path = ApiEndpoints.BlocksApiUrls.Update(blockId); - var jsonData = await File.ReadAllTextAsync("data/blocks/UpdateBlockResponse.json"); + [Fact] + public async Task UpdateAsync() + { + var blockId = "9bc30ad4-9373-46a5-84ab-0a7845ee52e6"; + var path = ApiEndpoints.BlocksApiUrls.Update(blockId); + var jsonData = await File.ReadAllTextAsync("data/blocks/UpdateBlockResponse.json"); - Server.Given(CreatePatchRequestBuilder(path)) - .RespondWith( + Server.Given(CreatePatchRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var updateBlock = new ToDoUpdateBlock + var updateBlock = new ToDoUpdateBlock + { + ToDo = new ToDoUpdateBlock.Info { - ToDo = new ToDoUpdateBlock.Info + RichText = new List { - RichText = new List() - { - new RichTextTextInput - { - Text = new Text - { - Content = "Lacinato kale" - }, - } - }, - IsChecked = true - } - }; + new RichTextTextInput {Text = new Text {Content = "Lacinato kale"}}, + }, + IsChecked = true, + }, + }; - var block = await _client.UpdateAsync(blockId, updateBlock); + var block = await _client.UpdateAsync(blockId, updateBlock); - block.Id.Should().Be(blockId); - block.HasChildren.Should().BeFalse(); - block.Type.Should().Be(BlockType.ToDo); + block.Id.Should().Be(blockId); + block.HasChildren.Should().BeFalse(); + block.Type.Should().Be(BlockType.ToDo); - var todoBlock = ((ToDoBlock)block); - todoBlock.ToDo.RichText.Should().ContainSingle(); - todoBlock.ToDo.RichText.First().Should().BeAssignableTo(); - ((RichTextText)todoBlock.ToDo.RichText.First()).Text.Content.Should().Be("Lacinato kale"); - } + var todoBlock = (ToDoBlock)block; + todoBlock.ToDo.RichText.Should().ContainSingle(); + todoBlock.ToDo.RichText.First().Should().BeAssignableTo(); + ((RichTextText)todoBlock.ToDo.RichText.First()).Text.Content.Should().Be("Lacinato kale"); } } diff --git a/Test/Notion.UnitTests/DatabasesClientTests.cs b/Test/Notion.UnitTests/DatabasesClientTests.cs index cc4c2396..e78d0e68 100644 --- a/Test/Notion.UnitTests/DatabasesClientTests.cs +++ b/Test/Notion.UnitTests/DatabasesClientTests.cs @@ -7,483 +7,437 @@ using WireMock.ResponseBuilders; using Xunit; -namespace Notion.UnitTests +namespace Notion.UnitTests; + +public class DatabasesClientTests : ApiTestBase { - public class DatabasesClientTests : ApiTestBase + private readonly IDatabasesClient _client; + private readonly IPagesClient _pagesClient; + + public DatabasesClientTests() { - private readonly IDatabasesClient _client; - private readonly IPagesClient _pagesClient; - public DatabasesClientTests() - { - _client = new DatabasesClient(new RestClient(ClientOptions)); - _pagesClient = new PagesClient(new RestClient(ClientOptions)); - } + _client = new DatabasesClient(new RestClient(ClientOptions)); + _pagesClient = new PagesClient(new RestClient(ClientOptions)); + } - [Fact] - public async Task QueryAsync() - { - var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1"; - var path = ApiEndpoints.DatabasesApiUrls.Query(databaseId); - var jsonData = await File.ReadAllTextAsync("data/databases/DatabasesQueryResponse.json"); + [Fact] + public async Task QueryAsync() + { + var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1"; + var path = ApiEndpoints.DatabasesApiUrls.Query(databaseId); + var jsonData = await File.ReadAllTextAsync("data/databases/DatabasesQueryResponse.json"); - Server.Given(CreatePostRequestBuilder(path)) - .RespondWith( + Server.Given(CreatePostRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var databasesQueryParams = new DatabasesQueryParameters + var databasesQueryParams = new DatabasesQueryParameters + { + Filter = new CompoundFilter { - Filter = new CompoundFilter + Or = new List { - Or = new List { - new CheckboxFilter( - "In stock", - true - ), - new NumberFilter( - "Cost of next trip", - greaterThanOrEqualTo: 2 - ) - }, + new CheckboxFilter( + "In stock", + true + ), + new NumberFilter( + "Cost of next trip", + greaterThanOrEqualTo: 2 + ), }, - Sorts = new List - { - new Sort - { - Property = "Last ordered", - Direction = Direction.Ascending - } - } - }; + }, + Sorts = new List {new() {Property = "Last ordered", Direction = Direction.Ascending}}, + }; - var pagesPaginatedList = await _client.QueryAsync(databaseId, databasesQueryParams); + var pagesPaginatedList = await _client.QueryAsync(databaseId, databasesQueryParams); - pagesPaginatedList.Results.Should().ContainSingle(); + pagesPaginatedList.Results.Should().ContainSingle(); - foreach (var page in pagesPaginatedList.Results) - { - page.Parent.Should().BeAssignableTo(); - page.Object.Should().Be(ObjectType.Page); - } + foreach (var page in pagesPaginatedList.Results) + { + page.Parent.Should().BeAssignableTo(); + page.Object.Should().Be(ObjectType.Page); } + } - [Fact] - public async Task RetrieveDatabaseAsync() - { - var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1"; - var path = ApiEndpoints.DatabasesApiUrls.Retrieve(databaseId); - var jsonData = await File.ReadAllTextAsync("data/databases/DatabaseRetrieveResponse.json"); + [Fact] + public async Task RetrieveDatabaseAsync() + { + var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1"; + var path = ApiEndpoints.DatabasesApiUrls.Retrieve(databaseId); + var jsonData = await File.ReadAllTextAsync("data/databases/DatabaseRetrieveResponse.json"); - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var database = await _client.RetrieveAsync(databaseId); + var database = await _client.RetrieveAsync(databaseId); - database.Parent.Type.Should().Be(ParentType.PageId); - database.Parent.Should().BeOfType(); - ((PageParent)database.Parent).PageId.Should().Be("649089db-8984-4051-98fb-a03593b852d8"); - foreach (var property in database.Properties) - { - property.Key.Should().Be(property.Value.Name); - } + database.Parent.Type.Should().Be(ParentType.PageId); + database.Parent.Should().BeOfType(); + ((PageParent)database.Parent).PageId.Should().Be("649089db-8984-4051-98fb-a03593b852d8"); - HelperAsserts.IPageIconAsserts(database.Icon); - HelperAsserts.FileObjectAsserts(database.Cover); + foreach (var property in database.Properties) + { + property.Key.Should().Be(property.Value.Name); } - [Fact] - public async Task DatabasePropertyObjectContainNameProperty() - { - var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1"; - var path = ApiEndpoints.DatabasesApiUrls.Retrieve(databaseId); - var jsonData = await File.ReadAllTextAsync("data/databases/DatabasePropertyObjectContainNameProperty.json"); + HelperAsserts.IPageIconAsserts(database.Icon); + HelperAsserts.FileObjectAsserts(database.Cover); + } - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( + [Fact] + public async Task DatabasePropertyObjectContainNameProperty() + { + var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1"; + var path = ApiEndpoints.DatabasesApiUrls.Retrieve(databaseId); + var jsonData = await File.ReadAllTextAsync("data/databases/DatabasePropertyObjectContainNameProperty.json"); + + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var database = await _client.RetrieveAsync(databaseId); + var database = await _client.RetrieveAsync(databaseId); - foreach (var property in database.Properties) - { - property.Key.Should().Be(property.Value.Name); - } + foreach (var property in database.Properties) + { + property.Key.Should().Be(property.Value.Name); } + } - [Fact] - public async Task DatabasePropertyObjectContainRelationProperty() - { - var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1"; - var path = ApiEndpoints.DatabasesApiUrls.Retrieve(databaseId); - var jsonData = await File.ReadAllTextAsync("data/databases/DatabasePropertyObjectContainRelation.json"); + [Fact] + public async Task DatabasePropertyObjectContainRelationProperty() + { + var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1"; + var path = ApiEndpoints.DatabasesApiUrls.Retrieve(databaseId); + var jsonData = await File.ReadAllTextAsync("data/databases/DatabasePropertyObjectContainRelation.json"); - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var database = await _client.RetrieveAsync(databaseId); + var database = await _client.RetrieveAsync(databaseId); - database.Properties.Should().ContainKey("Property").WhichValue.Should().BeEquivalentTo( - new RelationProperty() + database.Properties.Should().ContainKey("Property").WhichValue.Should().BeEquivalentTo( + new RelationProperty + { + Id = "zDGa", + Name = "Property", + Relation = new DualPropertyRelation + { + DatabaseId = "f86f2262-0751-40f2-8f63-e3f7a3c39fcb", + DualProperty = new DualPropertyRelation.Data { - Id = "zDGa", - Name = "Property", - Relation = new DualPropertyRelation() - { - DatabaseId = "f86f2262-0751-40f2-8f63-e3f7a3c39fcb", - DualProperty = new DualPropertyRelation.Data - { - SyncedPropertyName = "Related to sample table (Property)", - SyncedPropertyId = "VQ}{" - } - } - }); - } + SyncedPropertyName = "Related to sample table (Property)", + SyncedPropertyId = "VQ}{", + }, + }, + }); + } - [Fact] - public async Task DatabasePropertyObjectContainParentProperty() - { - var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1"; - var path = ApiEndpoints.DatabasesApiUrls.Retrieve(databaseId); - var jsonData = await File.ReadAllTextAsync("data/databases/DatabasePropertyObjectContainParentProperty.json"); + [Fact] + public async Task DatabasePropertyObjectContainParentProperty() + { + var databaseId = "f0212efc-caf6-4afc-87f6-1c06f1dfc8a1"; + var path = ApiEndpoints.DatabasesApiUrls.Retrieve(databaseId); + var jsonData = await File.ReadAllTextAsync("data/databases/DatabasePropertyObjectContainParentProperty.json"); - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var database = await _client.RetrieveAsync(databaseId); + var database = await _client.RetrieveAsync(databaseId); - database.Parent.Type.Should().Be(ParentType.PageId); - database.Parent.Should().BeOfType(); - ((PageParent)database.Parent).PageId.Should().Be("649089db-8984-4051-98fb-a03593b852d8"); - } + database.Parent.Type.Should().Be(ParentType.PageId); + database.Parent.Should().BeOfType(); + ((PageParent)database.Parent).PageId.Should().Be("649089db-8984-4051-98fb-a03593b852d8"); + } - [Fact] - public async Task CreateDatabaseAsync() - { - var pageId = "533578e3-edf1-4c0a-91a9-da6b09bac3ee"; - var path = ApiEndpoints.DatabasesApiUrls.Create; - var jsonData = await File.ReadAllTextAsync("data/databases/CreateDatabaseResponse.json"); + [Fact] + public async Task CreateDatabaseAsync() + { + var pageId = "533578e3-edf1-4c0a-91a9-da6b09bac3ee"; + var path = ApiEndpoints.DatabasesApiUrls.Create; + var jsonData = await File.ReadAllTextAsync("data/databases/CreateDatabaseResponse.json"); - Server.Given(CreatePostRequestBuilder(path)) - .RespondWith( + Server.Given(CreatePostRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var createDatabaseParameters = new DatabasesCreateParameters(); + var createDatabaseParameters = new DatabasesCreateParameters(); - createDatabaseParameters.Parent = new ParentPageInput - { - PageId = pageId - }; + createDatabaseParameters.Parent = new ParentPageInput {PageId = pageId}; + + createDatabaseParameters.Title = new List + { + new RichTextTextInput {Text = new Text {Content = "Grocery List", Link = null}}, + }; - createDatabaseParameters.Title = new List + createDatabaseParameters.Properties = new Dictionary + { + {"Name", new TitlePropertySchema {Title = new Dictionary()}}, + {"Price", new NumberPropertySchema {Number = new Number {Format = "dollar"}}}, { - new RichTextTextInput + "Food group", + new SelectPropertySchema { - Text = new Text + Select = new OptionWrapper { - Content = "Grocery List", - Link = null - } + Options = new List + { + new() {Color = Color.Green, Name = "🥦Vegetable"}, + new() {Color = Color.Red, Name = "🍎Fruit"}, + new() {Color = Color.Yellow, Name = "💪Protein"}, + }, + }, } - }; + }, + {"Last ordered", new DatePropertySchema {Date = new Dictionary()}}, + }; - createDatabaseParameters.Properties = new Dictionary - { - { "Name", new TitlePropertySchema { Title = new Dictionary() } }, - { "Price", new NumberPropertySchema { Number = new Number { Format = "dollar" } } }, - { "Food group", new SelectPropertySchema - { - Select = new OptionWrapper - { - Options = new List - { - new SelectOptionSchema - { - Color = Color.Green, - Name = "🥦Vegetable" - }, - new SelectOptionSchema - { - Color = Color.Red, - Name = "🍎Fruit" - }, - new SelectOptionSchema - { - Color = Color.Yellow, - Name = "💪Protein" - } - } - } - } - }, - { "Last ordered", new DatePropertySchema{ Date = new Dictionary() } } - }; + var database = await _client.CreateAsync(createDatabaseParameters); - var database = await _client.CreateAsync(createDatabaseParameters); + database.Parent.Type.Should().Be(ParentType.PageId); + database.Parent.Should().BeOfType(); + ((PageParent)database.Parent).PageId.Should().Be(pageId); - database.Parent.Type.Should().Be(ParentType.PageId); - database.Parent.Should().BeOfType(); - ((PageParent)database.Parent).PageId.Should().Be(pageId); + database.Properties.Should().HaveCount(4); - database.Properties.Should().HaveCount(4); + var selectOptions = (SelectProperty)database.Properties["Food group"]; + selectOptions.Name.Should().Be("Food group"); - var selectOptions = (SelectProperty)database.Properties["Food group"]; - selectOptions.Name.Should().Be("Food group"); - selectOptions.Select.Options.Should().SatisfyRespectively( - option => - { - option.Name.Should().Be("🥦Vegetable"); - option.Color.Should().Be(Color.Green); - }, - option => - { - option.Name.Should().Be("🍎Fruit"); - option.Color.Should().Be(Color.Red); - }, - option => - { - option.Name.Should().Be("💪Protein"); - option.Color.Should().Be(Color.Yellow); - } - ); - } + selectOptions.Select.Options.Should().SatisfyRespectively( + option => + { + option.Name.Should().Be("🥦Vegetable"); + option.Color.Should().Be(Color.Green); + }, + option => + { + option.Name.Should().Be("🍎Fruit"); + option.Color.Should().Be(Color.Red); + }, + option => + { + option.Name.Should().Be("💪Protein"); + option.Color.Should().Be(Color.Yellow); + } + ); + } - [Fact] - public async Task UpdateDatabaseAsync() - { - var databaseId = "1e9eee34-9c5c-4fe6-a4e1-8244eb141ed8"; - var path = ApiEndpoints.DatabasesApiUrls.Update(databaseId); - var jsonData = await File.ReadAllTextAsync("data/databases/UpdateDatabaseResponse.json"); + [Fact] + public async Task UpdateDatabaseAsync() + { + var databaseId = "1e9eee34-9c5c-4fe6-a4e1-8244eb141ed8"; + var path = ApiEndpoints.DatabasesApiUrls.Update(databaseId); + var jsonData = await File.ReadAllTextAsync("data/databases/UpdateDatabaseResponse.json"); - Server.Given(CreatePatchRequestBuilder(path)) - .RespondWith( + Server.Given(CreatePatchRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var updateDatabaseParameters = new DatabasesUpdateParameters(); + var updateDatabaseParameters = new DatabasesUpdateParameters(); + + updateDatabaseParameters.Title = new List + { + new RichTextTextInput {Text = new Text {Content = "Grocery List New", Link = null}}, + }; - updateDatabaseParameters.Title = new List + updateDatabaseParameters.Properties = new Dictionary + { + {"Name", new TitleUpdatePropertySchema {Title = new Dictionary()}}, + {"Price", new NumberUpdatePropertySchema {Number = new Number {Format = "yen"}}}, { - new RichTextTextInput + "Food group", + new SelectUpdatePropertySchema { - Text = new Text + Select = new OptionWrapper { - Content = "Grocery List New", - Link = null - } + Options = new List + { + new() {Color = Color.Green, Name = "🥦Vegetables"}, + new() {Color = Color.Red, Name = "🍎Fruit"}, + new() {Color = Color.Yellow, Name = "💪Protein"}, + }, + }, } - }; + }, + {"Last ordered", new DateUpdatePropertySchema {Date = new Dictionary()}}, + }; - updateDatabaseParameters.Properties = new Dictionary - { - { "Name", new TitleUpdatePropertySchema { Title = new Dictionary() } }, - { "Price", new NumberUpdatePropertySchema { Number = new Number { Format = "yen" } } }, - { "Food group", new SelectUpdatePropertySchema - { - Select = new OptionWrapper - { - Options = new List - { - new SelectOption - { - Color = Color.Green, - Name = "🥦Vegetables" - }, - new SelectOption - { - Color = Color.Red, - Name = "🍎Fruit" - }, - new SelectOption - { - Color = Color.Yellow, - Name = "💪Protein" - } - } - } - } - }, - { "Last ordered", new DateUpdatePropertySchema{ Date = new Dictionary() } } - }; + var database = await _client.UpdateAsync(databaseId, updateDatabaseParameters); - var database = await _client.UpdateAsync(databaseId, updateDatabaseParameters); + database.Parent.Type.Should().Be(ParentType.PageId); + database.Parent.Should().BeOfType(); + ((PageParent)database.Parent).PageId.Should().Be("533578e3-edf1-4c0a-91a9-da6b09bac3ee"); - database.Parent.Type.Should().Be(ParentType.PageId); - database.Parent.Should().BeOfType(); - ((PageParent)database.Parent).PageId.Should().Be("533578e3-edf1-4c0a-91a9-da6b09bac3ee"); + database.Properties.Should().HaveCount(4); - database.Properties.Should().HaveCount(4); + database.Title.Should().ContainSingle(); - database.Title.Should().ContainSingle(); - database.Title.Should().SatisfyRespectively( - title => - { - title.Should().BeAssignableTo(); - ((RichTextText)title).Text.Content.Should().Be("Grocery List New"); - } - ); + database.Title.Should().SatisfyRespectively( + title => + { + title.Should().BeAssignableTo(); + ((RichTextText)title).Text.Content.Should().Be("Grocery List New"); + } + ); - var selectOptions = (SelectProperty)database.Properties["Food group"]; - selectOptions.Name.Should().Be("Food group"); - selectOptions.Select.Options.Should().SatisfyRespectively( - option => - { - option.Name.Should().Be("🥦Vegetables"); - option.Color.Should().Be(Color.Green); - }, - option => - { - option.Name.Should().Be("🍎Fruit"); - option.Color.Should().Be(Color.Red); - }, - option => - { - option.Name.Should().Be("💪Protein"); - option.Color.Should().Be(Color.Yellow); - } - ); + var selectOptions = (SelectProperty)database.Properties["Food group"]; + selectOptions.Name.Should().Be("Food group"); - var price = (NumberProperty)database.Properties["Price"]; - price.Number.Format.Should().Be("yen"); - } + selectOptions.Select.Options.Should().SatisfyRespectively( + option => + { + option.Name.Should().Be("🥦Vegetables"); + option.Color.Should().Be(Color.Green); + }, + option => + { + option.Name.Should().Be("🍎Fruit"); + option.Color.Should().Be(Color.Red); + }, + option => + { + option.Name.Should().Be("💪Protein"); + option.Color.Should().Be(Color.Yellow); + } + ); - [Fact] - public async Task FormulaPropertyCanBeSetWhenCreatingDatabase() - { - var pageId = "98ad959b-2b6a-4774-80ee-00246fb0ea9b"; - var path = ApiEndpoints.DatabasesApiUrls.Create; - var jsonData = await File.ReadAllTextAsync("data/databases/FormulaPropertyCanBeSetWhenCreatingDatabaseResponse.json"); + var price = (NumberProperty)database.Properties["Price"]; + price.Number.Format.Should().Be("yen"); + } - Server.Given(CreatePostRequestBuilder(path)) - .RespondWith( + [Fact] + public async Task FormulaPropertyCanBeSetWhenCreatingDatabase() + { + var pageId = "98ad959b-2b6a-4774-80ee-00246fb0ea9b"; + var path = ApiEndpoints.DatabasesApiUrls.Create; + + var jsonData + = await File.ReadAllTextAsync("data/databases/FormulaPropertyCanBeSetWhenCreatingDatabaseResponse.json"); + + Server.Given(CreatePostRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var createDatabaseParameters = new DatabasesCreateParameters(); + var createDatabaseParameters = new DatabasesCreateParameters(); - createDatabaseParameters.Parent = new ParentPageInput - { - PageId = pageId - }; + createDatabaseParameters.Parent = new ParentPageInput {PageId = pageId}; - createDatabaseParameters.Title = new List + createDatabaseParameters.Title = new List + { + new RichTextTextInput {Text = new Text {Content = "Grocery List", Link = null}}, + }; + + createDatabaseParameters.Properties = new Dictionary + { { - new RichTextTextInput + "Cost of next trip", + new FormulaPropertySchema { - Text = new Text - { - Content = "Grocery List", - Link = null - } + Formula = new Formula {Expression = "if(prop(\"In stock\"), 0, prop(\"Price\"))"}, } - }; + }, + {"Price", new NumberPropertySchema {Number = new Number {Format = "dollar"}}}, + }; - createDatabaseParameters.Properties = new Dictionary - { - { "Cost of next trip", new FormulaPropertySchema { Formula = new Formula { Expression = "if(prop(\"In stock\"), 0, prop(\"Price\"))" } } }, - { "Price", new NumberPropertySchema { Number = new Number { Format = "dollar" } } } - }; + var database = await _client.CreateAsync(createDatabaseParameters); - var database = await _client.CreateAsync(createDatabaseParameters); + database.Parent.Type.Should().Be(ParentType.PageId); + database.Parent.Should().BeOfType(); + ((PageParent)database.Parent).PageId.Should().Be(pageId); - database.Parent.Type.Should().Be(ParentType.PageId); - database.Parent.Should().BeOfType(); - ((PageParent)database.Parent).PageId.Should().Be(pageId); + database.Properties.Should().HaveCount(2); - database.Properties.Should().HaveCount(2); + var formulaProperty = (FormulaProperty)database.Properties["Cost of next trip"]; + formulaProperty.Formula.Expression.Should().Be("if(prop(\"In stock\"), 0, prop(\"Price\"))"); + } - var formulaProperty = (FormulaProperty)database.Properties["Cost of next trip"]; - formulaProperty.Formula.Expression.Should().Be("if(prop(\"In stock\"), 0, prop(\"Price\"))"); - } + [Fact] + public async Task Fix123_QueryAsync_DateFormulaValue_Returns_Null() + { + var databaseId = "f86f2262-0751-40f2-8f63-e3f7a3c39fcb"; + var path = ApiEndpoints.DatabasesApiUrls.Query(databaseId); - [Fact] - public async Task Fix123_QueryAsync_DateFormulaValue_Returns_Null() - { - var databaseId = "f86f2262-0751-40f2-8f63-e3f7a3c39fcb"; - var path = ApiEndpoints.DatabasesApiUrls.Query(databaseId); - var jsonData = await File.ReadAllTextAsync("data/databases/Fix123QueryAsyncDateFormulaValueReturnsNullResponse.json"); + var jsonData + = await File.ReadAllTextAsync("data/databases/Fix123QueryAsyncDateFormulaValueReturnsNullResponse.json"); - Server.Given(CreatePostRequestBuilder(path)) - .RespondWith( + Server.Given(CreatePostRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var databasesQueryParams = new DatabasesQueryParameters + var databasesQueryParams = new DatabasesQueryParameters + { + Filter = new CompoundFilter { - Filter = new CompoundFilter + Or = new List { - Or = new List { - new CheckboxFilter( - "In stock", - true - ), - new NumberFilter( - "Cost of next trip", - greaterThanOrEqualTo: 2 - ) - }, + new CheckboxFilter( + "In stock", + true + ), + new NumberFilter( + "Cost of next trip", + greaterThanOrEqualTo: 2 + ), }, - Sorts = new List - { - new Sort - { - Property = "Last ordered", - Direction = Direction.Ascending - } - } - }; + }, + Sorts = new List {new() {Property = "Last ordered", Direction = Direction.Ascending}}, + }; - var pagesPaginatedList = await _client.QueryAsync(databaseId, databasesQueryParams); + var pagesPaginatedList = await _client.QueryAsync(databaseId, databasesQueryParams); - pagesPaginatedList.Results.Should().ContainSingle(); + pagesPaginatedList.Results.Should().ContainSingle(); - foreach (var page in pagesPaginatedList.Results) - { - page.Parent.Should().BeAssignableTo(); - page.Object.Should().Be(ObjectType.Page); + foreach (var page in pagesPaginatedList.Results) + { + page.Parent.Should().BeAssignableTo(); + page.Object.Should().Be(ObjectType.Page); - Server.Given(CreateGetRequestBuilder(ApiEndpoints.PagesApiUrls.RetrievePropertyItem(page.Id, page.Properties["FormulaProp"].Id))) + Server.Given(CreateGetRequestBuilder( + ApiEndpoints.PagesApiUrls.RetrievePropertyItem(page.Id, page.Properties["FormulaProp"].Id))) .RespondWith( Response.Create() - .WithStatusCode(200) - .WithBody("{\"object\":\"property_item\",\"id\":\"JwY^\",\"type\":\"formula\",\"formula\":{\"type\":\"date\",\"date\":{\"start\":\"2021-06-28\",\"end\":null}}}") + .WithStatusCode(200) + .WithBody( + "{\"object\":\"property_item\",\"id\":\"JwY^\",\"type\":\"formula\",\"formula\":{\"type\":\"date\",\"date\":{\"start\":\"2021-06-28\",\"end\":null}}}") ); - var formulaPropertyValue = (FormulaPropertyItem)await _pagesClient.RetrievePagePropertyItem(new RetrievePropertyItemParameters - { - PageId = page.Id, - PropertyId = page.Properties["FormulaProp"].Id - }); + var formulaPropertyValue = (FormulaPropertyItem)await _pagesClient.RetrievePagePropertyItem( + new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = page.Properties["FormulaProp"].Id}); - //var formulaPropertyValue = (FormulaPropertyValue)page.Properties["FormulaProp"]; - formulaPropertyValue.Formula.Date.Start.Should().Be(DateTime.Parse("2021-06-28")); - formulaPropertyValue.Formula.Date.End.Should().BeNull(); - } + //var formulaPropertyValue = (FormulaPropertyValue)page.Properties["FormulaProp"]; + formulaPropertyValue.Formula.Date.Start.Should().Be(DateTime.Parse("2021-06-28")); + formulaPropertyValue.Formula.Date.End.Should().BeNull(); } } } diff --git a/Test/Notion.UnitTests/FilterTests.cs b/Test/Notion.UnitTests/FilterTests.cs index 5b4650a5..b31a6530 100644 --- a/Test/Notion.UnitTests/FilterTests.cs +++ b/Test/Notion.UnitTests/FilterTests.cs @@ -4,131 +4,138 @@ using Notion.Client; using Xunit; -namespace Notion.UnitTests +namespace Notion.UnitTests; + +public class SerializerSettingsSource : RestClient +{ + public SerializerSettingsSource(ClientOptions options) : base(options) + { + } + + public JsonSerializerSettings GetSerializerSettings() + { + return defaultSerializerSettings; + } +} + +public class FilterTests { - public class SerializerSettingsSource : RestClient + private readonly SerializerSettingsSource _settingsSource = new(new ClientOptions()); + + private string SerializeFilter(Filter filter) + { + return JsonConvert.SerializeObject(filter, _settingsSource.GetSerializerSettings()); + } + + [Fact] + public void CompoundFilterTest() + { + var selectFilter = new SelectFilter("A select", "Option"); + var relationFilter = new RelationFilter("Link", "subtask#1"); + var dateFilter = new DateFilter("Due", pastMonth: new Dictionary()); + + var filterGroup = new List {relationFilter, selectFilter}; + + var complexFiler = new CompoundFilter( + and: new List {dateFilter, new CompoundFilter(filterGroup)} + ); + + Assert.Equal( + "{\"and\":[{\"date\":{\"past_month\":{}},\"property\":\"Due\"}," + + "{\"or\":[{\"relation\":{\"contains\":\"subtask#1\"},\"property\":\"Link\"}," + + "{\"select\":{\"equals\":\"Option\"},\"property\":\"A select\"}]}]}", + SerializeFilter(complexFiler) + ); + } + + [Fact] + public void CheckboxFilterTest() + { + var filter = new CheckboxFilter("Property name", false); + + Assert.Equal( + "{\"checkbox\":{\"equals\":false},\"property\":\"Property name\"}", + SerializeFilter(filter) + ); + } + + [Fact] + public void DateFilterTest() { - public SerializerSettingsSource(ClientOptions options) : base(options) - { + var filter = new DateFilter("When", onOrAfter: new DateTime(2042, 11, 29)); - } + Assert.Equal( + "{\"date\":{\"on_or_after\":\"2042-11-29T00:00:00\"},\"property\":\"When\"}", + SerializeFilter(filter) + ); + } + + [Fact] + public void FilesFilterTest() + { + var filter = new FilesFilter("Attachments", isNotEmpty: false); + + Assert.Equal( + "{\"files\":{\"is_not_empty\":false},\"property\":\"Attachments\"}", + SerializeFilter(filter) + ); + } - public JsonSerializerSettings GetSerializerSettings() - { - return defaultSerializerSettings; - } + [Fact] + public void FormulaFilterTest() + { + var filter = new FormulaFilter( + "Some", + number: new NumberFilter.Condition(isEmpty: true) + ); + + Assert.Equal( + "{\"formula\":{\"number\":{\"is_empty\":true}},\"property\":\"Some\"}", + SerializeFilter(filter) + ); + } + [Fact] + public void MultiSelectFilterTest() + { + var filter = new MultiSelectFilter("category 1", doesNotContain: "tag"); + + Assert.Equal( + "{\"multi_select\":{\"does_not_contain\":\"tag\"},\"property\":\"category 1\"}", + SerializeFilter(filter) + ); } - public class FilterTests + + [Fact(Skip = "Not sure if integer should be serialized as a number with decimals")] + public void NumberFilterTest() { - private readonly SerializerSettingsSource _settingsSource = new SerializerSettingsSource(new ClientOptions()); - - private string SerializeFilter(Filter filter) - { - return JsonConvert.SerializeObject(filter, _settingsSource.GetSerializerSettings()); - } - - [Fact] - public void CompoundFilterTest() - { - var selectFilter = new SelectFilter("A select", equal: "Option"); - var relationFilter = new RelationFilter("Link", contains: "subtask#1"); - var dateFilter = new DateFilter("Due", pastMonth: new Dictionary()); - - var filterGroup = new List { relationFilter, selectFilter }; - var complexFiler = new CompoundFilter( - and: new List { dateFilter, new CompoundFilter(or: filterGroup) } - ); - - Assert.Equal( - "{\"and\":[{\"date\":{\"past_month\":{}},\"property\":\"Due\"}," - + "{\"or\":[{\"relation\":{\"contains\":\"subtask#1\"},\"property\":\"Link\"}," + - "{\"select\":{\"equals\":\"Option\"},\"property\":\"A select\"}]}]}", - SerializeFilter(complexFiler) - ); - } - - [Fact] - public void CheckboxFilterTest() - { - var filter = new CheckboxFilter("Property name", equal: false); - Assert.Equal( - "{\"checkbox\":{\"equals\":false},\"property\":\"Property name\"}", - SerializeFilter(filter) - ); - } - - [Fact] - public void DateFilterTest() - { - var filter = new DateFilter("When", onOrAfter: new DateTime(2042, 11, 29)); - Assert.Equal( - "{\"date\":{\"on_or_after\":\"2042-11-29T00:00:00\"},\"property\":\"When\"}", - SerializeFilter(filter) - ); - } - - [Fact] - public void FilesFilterTest() - { - var filter = new FilesFilter("Attachments", isNotEmpty: false); - Assert.Equal( - "{\"files\":{\"is_not_empty\":false},\"property\":\"Attachments\"}", - SerializeFilter(filter) - ); - } - - [Fact] - public void FormulaFilterTest() - { - var filter = new FormulaFilter( - "Some", - number: new NumberFilter.Condition(isEmpty: true) - ); - Assert.Equal( - "{\"formula\":{\"number\":{\"is_empty\":true}},\"property\":\"Some\"}", - SerializeFilter(filter) - ); - } - - [Fact] - public void MultiSelectFilterTest() - { - var filter = new MultiSelectFilter("category 1", doesNotContain: "tag"); - Assert.Equal( - "{\"multi_select\":{\"does_not_contain\":\"tag\"},\"property\":\"category 1\"}", - SerializeFilter(filter) - ); - } - - [Fact(Skip = "Not sure if integer should be serialized as a number with decimals")] - public void NumberFilterTest() - { - var filter = new NumberFilter("sum", greaterThanOrEqualTo: -54); - Assert.Equal( - "{\"number\":{\"greater_than_or_equal_to\":-54.0},\"property\":\"sum\"}", - SerializeFilter(filter) - ); - } - - [Fact] - public void PeopleFilter() - { - var filter = new PeopleFilter("assignee PM", doesNotContain: "some-uuid"); - Assert.Equal( - "{\"people\":{\"does_not_contain\":\"some-uuid\"},\"property\":\"assignee PM\"}", - SerializeFilter(filter) - ); - } - - [Fact] - public void RichTextFilterTest() - { - var filter = new RichTextFilter("Some property", doesNotEqual: "Example text"); - Assert.Equal( - "{\"rich_text\":{\"does_not_equal\":\"Example text\"},\"property\":\"Some property\"}", - SerializeFilter(filter) - ); - } + var filter = new NumberFilter("sum", greaterThanOrEqualTo: -54); + + Assert.Equal( + "{\"number\":{\"greater_than_or_equal_to\":-54.0},\"property\":\"sum\"}", + SerializeFilter(filter) + ); + } + + [Fact] + public void PeopleFilter() + { + var filter = new PeopleFilter("assignee PM", doesNotContain: "some-uuid"); + + Assert.Equal( + "{\"people\":{\"does_not_contain\":\"some-uuid\"},\"property\":\"assignee PM\"}", + SerializeFilter(filter) + ); + } + + [Fact] + public void RichTextFilterTest() + { + var filter = new RichTextFilter("Some property", doesNotEqual: "Example text"); + + Assert.Equal( + "{\"rich_text\":{\"does_not_equal\":\"Example text\"},\"property\":\"Some property\"}", + SerializeFilter(filter) + ); } -} +} diff --git a/Test/Notion.UnitTests/HelperAsserts.cs b/Test/Notion.UnitTests/HelperAsserts.cs index 1b07fbf5..3b1a29ec 100644 --- a/Test/Notion.UnitTests/HelperAsserts.cs +++ b/Test/Notion.UnitTests/HelperAsserts.cs @@ -1,41 +1,44 @@ using FluentAssertions; using Notion.Client; -namespace Notion.UnitTests +namespace Notion.UnitTests; + +public static class HelperAsserts { - public static class HelperAsserts + public static void IPageIconAsserts(IPageIcon icon) { - public static void IPageIconAsserts(IPageIcon icon) + icon.Should().NotBeNull(); + + switch (icon) { - icon.Should().NotBeNull(); - - switch (icon) - { - case EmojiObject emoji: - emoji.Emoji.Should().NotBeNull(); - break; - case FileObject fileObject: - FileObjectAsserts(fileObject); - break; - } + case EmojiObject emoji: + emoji.Emoji.Should().NotBeNull(); + + break; + case FileObject fileObject: + FileObjectAsserts(fileObject); + + break; } + } - public static void FileObjectAsserts(FileObject fileObject) + public static void FileObjectAsserts(FileObject fileObject) + { + fileObject.Should().NotBeNull(); + + switch (fileObject) { - fileObject.Should().NotBeNull(); - - switch (fileObject) - { - case UploadedFile uploadedFile: - uploadedFile.File.Should().NotBeNull(); - uploadedFile.File.Url.Should().NotBeNull(); - uploadedFile.File.ExpiryTime.Should().NotBeSameDateAs(default); - break; - case ExternalFile externalFile: - externalFile.External.Should().NotBeNull(); - externalFile.External.Url.Should().NotBeNull(); - break; - } + case UploadedFile uploadedFile: + uploadedFile.File.Should().NotBeNull(); + uploadedFile.File.Url.Should().NotBeNull(); + uploadedFile.File.ExpiryTime.Should().NotBeSameDateAs(default); + + break; + case ExternalFile externalFile: + externalFile.External.Should().NotBeNull(); + externalFile.External.Url.Should().NotBeNull(); + + break; } } } diff --git a/Test/Notion.UnitTests/PagesClientTests.cs b/Test/Notion.UnitTests/PagesClientTests.cs index 13598b0f..3f6710a5 100644 --- a/Test/Notion.UnitTests/PagesClientTests.cs +++ b/Test/Notion.UnitTests/PagesClientTests.cs @@ -8,264 +8,246 @@ using WireMock.ResponseBuilders; using Xunit; -namespace Notion.UnitTests +namespace Notion.UnitTests; + +public class PagesClientTests : ApiTestBase { - public class PagesClientTests : ApiTestBase - { - private readonly IPagesClient _client; + private readonly IPagesClient _client; - public PagesClientTests() - { - _client = new PagesClient(new RestClient(ClientOptions)); - } + public PagesClientTests() + { + _client = new PagesClient(new RestClient(ClientOptions)); + } - [Fact] - public async Task RetrieveAsync() - { - var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; - var path = ApiEndpoints.PagesApiUrls.Retrieve(pageId); - var jsonData = await File.ReadAllTextAsync("data/pages/PageObjectShouldHaveUrlPropertyResponse.json"); + [Fact] + public async Task RetrieveAsync() + { + var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; + var path = ApiEndpoints.PagesApiUrls.Retrieve(pageId); + var jsonData = await File.ReadAllTextAsync("data/pages/PageObjectShouldHaveUrlPropertyResponse.json"); - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var page = await _client.RetrieveAsync(pageId); + var page = await _client.RetrieveAsync(pageId); - page.Url.Should().Be("https://www.notion.so/Avocado-251d2b5f268c4de2afe9c71ff92ca95c"); - page.Id.Should().Be(pageId); - page.Parent.Type.Should().Be(ParentType.DatabaseId); - ((DatabaseParent)page.Parent).DatabaseId.Should().Be("48f8fee9-cd79-4180-bc2f-ec0398253067"); - page.IsArchived.Should().BeFalse(); - } + page.Url.Should().Be("https://www.notion.so/Avocado-251d2b5f268c4de2afe9c71ff92ca95c"); + page.Id.Should().Be(pageId); + page.Parent.Type.Should().Be(ParentType.DatabaseId); + ((DatabaseParent)page.Parent).DatabaseId.Should().Be("48f8fee9-cd79-4180-bc2f-ec0398253067"); + page.IsArchived.Should().BeFalse(); + } - [Fact] - public async Task CreateAsync() - { - var path = ApiEndpoints.PagesApiUrls.Create(); + [Fact] + public async Task CreateAsync() + { + var path = ApiEndpoints.PagesApiUrls.Create(); - var jsonData = await File.ReadAllTextAsync("data/pages/CreatePageResponse.json"); + var jsonData = await File.ReadAllTextAsync("data/pages/CreatePageResponse.json"); - Server.Given(CreatePostRequestBuilder(path)) - .RespondWith( - Response.Create() + Server.Given(CreatePostRequestBuilder(path)) + .RespondWith( + Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var pagesCreateParameters = PagesCreateParametersBuilder.Create(new DatabaseParentInput - { - DatabaseId = "3c357473-a281-49a4-88c0-10d2b245a589" - }).AddProperty("Name", new TitlePropertyValue() - { - Title = new List() + var pagesCreateParameters = PagesCreateParametersBuilder + .Create(new DatabaseParentInput {DatabaseId = "3c357473-a281-49a4-88c0-10d2b245a589"}).AddProperty("Name", + new TitlePropertyValue { - new RichTextText() - { - Text = new Text - { - Content = "Test" - } - } - } - }).Build(); - - var page = await _client.CreateAsync(pagesCreateParameters); - - page.Id.Should().NotBeNullOrEmpty(); - page.Url.Should().NotBeNullOrEmpty(); - page.Properties.Should().HaveCount(1); - page.Properties.First().Key.Should().Be("Name"); - page.IsArchived.Should().BeFalse(); - page.Parent.Should().NotBeNull(); - ((DatabaseParent)page.Parent).DatabaseId.Should().Be("3c357473-a281-49a4-88c0-10d2b245a589"); - } - - [Fact] - public async Task UpdatePropertiesAsync() - { - var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; - var propertyId = "{>U;"; - var path = ApiEndpoints.PagesApiUrls.UpdateProperties(pageId); + Title = new List {new RichTextText {Text = new Text {Content = "Test"}}}, + }).Build(); + + var page = await _client.CreateAsync(pagesCreateParameters); + + page.Id.Should().NotBeNullOrEmpty(); + page.Url.Should().NotBeNullOrEmpty(); + page.Properties.Should().HaveCount(1); + page.Properties.First().Key.Should().Be("Name"); + page.IsArchived.Should().BeFalse(); + page.Parent.Should().NotBeNull(); + ((DatabaseParent)page.Parent).DatabaseId.Should().Be("3c357473-a281-49a4-88c0-10d2b245a589"); + } - var jsonData = await File.ReadAllTextAsync("data/pages/UpdatePagePropertiesResponse.json"); + [Fact] + public async Task UpdatePropertiesAsync() + { + var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; + var propertyId = "{>U;"; + var path = ApiEndpoints.PagesApiUrls.UpdateProperties(pageId); + + var jsonData = await File.ReadAllTextAsync("data/pages/UpdatePagePropertiesResponse.json"); - Server.Given(CreatePatchRequestBuilder(path)) - .RespondWith( - Response.Create() + Server.Given(CreatePatchRequestBuilder(path)) + .RespondWith( + Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - Server.Given(CreateGetRequestBuilder(ApiEndpoints.PagesApiUrls.RetrievePropertyItem(pageId, propertyId))) - .RespondWith( - Response.Create().WithStatusCode(200).WithBody("{\"object\":\"property_item\",\"id\":\"{>U;\",\"type\":\"checkbox\",\"checkbox\":true}")); + Server.Given(CreateGetRequestBuilder(ApiEndpoints.PagesApiUrls.RetrievePropertyItem(pageId, propertyId))) + .RespondWith( + Response.Create().WithStatusCode(200) + .WithBody( + "{\"object\":\"property_item\",\"id\":\"{>U;\",\"type\":\"checkbox\",\"checkbox\":true}")); - var updatedProperties = new Dictionary() - { - { "In stock", new CheckboxPropertyValue() { Checkbox = true } } - }; + var updatedProperties = new Dictionary + { + {"In stock", new CheckboxPropertyValue {Checkbox = true}}, + }; - var page = await _client.UpdatePropertiesAsync(pageId, updatedProperties); + var page = await _client.UpdatePropertiesAsync(pageId, updatedProperties); - page.Id.Should().Be(pageId); - page.Properties.Should().HaveCount(2); - var updatedProperty = page.Properties.First(x => x.Key == "In stock"); + page.Id.Should().Be(pageId); + page.Properties.Should().HaveCount(2); + var updatedProperty = page.Properties.First(x => x.Key == "In stock"); - var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItem(new RetrievePropertyItemParameters - { - PageId = page.Id, - PropertyId = updatedProperty.Value.Id - }); + var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItem( + new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = updatedProperty.Value.Id}); - checkboxPropertyValue.Checkbox.Should().BeTrue(); - } + checkboxPropertyValue.Checkbox.Should().BeTrue(); + } - [Fact] - public async Task PageObjectShouldHaveUrlProperty() - { - var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; - var path = ApiEndpoints.PagesApiUrls.Retrieve(pageId); - var jsonData = await File.ReadAllTextAsync("data/pages/PageObjectShouldHaveUrlPropertyResponse.json"); + [Fact] + public async Task PageObjectShouldHaveUrlProperty() + { + var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; + var path = ApiEndpoints.PagesApiUrls.Retrieve(pageId); + var jsonData = await File.ReadAllTextAsync("data/pages/PageObjectShouldHaveUrlPropertyResponse.json"); - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - var page = await _client.RetrieveAsync(pageId); + var page = await _client.RetrieveAsync(pageId); - page.Url.Should().Be("https://www.notion.so/Avocado-251d2b5f268c4de2afe9c71ff92ca95c"); - } + page.Url.Should().Be("https://www.notion.so/Avocado-251d2b5f268c4de2afe9c71ff92ca95c"); + } - [Fact] - public async Task UpdatePageAsync() - { - var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; - var propertyId = "{>U;"; - var path = ApiEndpoints.PagesApiUrls.UpdateProperties(pageId); + [Fact] + public async Task UpdatePageAsync() + { + var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; + var propertyId = "{>U;"; + var path = ApiEndpoints.PagesApiUrls.UpdateProperties(pageId); - var jsonData = await File.ReadAllTextAsync("data/pages/UpdatePagePropertiesResponse.json"); + var jsonData = await File.ReadAllTextAsync("data/pages/UpdatePagePropertiesResponse.json"); - Server.Given(CreatePatchRequestBuilder(path)) - .RespondWith( - Response.Create() + Server.Given(CreatePatchRequestBuilder(path)) + .RespondWith( + Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - Server.Given(CreateGetRequestBuilder(ApiEndpoints.PagesApiUrls.RetrievePropertyItem(pageId, propertyId))) - .RespondWith( - Response.Create().WithStatusCode(200).WithBody("{\"object\":\"property_item\",\"id\":\"{>U;\",\"type\":\"checkbox\",\"checkbox\":true}")); + Server.Given(CreateGetRequestBuilder(ApiEndpoints.PagesApiUrls.RetrievePropertyItem(pageId, propertyId))) + .RespondWith( + Response.Create().WithStatusCode(200) + .WithBody( + "{\"object\":\"property_item\",\"id\":\"{>U;\",\"type\":\"checkbox\",\"checkbox\":true}")); - var pagesUpdateParameters = new PagesUpdateParameters + var pagesUpdateParameters = new PagesUpdateParameters + { + Properties = new Dictionary { - Properties = new Dictionary() - { - { "In stock", new CheckboxPropertyValue() { Checkbox = true } } - } - }; + {"In stock", new CheckboxPropertyValue {Checkbox = true}}, + }, + }; - var page = await _client.UpdateAsync(pageId, pagesUpdateParameters); + var page = await _client.UpdateAsync(pageId, pagesUpdateParameters); - page.Id.Should().Be(pageId); - page.IsArchived.Should().BeFalse(); - page.Properties.Should().HaveCount(2); - var updatedProperty = page.Properties.First(x => x.Key == "In stock"); + page.Id.Should().Be(pageId); + page.IsArchived.Should().BeFalse(); + page.Properties.Should().HaveCount(2); + var updatedProperty = page.Properties.First(x => x.Key == "In stock"); - var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItem(new RetrievePropertyItemParameters - { - PageId = page.Id, - PropertyId = updatedProperty.Value.Id - }); + var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItem( + new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = updatedProperty.Value.Id}); - checkboxPropertyValue.Checkbox.Should().BeTrue(); - } + checkboxPropertyValue.Checkbox.Should().BeTrue(); + } - [Fact] - public async Task ArchivePageAsync() - { - var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; - var propertyId = "{>U;"; + [Fact] + public async Task ArchivePageAsync() + { + var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; + var propertyId = "{>U;"; - var path = ApiEndpoints.PagesApiUrls.UpdateProperties(pageId); + var path = ApiEndpoints.PagesApiUrls.UpdateProperties(pageId); - var jsonData = await File.ReadAllTextAsync("data/pages/ArchivePageResponse.json"); + var jsonData = await File.ReadAllTextAsync("data/pages/ArchivePageResponse.json"); - Server.Given(CreatePatchRequestBuilder(path)) - .RespondWith( - Response.Create() + Server.Given(CreatePatchRequestBuilder(path)) + .RespondWith( + Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - Server.Given(CreateGetRequestBuilder(ApiEndpoints.PagesApiUrls.RetrievePropertyItem(pageId, propertyId))) - .RespondWith( - Response.Create().WithStatusCode(200).WithBody("{\"object\":\"property_item\",\"id\":\"{>U;\",\"type\":\"checkbox\",\"checkbox\":true}")); + Server.Given(CreateGetRequestBuilder(ApiEndpoints.PagesApiUrls.RetrievePropertyItem(pageId, propertyId))) + .RespondWith( + Response.Create().WithStatusCode(200) + .WithBody( + "{\"object\":\"property_item\",\"id\":\"{>U;\",\"type\":\"checkbox\",\"checkbox\":true}")); - var pagesUpdateParameters = new PagesUpdateParameters + var pagesUpdateParameters = new PagesUpdateParameters + { + Archived = true, + Properties = new Dictionary { - Archived = true, - Properties = new Dictionary() - { - { "In stock", new CheckboxPropertyValue() { Checkbox = true } } - } - }; + {"In stock", new CheckboxPropertyValue {Checkbox = true}}, + }, + }; - var page = await _client.UpdateAsync(pageId, pagesUpdateParameters); + var page = await _client.UpdateAsync(pageId, pagesUpdateParameters); - page.Id.Should().Be(pageId); - page.IsArchived.Should().BeTrue(); - page.Properties.Should().HaveCount(2); - var updatedProperty = page.Properties.First(x => x.Key == "In stock"); + page.Id.Should().Be(pageId); + page.IsArchived.Should().BeTrue(); + page.Properties.Should().HaveCount(2); + var updatedProperty = page.Properties.First(x => x.Key == "In stock"); - var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItem(new RetrievePropertyItemParameters - { - PageId = page.Id, - PropertyId = updatedProperty.Value.Id - }); + var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItem( + new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = updatedProperty.Value.Id}); - checkboxPropertyValue.Checkbox.Should().BeTrue(); - } + checkboxPropertyValue.Checkbox.Should().BeTrue(); + } - [Fact] - public async Task CreateAsync_Throws_ArgumentNullException_When_Parameter_Is_Null() - { - Func act = async () => await _client.CreateAsync(null); + [Fact] + public async Task CreateAsync_Throws_ArgumentNullException_When_Parameter_Is_Null() + { + Func act = async () => await _client.CreateAsync(null); - (await act.Should().ThrowAsync()).And.ParamName.Should().Be("pagesCreateParameters"); - } + (await act.Should().ThrowAsync()).And.ParamName.Should().Be("pagesCreateParameters"); + } - [Fact] - public async Task CreateAsync_Throws_ArgumentNullException_When_Parent_Is_Missing() - { - var pagesCreateParameters = PagesCreateParametersBuilder.Create(null).Build(); + [Fact] + public async Task CreateAsync_Throws_ArgumentNullException_When_Parent_Is_Missing() + { + var pagesCreateParameters = PagesCreateParametersBuilder.Create(null).Build(); - Func act = async () => await _client.CreateAsync(pagesCreateParameters); + Func act = async () => await _client.CreateAsync(pagesCreateParameters); - (await act.Should().ThrowAsync()).And.ParamName.Should().Be("Parent"); - } + (await act.Should().ThrowAsync()).And.ParamName.Should().Be("Parent"); + } - [Fact] - public async Task CreateAsync_Throws_ArgumentNullException_When_Properties_Is_Missing() + [Fact] + public async Task CreateAsync_Throws_ArgumentNullException_When_Properties_Is_Missing() + { + var pagesCreateParameters = new PagesCreateParameters { - var pagesCreateParameters = new PagesCreateParameters - { - Parent = new ParentPageInput() - { - PageId = "3c357473-a281-49a4-88c0-10d2b245a589", - }, - Properties = null - }; + Parent = new ParentPageInput {PageId = "3c357473-a281-49a4-88c0-10d2b245a589"}, Properties = null, + }; - Func act = async () => await _client.CreateAsync(pagesCreateParameters); + Func act = async () => await _client.CreateAsync(pagesCreateParameters); - (await act.Should().ThrowAsync()).And.ParamName.Should().Be("Properties"); - } + (await act.Should().ThrowAsync()).And.ParamName.Should().Be("Properties"); } } diff --git a/Test/Notion.UnitTests/PropertyTests.cs b/Test/Notion.UnitTests/PropertyTests.cs index d09e4a87..c8196f15 100644 --- a/Test/Notion.UnitTests/PropertyTests.cs +++ b/Test/Notion.UnitTests/PropertyTests.cs @@ -1,67 +1,65 @@ using System; -using FluentAssertions; using Notion.Client; using Notion.Client.Extensions; using Xunit; -namespace Notion.UnitTests +namespace Notion.UnitTests; + +public class PropertyTests { - public class PropertyTests + [Theory] + [InlineData(typeof(CheckboxProperty), PropertyType.Checkbox)] + [InlineData(typeof(CreatedByProperty), PropertyType.CreatedBy)] + [InlineData(typeof(CreatedTimeProperty), PropertyType.CreatedTime)] + [InlineData(typeof(DateProperty), PropertyType.Date)] + [InlineData(typeof(EmailProperty), PropertyType.Email)] + [InlineData(typeof(FilesProperty), PropertyType.Files)] + [InlineData(typeof(FormulaProperty), PropertyType.Formula)] + [InlineData(typeof(LastEditedByProperty), PropertyType.LastEditedBy)] + [InlineData(typeof(LastEditedTimeProperty), PropertyType.LastEditedTime)] + [InlineData(typeof(NumberProperty), PropertyType.Number)] + [InlineData(typeof(PeopleProperty), PropertyType.People)] + [InlineData(typeof(PhoneNumberProperty), PropertyType.PhoneNumber)] + [InlineData(typeof(RelationProperty), PropertyType.Relation)] + [InlineData(typeof(RichTextProperty), PropertyType.RichText)] + [InlineData(typeof(RollupProperty), PropertyType.Rollup)] + [InlineData(typeof(SelectProperty), PropertyType.Select)] + [InlineData(typeof(TitleProperty), PropertyType.Title)] + [InlineData(typeof(UrlProperty), PropertyType.Url)] + public void TestPropertyType(Type type, PropertyType expectedPropertyType) { - [Theory] - [InlineData(typeof(CheckboxProperty), PropertyType.Checkbox)] - [InlineData(typeof(CreatedByProperty), PropertyType.CreatedBy)] - [InlineData(typeof(CreatedTimeProperty), PropertyType.CreatedTime)] - [InlineData(typeof(DateProperty), PropertyType.Date)] - [InlineData(typeof(EmailProperty), PropertyType.Email)] - [InlineData(typeof(FilesProperty), PropertyType.Files)] - [InlineData(typeof(FormulaProperty), PropertyType.Formula)] - [InlineData(typeof(LastEditedByProperty), PropertyType.LastEditedBy)] - [InlineData(typeof(LastEditedTimeProperty), PropertyType.LastEditedTime)] - [InlineData(typeof(NumberProperty), PropertyType.Number)] - [InlineData(typeof(PeopleProperty), PropertyType.People)] - [InlineData(typeof(PhoneNumberProperty), PropertyType.PhoneNumber)] - [InlineData(typeof(RelationProperty), PropertyType.Relation)] - [InlineData(typeof(RichTextProperty), PropertyType.RichText)] - [InlineData(typeof(RollupProperty), PropertyType.Rollup)] - [InlineData(typeof(SelectProperty), PropertyType.Select)] - [InlineData(typeof(TitleProperty), PropertyType.Title)] - [InlineData(typeof(UrlProperty), PropertyType.Url)] - public void TestPropertyType(Type type, PropertyType expectedPropertyType) - { - var typeInstance = (Property)Activator.CreateInstance(type); + var typeInstance = (Property)Activator.CreateInstance(type); - var actualPropertyType = typeInstance.Type; + var actualPropertyType = typeInstance.Type; - Assert.Equal(expectedPropertyType, actualPropertyType); - } + Assert.Equal(expectedPropertyType, actualPropertyType); + } - [Theory] - [InlineData(typeof(CheckboxProperty), "checkbox")] - [InlineData(typeof(CreatedByProperty), "created_by")] - [InlineData(typeof(CreatedTimeProperty), "created_time")] - [InlineData(typeof(DateProperty), "date")] - [InlineData(typeof(EmailProperty), "email")] - [InlineData(typeof(FilesProperty), "files")] - [InlineData(typeof(FormulaProperty), "formula")] - [InlineData(typeof(LastEditedByProperty), "last_edited_by")] - [InlineData(typeof(LastEditedTimeProperty), "last_edited_time")] - [InlineData(typeof(NumberProperty), "number")] - [InlineData(typeof(PeopleProperty), "people")] - [InlineData(typeof(PhoneNumberProperty), "phone_number")] - [InlineData(typeof(RelationProperty), "relation")] - [InlineData(typeof(RichTextProperty), "rich_text")] - [InlineData(typeof(RollupProperty), "rollup")] - [InlineData(typeof(SelectProperty), "select")] - [InlineData(typeof(TitleProperty), "title")] - [InlineData(typeof(UrlProperty), "url")] - public void TestPropertyTypeText(Type type, string expectedPropertyType) - { - var typeInstance = (Property)Activator.CreateInstance(type); + [Theory] + [InlineData(typeof(CheckboxProperty), "checkbox")] + [InlineData(typeof(CreatedByProperty), "created_by")] + [InlineData(typeof(CreatedTimeProperty), "created_time")] + [InlineData(typeof(DateProperty), "date")] + [InlineData(typeof(EmailProperty), "email")] + [InlineData(typeof(FilesProperty), "files")] + [InlineData(typeof(FormulaProperty), "formula")] + [InlineData(typeof(LastEditedByProperty), "last_edited_by")] + [InlineData(typeof(LastEditedTimeProperty), "last_edited_time")] + [InlineData(typeof(NumberProperty), "number")] + [InlineData(typeof(PeopleProperty), "people")] + [InlineData(typeof(PhoneNumberProperty), "phone_number")] + [InlineData(typeof(RelationProperty), "relation")] + [InlineData(typeof(RichTextProperty), "rich_text")] + [InlineData(typeof(RollupProperty), "rollup")] + [InlineData(typeof(SelectProperty), "select")] + [InlineData(typeof(TitleProperty), "title")] + [InlineData(typeof(UrlProperty), "url")] + public void TestPropertyTypeText(Type type, string expectedPropertyType) + { + var typeInstance = (Property)Activator.CreateInstance(type); - var actualPropertyType = typeInstance.Type.GetEnumMemberValue(); + var actualPropertyType = typeInstance.Type.GetEnumMemberValue(); - Assert.Equal(expectedPropertyType, actualPropertyType); - } + Assert.Equal(expectedPropertyType, actualPropertyType); } } diff --git a/Test/Notion.UnitTests/SearchClientTest.cs b/Test/Notion.UnitTests/SearchClientTest.cs index aa506572..3ca7dd27 100644 --- a/Test/Notion.UnitTests/SearchClientTest.cs +++ b/Test/Notion.UnitTests/SearchClientTest.cs @@ -1,71 +1,65 @@ -using System; -using System.IO; +using System.IO; using System.Threading.Tasks; using FluentAssertions; using Notion.Client; using WireMock.ResponseBuilders; using Xunit; -namespace Notion.UnitTests +namespace Notion.UnitTests; + +public class SearchClientTest : ApiTestBase { - public class SearchClientTest : ApiTestBase - { - private readonly SearchClient _client; + private readonly SearchClient _client; - public SearchClientTest() - { - _client = new SearchClient(new RestClient(ClientOptions)); - } + public SearchClientTest() + { + _client = new SearchClient(new RestClient(ClientOptions)); + } - [Fact] - public async Task Search() - { - // Arrange - var path = ApiEndpoints.SearchApiUrls.Search(); - var jsonData = await File.ReadAllTextAsync("data/search/SearchResponse.json"); + [Fact] + public async Task Search() + { + // Arrange + var path = ApiEndpoints.SearchApiUrls.Search(); + var jsonData = await File.ReadAllTextAsync("data/search/SearchResponse.json"); - Server.Given(CreatePostRequestBuilder(path)) - .RespondWith( + Server.Given(CreatePostRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - SearchParameters searchParameters = new SearchParameters() - { - Query = "External tasks", - Sort = new SearchSort - { - Direction = SearchDirection.Ascending, - Timestamp = "last_edited_time" - } - }; + var searchParameters = new SearchParameters + { + Query = "External tasks", + Sort = new SearchSort {Direction = SearchDirection.Ascending, Timestamp = "last_edited_time"}, + }; - // Act - var searchResult = await _client.SearchAsync(searchParameters); + // Act + var searchResult = await _client.SearchAsync(searchParameters); - // Assert - var results = searchResult.Results; + // Assert + var results = searchResult.Results; - results.Should().SatisfyRespectively( - obj => - { - obj.Object.Should().Be(ObjectType.Database); + results.Should().SatisfyRespectively( + obj => + { + obj.Object.Should().Be(ObjectType.Database); - var database = (Database)obj; - database.Properties.Should().HaveCount(2); - }, - obj => - { - obj.Object.Should().Be(ObjectType.Page); + var database = (Database)obj; + database.Properties.Should().HaveCount(2); + }, + obj => + { + obj.Object.Should().Be(ObjectType.Page); - var page = (Page)obj; - page.IsArchived.Should().BeFalse(); - page.Properties.Should().HaveCount(1); - page.Parent.Should().BeAssignableTo(); - ((DatabaseParent)page.Parent).DatabaseId.Should().Be("e6c6f8ff-c70e-4970-91ba-98f03e0d7fc6"); - } - ); - } + var page = (Page)obj; + page.IsArchived.Should().BeFalse(); + page.Properties.Should().HaveCount(1); + page.Parent.Should().BeAssignableTo(); + ((DatabaseParent)page.Parent).DatabaseId.Should().Be("e6c6f8ff-c70e-4970-91ba-98f03e0d7fc6"); + } + ); } } diff --git a/Test/Notion.UnitTests/UserClientTest.cs b/Test/Notion.UnitTests/UserClientTest.cs index d9b27984..6e93decc 100644 --- a/Test/Notion.UnitTests/UserClientTest.cs +++ b/Test/Notion.UnitTests/UserClientTest.cs @@ -5,145 +5,144 @@ using WireMock.ResponseBuilders; using Xunit; -namespace Notion.UnitTests +namespace Notion.UnitTests; + +public class UserClientTest : ApiTestBase { - public class UserClientTest : ApiTestBase + private readonly IUsersClient _client; + + public UserClientTest() + { + _client = new UsersClient(new RestClient(ClientOptions)); + } + + [Fact] + public async Task ListUsers() + { + // Arrange + var jsonData = await File.ReadAllTextAsync("data/users/ListUsersResponse.json"); + var path = ApiEndpoints.UsersApiUrls.List(); + + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( + Response.Create() + .WithStatusCode(200) + .WithBody(jsonData) + ); + + // Act + var users = await _client.ListAsync(); + + // Assert + users.Results.Should().SatisfyRespectively( + user => + { + user.Id.Should().Be("5e37c1b4-630f-4e81-bd6b-296af31e345f"); + user.Name.Should().Be("Vedant Koditkar"); + user.Type.Should().Be("person"); + user.Person.Email.Should().Be("vedkoditkar@gmail.com"); + user.Bot.Should().BeNull(); + }, + user => + { + user.Id.Should().Be("590693f3-797f-4970-98ff-7284106393e5"); + user.Name.Should().Be("Test"); + user.Type.Should().Be("bot"); + user.Person.Should().BeNull(); + } + ); + } + + [Fact] + public async Task RetrieveUser() { - private readonly IUsersClient _client; - - public UserClientTest() - { - _client = new UsersClient(new RestClient(ClientOptions)); - } - - [Fact] - public async Task ListUsers() - { - // Arrange - var jsonData = await File.ReadAllTextAsync("data/users/ListUsersResponse.json"); - var path = ApiEndpoints.UsersApiUrls.List(); - - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( + // Arrange + var jsonData = await File.ReadAllTextAsync("data/users/RetrieveUserResponse.json"); + var userId = "5e37c1b4-630f-4e81-bd6b-296af31e345f"; + var path = ApiEndpoints.UsersApiUrls.Retrieve(userId); + + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - // Act - var users = await _client.ListAsync(); - - // Assert - users.Results.Should().SatisfyRespectively( - user => - { - user.Id.Should().Be("5e37c1b4-630f-4e81-bd6b-296af31e345f"); - user.Name.Should().Be("Vedant Koditkar"); - user.Type.Should().Be("person"); - user.Person.Email.Should().Be("vedkoditkar@gmail.com"); - user.Bot.Should().BeNull(); - }, - user => - { - user.Id.Should().Be("590693f3-797f-4970-98ff-7284106393e5"); - user.Name.Should().Be("Test"); - user.Type.Should().Be("bot"); - user.Person.Should().BeNull(); - } + // Act + var user = await _client.RetrieveAsync(userId); + + // Assert + user.Id.Should().Be("5e37c1b4-630f-4e81-bd6b-296af31e345f"); + user.Name.Should().Be("Vedant Koditkar"); + user.Type.Should().Be("person"); + user.Person.Email.Should().Be("vedkoditkar@gmail.com"); + user.Bot.Should().BeNull(); + } + + [Fact] + public async Task RetrieveTokenUser_WorkspaceInternalToken() + { + // Arrange + var jsonData = await File.ReadAllTextAsync("data/users/MeResponse.json"); + + var path = ApiEndpoints.UsersApiUrls.Me(); + + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( + Response.Create() + .WithStatusCode(200) + .WithBody(jsonData) ); - } - - [Fact] - public async Task RetrieveUser() - { - // Arrange - var jsonData = await File.ReadAllTextAsync("data/users/RetrieveUserResponse.json"); - var userId = "5e37c1b4-630f-4e81-bd6b-296af31e345f"; - var path = ApiEndpoints.UsersApiUrls.Retrieve(userId); - - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( + + // Act + var user = await _client.MeAsync(); + + // Assert + user.Id.Should().Be("590693f3-797f-4970-98ff-7284106393e5"); + user.Name.Should().Be("Test"); + user.AvatarUrl.Should().BeNull(); + user.Type.Should().Be("bot"); + user.Person.Should().BeNull(); + user.Bot.Should().NotBeNull(); + user.Bot.Owner.Should().BeOfType(); + + var owner = (WorkspaceIntegrationOwner)user.Bot.Owner; + owner.Workspace.Should().BeTrue(); + } + + [Fact] + public async Task RetrieveTokenUser_UserLevelToken() + { + // Arrange + var jsonData = await File.ReadAllTextAsync("data/users/MeUserLevelResponse.json"); + + var path = ApiEndpoints.UsersApiUrls.Me(); + + Server.Given(CreateGetRequestBuilder(path)) + .RespondWith( Response.Create() .WithStatusCode(200) .WithBody(jsonData) ); - // Act - var user = await _client.RetrieveAsync(userId); - - // Assert - user.Id.Should().Be("5e37c1b4-630f-4e81-bd6b-296af31e345f"); - user.Name.Should().Be("Vedant Koditkar"); - user.Type.Should().Be("person"); - user.Person.Email.Should().Be("vedkoditkar@gmail.com"); - user.Bot.Should().BeNull(); - } - - [Fact] - public async Task RetrieveTokenUser_WorkspaceInternalToken() - { - // Arrange - var jsonData = await File.ReadAllTextAsync("data/users/MeResponse.json"); - - var path = ApiEndpoints.UsersApiUrls.Me(); - - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( - Response.Create() - .WithStatusCode(200) - .WithBody(jsonData) - ); - - // Act - var user = await _client.MeAsync(); - - // Assert - user.Id.Should().Be("590693f3-797f-4970-98ff-7284106393e5"); - user.Name.Should().Be("Test"); - user.AvatarUrl.Should().BeNull(); - user.Type.Should().Be("bot"); - user.Person.Should().BeNull(); - user.Bot.Should().NotBeNull(); - user.Bot.Owner.Should().BeOfType(); - - var owner = (WorkspaceIntegrationOwner)user.Bot.Owner; - owner.Workspace.Should().BeTrue(); - } - - [Fact] - public async Task RetrieveTokenUser_UserLevelToken() - { - // Arrange - var jsonData = await File.ReadAllTextAsync("data/users/MeUserLevelResponse.json"); - - var path = ApiEndpoints.UsersApiUrls.Me(); - - Server.Given(CreateGetRequestBuilder(path)) - .RespondWith( - Response.Create() - .WithStatusCode(200) - .WithBody(jsonData) - ); - - // Act - var user = await _client.MeAsync(); - - // Assert - user.Id.Should().Be("16d84278-ab0e-484c-9bdd-b35da3bd8905"); - user.Name.Should().Be("pied piper"); - user.AvatarUrl.Should().BeNull(); - user.Type.Should().Be("bot"); - user.Person.Should().BeNull(); - user.Bot.Should().NotBeNull(); - user.Bot.Owner.Should().BeOfType(); - - var owner = (UserOwner)user.Bot.Owner; - owner.User.Id.Should().Be("5389a034-eb5c-47b5-8a9e-f79c99ef166c"); - owner.User.Name.Should().Be("christine makenotion"); - owner.User.AvatarUrl.Should().BeNull(); - owner.User.Type.Should().Be("person"); - owner.User.Person.Email.Should().Be("christine@makenotion.com"); - owner.User.Bot.Should().BeNull(); - } + // Act + var user = await _client.MeAsync(); + + // Assert + user.Id.Should().Be("16d84278-ab0e-484c-9bdd-b35da3bd8905"); + user.Name.Should().Be("pied piper"); + user.AvatarUrl.Should().BeNull(); + user.Type.Should().Be("bot"); + user.Person.Should().BeNull(); + user.Bot.Should().NotBeNull(); + user.Bot.Owner.Should().BeOfType(); + + var owner = (UserOwner)user.Bot.Owner; + owner.User.Id.Should().Be("5389a034-eb5c-47b5-8a9e-f79c99ef166c"); + owner.User.Name.Should().Be("christine makenotion"); + owner.User.AvatarUrl.Should().BeNull(); + owner.User.Type.Should().Be("person"); + owner.User.Person.Email.Should().Be("christine@makenotion.com"); + owner.User.Bot.Should().BeNull(); } } From e740f751c8c0a311ddf968ff72f9517551d17a9c Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 8 Oct 2022 13:11:39 +0530 Subject: [PATCH 110/216] =?UTF-8?q?Update=20editor=20config=20and=20fix=20?= =?UTF-8?q?linter=20issues=20=F0=9F=9A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .editorconfig | 110 ++++-------- Src/Notion.Client/Api/Blocks/BlocksClient.cs | 4 +- .../Create/Request/CreateCommentParameters.cs | 12 +- .../Api/Comments/Retrieve/CommentsClient.cs | 4 +- .../Api/Databases/RequestParams/Direction.cs | 2 +- .../Api/Databases/RequestParams/Timestamp.cs | 2 +- Src/Notion.Client/Api/Pages/PagesClient.cs | 7 +- .../PagesCreateParametersBuilder.cs | 4 +- .../Api/Search/Parameters/SearchDirection.cs | 2 +- .../Api/Search/Parameters/SearchObjectType.cs | 2 +- Src/Notion.Client/Models/Blocks/BlockType.cs | 2 +- Src/Notion.Client/Models/Blocks/Color.cs | 2 +- .../Database/Properties/PropertyType.cs | 2 +- .../RelationProperty/RelationType.cs | 2 +- .../Models/Database/RichText/RichTextType.cs | 2 +- Src/Notion.Client/Models/ObjectType.cs | 2 +- .../Models/Parents/ParentType.cs | 2 +- .../Models/PropertyValue/PropertyValueType.cs | 2 +- .../PropertyValue/StatusPropertyValue.cs | 2 +- Src/Notion.Client/NotionAPIErrorCode.cs | 2 +- Src/Notion.Client/RestClient/RestClient.cs | 11 +- Src/Notion.Client/http/QueryHelpers.cs | 2 +- .../CommentsClientTests.cs | 19 +- .../IBlocksClientTests.cs | 169 +++++++++--------- .../IPageClientTests.cs | 91 ++++++---- Test/Notion.UnitTests/ApiTestBase.cs | 9 +- Test/Notion.UnitTests/BlocksClientTests.cs | 28 +-- Test/Notion.UnitTests/DatabasesClientTests.cs | 129 +++++++++---- Test/Notion.UnitTests/FilterTests.cs | 12 +- Test/Notion.UnitTests/PagesClientTests.cs | 40 +++-- Test/Notion.UnitTests/SearchClientTest.cs | 6 +- 31 files changed, 392 insertions(+), 293 deletions(-) diff --git a/.editorconfig b/.editorconfig index 7e8f258c..76a523b0 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,6 +8,43 @@ root = true indent_style = space [*.cs] + +# ReSharper properties + +# Blank lines +resharper_blank_lines_after_control_transfer_statements = 1 +resharper_blank_lines_after_multiline_statements = 1 +resharper_blank_lines_around_single_line_auto_property = 1 +resharper_blank_lines_around_single_line_local_method = 1 +resharper_blank_lines_around_single_line_property = 1 +resharper_blank_lines_before_block_statements = 1 +resharper_blank_lines_before_control_transfer_statements = 1 +resharper_blank_lines_before_multiline_statements = 1 +resharper_blank_lines_before_single_line_comment = 1 + +# Baces +resharper_braces_for_for = required +resharper_braces_for_foreach = required +resharper_braces_for_ifelse = required +resharper_braces_for_while = required +resharper_braces_redundant = false +resharper_indent_nested_fixed_stmt = true +resharper_indent_nested_foreach_stmt = true +resharper_indent_nested_for_stmt = true +resharper_indent_nested_lock_stmt = true +resharper_indent_nested_usings_stmt = true +resharper_indent_nested_while_stmt = true +resharper_max_enum_members_on_line = 1 + +resharper_csharp_force_attribute_style=separate +resharper_csharp_method_or_operator_body=expression_body +resharper_csharp_max_enum_members_on_line=1 +resharper_csharp_place_attribute_on_same_line=false +resharper_csharp_wrap_object_and_collection_initializer_style=chop_always +resharper_csharp_use_heuristics_for_body_style=true + +resharper_csharp_max_initializer_elements_on_line=0 + # Microsoft .NET properties csharp_preferred_modifier_order = public, private, protected, internal, new, static, abstract, virtual, sealed, readonly, override, extern, unsafe, volatile, async:suggestion csharp_style_var_elsewhere = true:suggestion @@ -181,79 +218,6 @@ dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion dotnet_style_predefined_type_for_member_access = true:suggestion dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion -# ReSharper properties -# resharper_arguments_anonymous_function = named -# resharper_arguments_literal = named -# resharper_arguments_named = named -# resharper_arguments_other = named -# resharper_arguments_string_literal = named -resharper_blank_lines_after_control_transfer_statements = 1 -resharper_blank_lines_after_multiline_statements = 1 -resharper_blank_lines_around_single_line_auto_property = 1 -resharper_blank_lines_around_single_line_local_method = 1 -resharper_blank_lines_around_single_line_property = 1 -resharper_blank_lines_before_block_statements = 1 -resharper_blank_lines_before_control_transfer_statements = 1 -resharper_blank_lines_before_multiline_statements = 1 -resharper_blank_lines_before_single_line_comment = 1 -resharper_braces_for_for = required -resharper_braces_for_foreach = required -resharper_braces_for_ifelse = required -resharper_braces_for_while = required -resharper_braces_redundant = false -resharper_case_block_braces = next_line_shifted_2 -resharper_csharp_blank_lines_around_single_line_invocable = 1 -resharper_csharp_keep_blank_lines_in_code = 1 -resharper_csharp_keep_blank_lines_in_declarations = 1 -resharper_csharp_wrap_after_declaration_lpar = true -resharper_csharp_wrap_extends_list_style = chop_if_long -resharper_csharp_wrap_parameters_style = chop_if_long -resharper_indent_nested_fixed_stmt = true -resharper_indent_nested_foreach_stmt = true -resharper_indent_nested_for_stmt = true -resharper_indent_nested_lock_stmt = true -resharper_indent_nested_usings_stmt = true -resharper_indent_nested_while_stmt = true -resharper_keep_existing_declaration_block_arrangement = true -resharper_keep_existing_declaration_parens_arrangement = false -resharper_keep_existing_embedded_block_arrangement = true -resharper_keep_existing_enum_arrangement = true -resharper_keep_existing_expr_member_arrangement = false -resharper_keep_existing_initializer_arrangement = false -resharper_local_function_body = expression_body -resharper_max_enum_members_on_line = 1 -resharper_max_formal_parameters_on_line = 4 -resharper_place_field_attribute_on_same_line = if_owner_is_single_line -resharper_space_within_single_line_array_initializer_braces = false -resharper_trailing_comma_in_multiline_lists = true -resharper_use_heuristics_for_body_style = false -resharper_use_indent_from_vs = false -resharper_wrap_before_eq = true -resharper_wrap_before_first_type_parameter_constraint = true - -# ReSharper inspection severities -resharper_arrange_accessor_owner_body_highlighting = none -resharper_arrange_local_function_body_highlighting = suggestion -resharper_arrange_namespace_body_highlighting = suggestion -resharper_arrange_redundant_parentheses_highlighting = hint -resharper_arrange_this_qualifier_highlighting = none -resharper_arrange_type_member_modifiers_highlighting = hint -resharper_arrange_type_modifiers_highlighting = hint -resharper_built_in_type_reference_style_for_member_access_highlighting = suggestion -resharper_built_in_type_reference_style_highlighting = suggestion -resharper_inconsistent_naming_highlighting = suggestion -resharper_redundant_base_qualifier_highlighting = none -resharper_suggest_var_or_type_built_in_types_highlighting = suggestion -resharper_suggest_var_or_type_elsewhere_highlighting = suggestion -resharper_suggest_var_or_type_simple_types_highlighting = suggestion - -resharper_csharp_force_attribute_style=separate -resharper_csharp_method_or_operator_body=expression_body -resharper_csharp_max_enum_members_on_line=1 -resharper_csharp_place_attribute_on_same_line=false -resharper_csharp_wrap_object_and_collection_initializer_style=chop_always -resharper_csharp_use_heuristics_for_body_style=true - # Standard properties insert_final_newline = true # (Please don't specify an indent_size here; that has too many unintended consequences.) diff --git a/Src/Notion.Client/Api/Blocks/BlocksClient.cs b/Src/Notion.Client/Api/Blocks/BlocksClient.cs index 8fbdcd26..1282a346 100644 --- a/Src/Notion.Client/Api/Blocks/BlocksClient.cs +++ b/Src/Notion.Client/Api/Blocks/BlocksClient.cs @@ -29,8 +29,8 @@ public async Task> RetrieveChildrenAsync( var queryParams = new Dictionary { - {"start_cursor", queryParameters?.StartCursor}, - {"page_size", queryParameters?.PageSize?.ToString()}, + { "start_cursor", queryParameters?.StartCursor }, + { "page_size", queryParameters?.PageSize?.ToString() } }; return await _client.GetAsync>(url, queryParams); diff --git a/Src/Notion.Client/Api/Comments/Create/Request/CreateCommentParameters.cs b/Src/Notion.Client/Api/Comments/Create/Request/CreateCommentParameters.cs index 3b676133..f9532726 100644 --- a/Src/Notion.Client/Api/Comments/Create/Request/CreateCommentParameters.cs +++ b/Src/Notion.Client/Api/Comments/Create/Request/CreateCommentParameters.cs @@ -33,14 +33,22 @@ public static CreateCommentParameters CreatePageComment( ParentPageInput parent, IEnumerable richText) { - return new CreateCommentParameters {Parent = parent, RichText = richText}; + return new CreateCommentParameters + { + Parent = parent, + RichText = richText + }; } public static CreateCommentParameters CreateDiscussionComment( string discussionId, IEnumerable richText) { - return new CreateCommentParameters {DiscussionId = discussionId, RichText = richText}; + return new CreateCommentParameters + { + DiscussionId = discussionId, + RichText = richText + }; } } } diff --git a/Src/Notion.Client/Api/Comments/Retrieve/CommentsClient.cs b/Src/Notion.Client/Api/Comments/Retrieve/CommentsClient.cs index b979086f..cb32978e 100644 --- a/Src/Notion.Client/Api/Comments/Retrieve/CommentsClient.cs +++ b/Src/Notion.Client/Api/Comments/Retrieve/CommentsClient.cs @@ -11,7 +11,9 @@ public async Task Retrieve(RetrieveCommentsParameters var queryParams = new Dictionary { - {"block_id", qp.BlockId}, {"start_cursor", qp.StartCursor}, {"page_size", qp.PageSize.ToString()}, + { "block_id", qp.BlockId }, + { "start_cursor", qp.StartCursor }, + { "page_size", qp.PageSize.ToString() } }; return await _client.GetAsync( diff --git a/Src/Notion.Client/Api/Databases/RequestParams/Direction.cs b/Src/Notion.Client/Api/Databases/RequestParams/Direction.cs index 76b87da3..c79d501d 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/Direction.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/Direction.cs @@ -11,6 +11,6 @@ public enum Direction Ascending, [EnumMember(Value = "descending")] - Descending, + Descending } } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/Timestamp.cs b/Src/Notion.Client/Api/Databases/RequestParams/Timestamp.cs index 4eb359d4..334b8c22 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/Timestamp.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/Timestamp.cs @@ -11,6 +11,6 @@ public enum Timestamp CreatedTime, [EnumMember(Value = "last_edited_time")] - LastEditedTime, + LastEditedTime } } diff --git a/Src/Notion.Client/Api/Pages/PagesClient.cs b/Src/Notion.Client/Api/Pages/PagesClient.cs index b71f924f..b4a3c58f 100644 --- a/Src/Notion.Client/Api/Pages/PagesClient.cs +++ b/Src/Notion.Client/Api/Pages/PagesClient.cs @@ -63,8 +63,8 @@ public async Task RetrievePagePropertyItem( var queryParams = new Dictionary { - {"start_cursor", queryParameters?.StartCursor}, - {"page_size", queryParameters?.PageSize?.ToString()}, + { "start_cursor", queryParameters?.StartCursor }, + { "page_size", queryParameters?.PageSize?.ToString() } }; return await _client.GetAsync(url, queryParams); @@ -84,7 +84,8 @@ public async Task UpdatePropertiesAsync( IDictionary updatedProperties) { var url = PagesApiUrls.UpdateProperties(pageId); - var body = new UpdatePropertiesParameters {Properties = updatedProperties}; + + var body = new UpdatePropertiesParameters { Properties = updatedProperties }; return await _client.PatchAsync(url, body); } diff --git a/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParametersBuilder.cs b/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParametersBuilder.cs index 7df2fe4c..6b263beb 100644 --- a/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParametersBuilder.cs +++ b/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParametersBuilder.cs @@ -16,7 +16,7 @@ private PagesCreateParametersBuilder() public static PagesCreateParametersBuilder Create(IPageParentInput parent) { - return new PagesCreateParametersBuilder {parent = parent}; + return new PagesCreateParametersBuilder { parent = parent }; } public PagesCreateParametersBuilder AddProperty(string nameOrId, PropertyValue value) @@ -55,7 +55,7 @@ public PagesCreateParameters Build() Properties = properties, Children = children, Icon = icon, - Cover = cover, + Cover = cover }; } } diff --git a/Src/Notion.Client/Api/Search/Parameters/SearchDirection.cs b/Src/Notion.Client/Api/Search/Parameters/SearchDirection.cs index 0bde8d23..fdac0b59 100644 --- a/Src/Notion.Client/Api/Search/Parameters/SearchDirection.cs +++ b/Src/Notion.Client/Api/Search/Parameters/SearchDirection.cs @@ -8,6 +8,6 @@ public enum SearchDirection Ascending, [EnumMember(Value = "descending")] - Descending, + Descending } } diff --git a/Src/Notion.Client/Api/Search/Parameters/SearchObjectType.cs b/Src/Notion.Client/Api/Search/Parameters/SearchObjectType.cs index 773ef95a..78a012df 100644 --- a/Src/Notion.Client/Api/Search/Parameters/SearchObjectType.cs +++ b/Src/Notion.Client/Api/Search/Parameters/SearchObjectType.cs @@ -8,6 +8,6 @@ public enum SearchObjectType Page, [EnumMember(Value = "database")] - Database, + Database } } diff --git a/Src/Notion.Client/Models/Blocks/BlockType.cs b/Src/Notion.Client/Models/Blocks/BlockType.cs index f15c3b37..8a2c626a 100644 --- a/Src/Notion.Client/Models/Blocks/BlockType.cs +++ b/Src/Notion.Client/Models/Blocks/BlockType.cs @@ -101,6 +101,6 @@ public enum BlockType LinkPreview, [EnumMember(Value = "unsupported")] - Unsupported, + Unsupported } } diff --git a/Src/Notion.Client/Models/Blocks/Color.cs b/Src/Notion.Client/Models/Blocks/Color.cs index b4682a7b..ec22b0dc 100644 --- a/Src/Notion.Client/Models/Blocks/Color.cs +++ b/Src/Notion.Client/Models/Blocks/Color.cs @@ -59,6 +59,6 @@ public enum Color PinkBackground, [EnumMember(Value = "red_background")] - RedBackground, + RedBackground } } diff --git a/Src/Notion.Client/Models/Database/Properties/PropertyType.cs b/Src/Notion.Client/Models/Database/Properties/PropertyType.cs index a67b8cd8..5ca4c7f8 100644 --- a/Src/Notion.Client/Models/Database/Properties/PropertyType.cs +++ b/Src/Notion.Client/Models/Database/Properties/PropertyType.cs @@ -65,6 +65,6 @@ public enum PropertyType LastEditedTime, [EnumMember(Value = "status")] - Status, + Status } } diff --git a/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationType.cs b/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationType.cs index a0a58a47..89ce1c56 100644 --- a/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationType.cs +++ b/Src/Notion.Client/Models/Database/Properties/RelationProperty/RelationType.cs @@ -8,6 +8,6 @@ public enum RelationType Single, [EnumMember(Value = "dual_property")] - Dual, + Dual } } diff --git a/Src/Notion.Client/Models/Database/RichText/RichTextType.cs b/Src/Notion.Client/Models/Database/RichText/RichTextType.cs index 58406612..59bc414f 100644 --- a/Src/Notion.Client/Models/Database/RichText/RichTextType.cs +++ b/Src/Notion.Client/Models/Database/RichText/RichTextType.cs @@ -14,6 +14,6 @@ public enum RichTextType Mention, [EnumMember(Value = "equation")] - Equation, + Equation } } diff --git a/Src/Notion.Client/Models/ObjectType.cs b/Src/Notion.Client/Models/ObjectType.cs index 21995840..4a9dc77d 100644 --- a/Src/Notion.Client/Models/ObjectType.cs +++ b/Src/Notion.Client/Models/ObjectType.cs @@ -17,6 +17,6 @@ public enum ObjectType User, [EnumMember(Value = "comment")] - Comment, + Comment } } diff --git a/Src/Notion.Client/Models/Parents/ParentType.cs b/Src/Notion.Client/Models/Parents/ParentType.cs index 96c2a00d..29126694 100644 --- a/Src/Notion.Client/Models/Parents/ParentType.cs +++ b/Src/Notion.Client/Models/Parents/ParentType.cs @@ -17,6 +17,6 @@ public enum ParentType Workspace, [EnumMember(Value = "block_id")] - BlockId, + BlockId } } diff --git a/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs b/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs index 93a8d63e..f8fb0a30 100644 --- a/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs +++ b/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs @@ -68,6 +68,6 @@ public enum PropertyValueType LastEditedBy, [EnumMember(Value = "status")] - Status, + Status } } diff --git a/Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs index f4a82e48..487b27c8 100644 --- a/Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs @@ -39,7 +39,7 @@ public enum Color Pink, [EnumMember(Value = "red")] - Red, + Red } public override PropertyValueType Type => PropertyValueType.Status; diff --git a/Src/Notion.Client/NotionAPIErrorCode.cs b/Src/Notion.Client/NotionAPIErrorCode.cs index f4cf699c..71e99d29 100644 --- a/Src/Notion.Client/NotionAPIErrorCode.cs +++ b/Src/Notion.Client/NotionAPIErrorCode.cs @@ -38,6 +38,6 @@ public enum NotionAPIErrorCode InternalServerError, [EnumMember(Value = "service_unavailable")] - ServiceUnavailable, + ServiceUnavailable } } diff --git a/Src/Notion.Client/RestClient/RestClient.cs b/Src/Notion.Client/RestClient/RestClient.cs index 5da38f61..23993086 100644 --- a/Src/Notion.Client/RestClient/RestClient.cs +++ b/Src/Notion.Client/RestClient/RestClient.cs @@ -19,7 +19,7 @@ public class RestClient : IRestClient protected readonly JsonSerializerSettings defaultSerializerSettings = new() { NullValueHandling = NullValueHandling.Ignore, - ContractResolver = new DefaultContractResolver {NamingStrategy = new CamelCaseNamingStrategy()}, + ContractResolver = new DefaultContractResolver { NamingStrategy = new CamelCaseNamingStrategy() } }; private HttpClient _httpClient; @@ -50,9 +50,11 @@ public async Task PostAsync( JsonSerializerSettings serializerSettings = null, CancellationToken cancellationToken = default) { - void AttachContent(HttpRequestMessage httpRequest) => + void AttachContent(HttpRequestMessage httpRequest) + { httpRequest.Content = new StringContent(JsonConvert.SerializeObject(body, defaultSerializerSettings), Encoding.UTF8, "application/json"); + } var response = await SendAsync(uri, HttpMethod.Post, queryParams, headers, AttachContent, cancellationToken); @@ -96,7 +98,7 @@ private static ClientOptions MergeOptions(ClientOptions options) { AuthToken = options.AuthToken, BaseUrl = options.BaseUrl ?? Constants.BASE_URL, - NotionVersion = options.NotionVersion ?? Constants.DEFAULT_NOTION_VERSION, + NotionVersion = options.NotionVersion ?? Constants.DEFAULT_NOTION_VERSION }; } @@ -166,7 +168,8 @@ private HttpClient EnsureHttpClient() { if (_httpClient == null) { - var pipeline = new LoggingHandler {InnerHandler = new HttpClientHandler()}; + var pipeline = new LoggingHandler { InnerHandler = new HttpClientHandler() }; + _httpClient = new HttpClient(pipeline); _httpClient.BaseAddress = new Uri(_options.BaseUrl); } diff --git a/Src/Notion.Client/http/QueryHelpers.cs b/Src/Notion.Client/http/QueryHelpers.cs index 86a2f0fb..243bfbcd 100644 --- a/Src/Notion.Client/http/QueryHelpers.cs +++ b/Src/Notion.Client/http/QueryHelpers.cs @@ -25,7 +25,7 @@ public static string AddQueryString(string uri, string name, string value) throw new ArgumentNullException(nameof(value)); } - return AddQueryString(uri, new[] {new KeyValuePair(name, value)}); + return AddQueryString(uri, new[] { new KeyValuePair(name, value) }); } public static string AddQueryString(string uri, IDictionary queryParams) diff --git a/Test/Notion.IntegrationTests/CommentsClientTests.cs b/Test/Notion.IntegrationTests/CommentsClientTests.cs index 32d887eb..118a09d6 100644 --- a/Test/Notion.IntegrationTests/CommentsClientTests.cs +++ b/Test/Notion.IntegrationTests/CommentsClientTests.cs @@ -15,7 +15,7 @@ public class CommentsClientTests : IDisposable public CommentsClientTests() { - var options = new ClientOptions {AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN")}; + var options = new ClientOptions { AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN") }; _client = NotionClientFactory.Create(options); @@ -24,14 +24,14 @@ public CommentsClientTests() _page = _client.Pages.CreateAsync( PagesCreateParametersBuilder.Create( - new ParentPageInput {PageId = _pageParentId} + new ParentPageInput { PageId = _pageParentId } ).Build() ).Result; } public void Dispose() { - _client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters {Archived = true}).Wait(); + _client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters { Archived = true }).Wait(); } [Fact] @@ -39,8 +39,8 @@ public async Task ShouldCreatePageComment() { // Arrange var parameters = CreateCommentParameters.CreatePageComment( - new ParentPageInput {PageId = _page.Id}, - new List {new RichTextTextInput {Text = new Text {Content = "This is a comment"}}} + new ParentPageInput { PageId = _page.Id }, + new List { new RichTextTextInput { Text = new Text { Content = "This is a comment" } } } ); // Act @@ -67,8 +67,11 @@ public async Task ShouldCreateADiscussionComment() // Arrange var comment = await _client.Comments.Create( CreateCommentParameters.CreatePageComment( - new ParentPageInput {PageId = _page.Id}, - new List {new RichTextTextInput {Text = new Text {Content = "This is a comment"}}} + new ParentPageInput { PageId = _page.Id }, + new List + { + new RichTextTextInput { Text = new Text { Content = "This is a comment" } } + } ) ); @@ -78,7 +81,7 @@ public async Task ShouldCreateADiscussionComment() comment.DiscussionId, new List { - new RichTextTextInput {Text = new Text {Content = "This is a sub comment"}}, + new RichTextTextInput { Text = new Text { Content = "This is a sub comment" } } } ) ); diff --git a/Test/Notion.IntegrationTests/IBlocksClientTests.cs b/Test/Notion.IntegrationTests/IBlocksClientTests.cs index 1aaa2726..6fc53999 100644 --- a/Test/Notion.IntegrationTests/IBlocksClientTests.cs +++ b/Test/Notion.IntegrationTests/IBlocksClientTests.cs @@ -14,7 +14,7 @@ public class IBlocksClientTests public IBlocksClientTests() { - var options = new ClientOptions {AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN")}; + var options = new ClientOptions { AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN") }; _client = NotionClientFactory.Create(options); } @@ -26,7 +26,7 @@ public async Task AppendChildrenAsync_AppendsBlocksGivenBlocks() var page = await _client.Pages.CreateAsync( PagesCreateParametersBuilder.Create( - new ParentPageInput {PageId = pageParentId} + new ParentPageInput { PageId = pageParentId } ).Build() ); @@ -36,27 +36,27 @@ public async Task AppendChildrenAsync_AppendsBlocksGivenBlocks() { Children = new List { - new BreadcrumbBlock {Breadcrumb = new BreadcrumbBlock.Data()}, - new DividerBlock {Divider = new DividerBlock.Data()}, - new TableOfContentsBlock {TableOfContents = new TableOfContentsBlock.Data()}, + new BreadcrumbBlock { Breadcrumb = new BreadcrumbBlock.Data() }, + new DividerBlock { Divider = new DividerBlock.Data() }, + new TableOfContentsBlock { TableOfContents = new TableOfContentsBlock.Data() }, new CalloutBlock { Callout = new CalloutBlock.Info { RichText = new List { - new RichTextTextInput {Text = new Text {Content = "Test"}}, - }, - }, - }, - }, + new RichTextTextInput { Text = new Text { Content = "Test" } } + } + } + } + } } ); blocks.Results.Should().HaveCount(4); // cleanup - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); } [Fact] @@ -66,7 +66,7 @@ public async Task UpdateBlockAsync_UpdatesGivenBlock() var page = await _client.Pages.CreateAsync( PagesCreateParametersBuilder.Create( - new ParentPageInput {PageId = pageParentId} + new ParentPageInput { PageId = pageParentId } ).Build() ); @@ -74,7 +74,7 @@ public async Task UpdateBlockAsync_UpdatesGivenBlock() page.Id, new BlocksAppendChildrenParameters { - Children = new List {new BreadcrumbBlock {Breadcrumb = new BreadcrumbBlock.Data()}}, + Children = new List { new BreadcrumbBlock { Breadcrumb = new BreadcrumbBlock.Data() } } } ); @@ -85,7 +85,7 @@ public async Task UpdateBlockAsync_UpdatesGivenBlock() blocks.Results.Should().HaveCount(1); // cleanup - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); } [Fact] @@ -95,7 +95,7 @@ public async Task DeleteAsync_DeleteBlockWithGivenId() var page = await _client.Pages.CreateAsync( PagesCreateParametersBuilder.Create( - new ParentPageInput {PageId = pageParentId} + new ParentPageInput { PageId = pageParentId } ).Build() ); @@ -105,16 +105,16 @@ public async Task DeleteAsync_DeleteBlockWithGivenId() { Children = new List { - new DividerBlock {Divider = new DividerBlock.Data()}, - new TableOfContentsBlock {TableOfContents = new TableOfContentsBlock.Data()}, - }, + new DividerBlock { Divider = new DividerBlock.Data() }, + new TableOfContentsBlock { TableOfContents = new TableOfContentsBlock.Data() } + } } ); blocks.Results.Should().HaveCount(2); // cleanup - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); } [Theory] @@ -125,13 +125,13 @@ public async Task UpdateAsync_UpdatesGivenBlock(IBlock block, IUpdateBlock updat var page = await _client.Pages.CreateAsync( PagesCreateParametersBuilder.Create( - new ParentPageInput {PageId = pageParentId} + new ParentPageInput { PageId = pageParentId } ).Build() ); var blocks = await _client.Blocks.AppendChildrenAsync( page.Id, - new BlocksAppendChildrenParameters {Children = new List {block}} + new BlocksAppendChildrenParameters { Children = new List { block } } ); var blockId = blocks.Results.First().Id; @@ -145,7 +145,7 @@ public async Task UpdateAsync_UpdatesGivenBlock(IBlock block, IUpdateBlock updat assert.Invoke(updatedBlock); // cleanup - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); } private static IEnumerable BlockData() @@ -161,9 +161,9 @@ private static IEnumerable BlockData() Url = "https://developers.notion.com/reference/rich-text", Caption = new List { - new RichTextTextInput {Text = new Text {Content = "Notion API"}}, - }, - }, + new RichTextTextInput { Text = new Text { Content = "Notion API" } } + } + } }, new BookmarkUpdateBlock { @@ -172,35 +172,35 @@ private static IEnumerable BlockData() Url = "https://github.com/notion-dotnet/notion-sdk-net", Caption = new List { - new RichTextTextInput {Text = new Text {Content = "Github"}}, - }, - }, + new RichTextTextInput { Text = new Text { Content = "Github" } } + } + } }, new Action(block => { var updatedBlock = (BookmarkBlock)block; Assert.Equal("https://github.com/notion-dotnet/notion-sdk-net", updatedBlock.Bookmark.Url); Assert.Equal("Github", updatedBlock.Bookmark.Caption.OfType().First().Text.Content); - }), + }) }, new object[] { - new EquationBlock {Equation = new EquationBlock.Info {Expression = "e=mc^3"}}, - new EquationUpdateBlock {Equation = new EquationUpdateBlock.Info {Expression = "e=mc^2"}}, + new EquationBlock { Equation = new EquationBlock.Info { Expression = "e=mc^3" } }, + new EquationUpdateBlock { Equation = new EquationUpdateBlock.Info { Expression = "e=mc^2" } }, new Action(block => { var updatedBlock = (EquationBlock)block; Assert.Equal("e=mc^2", updatedBlock.Equation.Expression); - }), + }) }, new object[] { - new DividerBlock {Divider = new DividerBlock.Data()}, new DividerUpdateBlock(), new Action( + new DividerBlock { Divider = new DividerBlock.Data() }, new DividerUpdateBlock(), new Action( block => { Assert.NotNull(block); Assert.IsType(block); - }), + }) }, new object[] { @@ -210,9 +210,9 @@ private static IEnumerable BlockData() { External = new ExternalFile.Info { - Url = "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3", - }, - }, + Url = "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3" + } + } }, new AudioUpdateBlock { @@ -220,9 +220,9 @@ private static IEnumerable BlockData() { External = new ExternalFileInput.Data { - Url = "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3", - }, - }, + Url = "https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3" + } + } }, new Action(block => { @@ -231,16 +231,16 @@ private static IEnumerable BlockData() block.Should().BeOfType().Subject .Audio.Should().BeOfType().Subject .External.Url.Should().Be("https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3"); - }), + }) }, new object[] { - new TableOfContentsBlock {TableOfContents = new TableOfContentsBlock.Data()}, + new TableOfContentsBlock { TableOfContents = new TableOfContentsBlock.Data() }, new TableOfContentsUpdateBlock(), new Action(block => { Assert.NotNull(block); Assert.IsType(block); - }), + }) }, new object[] { @@ -250,9 +250,9 @@ private static IEnumerable BlockData() { RichText = new List { - new RichTextTextInput {Text = new Text {Content = "Test"}}, - }, - }, + new RichTextTextInput { Text = new Text { Content = "Test" } } + } + } }, new CalloutUpdateBlock { @@ -260,9 +260,9 @@ private static IEnumerable BlockData() { RichText = new List { - new RichTextTextInput {Text = new Text {Content = "Test 2"}}, - }, - }, + new RichTextTextInput { Text = new Text { Content = "Test 2" } } + } + } }, new Action(block => { @@ -270,7 +270,7 @@ private static IEnumerable BlockData() var calloutBlock = Assert.IsType(block); Assert.Equal("Test 2", calloutBlock.Callout.RichText.OfType().First().Text.Content); - }), + }) }, new object[] { @@ -280,9 +280,9 @@ private static IEnumerable BlockData() { RichText = new List { - new RichTextTextInput {Text = new Text {Content = "Test"}}, - }, - }, + new RichTextTextInput { Text = new Text { Content = "Test" } } + } + } }, new QuoteUpdateBlock { @@ -290,9 +290,9 @@ private static IEnumerable BlockData() { RichText = new List { - new RichTextTextInput {Text = new Text {Content = "Test 2"}}, - }, - }, + new RichTextTextInput { Text = new Text { Content = "Test 2" } } + } + } }, new Action(block => { @@ -300,7 +300,7 @@ private static IEnumerable BlockData() var quoteBlock = Assert.IsType(block); Assert.Equal("Test 2", quoteBlock.Quote.RichText.OfType().First().Text.Content); - }), + }) }, new object[] { @@ -310,9 +310,9 @@ private static IEnumerable BlockData() { External = new ExternalFile.Info { - Url = "https://zephoria.com/wp-content/uploads/2014/08/online-community.jpg", - }, - }, + Url = "https://zephoria.com/wp-content/uploads/2014/08/online-community.jpg" + } + } }, new ImageUpdateBlock { @@ -321,9 +321,9 @@ private static IEnumerable BlockData() External = new ExternalFileInput.Data { Url - = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", - }, - }, + = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg" + } + } }, new Action(block => { @@ -333,7 +333,7 @@ private static IEnumerable BlockData() Assert.Equal("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", imageFile.External.Url); - }), + }) }, new object[] { @@ -341,15 +341,15 @@ private static IEnumerable BlockData() { Embed = new EmbedBlock.Info { - Url = "https://zephoria.com/wp-content/uploads/2014/08/online-community.jpg", - }, + Url = "https://zephoria.com/wp-content/uploads/2014/08/online-community.jpg" + } }, new EmbedUpdateBlock { Embed = new EmbedUpdateBlock.Info { - Url = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", - }, + Url = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg" + } }, new Action(block => { @@ -358,7 +358,7 @@ private static IEnumerable BlockData() Assert.Equal("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", embedBlock.Embed.Url); - }), + }) }, new object[] { @@ -368,7 +368,7 @@ private static IEnumerable BlockData() { RichText = new List { - new RichTextText {Text = new Text {Content = "Test Template"}}, + new RichTextText { Text = new Text { Content = "Test Template" } } }, Children = new List { @@ -377,11 +377,11 @@ private static IEnumerable BlockData() Embed = new EmbedBlock.Info { Url - = "https://zephoria.com/wp-content/uploads/2014/08/online-community.jpg", - }, - }, - }, - }, + = "https://zephoria.com/wp-content/uploads/2014/08/online-community.jpg" + } + } + } + } }, new TemplateUpdateBlock { @@ -389,9 +389,9 @@ private static IEnumerable BlockData() { RichText = new List { - new RichTextTextInput {Text = new Text {Content = "Test Template 2"}}, - }, - }, + new RichTextTextInput { Text = new Text { Content = "Test Template 2" } } + } + } }, new Action(block => { @@ -403,7 +403,7 @@ private static IEnumerable BlockData() Assert.Equal("Test Template 2", templateBlock.Template.RichText.OfType().First().Text.Content); - }), + }) }, new object[] { @@ -411,12 +411,13 @@ private static IEnumerable BlockData() { LinkToPage = new PageParent { - Type = ParentType.PageId, PageId = "533578e3edf14c0a91a9da6b09bac3ee", - }, + Type = ParentType.PageId, + PageId = "533578e3edf14c0a91a9da6b09bac3ee" + } }, new LinkToPageUpdateBlock { - LinkToPage = new ParentPageInput {PageId = "3c357473a28149a488c010d2b245a589"}, + LinkToPage = new ParentPageInput { PageId = "3c357473a28149a488c010d2b245a589" } }, new Action(block => { @@ -428,8 +429,8 @@ private static IEnumerable BlockData() // TODO: Currently the api doesn't allow to update the link_to_page block type // This will change to updated ID once api start to support Assert.Equal(Guid.Parse("533578e3edf14c0a91a9da6b09bac3ee"), Guid.Parse(pageParent.PageId)); - }), - }, + }) + } }; } } diff --git a/Test/Notion.IntegrationTests/IPageClientTests.cs b/Test/Notion.IntegrationTests/IPageClientTests.cs index 24f11940..3b861f8e 100644 --- a/Test/Notion.IntegrationTests/IPageClientTests.cs +++ b/Test/Notion.IntegrationTests/IPageClientTests.cs @@ -15,7 +15,7 @@ public class IPageClientTests public IPageClientTests() { - var options = new ClientOptions {AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN")}; + var options = new ClientOptions { AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN") }; _client = NotionClientFactory.Create(options); _databaseId = Environment.GetEnvironmentVariable("DATABASE_ID") ?? "f86f2262-0751-40f2-8f63-e3f7a3c39fcb"; @@ -25,14 +25,14 @@ public IPageClientTests() public async Task CreateAsync_CreatesANewPage() { var pagesCreateParameters = PagesCreateParametersBuilder - .Create(new DatabaseParentInput {DatabaseId = _databaseId}) + .Create(new DatabaseParentInput { DatabaseId = _databaseId }) .AddProperty("Name", new TitlePropertyValue { Title = new List { - new RichTextText {Text = new Text {Content = "Test Page Title"}}, - }, + new RichTextText { Text = new Text { Content = "Test Page Title" } } + } }) .Build(); @@ -48,28 +48,32 @@ public async Task CreateAsync_CreatesANewPage() var titleProperty = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItem( - new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = pageProperty.Id}); + new RetrievePropertyItemParameters + { + PageId = page.Id, + PropertyId = pageProperty.Id + }); titleProperty.Results.First().As().Title.PlainText.Should().Be("Test Page Title"); - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); } [Fact] public async Task Bug_unable_to_create_page_with_select_property() { var pagesCreateParameters = PagesCreateParametersBuilder - .Create(new DatabaseParentInput {DatabaseId = _databaseId}) + .Create(new DatabaseParentInput { DatabaseId = _databaseId }) .AddProperty("Name", new TitlePropertyValue { Title = new List { - new RichTextText {Text = new Text {Content = "Test Page Title"}}, - }, + new RichTextText { Text = new Text { Content = "Test Page Title" } } + } }) .AddProperty("TestSelect", - new SelectPropertyValue {Select = new SelectOption {Id = "dfbfbe65-6f67-4876-9f75-699124334d06"}}) + new SelectPropertyValue { Select = new SelectOption { Id = "dfbfbe65-6f67-4876-9f75-699124334d06" } }) .Build(); var page = await _client.Pages.CreateAsync(pagesCreateParameters); @@ -84,25 +88,29 @@ public async Task Bug_unable_to_create_page_with_select_property() var titleProperty = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItem( - new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = pageProperty.Id}); + new RetrievePropertyItemParameters + { + PageId = page.Id, + PropertyId = pageProperty.Id + }); titleProperty.Results.First().As().Title.PlainText.Should().Be("Test Page Title"); - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); } [Fact] public async Task Test_RetrievePagePropertyItemAsync() { var pagesCreateParameters = PagesCreateParametersBuilder - .Create(new DatabaseParentInput {DatabaseId = _databaseId}) + .Create(new DatabaseParentInput { DatabaseId = _databaseId }) .AddProperty("Name", new TitlePropertyValue { Title = new List { - new RichTextText {Text = new Text {Content = "Test Page Title"}}, - }, + new RichTextText { Text = new Text { Content = "Test Page Title" } } + } }) .Build(); @@ -110,7 +118,8 @@ public async Task Test_RetrievePagePropertyItemAsync() var property = await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters { - PageId = page.Id, PropertyId = "title", + PageId = page.Id, + PropertyId = "title" }); property.Should().NotBeNull(); @@ -129,7 +138,7 @@ public async Task Test_RetrievePagePropertyItemAsync() }); // cleanup - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); } [Fact] @@ -142,19 +151,19 @@ public async Task Test_UpdatePageProperty_with_date_as_null() updateDatabaseParameters.Properties = new Dictionary { - {"Name", new TitleUpdatePropertySchema {Title = new Dictionary()}}, - {"Test Date Property", new DateUpdatePropertySchema {Date = new Dictionary()}}, + { "Name", new TitleUpdatePropertySchema { Title = new Dictionary() } }, + { "Test Date Property", new DateUpdatePropertySchema { Date = new Dictionary() } } }; var pagesCreateParameters = PagesCreateParametersBuilder - .Create(new DatabaseParentInput {DatabaseId = _databaseId}) + .Create(new DatabaseParentInput { DatabaseId = _databaseId }) .AddProperty("Name", new TitlePropertyValue { Title = new List { - new RichTextText {Text = new Text {Content = "Test Page Title"}}, - }, + new RichTextText { Text = new Text { Content = "Test Page Title" } } + } }) .AddProperty(datePropertyName, new DatePropertyValue @@ -162,8 +171,8 @@ public async Task Test_UpdatePageProperty_with_date_as_null() Date = new Date { Start = Convert.ToDateTime("2020-12-08T12:00:00Z"), - End = Convert.ToDateTime("2025-12-08T12:00:00Z"), - }, + End = Convert.ToDateTime("2025-12-08T12:00:00Z") + } }) .Build(); @@ -173,21 +182,25 @@ public async Task Test_UpdatePageProperty_with_date_as_null() var setDate = (DatePropertyItem)await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters { - PageId = page.Id, PropertyId = page.Properties[datePropertyName].Id, + PageId = page.Id, + PropertyId = page.Properties[datePropertyName].Id }); setDate?.Date?.Start.Should().Be(Convert.ToDateTime("2020-12-08T12:00:00Z")); // verify IDictionary testProps = new Dictionary(); - testProps.Add(datePropertyName, new DatePropertyValue {Date = null}); - var updatedPage = await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Properties = testProps}); + testProps.Add(datePropertyName, new DatePropertyValue { Date = null }); + + var updatedPage = + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Properties = testProps }); var verifyDate = (DatePropertyItem)await _client.Pages.RetrievePagePropertyItem( new RetrievePropertyItemParameters { - PageId = page.Id, PropertyId = updatedPage.Properties[datePropertyName].Id, + PageId = page.Id, + PropertyId = updatedPage.Properties[datePropertyName].Id }); verifyDate?.Date.Should().BeNull(); @@ -201,14 +214,14 @@ public async Task Bug_Unable_To_Parse_NumberPropertyItem() { // Arrange var pagesCreateParameters = PagesCreateParametersBuilder - .Create(new DatabaseParentInput {DatabaseId = _databaseId}).AddProperty("Name", + .Create(new DatabaseParentInput { DatabaseId = _databaseId }).AddProperty("Name", new TitlePropertyValue { Title = new List { - new RichTextText {Text = new Text {Content = "Test Page Title"}}, - }, - }).AddProperty("Number", new NumberPropertyValue {Number = 200.00}).Build(); + new RichTextText { Text = new Text { Content = "Test Page Title" } } + } + }).AddProperty("Number", new NumberPropertyValue { Number = 200.00 }).Build(); // Act var page = await _client.Pages.CreateAsync(pagesCreateParameters); @@ -219,15 +232,23 @@ public async Task Bug_Unable_To_Parse_NumberPropertyItem() Assert.Equal(_databaseId, pageParent.DatabaseId); var titleProperty = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItem( - new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = page.Properties["Name"].Id}); + new RetrievePropertyItemParameters + { + PageId = page.Id, + PropertyId = page.Properties["Name"].Id + }); Assert.Equal("Test Page Title", titleProperty.Results.First().As().Title.PlainText); var numberProperty = (NumberPropertyItem)await _client.Pages.RetrievePagePropertyItem( - new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = page.Properties["Number"].Id}); + new RetrievePropertyItemParameters + { + PageId = page.Id, + PropertyId = page.Properties["Number"].Id + }); Assert.Equal(200.00, numberProperty.Number); - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters {Archived = true}); + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); } } diff --git a/Test/Notion.UnitTests/ApiTestBase.cs b/Test/Notion.UnitTests/ApiTestBase.cs index ceb415d2..6c0f3a97 100644 --- a/Test/Notion.UnitTests/ApiTestBase.cs +++ b/Test/Notion.UnitTests/ApiTestBase.cs @@ -14,7 +14,7 @@ public class ApiTestBase : IDisposable protected static readonly JsonSerializerSettings JsonSerializerSettings = new() { Formatting = Formatting.Indented, - ContractResolver = new DefaultContractResolver {NamingStrategy = new CamelCaseNamingStrategy()}, + ContractResolver = new DefaultContractResolver { NamingStrategy = new CamelCaseNamingStrategy() } }; protected readonly ClientOptions ClientOptions; @@ -23,7 +23,12 @@ public class ApiTestBase : IDisposable protected ApiTestBase() { Server = WireMockServer.Start(); - ClientOptions = new ClientOptions {BaseUrl = Server.Urls.First(), AuthToken = ""}; + + ClientOptions = new ClientOptions + { + BaseUrl = Server.Urls.First(), + AuthToken = "" + }; } public void Dispose() diff --git a/Test/Notion.UnitTests/BlocksClientTests.cs b/Test/Notion.UnitTests/BlocksClientTests.cs index 8a568a13..97e54404 100644 --- a/Test/Notion.UnitTests/BlocksClientTests.cs +++ b/Test/Notion.UnitTests/BlocksClientTests.cs @@ -67,9 +67,9 @@ public async Task AppendBlockChildren() { RichText = new List { - new RichTextText {Text = new Text {Content = "Lacinato kale"}}, - }, - }, + new RichTextText { Text = new Text { Content = "Lacinato kale" } } + } + } }, new ParagraphBlock { @@ -86,14 +86,14 @@ public async Task AppendBlockChildren() Link = new Link { Url - = "https://en.wikipedia.org/wiki/Lacinato_kale", - }, - }, - }, - }, - }, - }, - }, + = "https://en.wikipedia.org/wiki/Lacinato_kale" + } + } + } + } + } + } + } }; // Act @@ -170,10 +170,10 @@ public async Task UpdateAsync() { RichText = new List { - new RichTextTextInput {Text = new Text {Content = "Lacinato kale"}}, + new RichTextTextInput { Text = new Text { Content = "Lacinato kale" } } }, - IsChecked = true, - }, + IsChecked = true + } }; var block = await _client.UpdateAsync(blockId, updateBlock); diff --git a/Test/Notion.UnitTests/DatabasesClientTests.cs b/Test/Notion.UnitTests/DatabasesClientTests.cs index e78d0e68..d29677ea 100644 --- a/Test/Notion.UnitTests/DatabasesClientTests.cs +++ b/Test/Notion.UnitTests/DatabasesClientTests.cs @@ -47,10 +47,17 @@ public async Task QueryAsync() new NumberFilter( "Cost of next trip", greaterThanOrEqualTo: 2 - ), - }, + ) + } }, - Sorts = new List {new() {Property = "Last ordered", Direction = Direction.Ascending}}, + Sorts = new List + { + new() + { + Property = "Last ordered", + Direction = Direction.Ascending + } + } }; var pagesPaginatedList = await _client.QueryAsync(databaseId, databasesQueryParams); @@ -142,9 +149,9 @@ public async Task DatabasePropertyObjectContainRelationProperty() DualProperty = new DualPropertyRelation.Data { SyncedPropertyName = "Related to sample table (Property)", - SyncedPropertyId = "VQ}{", - }, - }, + SyncedPropertyId = "VQ}{" + } + } }); } @@ -185,17 +192,24 @@ public async Task CreateDatabaseAsync() var createDatabaseParameters = new DatabasesCreateParameters(); - createDatabaseParameters.Parent = new ParentPageInput {PageId = pageId}; + createDatabaseParameters.Parent = new ParentPageInput { PageId = pageId }; createDatabaseParameters.Title = new List { - new RichTextTextInput {Text = new Text {Content = "Grocery List", Link = null}}, + new RichTextTextInput + { + Text = new Text + { + Content = "Grocery List", + Link = null + } + } }; createDatabaseParameters.Properties = new Dictionary { - {"Name", new TitlePropertySchema {Title = new Dictionary()}}, - {"Price", new NumberPropertySchema {Number = new Number {Format = "dollar"}}}, + { "Name", new TitlePropertySchema { Title = new Dictionary() } }, + { "Price", new NumberPropertySchema { Number = new Number { Format = "dollar" } } }, { "Food group", new SelectPropertySchema @@ -204,14 +218,26 @@ public async Task CreateDatabaseAsync() { Options = new List { - new() {Color = Color.Green, Name = "🥦Vegetable"}, - new() {Color = Color.Red, Name = "🍎Fruit"}, - new() {Color = Color.Yellow, Name = "💪Protein"}, - }, - }, + new() + { + Color = Color.Green, + Name = "🥦Vegetable" + }, + new() + { + Color = Color.Red, + Name = "🍎Fruit" + }, + new() + { + Color = Color.Yellow, + Name = "💪Protein" + } + } + } } }, - {"Last ordered", new DatePropertySchema {Date = new Dictionary()}}, + { "Last ordered", new DatePropertySchema { Date = new Dictionary() } } }; var database = await _client.CreateAsync(createDatabaseParameters); @@ -262,13 +288,20 @@ public async Task UpdateDatabaseAsync() updateDatabaseParameters.Title = new List { - new RichTextTextInput {Text = new Text {Content = "Grocery List New", Link = null}}, + new RichTextTextInput + { + Text = new Text + { + Content = "Grocery List New", + Link = null + } + } }; updateDatabaseParameters.Properties = new Dictionary { - {"Name", new TitleUpdatePropertySchema {Title = new Dictionary()}}, - {"Price", new NumberUpdatePropertySchema {Number = new Number {Format = "yen"}}}, + { "Name", new TitleUpdatePropertySchema { Title = new Dictionary() } }, + { "Price", new NumberUpdatePropertySchema { Number = new Number { Format = "yen" } } }, { "Food group", new SelectUpdatePropertySchema @@ -277,14 +310,26 @@ public async Task UpdateDatabaseAsync() { Options = new List { - new() {Color = Color.Green, Name = "🥦Vegetables"}, - new() {Color = Color.Red, Name = "🍎Fruit"}, - new() {Color = Color.Yellow, Name = "💪Protein"}, - }, - }, + new() + { + Color = Color.Green, + Name = "🥦Vegetables" + }, + new() + { + Color = Color.Red, + Name = "🍎Fruit" + }, + new() + { + Color = Color.Yellow, + Name = "💪Protein" + } + } + } } }, - {"Last ordered", new DateUpdatePropertySchema {Date = new Dictionary()}}, + { "Last ordered", new DateUpdatePropertySchema { Date = new Dictionary() } } }; var database = await _client.UpdateAsync(databaseId, updateDatabaseParameters); @@ -348,11 +393,18 @@ var jsonData var createDatabaseParameters = new DatabasesCreateParameters(); - createDatabaseParameters.Parent = new ParentPageInput {PageId = pageId}; + createDatabaseParameters.Parent = new ParentPageInput { PageId = pageId }; createDatabaseParameters.Title = new List { - new RichTextTextInput {Text = new Text {Content = "Grocery List", Link = null}}, + new RichTextTextInput + { + Text = new Text + { + Content = "Grocery List", + Link = null + } + } }; createDatabaseParameters.Properties = new Dictionary @@ -361,10 +413,10 @@ var jsonData "Cost of next trip", new FormulaPropertySchema { - Formula = new Formula {Expression = "if(prop(\"In stock\"), 0, prop(\"Price\"))"}, + Formula = new Formula { Expression = "if(prop(\"In stock\"), 0, prop(\"Price\"))" } } }, - {"Price", new NumberPropertySchema {Number = new Number {Format = "dollar"}}}, + { "Price", new NumberPropertySchema { Number = new Number { Format = "dollar" } } } }; var database = await _client.CreateAsync(createDatabaseParameters); @@ -408,10 +460,17 @@ var jsonData new NumberFilter( "Cost of next trip", greaterThanOrEqualTo: 2 - ), - }, + ) + } }, - Sorts = new List {new() {Property = "Last ordered", Direction = Direction.Ascending}}, + Sorts = new List + { + new() + { + Property = "Last ordered", + Direction = Direction.Ascending + } + } }; var pagesPaginatedList = await _client.QueryAsync(databaseId, databasesQueryParams); @@ -433,7 +492,11 @@ var jsonData ); var formulaPropertyValue = (FormulaPropertyItem)await _pagesClient.RetrievePagePropertyItem( - new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = page.Properties["FormulaProp"].Id}); + new RetrievePropertyItemParameters + { + PageId = page.Id, + PropertyId = page.Properties["FormulaProp"].Id + }); //var formulaPropertyValue = (FormulaPropertyValue)page.Properties["FormulaProp"]; formulaPropertyValue.Formula.Date.Start.Should().Be(DateTime.Parse("2021-06-28")); diff --git a/Test/Notion.UnitTests/FilterTests.cs b/Test/Notion.UnitTests/FilterTests.cs index b31a6530..6fab8aaa 100644 --- a/Test/Notion.UnitTests/FilterTests.cs +++ b/Test/Notion.UnitTests/FilterTests.cs @@ -34,10 +34,18 @@ public void CompoundFilterTest() var relationFilter = new RelationFilter("Link", "subtask#1"); var dateFilter = new DateFilter("Due", pastMonth: new Dictionary()); - var filterGroup = new List {relationFilter, selectFilter}; + var filterGroup = new List + { + relationFilter, + selectFilter + }; var complexFiler = new CompoundFilter( - and: new List {dateFilter, new CompoundFilter(filterGroup)} + and: new List + { + dateFilter, + new CompoundFilter(filterGroup) + } ); Assert.Equal( diff --git a/Test/Notion.UnitTests/PagesClientTests.cs b/Test/Notion.UnitTests/PagesClientTests.cs index 3f6710a5..87c32dae 100644 --- a/Test/Notion.UnitTests/PagesClientTests.cs +++ b/Test/Notion.UnitTests/PagesClientTests.cs @@ -57,11 +57,14 @@ public async Task CreateAsync() ); var pagesCreateParameters = PagesCreateParametersBuilder - .Create(new DatabaseParentInput {DatabaseId = "3c357473-a281-49a4-88c0-10d2b245a589"}).AddProperty("Name", + .Create(new DatabaseParentInput { DatabaseId = "3c357473-a281-49a4-88c0-10d2b245a589" }) + .AddProperty( + "Name", new TitlePropertyValue { - Title = new List {new RichTextText {Text = new Text {Content = "Test"}}}, - }).Build(); + Title = new List { new RichTextText { Text = new Text { Content = "Test" } } } + } + ).Build(); var page = await _client.CreateAsync(pagesCreateParameters); @@ -98,7 +101,7 @@ public async Task UpdatePropertiesAsync() var updatedProperties = new Dictionary { - {"In stock", new CheckboxPropertyValue {Checkbox = true}}, + { "In stock", new CheckboxPropertyValue { Checkbox = true } } }; var page = await _client.UpdatePropertiesAsync(pageId, updatedProperties); @@ -108,7 +111,11 @@ public async Task UpdatePropertiesAsync() var updatedProperty = page.Properties.First(x => x.Key == "In stock"); var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItem( - new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = updatedProperty.Value.Id}); + new RetrievePropertyItemParameters + { + PageId = page.Id, + PropertyId = updatedProperty.Value.Id + }); checkboxPropertyValue.Checkbox.Should().BeTrue(); } @@ -158,8 +165,8 @@ public async Task UpdatePageAsync() { Properties = new Dictionary { - {"In stock", new CheckboxPropertyValue {Checkbox = true}}, - }, + { "In stock", new CheckboxPropertyValue { Checkbox = true } } + } }; var page = await _client.UpdateAsync(pageId, pagesUpdateParameters); @@ -170,7 +177,11 @@ public async Task UpdatePageAsync() var updatedProperty = page.Properties.First(x => x.Key == "In stock"); var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItem( - new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = updatedProperty.Value.Id}); + new RetrievePropertyItemParameters + { + PageId = page.Id, + PropertyId = updatedProperty.Value.Id + }); checkboxPropertyValue.Checkbox.Should().BeTrue(); } @@ -203,8 +214,8 @@ public async Task ArchivePageAsync() Archived = true, Properties = new Dictionary { - {"In stock", new CheckboxPropertyValue {Checkbox = true}}, - }, + { "In stock", new CheckboxPropertyValue { Checkbox = true } } + } }; var page = await _client.UpdateAsync(pageId, pagesUpdateParameters); @@ -215,7 +226,11 @@ public async Task ArchivePageAsync() var updatedProperty = page.Properties.First(x => x.Key == "In stock"); var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItem( - new RetrievePropertyItemParameters {PageId = page.Id, PropertyId = updatedProperty.Value.Id}); + new RetrievePropertyItemParameters + { + PageId = page.Id, + PropertyId = updatedProperty.Value.Id + }); checkboxPropertyValue.Checkbox.Should().BeTrue(); } @@ -243,7 +258,8 @@ public async Task CreateAsync_Throws_ArgumentNullException_When_Properties_Is_Mi { var pagesCreateParameters = new PagesCreateParameters { - Parent = new ParentPageInput {PageId = "3c357473-a281-49a4-88c0-10d2b245a589"}, Properties = null, + Parent = new ParentPageInput { PageId = "3c357473-a281-49a4-88c0-10d2b245a589" }, + Properties = null }; Func act = async () => await _client.CreateAsync(pagesCreateParameters); diff --git a/Test/Notion.UnitTests/SearchClientTest.cs b/Test/Notion.UnitTests/SearchClientTest.cs index 3ca7dd27..63fb4a94 100644 --- a/Test/Notion.UnitTests/SearchClientTest.cs +++ b/Test/Notion.UnitTests/SearchClientTest.cs @@ -33,7 +33,11 @@ public async Task Search() var searchParameters = new SearchParameters { Query = "External tasks", - Sort = new SearchSort {Direction = SearchDirection.Ascending, Timestamp = "last_edited_time"}, + Sort = new SearchSort + { + Direction = SearchDirection.Ascending, + Timestamp = "last_edited_time" + } }; // Act From ff578256b9847467b7f6339f6e5984517a0d610f Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 8 Oct 2022 13:29:14 +0530 Subject: [PATCH 111/216] Add helper script to run linter fixer --- package.json | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 package.json diff --git a/package.json b/package.json new file mode 100644 index 00000000..a32bb1db --- /dev/null +++ b/package.json @@ -0,0 +1,11 @@ +{ + "name": "notion-sdk-net", + "version": "1.0.0", + "main": "index.js", + "repository": "git@github.com:notion-dotnet/notion-sdk-net.git", + "author": "Vedant Koditkar", + "license": "MIT", + "scripts": { + "lint": "dotnet jb cleanupcode --include=\"**/**.cs\" .\\Notion.sln" + } +} From 95a3c7d6ac5528fb8ce14e04b839fc9f74dab4fa Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 8 Oct 2022 13:29:41 +0530 Subject: [PATCH 112/216] Update .gitignore --- .gitignore | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.gitignore b/.gitignore index dfcfd56f..c6d337c2 100644 --- a/.gitignore +++ b/.gitignore @@ -348,3 +348,9 @@ MigrationBackup/ # Ionide (cross platform F# VS Code tools) working folder .ionide/ + +# Resharper linter +.lint/ + +# Rider +.idea/ From 680aa99a94cf45c9b46edffea13d23ca0ae52fe6 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 8 Oct 2022 13:29:57 +0530 Subject: [PATCH 113/216] Add linter step in CI build workflow --- .github/workflows/ci-build.yml | 13 +++++-------- check.sh | 11 +++++++++++ 2 files changed, 16 insertions(+), 8 deletions(-) create mode 100644 check.sh diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index c69148e8..378d6a85 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -21,15 +21,12 @@ jobs: - name: Restore dependencies run: dotnet restore - # Format the output of dotnet format - - name: Add dotnet-format problem matcher - uses: xt0rted/dotnet-format-problem-matcher@v1 - # Install dotnet format as a global tool - - name: Install dotnet format - run: | - dotnet tool install --global dotnet-format - dotnet format --verify-no-changes --verbosity diagnostic + - name: Install dotnet tools + run: dotnet tool restore + + - name: Run Linter + run: check.sh - name: Build run: dotnet build --no-restore diff --git a/check.sh b/check.sh new file mode 100644 index 00000000..d6132c92 --- /dev/null +++ b/check.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +dotnet jb inspectcode Notion.sln -f="Text" --no-build --include="**.cs" -o=".lint/CodeWarningResults.txt" + +totalLines=`cat .lint/CodeWarningResults.txt | grep "^.*$" -c` + +if [[ "$totalLines" -gt 1 ]]; then + echo "There are few linter warnings - please fix them before running the pipeline" + cat .lint/CodeWarningResults.txt + exit 1 +fi From 5387196f94728152f9dfa1d0a228f46c2d0140dd Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 8 Oct 2022 13:41:21 +0530 Subject: [PATCH 114/216] Try fixing bash script execution --- .github/workflows/ci-build.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index 378d6a85..6881c42a 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -26,7 +26,8 @@ jobs: run: dotnet tool restore - name: Run Linter - run: check.sh + run: ./check.sh + shell: bash - name: Build run: dotnet build --no-restore From 5eccdaff54eba8bd3ff2fd8b36d956581f487f8a Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 8 Oct 2022 13:46:17 +0530 Subject: [PATCH 115/216] Fix .sh file execution permission --- .github/workflows/ci-build.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index 6881c42a..84faaff0 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -26,7 +26,9 @@ jobs: run: dotnet tool restore - name: Run Linter - run: ./check.sh + run: | + sudo chmod 600 ./check.sh + ./check.sh shell: bash - name: Build From 77fad8f58577dc67970844adc710dc1a7f7ae40a Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 8 Oct 2022 13:48:19 +0530 Subject: [PATCH 116/216] make .sh file executable --- .github/workflows/ci-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index 84faaff0..5a50f35b 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -27,7 +27,7 @@ jobs: - name: Run Linter run: | - sudo chmod 600 ./check.sh + sudo chmod +x ./check.sh ./check.sh shell: bash From 451821f4c062cac99808b20fc1efbc1212d57a76 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 8 Oct 2022 13:53:08 +0530 Subject: [PATCH 117/216] =?UTF-8?q?Move=20CI=20scripts=20under=20.github/?= =?UTF-8?q?=20folder=20=F0=9F=9A=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- check.sh => .github/scripts/check.sh | 0 .github/workflows/ci-build.yml | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) rename check.sh => .github/scripts/check.sh (100%) diff --git a/check.sh b/.github/scripts/check.sh similarity index 100% rename from check.sh rename to .github/scripts/check.sh diff --git a/.github/workflows/ci-build.yml b/.github/workflows/ci-build.yml index 5a50f35b..35959b57 100644 --- a/.github/workflows/ci-build.yml +++ b/.github/workflows/ci-build.yml @@ -27,8 +27,8 @@ jobs: - name: Run Linter run: | - sudo chmod +x ./check.sh - ./check.sh + sudo chmod +x ./.github/scripts/check.sh + ./.github/scripts/check.sh shell: bash - name: Build From e7cafc9ee6fe607ce1226f37f4c77a651e214d0f Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 8 Oct 2022 18:21:38 +0530 Subject: [PATCH 118/216] =?UTF-8?q?Fix=20linter=20warnings=20=F0=9F=9A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .editorconfig | 184 +----------------- Notion.sln.DotSettings | 5 + Src/Notion.Client/Api/ApiEndpoints.cs | 17 +- .../UpdateBlocks/AudioUpdateBlock.cs | 2 +- .../BulletedListItemUpdateBlock.cs | 2 +- .../UpdateBlocks/CalloutUpdateBlock.cs | 2 +- .../UpdateBlocks/CodeUpdateBlock.cs | 2 +- .../UpdateBlocks/EmbedUpdateBlock.cs | 2 +- .../UpdateBlocks/EquationUpdateBlock.cs | 2 +- .../UpdateBlocks/FileUpdateBlock.cs | 2 +- .../UpdateBlocks/HeadingOneUpdateBlock.cs | 4 +- .../UpdateBlocks/HeadingThreeeUpdateBlock.cs | 4 +- .../UpdateBlocks/HeadingTwoUpdateBlock.cs | 4 +- .../UpdateBlocks/ImageUpdateBlock.cs | 2 +- .../UpdateBlocks/LinkToPageUpdateBlock.cs | 2 +- .../NumberedListItemUpdateBlock.cs | 2 +- .../UpdateBlocks/PDFUpdateBlock.cs | 6 +- .../UpdateBlocks/ParagraphUpdateBlock.cs | 2 +- .../UpdateBlocks/QuoteUpdateBlock.cs | 2 +- .../UpdateBlocks/SyncedBlockUpdateBlock.cs | 2 +- .../UpdateBlocks/TableRowUpdateBlock.cs | 2 +- .../UpdateBlocks/TableUpdateBlock.cs | 2 +- .../UpdateBlocks/TemplateUpdateBlock.cs | 2 +- .../UpdateBlocks/ToDoUpdateBlock.cs | 2 +- .../UpdateBlocks/ToggleUpdateBlock.cs | 2 +- .../UpdateBlocks/VideoUpdateBlock.cs | 2 +- .../Create/Response/CreateCommentResponse.cs | 5 +- .../Api/Comments/ICommentsClient.cs | 9 - .../Api/Comments/Retrieve/CommentsClient.cs | 2 + .../Request/RetrieveCommentsParameters.cs | 5 +- .../PropertySchema/MultiSelectOptionSchema.cs | 5 +- .../RequestParams/DatabasesListParameters.cs | 9 - .../CheckboxUpdatePropertySchema.cs | 2 +- .../CreatedByUpdatePropertySchema.cs | 2 +- .../CreatedTimeUpdatePropertySchema.cs | 2 +- .../DateUpdatePropertySchema.cs | 2 +- .../EmailUpdatePropertySchema.cs | 2 +- .../FilesUpdatePropertySchema.cs | 2 +- .../FormulaUpdatePropertySchema.cs | 2 +- .../LastEditedByUpdatePropertySchema.cs | 2 +- .../LastEditedTimeUpdatePropertySchema.cs | 2 +- .../MultiSelectUpdatePropertySchema.cs | 2 +- .../NumberUpdatePropertySchema.cs | 2 +- .../PeopleUpdatePropertySchema.cs | 2 +- .../PhoneNumberUpdatePropertySchema.cs | 2 +- .../RelationUpdatePropertySchema.cs | 2 +- .../RichTextUpdatePropertySchema.cs | 2 +- .../RollupConfigUpdatePropertySchema.cs | 2 +- .../SelectUpdatePropertySchema.cs | 2 +- .../TitleUpdatePropertySchema.cs | 2 +- .../PropertySchema/URLUpdatePropertySchema.cs | 2 +- .../Api/Databases/RequestParams/Direction.cs | 4 +- .../IDatabasesListQueryParmaters.cs | 6 - .../Api/Databases/RequestParams/Timestamp.cs | 4 +- Src/Notion.Client/Api/Pages/PagesClient.cs | 4 +- .../PagesCreateParametersBuilder.cs | 32 +-- Src/Notion.Client/Api/Search/ISearchClient.cs | 4 +- .../Api/Search/Parameters/SearchDirection.cs | 4 +- .../Api/Search/Parameters/SearchFilter.cs | 5 +- .../Api/Search/Parameters/SearchObjectType.cs | 4 +- Src/Notion.Client/Api/Search/SearchClient.cs | 6 +- Src/Notion.Client/Constants.cs | 6 +- .../DI/ServiceCollectionExtensions.cs | 5 +- .../HttpResponseMessageExtensions.cs | 26 +-- Src/Notion.Client/Logging/Log.cs | 10 +- .../Logging/NotionClientLogging.cs | 11 +- Src/Notion.Client/Models/Blocks/BlockType.cs | 6 +- Src/Notion.Client/Models/Blocks/Color.cs | 4 +- .../Models/Blocks/HeadingOneBlock.cs | 2 + .../Models/Blocks/HeadingThreeeBlock.cs | 2 + .../Models/Blocks/HeadingTwoBlock.cs | 2 + .../Models/Blocks/IColumnChildrenBlock.cs | 2 +- Src/Notion.Client/Models/Blocks/PDFBlock.cs | 4 +- .../Database/Properties/PropertyType.cs | 4 +- .../Database/Properties/SelectProperty.cs | 2 + .../Models/Database/RichText/RichTextType.cs | 4 +- .../Filters/TimestampCreatedTimeFilter.cs | 6 +- .../Filters/TimestampLastEditedTimeFilter.cs | 6 +- Src/Notion.Client/Models/Filters/URLFilter.cs | 4 +- Src/Notion.Client/Models/Parents/IParent.cs | 4 +- .../Models/Parents/ParentType.cs | 4 +- .../Models/PropertyItems/ListPropertyItem.cs | 3 + .../PropertyItems/SimplePropertyItem.cs | 4 +- .../Models/PropertyValue/PropertyValue.cs | 5 +- .../Models/PropertyValue/PropertyValueType.cs | 4 +- .../PropertyValue/StatusPropertyValue.cs | 9 +- Src/Notion.Client/Models/User/PartialUser.cs | 5 +- Src/Notion.Client/NotionAPIErrorCode.cs | 4 +- Src/Notion.Client/NotionApiException.cs | 13 +- Src/Notion.Client/NotionClient.cs | 19 +- Src/Notion.Client/RestClient/IRestClient.cs | 1 - Src/Notion.Client/RestClient/RestClient.cs | 27 ++- Src/Notion.Client/http/QueryHelpers.cs | 2 + .../CommentsClientTests.cs | 7 +- .../IBlocksClientTests.cs | 4 +- .../IPageClientTests.cs | 25 ++- Test/Notion.UnitTests/ApiTestBase.cs | 14 +- Test/Notion.UnitTests/BlocksClientTests.cs | 4 +- Test/Notion.UnitTests/DatabasesClientTests.cs | 183 +++++++++-------- Test/Notion.UnitTests/FilterTests.cs | 24 +-- Test/Notion.UnitTests/PropertyTests.cs | 4 +- 101 files changed, 383 insertions(+), 500 deletions(-) create mode 100644 Notion.sln.DotSettings delete mode 100644 Src/Notion.Client/Api/Databases/RequestParams/DatabasesListParameters.cs delete mode 100644 Src/Notion.Client/Api/Databases/RequestParams/IDatabasesListQueryParmaters.cs diff --git a/.editorconfig b/.editorconfig index 76a523b0..1745f593 100644 --- a/.editorconfig +++ b/.editorconfig @@ -45,179 +45,6 @@ resharper_csharp_use_heuristics_for_body_style=true resharper_csharp_max_initializer_elements_on_line=0 -# Microsoft .NET properties -csharp_preferred_modifier_order = public, private, protected, internal, new, static, abstract, virtual, sealed, readonly, override, extern, unsafe, volatile, async:suggestion -csharp_style_var_elsewhere = true:suggestion -csharp_style_var_for_built_in_types = true:suggestion -csharp_style_var_when_type_is_apparent = true:suggestion -dotnet_naming_rule.constants_rule.import_to_resharper = as_predefined -dotnet_naming_rule.constants_rule.resharper_style = AaBb, _ + aaBb -dotnet_naming_rule.constants_rule.severity = suggestion -dotnet_naming_rule.constants_rule.style = upper_camel_case_style -dotnet_naming_rule.constants_rule.symbols = constants_symbols -dotnet_naming_rule.constants_should_be_pascal_case_rule.import_to_resharper = True -dotnet_naming_rule.constants_should_be_pascal_case_rule.resharper_description = constants_should_be_pascal_case -dotnet_naming_rule.constants_should_be_pascal_case_rule.resharper_guid = a0135172-b297-46cb-bb0f-b1f267109d7b -dotnet_naming_rule.constants_should_be_pascal_case_rule.severity = suggestion -dotnet_naming_rule.constants_should_be_pascal_case_rule.style = upper_camel_case_style -dotnet_naming_rule.constants_should_be_pascal_case_rule.symbols = constants_should_be_pascal_case_symbols -dotnet_naming_rule.constants_should_be_pascal_case_rule_1.import_to_resharper = False -dotnet_naming_rule.constants_should_be_pascal_case_rule_1.severity = suggestion -dotnet_naming_rule.constants_should_be_pascal_case_rule_1.style = upper_camel_case_style -dotnet_naming_rule.constants_should_be_pascal_case_rule_1.symbols = constants_should_be_pascal_case_symbols_1 -dotnet_naming_rule.instance_fields_should_be_camel_case_rule.import_to_resharper = True -dotnet_naming_rule.instance_fields_should_be_camel_case_rule.resharper_description = instance_fields_should_be_camel_case -dotnet_naming_rule.instance_fields_should_be_camel_case_rule.resharper_guid = ed8be1d2-8aa4-45a9-a0fe-964e144ccec7 -dotnet_naming_rule.instance_fields_should_be_camel_case_rule.severity = suggestion -dotnet_naming_rule.instance_fields_should_be_camel_case_rule.style = lower_camel_case_style -dotnet_naming_rule.instance_fields_should_be_camel_case_rule.symbols = instance_fields_should_be_camel_case_symbols -dotnet_naming_rule.interfaces_rule.import_to_resharper = as_predefined -dotnet_naming_rule.interfaces_rule.severity = suggestion -dotnet_naming_rule.interfaces_rule.style = upper_camel_case_style -dotnet_naming_rule.interfaces_rule.symbols = interfaces_symbols -dotnet_naming_rule.locals_should_be_camel_case_rule.import_to_resharper = True -dotnet_naming_rule.locals_should_be_camel_case_rule.resharper_description = locals_should_be_camel_case -dotnet_naming_rule.locals_should_be_camel_case_rule.resharper_guid = dd900f14-6d42-4a58-8277-056e5dab89e7 -dotnet_naming_rule.locals_should_be_camel_case_rule.severity = suggestion -dotnet_naming_rule.locals_should_be_camel_case_rule.style = lower_camel_case_style_1 -dotnet_naming_rule.locals_should_be_camel_case_rule.symbols = locals_should_be_camel_case_symbols -dotnet_naming_rule.local_constants_rule.import_to_resharper = as_predefined -dotnet_naming_rule.local_constants_rule.resharper_style = AaBb, aaBb -dotnet_naming_rule.local_constants_rule.severity = suggestion -dotnet_naming_rule.local_constants_rule.style = upper_camel_case_style -dotnet_naming_rule.local_constants_rule.symbols = local_constants_symbols -dotnet_naming_rule.local_functions_should_be_pascal_case_rule.import_to_resharper = True -dotnet_naming_rule.local_functions_should_be_pascal_case_rule.resharper_description = local_functions_should_be_pascal_case -dotnet_naming_rule.local_functions_should_be_pascal_case_rule.resharper_guid = 67e7ac04-3277-4549-b0bb-98cbfad21765 -dotnet_naming_rule.local_functions_should_be_pascal_case_rule.severity = suggestion -dotnet_naming_rule.local_functions_should_be_pascal_case_rule.style = upper_camel_case_style -dotnet_naming_rule.local_functions_should_be_pascal_case_rule.symbols = local_functions_should_be_pascal_case_symbols -dotnet_naming_rule.members_should_be_pascal_case_rule.import_to_resharper = True -dotnet_naming_rule.members_should_be_pascal_case_rule.resharper_description = members_should_be_pascal_case -dotnet_naming_rule.members_should_be_pascal_case_rule.resharper_guid = 605fba47-8912-494e-9e4c-98aeb57fd884 -dotnet_naming_rule.members_should_be_pascal_case_rule.severity = suggestion -dotnet_naming_rule.members_should_be_pascal_case_rule.style = upper_camel_case_style -dotnet_naming_rule.members_should_be_pascal_case_rule.symbols = members_should_be_pascal_case_symbols -dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case_rule.import_to_resharper = True -dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case_rule.resharper_description = non_private_readonly_fields_should_be_pascal_case -dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case_rule.resharper_guid = e8e1b724-94dd-4cbe-9385-85343fea2b41 -dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case_rule.severity = suggestion -dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case_rule.style = upper_camel_case_style -dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case_rule.symbols = non_private_readonly_fields_should_be_pascal_case_symbols -dotnet_naming_rule.non_private_static_fields_should_be_pascal_case_rule.import_to_resharper = True -dotnet_naming_rule.non_private_static_fields_should_be_pascal_case_rule.resharper_description = non_private_static_fields_should_be_pascal_case -dotnet_naming_rule.non_private_static_fields_should_be_pascal_case_rule.resharper_guid = 51051115-1f5e-4eea-aa9d-2eac02e9b082 -dotnet_naming_rule.non_private_static_fields_should_be_pascal_case_rule.severity = suggestion -dotnet_naming_rule.non_private_static_fields_should_be_pascal_case_rule.style = upper_camel_case_style -dotnet_naming_rule.non_private_static_fields_should_be_pascal_case_rule.symbols = non_private_static_fields_should_be_pascal_case_symbols -dotnet_naming_rule.private_constants_rule.import_to_resharper = as_predefined -dotnet_naming_rule.private_constants_rule.resharper_style = AaBb, _ + aaBb -dotnet_naming_rule.private_constants_rule.severity = suggestion -dotnet_naming_rule.private_constants_rule.style = upper_camel_case_style -dotnet_naming_rule.private_constants_rule.symbols = private_constants_symbols -dotnet_naming_rule.private_static_fields_rule.import_to_resharper = as_predefined -dotnet_naming_rule.private_static_fields_rule.severity = suggestion -dotnet_naming_rule.private_static_fields_rule.style = s_lower_camel_case_style -dotnet_naming_rule.private_static_fields_rule.symbols = private_static_fields_symbols -dotnet_naming_rule.private_static_readonly_rule.import_to_resharper = as_predefined -dotnet_naming_rule.private_static_readonly_rule.severity = suggestion -dotnet_naming_rule.private_static_readonly_rule.style = s_lower_camel_case_style -dotnet_naming_rule.private_static_readonly_rule.symbols = private_static_readonly_symbols -dotnet_naming_rule.public_fields_rule.import_to_resharper = as_predefined -dotnet_naming_rule.public_fields_rule.severity = suggestion -dotnet_naming_rule.public_fields_rule.style = lower_camel_case_style -dotnet_naming_rule.public_fields_rule.symbols = public_fields_symbols -dotnet_naming_rule.static_fields_should_be_camel_case_rule.import_to_resharper = True -dotnet_naming_rule.static_fields_should_be_camel_case_rule.resharper_description = static_fields_should_be_camel_case -dotnet_naming_rule.static_fields_should_be_camel_case_rule.resharper_guid = f286ec29-34ab-4806-9c8a-586f11eedd52 -dotnet_naming_rule.static_fields_should_be_camel_case_rule.severity = suggestion -dotnet_naming_rule.static_fields_should_be_camel_case_rule.style = s_lower_camel_case_style -dotnet_naming_rule.static_fields_should_be_camel_case_rule.symbols = static_fields_should_be_camel_case_symbols -dotnet_naming_rule.static_readonly_rule.import_to_resharper = as_predefined -dotnet_naming_rule.static_readonly_rule.resharper_style = AaBb, s_ + aaBb -dotnet_naming_rule.static_readonly_rule.severity = suggestion -dotnet_naming_rule.static_readonly_rule.style = upper_camel_case_style -dotnet_naming_rule.static_readonly_rule.symbols = static_readonly_symbols -dotnet_naming_rule.type_parameters_rule.import_to_resharper = as_predefined -dotnet_naming_rule.type_parameters_rule.severity = suggestion -dotnet_naming_rule.type_parameters_rule.style = upper_camel_case_style -dotnet_naming_rule.type_parameters_rule.symbols = type_parameters_symbols -dotnet_naming_style.lower_camel_case_style.capitalization = camel_case -dotnet_naming_style.lower_camel_case_style.required_prefix = _ -dotnet_naming_style.lower_camel_case_style_1.capitalization = camel_case -dotnet_naming_style.s_lower_camel_case_style.capitalization = camel_case -dotnet_naming_style.s_lower_camel_case_style.required_prefix = s_ -dotnet_naming_style.upper_camel_case_style.capitalization = pascal_case -dotnet_naming_symbols.constants_should_be_pascal_case_symbols.applicable_accessibilities = local,public,internal,private,protected,protected_internal,private_protected -dotnet_naming_symbols.constants_should_be_pascal_case_symbols.applicable_kinds = local -dotnet_naming_symbols.constants_should_be_pascal_case_symbols.required_modifiers = const -dotnet_naming_symbols.constants_should_be_pascal_case_symbols.resharper_applicable_kinds = constant_field,local_constant -dotnet_naming_symbols.constants_should_be_pascal_case_symbols.resharper_required_modifiers = any -dotnet_naming_symbols.constants_should_be_pascal_case_symbols_1.applicable_accessibilities = local,public,internal,private,protected,protected_internal,private_protected -dotnet_naming_symbols.constants_should_be_pascal_case_symbols_1.applicable_kinds = field -dotnet_naming_symbols.constants_should_be_pascal_case_symbols_1.required_modifiers = const -dotnet_naming_symbols.constants_symbols.applicable_accessibilities = public,internal,protected,protected_internal,private_protected -dotnet_naming_symbols.constants_symbols.applicable_kinds = field -dotnet_naming_symbols.constants_symbols.required_modifiers = const -dotnet_naming_symbols.instance_fields_should_be_camel_case_symbols.applicable_accessibilities = local,public,internal,private,protected,protected_internal,private_protected -dotnet_naming_symbols.instance_fields_should_be_camel_case_symbols.applicable_kinds = field -dotnet_naming_symbols.instance_fields_should_be_camel_case_symbols.resharper_applicable_kinds = any_field -dotnet_naming_symbols.instance_fields_should_be_camel_case_symbols.resharper_required_modifiers = any -dotnet_naming_symbols.interfaces_symbols.applicable_accessibilities = * -dotnet_naming_symbols.interfaces_symbols.applicable_kinds = interface -dotnet_naming_symbols.locals_should_be_camel_case_symbols.applicable_accessibilities = local,public,internal,private,protected,protected_internal,private_protected -dotnet_naming_symbols.locals_should_be_camel_case_symbols.applicable_kinds = parameter,local -dotnet_naming_symbols.locals_should_be_camel_case_symbols.resharper_applicable_kinds = parameter,local -dotnet_naming_symbols.locals_should_be_camel_case_symbols.resharper_required_modifiers = any -dotnet_naming_symbols.local_constants_symbols.applicable_accessibilities = * -dotnet_naming_symbols.local_constants_symbols.applicable_kinds = local -dotnet_naming_symbols.local_constants_symbols.required_modifiers = const -dotnet_naming_symbols.local_functions_should_be_pascal_case_symbols.applicable_accessibilities = local,public,internal,private,protected,protected_internal,private_protected -dotnet_naming_symbols.local_functions_should_be_pascal_case_symbols.applicable_kinds = local_function -dotnet_naming_symbols.local_functions_should_be_pascal_case_symbols.resharper_applicable_kinds = local_function -dotnet_naming_symbols.local_functions_should_be_pascal_case_symbols.resharper_required_modifiers = any -dotnet_naming_symbols.members_should_be_pascal_case_symbols.applicable_accessibilities = local,public,internal,private,protected,protected_internal,private_protected -dotnet_naming_symbols.members_should_be_pascal_case_symbols.applicable_kinds = namespace,class,struct,interface,enum,property,method,field,event,delegate,parameter,type_parameter,local,local_function -dotnet_naming_symbols.members_should_be_pascal_case_symbols.resharper_applicable_kinds = namespace,class,struct,interface,enum,property,method,any_field,event,delegate,parameter,type_parameter,local,local_function -dotnet_naming_symbols.members_should_be_pascal_case_symbols.resharper_required_modifiers = any -dotnet_naming_symbols.non_private_readonly_fields_should_be_pascal_case_symbols.applicable_accessibilities = local,public,internal,protected,protected_internal,private_protected -dotnet_naming_symbols.non_private_readonly_fields_should_be_pascal_case_symbols.applicable_kinds = field -dotnet_naming_symbols.non_private_readonly_fields_should_be_pascal_case_symbols.required_modifiers = readonly -dotnet_naming_symbols.non_private_readonly_fields_should_be_pascal_case_symbols.resharper_applicable_kinds = readonly_field -dotnet_naming_symbols.non_private_readonly_fields_should_be_pascal_case_symbols.resharper_required_modifiers = any -dotnet_naming_symbols.non_private_static_fields_should_be_pascal_case_symbols.applicable_accessibilities = local,public,internal,protected,protected_internal,private_protected -dotnet_naming_symbols.non_private_static_fields_should_be_pascal_case_symbols.applicable_kinds = field -dotnet_naming_symbols.non_private_static_fields_should_be_pascal_case_symbols.required_modifiers = static -dotnet_naming_symbols.non_private_static_fields_should_be_pascal_case_symbols.resharper_applicable_kinds = any_field -dotnet_naming_symbols.non_private_static_fields_should_be_pascal_case_symbols.resharper_required_modifiers = static -dotnet_naming_symbols.private_constants_symbols.applicable_accessibilities = private -dotnet_naming_symbols.private_constants_symbols.applicable_kinds = field -dotnet_naming_symbols.private_constants_symbols.required_modifiers = const -dotnet_naming_symbols.private_static_fields_symbols.applicable_accessibilities = private -dotnet_naming_symbols.private_static_fields_symbols.applicable_kinds = field -dotnet_naming_symbols.private_static_fields_symbols.required_modifiers = static -dotnet_naming_symbols.private_static_readonly_symbols.applicable_accessibilities = private -dotnet_naming_symbols.private_static_readonly_symbols.applicable_kinds = field -dotnet_naming_symbols.private_static_readonly_symbols.required_modifiers = static,readonly -dotnet_naming_symbols.public_fields_symbols.applicable_accessibilities = public,internal,protected,protected_internal,private_protected -dotnet_naming_symbols.public_fields_symbols.applicable_kinds = field -dotnet_naming_symbols.static_fields_should_be_camel_case_symbols.applicable_accessibilities = local,public,internal,private,protected,protected_internal,private_protected -dotnet_naming_symbols.static_fields_should_be_camel_case_symbols.applicable_kinds = field -dotnet_naming_symbols.static_fields_should_be_camel_case_symbols.required_modifiers = static -dotnet_naming_symbols.static_fields_should_be_camel_case_symbols.resharper_applicable_kinds = any_field -dotnet_naming_symbols.static_fields_should_be_camel_case_symbols.resharper_required_modifiers = static -dotnet_naming_symbols.static_readonly_symbols.applicable_accessibilities = public,internal,protected,protected_internal,private_protected -dotnet_naming_symbols.static_readonly_symbols.applicable_kinds = field -dotnet_naming_symbols.static_readonly_symbols.required_modifiers = static,readonly -dotnet_naming_symbols.type_parameters_symbols.applicable_accessibilities = * -dotnet_naming_symbols.type_parameters_symbols.applicable_kinds = type_parameter -dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary:none -dotnet_style_parentheses_in_other_binary_operators = never_if_unnecessary:none -dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary:none -dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion -dotnet_style_predefined_type_for_member_access = true:suggestion -dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion - # Standard properties insert_final_newline = true # (Please don't specify an indent_size here; that has too many unintended consequences.) @@ -316,7 +143,7 @@ dotnet_naming_symbols.static_fields.applicable_kinds = field dotnet_naming_symbols.static_fields.required_modifiers = static dotnet_naming_style.static_field_style.capitalization = camel_case -dotnet_naming_style.static_field_style.required_prefix = s_ +dotnet_naming_style.static_field_style.required_prefix = _ # Instance fields are camelCase and start with _ dotnet_naming_rule.instance_fields_should_be_camel_case.severity = suggestion @@ -497,3 +324,12 @@ dotnet_diagnostic.ca1822.severity = suggestion indent_style = space indent_size = 4 tab_width = 4 + +[*.cs] +# IDE0130: Namespace does not match folder structure +dotnet_style_namespace_match_folder = false + +# IDE0130: Namespace does not match folder structure +dotnet_diagnostic.IDE0130.severity = silent + +resharper_check_namespace_highlighting=none diff --git a/Notion.sln.DotSettings b/Notion.sln.DotSettings new file mode 100644 index 00000000..833f39db --- /dev/null +++ b/Notion.sln.DotSettings @@ -0,0 +1,5 @@ + + PDF + API + JSON + URL diff --git a/Src/Notion.Client/Api/ApiEndpoints.cs b/Src/Notion.Client/Api/ApiEndpoints.cs index 51dbe7fd..a6434683 100644 --- a/Src/Notion.Client/Api/ApiEndpoints.cs +++ b/Src/Notion.Client/Api/ApiEndpoints.cs @@ -11,11 +11,6 @@ public static string Retrieve(string databaseId) return $"/v1/databases/{databaseId}"; } - public static string List() - { - return "/v1/databases"; - } - public static string Query(string databaseId) { return $"/v1/databases/{databaseId}/query"; @@ -40,9 +35,9 @@ public static string List() } /// - /// Get the for retrieve your token's bot user. + /// Get the Uri for retrieve your token's bot user. /// - /// Returns a retrieve your token's bot user. + /// Returns a Uri retrieve your token's bot user. public static string Me() { return "/v1/users/me"; @@ -62,10 +57,10 @@ public static string Update(string blockId) } /// - /// Get the for deleting a block. + /// Get the Uri for deleting a block. /// /// Identifier for a Notion block - /// Returns a for deleting a block. + /// Returns a Uri for deleting a block. public static string Delete(string blockId) { return $"/v1/blocks/{blockId}"; @@ -105,11 +100,11 @@ public static string UpdateProperties(string pageId) } /// - /// Get the for retrieve page property item + /// Get the Uri for retrieve page property item /// /// Identifier for a Notion Page /// Identifier for a Notion Property - /// + /// Returns a Uri for Retrieve page property item public static string RetrievePropertyItem(string pageId, string propertyId) { return $"/v1/pages/{pageId}/properties/{propertyId}"; diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/AudioUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/AudioUpdateBlock.cs index f341e441..0f4b1acb 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/AudioUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/AudioUpdateBlock.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - public class AudioUpdateBlock : UpdateBlock, IUpdateBlock + public class AudioUpdateBlock : UpdateBlock { [JsonProperty("audio")] public IFileObjectInput Audio { get; set; } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BulletedListItemUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BulletedListItemUpdateBlock.cs index 9225942f..cb1fa405 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BulletedListItemUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BulletedListItemUpdateBlock.cs @@ -3,7 +3,7 @@ namespace Notion.Client { - public class BulletedListItemUpdateBlock : UpdateBlock, IUpdateBlock + public class BulletedListItemUpdateBlock : UpdateBlock { [JsonProperty("bulleted_list_item")] public Info BulletedListItem { get; set; } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/CalloutUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/CalloutUpdateBlock.cs index f8562ff3..f4489ff8 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/CalloutUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/CalloutUpdateBlock.cs @@ -3,7 +3,7 @@ namespace Notion.Client { - public class CalloutUpdateBlock : UpdateBlock, IUpdateBlock + public class CalloutUpdateBlock : UpdateBlock { [JsonProperty("callout")] public Info Callout { get; set; } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/CodeUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/CodeUpdateBlock.cs index b4fcd6dc..164abb87 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/CodeUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/CodeUpdateBlock.cs @@ -3,7 +3,7 @@ namespace Notion.Client { - public class CodeUpdateBlock : UpdateBlock, IUpdateBlock + public class CodeUpdateBlock : UpdateBlock { [JsonProperty("code")] public Info Code { get; set; } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/EmbedUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/EmbedUpdateBlock.cs index b0419a23..8dba5a53 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/EmbedUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/EmbedUpdateBlock.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - public class EmbedUpdateBlock : UpdateBlock, IUpdateBlock + public class EmbedUpdateBlock : UpdateBlock { [JsonProperty("embed")] public Info Embed { get; set; } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/EquationUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/EquationUpdateBlock.cs index b7cb0ad9..b809ba7c 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/EquationUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/EquationUpdateBlock.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - public class EquationUpdateBlock : UpdateBlock, IUpdateBlock + public class EquationUpdateBlock : UpdateBlock { [JsonProperty("equation")] public Info Equation { get; set; } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/FileUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/FileUpdateBlock.cs index 30d0dd9c..10208c1a 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/FileUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/FileUpdateBlock.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - public class FileUpdateBlock : UpdateBlock, IUpdateBlock + public class FileUpdateBlock : UpdateBlock { [JsonProperty("file")] public IFileObjectInput File { get; set; } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/HeadingOneUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/HeadingOneUpdateBlock.cs index aeb4e087..672c8c85 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/HeadingOneUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/HeadingOneUpdateBlock.cs @@ -1,11 +1,13 @@ using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using Newtonsoft.Json; namespace Notion.Client { - public class HeadingOneUpdateBlock : UpdateBlock, IUpdateBlock + public class HeadingOneUpdateBlock : UpdateBlock { [JsonProperty("heading_1")] + [SuppressMessage("ReSharper", "InconsistentNaming")] public Info Heading_1 { get; set; } public class Info diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/HeadingThreeeUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/HeadingThreeeUpdateBlock.cs index 574ea0f0..353d1a98 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/HeadingThreeeUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/HeadingThreeeUpdateBlock.cs @@ -1,11 +1,13 @@ using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using Newtonsoft.Json; namespace Notion.Client { - public class HeadingThreeeUpdateBlock : UpdateBlock, IUpdateBlock + public class HeadingThreeeUpdateBlock : UpdateBlock { [JsonProperty("heading_3")] + [SuppressMessage("ReSharper", "InconsistentNaming")] public Info Heading_3 { get; set; } public class Info diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/HeadingTwoUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/HeadingTwoUpdateBlock.cs index 0269a0ce..da1f2833 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/HeadingTwoUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/HeadingTwoUpdateBlock.cs @@ -1,11 +1,13 @@ using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using Newtonsoft.Json; namespace Notion.Client { - public class HeadingTwoUpdateBlock : UpdateBlock, IUpdateBlock + public class HeadingTwoUpdateBlock : UpdateBlock { [JsonProperty("heading_2")] + [SuppressMessage("ReSharper", "InconsistentNaming")] public Info Heading_2 { get; set; } public class Info diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/ImageUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/ImageUpdateBlock.cs index 6679c61b..791198e9 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/ImageUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/ImageUpdateBlock.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - public class ImageUpdateBlock : UpdateBlock, IUpdateBlock + public class ImageUpdateBlock : UpdateBlock { [JsonProperty("image")] public IFileObjectInput Image { get; set; } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/LinkToPageUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/LinkToPageUpdateBlock.cs index f6407cd4..69e088c5 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/LinkToPageUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/LinkToPageUpdateBlock.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - public class LinkToPageUpdateBlock : UpdateBlock, IUpdateBlock + public class LinkToPageUpdateBlock : UpdateBlock { [JsonProperty("link_to_page")] public IPageParentInput LinkToPage { get; set; } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/NumberedListItemUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/NumberedListItemUpdateBlock.cs index c27363d3..11f92394 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/NumberedListItemUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/NumberedListItemUpdateBlock.cs @@ -3,7 +3,7 @@ namespace Notion.Client { - public class NumberedListItemUpdateBlock : UpdateBlock, IUpdateBlock + public class NumberedListItemUpdateBlock : UpdateBlock { [JsonProperty("numbered_list_item")] public Info NumberedListItem { get; set; } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/PDFUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/PDFUpdateBlock.cs index 8c56b7ff..c6e9ba0e 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/PDFUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/PDFUpdateBlock.cs @@ -1,8 +1,10 @@ -using Newtonsoft.Json; +using System.Diagnostics.CodeAnalysis; +using Newtonsoft.Json; namespace Notion.Client { - public class PDFUpdateBlock : UpdateBlock, IUpdateBlock + [SuppressMessage("ReSharper", "InconsistentNaming")] + public class PDFUpdateBlock : UpdateBlock { [JsonProperty("pdf")] public IFileObjectInput PDF { get; set; } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/ParagraphUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/ParagraphUpdateBlock.cs index 2e49c64a..63aa2724 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/ParagraphUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/ParagraphUpdateBlock.cs @@ -3,7 +3,7 @@ namespace Notion.Client { - public class ParagraphUpdateBlock : UpdateBlock, IUpdateBlock + public class ParagraphUpdateBlock : UpdateBlock { [JsonProperty("paragraph")] public Info Paragraph { get; set; } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/QuoteUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/QuoteUpdateBlock.cs index fdfd189c..9222112e 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/QuoteUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/QuoteUpdateBlock.cs @@ -3,7 +3,7 @@ namespace Notion.Client { - public class QuoteUpdateBlock : UpdateBlock, IUpdateBlock + public class QuoteUpdateBlock : UpdateBlock { [JsonProperty("quote")] public Info Quote { get; set; } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/SyncedBlockUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/SyncedBlockUpdateBlock.cs index 9cb234d8..e275f371 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/SyncedBlockUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/SyncedBlockUpdateBlock.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - public class SyncedBlockUpdateBlock : UpdateBlock, IUpdateBlock + public class SyncedBlockUpdateBlock : UpdateBlock { [JsonProperty("synced_block")] public Info SyncedBlock { get; set; } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableRowUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableRowUpdateBlock.cs index c228de66..143f3e2d 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableRowUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableRowUpdateBlock.cs @@ -3,7 +3,7 @@ namespace Notion.Client { - public class TableRowUpdateBlock : UpdateBlock, IUpdateBlock + public class TableRowUpdateBlock : UpdateBlock { [JsonProperty("table_row")] public Info TableRow { get; set; } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableUpdateBlock.cs index ef0e8933..7c1f8046 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableUpdateBlock.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - public class TableUpdateBlock : UpdateBlock, IUpdateBlock + public class TableUpdateBlock : UpdateBlock { [JsonProperty("table")] public Info Table { get; set; } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TemplateUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TemplateUpdateBlock.cs index 62457971..32a393cd 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TemplateUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TemplateUpdateBlock.cs @@ -3,7 +3,7 @@ namespace Notion.Client { - public class TemplateUpdateBlock : UpdateBlock, IUpdateBlock + public class TemplateUpdateBlock : UpdateBlock { [JsonProperty("template")] public Info Template { get; set; } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/ToDoUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/ToDoUpdateBlock.cs index f1accfc8..9e244f44 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/ToDoUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/ToDoUpdateBlock.cs @@ -3,7 +3,7 @@ namespace Notion.Client { - public class ToDoUpdateBlock : UpdateBlock, IUpdateBlock + public class ToDoUpdateBlock : UpdateBlock { [JsonProperty("to_do")] public Info ToDo { get; set; } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/ToggleUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/ToggleUpdateBlock.cs index b87834d1..3d7e8e87 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/ToggleUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/ToggleUpdateBlock.cs @@ -3,7 +3,7 @@ namespace Notion.Client { - public class ToggleUpdateBlock : UpdateBlock, IUpdateBlock + public class ToggleUpdateBlock : UpdateBlock { [JsonProperty("toggle")] public Info Toggle { get; set; } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/VideoUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/VideoUpdateBlock.cs index ec28aae3..a317139a 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/VideoUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/VideoUpdateBlock.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - public class VideoUpdateBlock : UpdateBlock, IUpdateBlock + public class VideoUpdateBlock : UpdateBlock { [JsonProperty("video")] public IFileObjectInput Video { get; set; } diff --git a/Src/Notion.Client/Api/Comments/Create/Response/CreateCommentResponse.cs b/Src/Notion.Client/Api/Comments/Create/Response/CreateCommentResponse.cs index 39bebd6b..0171d92d 100644 --- a/Src/Notion.Client/Api/Comments/Create/Response/CreateCommentResponse.cs +++ b/Src/Notion.Client/Api/Comments/Create/Response/CreateCommentResponse.cs @@ -1,5 +1,8 @@ -namespace Notion.Client +using System.Diagnostics.CodeAnalysis; + +namespace Notion.Client { + [SuppressMessage("ReSharper", "ClassNeverInstantiated.Global")] public class CreateCommentResponse : Comment { } diff --git a/Src/Notion.Client/Api/Comments/ICommentsClient.cs b/Src/Notion.Client/Api/Comments/ICommentsClient.cs index 871319da..8ec81348 100644 --- a/Src/Notion.Client/Api/Comments/ICommentsClient.cs +++ b/Src/Notion.Client/Api/Comments/ICommentsClient.cs @@ -4,15 +4,6 @@ namespace Notion.Client { public interface ICommentsClient { - /// - /// Retrieves a list of un-resolved Comment objects from a page or block. - /// - /// Retrieve comments parameters - /// - /// - /// - Task Retrieve(RetrieveCommentsParameters retrieveCommentsParameters); - Task Create(CreateCommentParameters createCommentParameters); } } diff --git a/Src/Notion.Client/Api/Comments/Retrieve/CommentsClient.cs b/Src/Notion.Client/Api/Comments/Retrieve/CommentsClient.cs index cb32978e..eb1546ab 100644 --- a/Src/Notion.Client/Api/Comments/Retrieve/CommentsClient.cs +++ b/Src/Notion.Client/Api/Comments/Retrieve/CommentsClient.cs @@ -1,10 +1,12 @@ using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Threading.Tasks; namespace Notion.Client { public partial class CommentsClient { + [SuppressMessage("ReSharper", "UnusedMember.Global")] public async Task Retrieve(RetrieveCommentsParameters parameters) { var qp = (IRetrieveCommentsQueryParameters)parameters; diff --git a/Src/Notion.Client/Api/Comments/Retrieve/Request/RetrieveCommentsParameters.cs b/Src/Notion.Client/Api/Comments/Retrieve/Request/RetrieveCommentsParameters.cs index d42ec9e7..25d3d54d 100644 --- a/Src/Notion.Client/Api/Comments/Retrieve/Request/RetrieveCommentsParameters.cs +++ b/Src/Notion.Client/Api/Comments/Retrieve/Request/RetrieveCommentsParameters.cs @@ -1,5 +1,8 @@ -namespace Notion.Client +using System.Diagnostics.CodeAnalysis; + +namespace Notion.Client { + [SuppressMessage("ReSharper", "ClassNeverInstantiated.Global")] public class RetrieveCommentsParameters : IRetrieveCommentsQueryParameters { public string BlockId { get; set; } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/MultiSelectOptionSchema.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/MultiSelectOptionSchema.cs index 89fdb0ab..a13d0930 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/MultiSelectOptionSchema.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/MultiSelectOptionSchema.cs @@ -1,5 +1,8 @@ -namespace Notion.Client +using System.Diagnostics.CodeAnalysis; + +namespace Notion.Client { + [SuppressMessage("ReSharper", "ClassNeverInstantiated.Global")] public class MultiSelectOptionSchema : SelectOptionSchema { } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesListParameters.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesListParameters.cs deleted file mode 100644 index 922e54fc..00000000 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesListParameters.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Notion.Client -{ - public class DatabasesListParameters : IDatabasesListQueryParmaters - { - public string StartCursor { get; set; } - - public int? PageSize { get; set; } - } -} diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/CheckboxUpdatePropertySchema.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/CheckboxUpdatePropertySchema.cs index a13f2911..a6890d6e 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/CheckboxUpdatePropertySchema.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/CheckboxUpdatePropertySchema.cs @@ -3,7 +3,7 @@ namespace Notion.Client { - public class CheckboxUpdatePropertySchema : UpdatePropertySchema, IUpdatePropertySchema + public class CheckboxUpdatePropertySchema : UpdatePropertySchema { [JsonProperty("checkbox")] public Dictionary Checkbox { get; set; } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/CreatedByUpdatePropertySchema.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/CreatedByUpdatePropertySchema.cs index 394868db..08a5cf74 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/CreatedByUpdatePropertySchema.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/CreatedByUpdatePropertySchema.cs @@ -3,7 +3,7 @@ namespace Notion.Client { - public class CreatedByUpdatePropertySchema : UpdatePropertySchema, IUpdatePropertySchema + public class CreatedByUpdatePropertySchema : UpdatePropertySchema { [JsonProperty("created_by")] public Dictionary CreatedBy { get; set; } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/CreatedTimeUpdatePropertySchema.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/CreatedTimeUpdatePropertySchema.cs index dee266f3..8089ecbb 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/CreatedTimeUpdatePropertySchema.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/CreatedTimeUpdatePropertySchema.cs @@ -3,7 +3,7 @@ namespace Notion.Client { - public class CreatedTimeUpdatePropertySchema : UpdatePropertySchema, IUpdatePropertySchema + public class CreatedTimeUpdatePropertySchema : UpdatePropertySchema { [JsonProperty("created_time")] public Dictionary CreatedTime { get; set; } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/DateUpdatePropertySchema.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/DateUpdatePropertySchema.cs index 0c2b2143..65487dd7 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/DateUpdatePropertySchema.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/DateUpdatePropertySchema.cs @@ -3,7 +3,7 @@ namespace Notion.Client { - public class DateUpdatePropertySchema : UpdatePropertySchema, IUpdatePropertySchema + public class DateUpdatePropertySchema : UpdatePropertySchema { [JsonProperty("date")] public Dictionary Date { get; set; } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/EmailUpdatePropertySchema.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/EmailUpdatePropertySchema.cs index 412c9115..5905e68e 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/EmailUpdatePropertySchema.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/EmailUpdatePropertySchema.cs @@ -3,7 +3,7 @@ namespace Notion.Client { - public class EmailUpdatePropertySchema : UpdatePropertySchema, IUpdatePropertySchema + public class EmailUpdatePropertySchema : UpdatePropertySchema { [JsonProperty("email")] public Dictionary Email { get; set; } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/FilesUpdatePropertySchema.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/FilesUpdatePropertySchema.cs index c7b84218..9fb3b531 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/FilesUpdatePropertySchema.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/FilesUpdatePropertySchema.cs @@ -3,7 +3,7 @@ namespace Notion.Client { - public class FilesUpdatePropertySchema : UpdatePropertySchema, IUpdatePropertySchema + public class FilesUpdatePropertySchema : UpdatePropertySchema { [JsonProperty("files")] public Dictionary Files { get; set; } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/FormulaUpdatePropertySchema.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/FormulaUpdatePropertySchema.cs index 158a42bb..40cc398a 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/FormulaUpdatePropertySchema.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/FormulaUpdatePropertySchema.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - public class FormulaUpdatePropertySchema : UpdatePropertySchema, IUpdatePropertySchema + public class FormulaUpdatePropertySchema : UpdatePropertySchema { [JsonProperty("formula")] public Formula Formula { get; set; } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/LastEditedByUpdatePropertySchema.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/LastEditedByUpdatePropertySchema.cs index 939bc69d..c547538a 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/LastEditedByUpdatePropertySchema.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/LastEditedByUpdatePropertySchema.cs @@ -3,7 +3,7 @@ namespace Notion.Client { - public class LastEditedByUpdatePropertySchema : UpdatePropertySchema, IUpdatePropertySchema + public class LastEditedByUpdatePropertySchema : UpdatePropertySchema { [JsonProperty("last_edited_by")] public Dictionary LastEditedBy { get; set; } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/LastEditedTimeUpdatePropertySchema.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/LastEditedTimeUpdatePropertySchema.cs index f48ddf5a..28c9e55b 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/LastEditedTimeUpdatePropertySchema.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/LastEditedTimeUpdatePropertySchema.cs @@ -3,7 +3,7 @@ namespace Notion.Client { - public class LastEditedTimeUpdatePropertySchema : UpdatePropertySchema, IUpdatePropertySchema + public class LastEditedTimeUpdatePropertySchema : UpdatePropertySchema { [JsonProperty("last_edited_time")] public Dictionary LastEditedTime { get; set; } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/MultiSelectUpdatePropertySchema.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/MultiSelectUpdatePropertySchema.cs index a6b32ad3..0b7b1c0c 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/MultiSelectUpdatePropertySchema.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/MultiSelectUpdatePropertySchema.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - public class MultiSelectUpdatePropertySchema : UpdatePropertySchema, IUpdatePropertySchema + public class MultiSelectUpdatePropertySchema : UpdatePropertySchema { [JsonProperty("multi_select")] public OptionWrapper MultiSelect { get; set; } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/NumberUpdatePropertySchema.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/NumberUpdatePropertySchema.cs index e1f0b734..23f3ea3a 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/NumberUpdatePropertySchema.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/NumberUpdatePropertySchema.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - public class NumberUpdatePropertySchema : UpdatePropertySchema, IUpdatePropertySchema + public class NumberUpdatePropertySchema : UpdatePropertySchema { [JsonProperty("number")] public Number Number { get; set; } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/PeopleUpdatePropertySchema.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/PeopleUpdatePropertySchema.cs index 6fab728e..41a8892d 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/PeopleUpdatePropertySchema.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/PeopleUpdatePropertySchema.cs @@ -3,7 +3,7 @@ namespace Notion.Client { - public class PeopleUpdatePropertySchema : UpdatePropertySchema, IUpdatePropertySchema + public class PeopleUpdatePropertySchema : UpdatePropertySchema { [JsonProperty("people")] public Dictionary People { get; set; } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/PhoneNumberUpdatePropertySchema.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/PhoneNumberUpdatePropertySchema.cs index 7813671c..7d01f506 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/PhoneNumberUpdatePropertySchema.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/PhoneNumberUpdatePropertySchema.cs @@ -3,7 +3,7 @@ namespace Notion.Client { - public class PhoneNumberUpdatePropertySchema : UpdatePropertySchema, IUpdatePropertySchema + public class PhoneNumberUpdatePropertySchema : UpdatePropertySchema { [JsonProperty("phone_number")] public Dictionary PhoneNumber { get; set; } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/RelationUpdatePropertySchema.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/RelationUpdatePropertySchema.cs index 2091df91..1565cd4a 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/RelationUpdatePropertySchema.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/RelationUpdatePropertySchema.cs @@ -3,7 +3,7 @@ namespace Notion.Client { - public class RelationUpdatePropertySchema : UpdatePropertySchema, IUpdatePropertySchema + public class RelationUpdatePropertySchema : UpdatePropertySchema { [JsonProperty("relation")] public RelationInfo Relation { get; set; } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/RichTextUpdatePropertySchema.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/RichTextUpdatePropertySchema.cs index 3d6c5ec2..a20ca0ea 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/RichTextUpdatePropertySchema.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/RichTextUpdatePropertySchema.cs @@ -3,7 +3,7 @@ namespace Notion.Client { - public class RichTextUpdatePropertySchema : UpdatePropertySchema, IUpdatePropertySchema + public class RichTextUpdatePropertySchema : UpdatePropertySchema { [JsonProperty("rich_text")] public Dictionary RichText { get; set; } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/RollupConfigUpdatePropertySchema.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/RollupConfigUpdatePropertySchema.cs index 2f38731b..8ee2d908 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/RollupConfigUpdatePropertySchema.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/RollupConfigUpdatePropertySchema.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - public class RollupConfigUpdatePropertySchema : UpdatePropertySchema, IUpdatePropertySchema + public class RollupConfigUpdatePropertySchema : UpdatePropertySchema { [JsonProperty("relation_property_name")] public string RelationPropertyName { get; set; } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/SelectUpdatePropertySchema.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/SelectUpdatePropertySchema.cs index b833d0bc..678e452d 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/SelectUpdatePropertySchema.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/SelectUpdatePropertySchema.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - public class SelectUpdatePropertySchema : UpdatePropertySchema, IUpdatePropertySchema + public class SelectUpdatePropertySchema : UpdatePropertySchema { [JsonProperty("select")] public OptionWrapper Select { get; set; } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/TitleUpdatePropertySchema.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/TitleUpdatePropertySchema.cs index 1a74085c..54052dfc 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/TitleUpdatePropertySchema.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/TitleUpdatePropertySchema.cs @@ -3,7 +3,7 @@ namespace Notion.Client { - public class TitleUpdatePropertySchema : UpdatePropertySchema, IUpdatePropertySchema + public class TitleUpdatePropertySchema : UpdatePropertySchema { [JsonProperty("title")] public Dictionary Title { get; set; } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/URLUpdatePropertySchema.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/URLUpdatePropertySchema.cs index 7aa9c701..f56d6507 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/URLUpdatePropertySchema.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/URLUpdatePropertySchema.cs @@ -3,7 +3,7 @@ namespace Notion.Client { - public class UrlUpdatePropertySchema : UpdatePropertySchema, IUpdatePropertySchema + public class UrlUpdatePropertySchema : UpdatePropertySchema { [JsonProperty("url")] public Dictionary Url { get; set; } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/Direction.cs b/Src/Notion.Client/Api/Databases/RequestParams/Direction.cs index c79d501d..059f42b3 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/Direction.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/Direction.cs @@ -1,7 +1,9 @@ -using System.Runtime.Serialization; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.Serialization; namespace Notion.Client { + [SuppressMessage("ReSharper", "UnusedMember.Global")] public enum Direction { [EnumMember(Value = null)] diff --git a/Src/Notion.Client/Api/Databases/RequestParams/IDatabasesListQueryParmaters.cs b/Src/Notion.Client/Api/Databases/RequestParams/IDatabasesListQueryParmaters.cs deleted file mode 100644 index 4432f421..00000000 --- a/Src/Notion.Client/Api/Databases/RequestParams/IDatabasesListQueryParmaters.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Notion.Client -{ - public interface IDatabasesListQueryParmaters : IPaginationParameters - { - } -} diff --git a/Src/Notion.Client/Api/Databases/RequestParams/Timestamp.cs b/Src/Notion.Client/Api/Databases/RequestParams/Timestamp.cs index 334b8c22..df2c69ca 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/Timestamp.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/Timestamp.cs @@ -1,7 +1,9 @@ -using System.Runtime.Serialization; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.Serialization; namespace Notion.Client { + [SuppressMessage("ReSharper", "UnusedMember.Global")] public enum Timestamp { [EnumMember(Value = null)] diff --git a/Src/Notion.Client/Api/Pages/PagesClient.cs b/Src/Notion.Client/Api/Pages/PagesClient.cs index b4a3c58f..91c59a64 100644 --- a/Src/Notion.Client/Api/Pages/PagesClient.cs +++ b/Src/Notion.Client/Api/Pages/PagesClient.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Threading.Tasks; using static Notion.Client.ApiEndpoints; @@ -78,7 +79,7 @@ public async Task UpdateAsync(string pageId, PagesUpdateParameters pagesUp return await _client.PatchAsync(url, body); } - [Obsolete("This method is obsolute. Use UpdateAsync instead. This API will be removed in future release")] + [Obsolete("This method is obsolete. Use UpdateAsync instead. This API will be removed in future release")] public async Task UpdatePropertiesAsync( string pageId, IDictionary updatedProperties) @@ -90,6 +91,7 @@ public async Task UpdatePropertiesAsync( return await _client.PatchAsync(url, body); } + [SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Local")] private class UpdatePropertiesParameters { public IDictionary Properties { get; set; } diff --git a/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParametersBuilder.cs b/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParametersBuilder.cs index 6b263beb..ed85117d 100644 --- a/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParametersBuilder.cs +++ b/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParametersBuilder.cs @@ -1,14 +1,16 @@ using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; namespace Notion.Client { + [SuppressMessage("ReSharper", "UnusedMember.Global")] public class PagesCreateParametersBuilder { - private readonly IList children = new List(); - private readonly Dictionary properties = new(); - private FileObject cover; - private IPageIcon icon; - private IPageParentInput parent; + private readonly IList _children = new List(); + private readonly Dictionary _properties = new(); + private FileObject _cover; + private IPageIcon _icon; + private IPageParentInput _parent; private PagesCreateParametersBuilder() { @@ -16,33 +18,33 @@ private PagesCreateParametersBuilder() public static PagesCreateParametersBuilder Create(IPageParentInput parent) { - return new PagesCreateParametersBuilder { parent = parent }; + return new PagesCreateParametersBuilder { _parent = parent }; } public PagesCreateParametersBuilder AddProperty(string nameOrId, PropertyValue value) { - properties[nameOrId] = value; + _properties[nameOrId] = value; return this; } public PagesCreateParametersBuilder AddPageContent(IBlock block) { - children.Add(block); + _children.Add(block); return this; } public PagesCreateParametersBuilder SetIcon(IPageIcon pageIcon) { - icon = pageIcon; + _icon = pageIcon; return this; } public PagesCreateParametersBuilder SetCover(FileObject pageCover) { - cover = pageCover; + _cover = pageCover; return this; } @@ -51,11 +53,11 @@ public PagesCreateParameters Build() { return new PagesCreateParameters { - Parent = parent, - Properties = properties, - Children = children, - Icon = icon, - Cover = cover + Parent = _parent, + Properties = _properties, + Children = _children, + Icon = _icon, + Cover = _cover }; } } diff --git a/Src/Notion.Client/Api/Search/ISearchClient.cs b/Src/Notion.Client/Api/Search/ISearchClient.cs index 8071db6d..835c14e4 100644 --- a/Src/Notion.Client/Api/Search/ISearchClient.cs +++ b/Src/Notion.Client/Api/Search/ISearchClient.cs @@ -1,7 +1,9 @@ -using System.Threading.Tasks; +using System.Diagnostics.CodeAnalysis; +using System.Threading.Tasks; namespace Notion.Client { + [SuppressMessage("ReSharper", "UnusedMemberInSuper.Global")] public interface ISearchClient { /// diff --git a/Src/Notion.Client/Api/Search/Parameters/SearchDirection.cs b/Src/Notion.Client/Api/Search/Parameters/SearchDirection.cs index fdac0b59..da52b11b 100644 --- a/Src/Notion.Client/Api/Search/Parameters/SearchDirection.cs +++ b/Src/Notion.Client/Api/Search/Parameters/SearchDirection.cs @@ -1,7 +1,9 @@ -using System.Runtime.Serialization; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.Serialization; namespace Notion.Client { + [SuppressMessage("ReSharper", "UnusedMember.Global")] public enum SearchDirection { [EnumMember(Value = "ascending")] diff --git a/Src/Notion.Client/Api/Search/Parameters/SearchFilter.cs b/Src/Notion.Client/Api/Search/Parameters/SearchFilter.cs index dbd5cf5f..b36ca873 100644 --- a/Src/Notion.Client/Api/Search/Parameters/SearchFilter.cs +++ b/Src/Notion.Client/Api/Search/Parameters/SearchFilter.cs @@ -1,8 +1,11 @@ -using Newtonsoft.Json; +using System.Diagnostics.CodeAnalysis; +using Newtonsoft.Json; using Newtonsoft.Json.Converters; namespace Notion.Client { + [SuppressMessage("ReSharper", "ClassNeverInstantiated.Global")] + [SuppressMessage("ReSharper", "UnusedMember.Global")] public class SearchFilter { [JsonConverter(typeof(StringEnumConverter))] diff --git a/Src/Notion.Client/Api/Search/Parameters/SearchObjectType.cs b/Src/Notion.Client/Api/Search/Parameters/SearchObjectType.cs index 78a012df..e3e6181b 100644 --- a/Src/Notion.Client/Api/Search/Parameters/SearchObjectType.cs +++ b/Src/Notion.Client/Api/Search/Parameters/SearchObjectType.cs @@ -1,7 +1,9 @@ -using System.Runtime.Serialization; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.Serialization; namespace Notion.Client { + [SuppressMessage("ReSharper", "UnusedMember.Global")] public enum SearchObjectType { [EnumMember(Value = "page")] diff --git a/Src/Notion.Client/Api/Search/SearchClient.cs b/Src/Notion.Client/Api/Search/SearchClient.cs index 87de9270..bd73acfc 100644 --- a/Src/Notion.Client/Api/Search/SearchClient.cs +++ b/Src/Notion.Client/Api/Search/SearchClient.cs @@ -5,11 +5,11 @@ namespace Notion.Client { public class SearchClient : ISearchClient { - private readonly IRestClient client; + private readonly IRestClient _client; public SearchClient(IRestClient client) { - this.client = client; + _client = client; } public async Task> SearchAsync(SearchParameters parameters) @@ -18,7 +18,7 @@ public async Task> SearchAsync(SearchParameters parameter var body = (ISearchBodyParameters)parameters; - return await client.PostAsync>(url, body); + return await _client.PostAsync>(url, body); } } } diff --git a/Src/Notion.Client/Constants.cs b/Src/Notion.Client/Constants.cs index 072291e1..779bcb47 100644 --- a/Src/Notion.Client/Constants.cs +++ b/Src/Notion.Client/Constants.cs @@ -4,9 +4,9 @@ namespace Notion.Client { - internal class Constants + internal static class Constants { - internal static string BASE_URL = "https://api.notion.com/"; - internal static string DEFAULT_NOTION_VERSION = "2022-06-28"; + internal const string BaseUrl = "https://api.notion.com/"; + internal const string DefaultNotionVersion = "2022-06-28"; } } diff --git a/Src/Notion.Client/DI/ServiceCollectionExtensions.cs b/Src/Notion.Client/DI/ServiceCollectionExtensions.cs index 866dc92d..9a658077 100644 --- a/Src/Notion.Client/DI/ServiceCollectionExtensions.cs +++ b/Src/Notion.Client/DI/ServiceCollectionExtensions.cs @@ -1,15 +1,18 @@ using System; +using System.Diagnostics.CodeAnalysis; using Notion.Client; namespace Microsoft.Extensions.DependencyInjection { + [SuppressMessage("ReSharper", "UnusedType.Global")] + [SuppressMessage("ReSharper", "UnusedMember.Global")] public static class ServiceCollectionExtensions { public static IServiceCollection AddNotionClient( this IServiceCollection services, Action options) { - services.AddSingleton(sp => + services.AddSingleton(_ => { var clientOptions = new ClientOptions(); options?.Invoke(clientOptions); diff --git a/Src/Notion.Client/Extensions/HttpResponseMessageExtensions.cs b/Src/Notion.Client/Extensions/HttpResponseMessageExtensions.cs index b6a9396d..cc6f9698 100644 --- a/Src/Notion.Client/Extensions/HttpResponseMessageExtensions.cs +++ b/Src/Notion.Client/Extensions/HttpResponseMessageExtensions.cs @@ -11,27 +11,15 @@ internal static async Task ParseStreamAsync( this HttpResponseMessage response, JsonSerializerSettings serializerSettings = null) { - using (var stream = await response.Content.ReadAsStreamAsync()) - { - using (var streamReader = new StreamReader(stream)) - { - using (JsonReader jsonReader = new JsonTextReader(streamReader)) - { - JsonSerializer serializer = null; + using var stream = await response.Content.ReadAsStreamAsync(); + using var streamReader = new StreamReader(stream); + using JsonReader jsonReader = new JsonTextReader(streamReader); - if (serializerSettings == null) - { - serializer = JsonSerializer.CreateDefault(); - } - else - { - serializer = JsonSerializer.Create(serializerSettings); - } + var serializer = serializerSettings == null + ? JsonSerializer.CreateDefault() + : JsonSerializer.Create(serializerSettings); - return serializer.Deserialize(jsonReader); - } - } - } + return serializer.Deserialize(jsonReader); } } } diff --git a/Src/Notion.Client/Logging/Log.cs b/Src/Notion.Client/Logging/Log.cs index 7fda66a5..47beea5e 100644 --- a/Src/Notion.Client/Logging/Log.cs +++ b/Src/Notion.Client/Logging/Log.cs @@ -1,25 +1,27 @@ using System; +using System.Diagnostics.CodeAnalysis; using Microsoft.Extensions.Logging; namespace Notion.Client { internal static class Log { - internal static ILogger logger; + internal static ILogger Logger; internal static void Trace(string message, params object[] args) { - logger?.LogTrace(message, args); + Logger?.LogTrace(message, args); } + [SuppressMessage("ReSharper", "UnusedMember.Global")] internal static void Information(string message, params object[] args) { - logger?.LogInformation(message, args); + Logger?.LogInformation(message, args); } internal static void Error(Exception ex, string message, params object[] args) { - logger?.LogError(ex, message, args); + Logger?.LogError(ex, message, args); } } } diff --git a/Src/Notion.Client/Logging/NotionClientLogging.cs b/Src/Notion.Client/Logging/NotionClientLogging.cs index b77ff15e..07a18514 100644 --- a/Src/Notion.Client/Logging/NotionClientLogging.cs +++ b/Src/Notion.Client/Logging/NotionClientLogging.cs @@ -1,16 +1,19 @@ -using Microsoft.Extensions.Logging; +using System.Diagnostics.CodeAnalysis; +using Microsoft.Extensions.Logging; namespace Notion.Client { + [SuppressMessage("ReSharper", "UnusedType.Global")] + [SuppressMessage("ReSharper", "UnusedMember.Global")] public static class NotionClientLogging { - internal static ILoggerFactory factory; + private static ILoggerFactory _factory; public static void ConfigureLogger(ILoggerFactory loggerFactory) { - factory = loggerFactory; + _factory = loggerFactory; - Log.logger = Log.logger == null ? factory?.CreateLogger("Notion.Client") : Log.logger; + Log.Logger = Log.Logger == null ? _factory?.CreateLogger("Notion.Client") : Log.Logger; } } } diff --git a/Src/Notion.Client/Models/Blocks/BlockType.cs b/Src/Notion.Client/Models/Blocks/BlockType.cs index 8a2c626a..92de4b6b 100644 --- a/Src/Notion.Client/Models/Blocks/BlockType.cs +++ b/Src/Notion.Client/Models/Blocks/BlockType.cs @@ -1,4 +1,5 @@ -using System.Runtime.Serialization; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.Serialization; namespace Notion.Client { @@ -8,12 +9,15 @@ public enum BlockType Paragraph, [EnumMember(Value = "heading_1")] + [SuppressMessage("ReSharper", "InconsistentNaming")] Heading_1, [EnumMember(Value = "heading_2")] + [SuppressMessage("ReSharper", "InconsistentNaming")] Heading_2, [EnumMember(Value = "heading_3")] + [SuppressMessage("ReSharper", "InconsistentNaming")] Heading_3, [EnumMember(Value = "bulleted_list_item")] diff --git a/Src/Notion.Client/Models/Blocks/Color.cs b/Src/Notion.Client/Models/Blocks/Color.cs index ec22b0dc..46e38e2a 100644 --- a/Src/Notion.Client/Models/Blocks/Color.cs +++ b/Src/Notion.Client/Models/Blocks/Color.cs @@ -1,7 +1,9 @@ -using System.Runtime.Serialization; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.Serialization; namespace Notion.Client { + [SuppressMessage("ReSharper", "UnusedMember.Global")] public enum Color { [EnumMember(Value = "default")] diff --git a/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs b/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs index aced5461..b0753122 100644 --- a/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs +++ b/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using Newtonsoft.Json; using Newtonsoft.Json.Converters; @@ -7,6 +8,7 @@ namespace Notion.Client public class HeadingOneBlock : Block, IColumnChildrenBlock, INonColumnBlock { [JsonProperty("heading_1")] + [SuppressMessage("ReSharper", "InconsistentNaming")] public Info Heading_1 { get; set; } public override BlockType Type => BlockType.Heading_1; diff --git a/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs b/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs index 10999e0e..c6abc213 100644 --- a/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs +++ b/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using Newtonsoft.Json; using Newtonsoft.Json.Converters; @@ -7,6 +8,7 @@ namespace Notion.Client public class HeadingThreeeBlock : Block, IColumnChildrenBlock, INonColumnBlock { [JsonProperty("heading_3")] + [SuppressMessage("ReSharper", "InconsistentNaming")] public Info Heading_3 { get; set; } public override BlockType Type => BlockType.Heading_3; diff --git a/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs b/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs index 553d56f2..f5ffd7ea 100644 --- a/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs +++ b/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using Newtonsoft.Json; using Newtonsoft.Json.Converters; @@ -7,6 +8,7 @@ namespace Notion.Client public class HeadingTwoBlock : Block, IColumnChildrenBlock, INonColumnBlock { [JsonProperty("heading_2")] + [SuppressMessage("ReSharper", "InconsistentNaming")] public Info Heading_2 { get; set; } public override BlockType Type => BlockType.Heading_2; diff --git a/Src/Notion.Client/Models/Blocks/IColumnChildrenBlock.cs b/Src/Notion.Client/Models/Blocks/IColumnChildrenBlock.cs index 673bc156..8c1e1446 100644 --- a/Src/Notion.Client/Models/Blocks/IColumnChildrenBlock.cs +++ b/Src/Notion.Client/Models/Blocks/IColumnChildrenBlock.cs @@ -8,7 +8,7 @@ public interface ISyncedBlockChildren : IBlock { } - public interface IColumnChildrenBlock : IBlock, ITemplateChildrendBlock, ISyncedBlockChildren + public interface IColumnChildrenBlock : ITemplateChildrendBlock, ISyncedBlockChildren { } diff --git a/Src/Notion.Client/Models/Blocks/PDFBlock.cs b/Src/Notion.Client/Models/Blocks/PDFBlock.cs index 55e3ce42..6d7486d7 100644 --- a/Src/Notion.Client/Models/Blocks/PDFBlock.cs +++ b/Src/Notion.Client/Models/Blocks/PDFBlock.cs @@ -1,7 +1,9 @@ -using Newtonsoft.Json; +using System.Diagnostics.CodeAnalysis; +using Newtonsoft.Json; namespace Notion.Client { + [SuppressMessage("ReSharper", "InconsistentNaming")] public class PDFBlock : Block, IColumnChildrenBlock, INonColumnBlock { [JsonProperty("pdf")] diff --git a/Src/Notion.Client/Models/Database/Properties/PropertyType.cs b/Src/Notion.Client/Models/Database/Properties/PropertyType.cs index 5ca4c7f8..e4db339a 100644 --- a/Src/Notion.Client/Models/Database/Properties/PropertyType.cs +++ b/Src/Notion.Client/Models/Database/Properties/PropertyType.cs @@ -1,7 +1,9 @@ -using System.Runtime.Serialization; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.Serialization; namespace Notion.Client { + [SuppressMessage("ReSharper", "UnusedMember.Global")] public enum PropertyType { [EnumMember(Value = null)] diff --git a/Src/Notion.Client/Models/Database/Properties/SelectProperty.cs b/Src/Notion.Client/Models/Database/Properties/SelectProperty.cs index 9af6397b..f9675443 100644 --- a/Src/Notion.Client/Models/Database/Properties/SelectProperty.cs +++ b/Src/Notion.Client/Models/Database/Properties/SelectProperty.cs @@ -1,9 +1,11 @@ using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using Newtonsoft.Json; using Newtonsoft.Json.Converters; namespace Notion.Client { + [SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global")] public class SelectProperty : Property { public override PropertyType Type => PropertyType.Select; diff --git a/Src/Notion.Client/Models/Database/RichText/RichTextType.cs b/Src/Notion.Client/Models/Database/RichText/RichTextType.cs index 59bc414f..91031138 100644 --- a/Src/Notion.Client/Models/Database/RichText/RichTextType.cs +++ b/Src/Notion.Client/Models/Database/RichText/RichTextType.cs @@ -1,7 +1,9 @@ -using System.Runtime.Serialization; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.Serialization; namespace Notion.Client { + [SuppressMessage("ReSharper", "UnusedMember.Global")] public enum RichTextType { [EnumMember(Value = null)] diff --git a/Src/Notion.Client/Models/Filters/TimestampCreatedTimeFilter.cs b/Src/Notion.Client/Models/Filters/TimestampCreatedTimeFilter.cs index d550817e..80f9dcf4 100644 --- a/Src/Notion.Client/Models/Filters/TimestampCreatedTimeFilter.cs +++ b/Src/Notion.Client/Models/Filters/TimestampCreatedTimeFilter.cs @@ -6,9 +6,6 @@ namespace Notion.Client { public class TimestampCreatedTimeFilter : Filter { - [JsonProperty("timestamp")] - public string Timestamp = "created_time"; - public TimestampCreatedTimeFilter( DateTime? equal = null, DateTime? before = null, @@ -41,6 +38,9 @@ public TimestampCreatedTimeFilter( ); } + [JsonProperty("timestamp")] + public string Timestamp => "created_time"; + [JsonProperty("created_time")] public DateFilter.Condition CreatedTime { get; set; } } diff --git a/Src/Notion.Client/Models/Filters/TimestampLastEditedTimeFilter.cs b/Src/Notion.Client/Models/Filters/TimestampLastEditedTimeFilter.cs index 51a6e39f..695183cc 100644 --- a/Src/Notion.Client/Models/Filters/TimestampLastEditedTimeFilter.cs +++ b/Src/Notion.Client/Models/Filters/TimestampLastEditedTimeFilter.cs @@ -6,9 +6,6 @@ namespace Notion.Client { public class TimestampLastEditedTimeFilter : Filter { - [JsonProperty("timestamp")] - public string Timestamp = "last_modified_time"; - public TimestampLastEditedTimeFilter( DateTime? equal = null, DateTime? before = null, @@ -41,6 +38,9 @@ public TimestampLastEditedTimeFilter( ); } + [JsonProperty("timestamp")] + public string Timestamp => "last_modified_time"; + [JsonProperty("last_edited_time")] public DateFilter.Condition LastEditedTime { get; set; } } diff --git a/Src/Notion.Client/Models/Filters/URLFilter.cs b/Src/Notion.Client/Models/Filters/URLFilter.cs index b2d4c611..7c722832 100644 --- a/Src/Notion.Client/Models/Filters/URLFilter.cs +++ b/Src/Notion.Client/Models/Filters/URLFilter.cs @@ -1,7 +1,9 @@ -using Newtonsoft.Json; +using System.Diagnostics.CodeAnalysis; +using Newtonsoft.Json; namespace Notion.Client { + [SuppressMessage("ReSharper", "InconsistentNaming")] public class URLFilter : SinglePropertyFilter { public URLFilter( diff --git a/Src/Notion.Client/Models/Parents/IParent.cs b/Src/Notion.Client/Models/Parents/IParent.cs index e2c50e5f..ccf3999b 100644 --- a/Src/Notion.Client/Models/Parents/IParent.cs +++ b/Src/Notion.Client/Models/Parents/IParent.cs @@ -1,8 +1,10 @@ -using Newtonsoft.Json; +using System.Diagnostics.CodeAnalysis; +using Newtonsoft.Json; using Newtonsoft.Json.Converters; namespace Notion.Client { + [SuppressMessage("ReSharper", "UnusedMemberInSuper.Global")] public interface IParent { [JsonConverter(typeof(StringEnumConverter))] diff --git a/Src/Notion.Client/Models/Parents/ParentType.cs b/Src/Notion.Client/Models/Parents/ParentType.cs index 29126694..347414f9 100644 --- a/Src/Notion.Client/Models/Parents/ParentType.cs +++ b/Src/Notion.Client/Models/Parents/ParentType.cs @@ -1,7 +1,9 @@ -using System.Runtime.Serialization; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.Serialization; namespace Notion.Client { + [SuppressMessage("ReSharper", "UnusedMember.Global")] public enum ParentType { [EnumMember(Value = null)] diff --git a/Src/Notion.Client/Models/PropertyItems/ListPropertyItem.cs b/Src/Notion.Client/Models/PropertyItems/ListPropertyItem.cs index 5e35159c..d337ccfd 100644 --- a/Src/Notion.Client/Models/PropertyItems/ListPropertyItem.cs +++ b/Src/Notion.Client/Models/PropertyItems/ListPropertyItem.cs @@ -1,8 +1,11 @@ using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using Newtonsoft.Json; namespace Notion.Client { + [SuppressMessage("ReSharper", "ClassWithVirtualMembersNeverInherited.Global")] + [SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global")] public class ListPropertyItem : IPropertyItemObject { [JsonProperty("results")] diff --git a/Src/Notion.Client/Models/PropertyItems/SimplePropertyItem.cs b/Src/Notion.Client/Models/PropertyItems/SimplePropertyItem.cs index ed3bef38..6ba77c67 100644 --- a/Src/Notion.Client/Models/PropertyItems/SimplePropertyItem.cs +++ b/Src/Notion.Client/Models/PropertyItems/SimplePropertyItem.cs @@ -1,4 +1,5 @@ -using JsonSubTypes; +using System.Diagnostics.CodeAnalysis; +using JsonSubTypes; using Newtonsoft.Json; namespace Notion.Client @@ -24,6 +25,7 @@ namespace Notion.Client [JsonSubtypes.KnownSubTypeAttribute(typeof(PeoplePropertyItem), "people")] [JsonSubtypes.KnownSubTypeAttribute(typeof(RelationPropertyItem), "relation")] [JsonSubtypes.KnownSubTypeAttribute(typeof(RollupPropertyItem), "rollup")] + [SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Global")] public abstract class SimplePropertyItem : IPropertyItemObject { public string Object => "property_item"; diff --git a/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs index f893e47a..c423be82 100644 --- a/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs @@ -1,4 +1,5 @@ -using JsonSubTypes; +using System.Diagnostics.CodeAnalysis; +using JsonSubTypes; using Newtonsoft.Json; using Newtonsoft.Json.Converters; @@ -28,6 +29,8 @@ namespace Notion.Client [JsonSubtypes.KnownSubTypeAttribute(typeof(StatusPropertyValue), PropertyValueType.Status)] [JsonSubtypes.KnownSubTypeAttribute(typeof(TitlePropertyValue), PropertyValueType.Title)] [JsonSubtypes.KnownSubTypeAttribute(typeof(UrlPropertyValue), PropertyValueType.Url)] + [SuppressMessage("ReSharper", "UnusedMember.Global")] + [SuppressMessage("ReSharper", "UnassignedGetOnlyAutoProperty")] public class PropertyValue { /// diff --git a/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs b/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs index f8fb0a30..96ddaf77 100644 --- a/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs +++ b/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs @@ -1,10 +1,12 @@ -using System.Runtime.Serialization; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.Serialization; namespace Notion.Client { /// /// Types of Property Value /// + [SuppressMessage("ReSharper", "UnusedMember.Global")] public enum PropertyValueType { [EnumMember(Value = null)] diff --git a/Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs index 487b27c8..29a64ef7 100644 --- a/Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs @@ -1,4 +1,5 @@ -using System.Runtime.Serialization; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.Serialization; using Newtonsoft.Json; using Newtonsoft.Json.Converters; @@ -9,7 +10,9 @@ namespace Notion.Client /// public class StatusPropertyValue : PropertyValue { - public enum Color + [SuppressMessage("ReSharper", "UnusedMember.Global")] + [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] + public enum StatusColor { [EnumMember(Value = "default")] Default, @@ -66,7 +69,7 @@ public class Data /// [JsonProperty("color")] [JsonConverter(typeof(StringEnumConverter))] - public Color? Color { get; set; } + public StatusColor? Color { get; set; } } } } diff --git a/Src/Notion.Client/Models/User/PartialUser.cs b/Src/Notion.Client/Models/User/PartialUser.cs index 5b335f0b..7e74c6d8 100644 --- a/Src/Notion.Client/Models/User/PartialUser.cs +++ b/Src/Notion.Client/Models/User/PartialUser.cs @@ -1,5 +1,8 @@ -namespace Notion.Client +using System.Diagnostics.CodeAnalysis; + +namespace Notion.Client { + [SuppressMessage("ReSharper", "ClassNeverInstantiated.Global")] public class PartialUser : IObject { public string Id { get; set; } diff --git a/Src/Notion.Client/NotionAPIErrorCode.cs b/Src/Notion.Client/NotionAPIErrorCode.cs index 71e99d29..1dc822bd 100644 --- a/Src/Notion.Client/NotionAPIErrorCode.cs +++ b/Src/Notion.Client/NotionAPIErrorCode.cs @@ -1,7 +1,9 @@ -using System.Runtime.Serialization; +using System.Diagnostics.CodeAnalysis; +using System.Runtime.Serialization; namespace Notion.Client { + [SuppressMessage("ReSharper", "UnusedMember.Global")] public enum NotionAPIErrorCode { [EnumMember(Value = "invalid_json")] diff --git a/Src/Notion.Client/NotionApiException.cs b/Src/Notion.Client/NotionApiException.cs index c7c9d7d4..d11fea6f 100644 --- a/Src/Notion.Client/NotionApiException.cs +++ b/Src/Notion.Client/NotionApiException.cs @@ -1,21 +1,18 @@ using System; +using System.Diagnostics.CodeAnalysis; using System.Net; namespace Notion.Client { - public class NotionApiException : Exception + [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] + public sealed class NotionApiException : Exception { public NotionApiException(HttpStatusCode statusCode, NotionAPIErrorCode? notionAPIErrorCode, string message) : this(statusCode, notionAPIErrorCode, message, null) { } - public NotionApiException(HttpStatusCode statusCode, string message) - : this(statusCode, null, message, null) - { - } - - public NotionApiException( + private NotionApiException( HttpStatusCode statusCode, NotionAPIErrorCode? notionAPIErrorCode, string message, @@ -24,7 +21,7 @@ public NotionApiException( NotionAPIErrorCode = notionAPIErrorCode; StatusCode = statusCode; - Data.Add("StatusCode", statusCode); + Data.Add("StatusCode", StatusCode); Data.Add("NotionApiErrorCode", NotionAPIErrorCode); } diff --git a/Src/Notion.Client/NotionClient.cs b/Src/Notion.Client/NotionClient.cs index f752413a..ca0c1334 100644 --- a/Src/Notion.Client/NotionClient.cs +++ b/Src/Notion.Client/NotionClient.cs @@ -1,5 +1,8 @@ -namespace Notion.Client +using System.Diagnostics.CodeAnalysis; + +namespace Notion.Client { + [SuppressMessage("ReSharper", "UnusedMemberInSuper.Global")] public interface INotionClient { IUsersClient Users { get; } @@ -20,13 +23,13 @@ public interface INotionClient public class NotionClient : INotionClient { public NotionClient( - RestClient restClient, - UsersClient users, - DatabasesClient databases, - PagesClient pages, - SearchClient search, - CommentsClient comments, - BlocksClient blocks) + IRestClient restClient, + IUsersClient users, + IDatabasesClient databases, + IPagesClient pages, + ISearchClient search, + ICommentsClient comments, + IBlocksClient blocks) { RestClient = restClient; Users = users; diff --git a/Src/Notion.Client/RestClient/IRestClient.cs b/Src/Notion.Client/RestClient/IRestClient.cs index 792840b6..7abb8553 100644 --- a/Src/Notion.Client/RestClient/IRestClient.cs +++ b/Src/Notion.Client/RestClient/IRestClient.cs @@ -34,7 +34,6 @@ Task DeleteAsync( string uri, IDictionary queryParams = null, IDictionary headers = null, - JsonSerializerSettings serializerSettings = null, CancellationToken cancellationToken = default); } } diff --git a/Src/Notion.Client/RestClient/RestClient.cs b/Src/Notion.Client/RestClient/RestClient.cs index 23993086..307fcd7a 100644 --- a/Src/Notion.Client/RestClient/RestClient.cs +++ b/Src/Notion.Client/RestClient/RestClient.cs @@ -16,7 +16,7 @@ public class RestClient : IRestClient { private readonly ClientOptions _options; - protected readonly JsonSerializerSettings defaultSerializerSettings = new() + protected readonly JsonSerializerSettings DefaultSerializerSettings = new() { NullValueHandling = NullValueHandling.Ignore, ContractResolver = new DefaultContractResolver { NamingStrategy = new CamelCaseNamingStrategy() } @@ -52,7 +52,7 @@ public async Task PostAsync( { void AttachContent(HttpRequestMessage httpRequest) { - httpRequest.Content = new StringContent(JsonConvert.SerializeObject(body, defaultSerializerSettings), + httpRequest.Content = new StringContent(JsonConvert.SerializeObject(body, DefaultSerializerSettings), Encoding.UTF8, "application/json"); } @@ -72,7 +72,7 @@ public async Task PatchAsync( { void AttachContent(HttpRequestMessage httpRequest) { - var serializedBody = JsonConvert.SerializeObject(body, defaultSerializerSettings); + var serializedBody = JsonConvert.SerializeObject(body, DefaultSerializerSettings); httpRequest.Content = new StringContent(serializedBody, Encoding.UTF8, "application/json"); } @@ -86,7 +86,6 @@ public async Task DeleteAsync( string uri, IDictionary queryParams = null, IDictionary headers = null, - JsonSerializerSettings serializerSettings = null, CancellationToken cancellationToken = default) { await SendAsync(uri, HttpMethod.Delete, queryParams, headers, null, cancellationToken); @@ -97,8 +96,8 @@ private static ClientOptions MergeOptions(ClientOptions options) return new ClientOptions { AuthToken = options.AuthToken, - BaseUrl = options.BaseUrl ?? Constants.BASE_URL, - NotionVersion = options.NotionVersion ?? Constants.DEFAULT_NOTION_VERSION + BaseUrl = options.BaseUrl ?? Constants.BaseUrl, + NotionVersion = options.NotionVersion ?? Constants.DefaultNotionVersion }; } @@ -123,7 +122,7 @@ private static async Task BuildException(HttpResponseMessage response return new NotionApiException(response.StatusCode, errorResponse?.ErrorCode, errorResponse?.Message); } - public async Task SendAsync( + private async Task SendAsync( string requestUri, HttpMethod httpMethod, IDictionary queryParams = null, @@ -164,17 +163,17 @@ private static void AddHeaders(HttpRequestMessage request, IDictionary queryParams) diff --git a/Src/Notion.Client/http/QueryHelpers.cs b/Src/Notion.Client/http/QueryHelpers.cs index 243bfbcd..530536f3 100644 --- a/Src/Notion.Client/http/QueryHelpers.cs +++ b/Src/Notion.Client/http/QueryHelpers.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Net; using System.Text; @@ -8,6 +9,7 @@ namespace Notion.Client.http { internal static class QueryHelpers { + [SuppressMessage("ReSharper", "UnusedMember.Global")] public static string AddQueryString(string uri, string name, string value) { if (uri == null) diff --git a/Test/Notion.IntegrationTests/CommentsClientTests.cs b/Test/Notion.IntegrationTests/CommentsClientTests.cs index 118a09d6..efc91a44 100644 --- a/Test/Notion.IntegrationTests/CommentsClientTests.cs +++ b/Test/Notion.IntegrationTests/CommentsClientTests.cs @@ -11,7 +11,6 @@ public class CommentsClientTests : IDisposable { private readonly INotionClient _client; private readonly Page _page; - private readonly string _pageParentId; public CommentsClientTests() { @@ -19,12 +18,12 @@ public CommentsClientTests() _client = NotionClientFactory.Create(options); - _pageParentId = Environment.GetEnvironmentVariable("NOTION_PAGE_PARENT_ID") ?? - throw new ArgumentNullException("Page parent id is required."); + var pageParentId = Environment.GetEnvironmentVariable("NOTION_PAGE_PARENT_ID") ?? + throw new InvalidOperationException("Page parent id is required."); _page = _client.Pages.CreateAsync( PagesCreateParametersBuilder.Create( - new ParentPageInput { PageId = _pageParentId } + new ParentPageInput { PageId = pageParentId } ).Build() ).Result; } diff --git a/Test/Notion.IntegrationTests/IBlocksClientTests.cs b/Test/Notion.IntegrationTests/IBlocksClientTests.cs index 6fc53999..34459f01 100644 --- a/Test/Notion.IntegrationTests/IBlocksClientTests.cs +++ b/Test/Notion.IntegrationTests/IBlocksClientTests.cs @@ -199,7 +199,7 @@ private static IEnumerable BlockData() block => { Assert.NotNull(block); - Assert.IsType(block); + _ = Assert.IsType(block); }) }, new object[] @@ -239,7 +239,7 @@ private static IEnumerable BlockData() new TableOfContentsUpdateBlock(), new Action(block => { Assert.NotNull(block); - Assert.IsType(block); + _ = Assert.IsType(block); }) }, new object[] diff --git a/Test/Notion.IntegrationTests/IPageClientTests.cs b/Test/Notion.IntegrationTests/IPageClientTests.cs index 3b861f8e..fb3dafaa 100644 --- a/Test/Notion.IntegrationTests/IPageClientTests.cs +++ b/Test/Notion.IntegrationTests/IPageClientTests.cs @@ -146,13 +146,18 @@ public async Task Test_UpdatePageProperty_with_date_as_null() { // setup - add property to db and create a page with the property having a date - var datePropertyName = "Test Date Property"; - var updateDatabaseParameters = new DatabasesUpdateParameters(); + const string DatePropertyName = "Test Date Property"; - updateDatabaseParameters.Properties = new Dictionary + var updateDatabaseParameters = new DatabasesUpdateParameters { - { "Name", new TitleUpdatePropertySchema { Title = new Dictionary() } }, - { "Test Date Property", new DateUpdatePropertySchema { Date = new Dictionary() } } + Properties = new Dictionary + { + { "Name", new TitleUpdatePropertySchema { Title = new Dictionary() } }, + { + "Test Date Property", + new DateUpdatePropertySchema { Date = new Dictionary() } + } + } }; var pagesCreateParameters = PagesCreateParametersBuilder @@ -165,7 +170,7 @@ public async Task Test_UpdatePageProperty_with_date_as_null() new RichTextText { Text = new Text { Content = "Test Page Title" } } } }) - .AddProperty(datePropertyName, + .AddProperty(DatePropertyName, new DatePropertyValue { Date = new Date @@ -176,14 +181,14 @@ public async Task Test_UpdatePageProperty_with_date_as_null() }) .Build(); - var updatedDb = await _client.Databases.UpdateAsync(_databaseId, updateDatabaseParameters); + await _client.Databases.UpdateAsync(_databaseId, updateDatabaseParameters); var page = await _client.Pages.CreateAsync(pagesCreateParameters); var setDate = (DatePropertyItem)await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters { PageId = page.Id, - PropertyId = page.Properties[datePropertyName].Id + PropertyId = page.Properties[DatePropertyName].Id }); setDate?.Date?.Start.Should().Be(Convert.ToDateTime("2020-12-08T12:00:00Z")); @@ -191,7 +196,7 @@ public async Task Test_UpdatePageProperty_with_date_as_null() // verify IDictionary testProps = new Dictionary(); - testProps.Add(datePropertyName, new DatePropertyValue { Date = null }); + testProps.Add(DatePropertyName, new DatePropertyValue { Date = null }); var updatedPage = await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Properties = testProps }); @@ -200,7 +205,7 @@ public async Task Test_UpdatePageProperty_with_date_as_null() new RetrievePropertyItemParameters { PageId = page.Id, - PropertyId = updatedPage.Properties[datePropertyName].Id + PropertyId = updatedPage.Properties[DatePropertyName].Id }); verifyDate?.Date.Should().BeNull(); diff --git a/Test/Notion.UnitTests/ApiTestBase.cs b/Test/Notion.UnitTests/ApiTestBase.cs index 6c0f3a97..51dfd7fc 100644 --- a/Test/Notion.UnitTests/ApiTestBase.cs +++ b/Test/Notion.UnitTests/ApiTestBase.cs @@ -1,7 +1,5 @@ using System; using System.Linq; -using Newtonsoft.Json; -using Newtonsoft.Json.Serialization; using Notion.Client; using WireMock.Matchers; using WireMock.RequestBuilders; @@ -11,12 +9,6 @@ namespace Notion.UnitTests; public class ApiTestBase : IDisposable { - protected static readonly JsonSerializerSettings JsonSerializerSettings = new() - { - Formatting = Formatting.Indented, - ContractResolver = new DefaultContractResolver { NamingStrategy = new CamelCaseNamingStrategy() } - }; - protected readonly ClientOptions ClientOptions; protected readonly WireMockServer Server; @@ -43,7 +35,7 @@ protected IRequestBuilder CreateGetRequestBuilder(string path) .WithPath(path) .UsingGet() .WithHeader("Authorization", $"Bearer {ClientOptions.AuthToken}", MatchBehaviour.AcceptOnMatch) - .WithHeader("Notion-Version", Constants.DEFAULT_NOTION_VERSION, MatchBehaviour.AcceptOnMatch); + .WithHeader("Notion-Version", Constants.DefaultNotionVersion, MatchBehaviour.AcceptOnMatch); } protected IRequestBuilder CreatePostRequestBuilder(string path) @@ -52,7 +44,7 @@ protected IRequestBuilder CreatePostRequestBuilder(string path) .WithPath(path) .UsingPost() .WithHeader("Authorization", $"Bearer {ClientOptions.AuthToken}", MatchBehaviour.AcceptOnMatch) - .WithHeader("Notion-Version", Constants.DEFAULT_NOTION_VERSION, MatchBehaviour.AcceptOnMatch); + .WithHeader("Notion-Version", Constants.DefaultNotionVersion, MatchBehaviour.AcceptOnMatch); } protected IRequestBuilder CreatePatchRequestBuilder(string path) @@ -61,6 +53,6 @@ protected IRequestBuilder CreatePatchRequestBuilder(string path) .WithPath(path) .UsingPatch() .WithHeader("Authorization", $"Bearer {ClientOptions.AuthToken}", MatchBehaviour.AcceptOnMatch) - .WithHeader("Notion-Version", Constants.DEFAULT_NOTION_VERSION, MatchBehaviour.AcceptOnMatch); + .WithHeader("Notion-Version", Constants.DefaultNotionVersion, MatchBehaviour.AcceptOnMatch); } } diff --git a/Test/Notion.UnitTests/BlocksClientTests.cs b/Test/Notion.UnitTests/BlocksClientTests.cs index 97e54404..5d436b97 100644 --- a/Test/Notion.UnitTests/BlocksClientTests.cs +++ b/Test/Notion.UnitTests/BlocksClientTests.cs @@ -107,14 +107,14 @@ public async Task AppendBlockChildren() { block.Type.Should().Be(BlockType.Heading_2); var headingBlock = (HeadingTwoBlock)block; - var text = headingBlock.Heading_2.RichText.OfType().FirstOrDefault(); + var text = headingBlock.Heading_2.RichText.OfType().First(); text.Text.Content.Should().Be("Lacinato kale"); }, block => { block.Type.Should().Be(BlockType.Paragraph); var paragraphBlock = (ParagraphBlock)block; - var text = paragraphBlock.Paragraph.RichText.OfType().LastOrDefault(); + var text = paragraphBlock.Paragraph.RichText.OfType().Last(); text.Text.Content.Should().Be( "Lacinato kale is a variety of kale with a long tradition in Italian cuisine, especially that of Tuscany. It is also known as Tuscan kale, Italian kale, dinosaur kale, kale, flat back kale, palm tree kale, or black Tuscan palm."); diff --git a/Test/Notion.UnitTests/DatabasesClientTests.cs b/Test/Notion.UnitTests/DatabasesClientTests.cs index d29677ea..326bd55a 100644 --- a/Test/Notion.UnitTests/DatabasesClientTests.cs +++ b/Test/Notion.UnitTests/DatabasesClientTests.cs @@ -190,54 +190,53 @@ public async Task CreateDatabaseAsync() .WithBody(jsonData) ); - var createDatabaseParameters = new DatabasesCreateParameters(); - - createDatabaseParameters.Parent = new ParentPageInput { PageId = pageId }; - - createDatabaseParameters.Title = new List + var createDatabaseParameters = new DatabasesCreateParameters { - new RichTextTextInput + Parent = new ParentPageInput { PageId = pageId }, + Title = new List { - Text = new Text + new RichTextTextInput { - Content = "Grocery List", - Link = null + Text = new Text + { + Content = "Grocery List", + Link = null + } } - } - }; - - createDatabaseParameters.Properties = new Dictionary - { - { "Name", new TitlePropertySchema { Title = new Dictionary() } }, - { "Price", new NumberPropertySchema { Number = new Number { Format = "dollar" } } }, + }, + Properties = new Dictionary { - "Food group", - new SelectPropertySchema + { "Name", new TitlePropertySchema { Title = new Dictionary() } }, + { "Price", new NumberPropertySchema { Number = new Number { Format = "dollar" } } }, { - Select = new OptionWrapper + "Food group", + new SelectPropertySchema { - Options = new List + Select = new OptionWrapper { - new() - { - Color = Color.Green, - Name = "🥦Vegetable" - }, - new() - { - Color = Color.Red, - Name = "🍎Fruit" - }, - new() + Options = new List { - Color = Color.Yellow, - Name = "💪Protein" + new() + { + Color = Color.Green, + Name = "🥦Vegetable" + }, + new() + { + Color = Color.Red, + Name = "🍎Fruit" + }, + new() + { + Color = Color.Yellow, + Name = "💪Protein" + } } } } - } - }, - { "Last ordered", new DatePropertySchema { Date = new Dictionary() } } + }, + { "Last ordered", new DatePropertySchema { Date = new Dictionary() } } + } }; var database = await _client.CreateAsync(createDatabaseParameters); @@ -284,52 +283,53 @@ public async Task UpdateDatabaseAsync() .WithBody(jsonData) ); - var updateDatabaseParameters = new DatabasesUpdateParameters(); - - updateDatabaseParameters.Title = new List + var updateDatabaseParameters = new DatabasesUpdateParameters { - new RichTextTextInput - { - Text = new Text + Title = + new List { - Content = "Grocery List New", - Link = null - } - } - }; - - updateDatabaseParameters.Properties = new Dictionary - { - { "Name", new TitleUpdatePropertySchema { Title = new Dictionary() } }, - { "Price", new NumberUpdatePropertySchema { Number = new Number { Format = "yen" } } }, + new RichTextTextInput + { + Text = new Text + { + Content = "Grocery List New", + Link = null + } + } + }, + Properties = new Dictionary { - "Food group", - new SelectUpdatePropertySchema + { "Name", new TitleUpdatePropertySchema { Title = new Dictionary() } }, + { "Price", new NumberUpdatePropertySchema { Number = new Number { Format = "yen" } } }, { - Select = new OptionWrapper + "Food group", + new SelectUpdatePropertySchema { - Options = new List + Select = new OptionWrapper { - new() + Options = new List { - Color = Color.Green, - Name = "🥦Vegetables" - }, - new() - { - Color = Color.Red, - Name = "🍎Fruit" - }, - new() - { - Color = Color.Yellow, - Name = "💪Protein" + new() + { + Color = Color.Green, + Name = "🥦Vegetables" + }, + new() + { + Color = Color.Red, + Name = "🍎Fruit" + }, + new() + { + Color = Color.Yellow, + Name = "💪Protein" + } } } } - } - }, - { "Last ordered", new DateUpdatePropertySchema { Date = new Dictionary() } } + }, + { "Last ordered", new DateUpdatePropertySchema { Date = new Dictionary() } } + } }; var database = await _client.UpdateAsync(databaseId, updateDatabaseParameters); @@ -391,32 +391,31 @@ var jsonData .WithBody(jsonData) ); - var createDatabaseParameters = new DatabasesCreateParameters(); - - createDatabaseParameters.Parent = new ParentPageInput { PageId = pageId }; - - createDatabaseParameters.Title = new List + var createDatabaseParameters = new DatabasesCreateParameters { - new RichTextTextInput + Parent = new ParentPageInput { PageId = pageId }, + Title = new List { - Text = new Text + new RichTextTextInput { - Content = "Grocery List", - Link = null + Text = new Text + { + Content = "Grocery List", + Link = null + } } - } - }; - - createDatabaseParameters.Properties = new Dictionary - { + }, + Properties = new Dictionary { - "Cost of next trip", - new FormulaPropertySchema { - Formula = new Formula { Expression = "if(prop(\"In stock\"), 0, prop(\"Price\"))" } - } - }, - { "Price", new NumberPropertySchema { Number = new Number { Format = "dollar" } } } + "Cost of next trip", + new FormulaPropertySchema + { + Formula = new Formula { Expression = "if(prop(\"In stock\"), 0, prop(\"Price\"))" } + } + }, + { "Price", new NumberPropertySchema { Number = new Number { Format = "dollar" } } } + } }; var database = await _client.CreateAsync(createDatabaseParameters); diff --git a/Test/Notion.UnitTests/FilterTests.cs b/Test/Notion.UnitTests/FilterTests.cs index 6fab8aaa..39b90229 100644 --- a/Test/Notion.UnitTests/FilterTests.cs +++ b/Test/Notion.UnitTests/FilterTests.cs @@ -6,18 +6,6 @@ namespace Notion.UnitTests; -public class SerializerSettingsSource : RestClient -{ - public SerializerSettingsSource(ClientOptions options) : base(options) - { - } - - public JsonSerializerSettings GetSerializerSettings() - { - return defaultSerializerSettings; - } -} - public class FilterTests { private readonly SerializerSettingsSource _settingsSource = new(new ClientOptions()); @@ -146,4 +134,16 @@ public void RichTextFilterTest() SerializeFilter(filter) ); } + + private class SerializerSettingsSource : RestClient + { + public SerializerSettingsSource(ClientOptions options) : base(options) + { + } + + public JsonSerializerSettings GetSerializerSettings() + { + return DefaultSerializerSettings; + } + } } diff --git a/Test/Notion.UnitTests/PropertyTests.cs b/Test/Notion.UnitTests/PropertyTests.cs index c8196f15..07949131 100644 --- a/Test/Notion.UnitTests/PropertyTests.cs +++ b/Test/Notion.UnitTests/PropertyTests.cs @@ -30,7 +30,7 @@ public void TestPropertyType(Type type, PropertyType expectedPropertyType) { var typeInstance = (Property)Activator.CreateInstance(type); - var actualPropertyType = typeInstance.Type; + var actualPropertyType = typeInstance!.Type; Assert.Equal(expectedPropertyType, actualPropertyType); } @@ -58,7 +58,7 @@ public void TestPropertyTypeText(Type type, string expectedPropertyType) { var typeInstance = (Property)Activator.CreateInstance(type); - var actualPropertyType = typeInstance.Type.GetEnumMemberValue(); + var actualPropertyType = typeInstance!.Type.GetEnumMemberValue(); Assert.Equal(expectedPropertyType, actualPropertyType); } From 00cbcbcbb1fae55f6ff3e11139d30377452db06d Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 8 Oct 2022 18:38:21 +0530 Subject: [PATCH 119/216] =?UTF-8?q?Modernize=20check.sh=20script=20?= =?UTF-8?q?=E2=99=BB=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/scripts/check.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/check.sh b/.github/scripts/check.sh index d6132c92..3006888a 100644 --- a/.github/scripts/check.sh +++ b/.github/scripts/check.sh @@ -2,7 +2,7 @@ dotnet jb inspectcode Notion.sln -f="Text" --no-build --include="**.cs" -o=".lint/CodeWarningResults.txt" -totalLines=`cat .lint/CodeWarningResults.txt | grep "^.*$" -c` +totalLines=$(file .lint/CodeWarningResults.txt | nl | wc -l) if [[ "$totalLines" -gt 1 ]]; then echo "There are few linter warnings - please fix them before running the pipeline" From 8f81dc44775a034ce762266bddea54b96b60c8e5 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 8 Oct 2022 19:47:13 +0530 Subject: [PATCH 120/216] =?UTF-8?q?Revert=20the=20removal=20of=20Retrieve?= =?UTF-8?q?=20API=20from=20ICommentsClient=20=E2=8F=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Notion.Client/Api/Comments/ICommentsClient.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Src/Notion.Client/Api/Comments/ICommentsClient.cs b/Src/Notion.Client/Api/Comments/ICommentsClient.cs index 8ec81348..49062a34 100644 --- a/Src/Notion.Client/Api/Comments/ICommentsClient.cs +++ b/Src/Notion.Client/Api/Comments/ICommentsClient.cs @@ -5,5 +5,7 @@ namespace Notion.Client public interface ICommentsClient { Task Create(CreateCommentParameters createCommentParameters); + + Task Retrieve(RetrieveCommentsParameters parameters); } } From a2d121f2eeb33f96331a88a71acd8c709a3e5c7c Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 8 Oct 2022 20:02:39 +0530 Subject: [PATCH 121/216] Add Async to follow same conventions --- .../Api/Comments/Create/CommentsClient.cs | 2 +- .../Api/Comments/ICommentsClient.cs | 4 +++- .../Api/Comments/Retrieve/CommentsClient.cs | 2 +- Src/Notion.Client/Api/Pages/IPagesClient.cs | 2 +- Src/Notion.Client/Api/Pages/PagesClient.cs | 2 +- .../CommentsClientTests.cs | 6 ++--- .../IPageClientTests.cs | 24 ++++++++++--------- Test/Notion.UnitTests/DatabasesClientTests.cs | 2 +- Test/Notion.UnitTests/PagesClientTests.cs | 6 ++--- 9 files changed, 27 insertions(+), 23 deletions(-) diff --git a/Src/Notion.Client/Api/Comments/Create/CommentsClient.cs b/Src/Notion.Client/Api/Comments/Create/CommentsClient.cs index 12f1207b..cb3b9bd1 100644 --- a/Src/Notion.Client/Api/Comments/Create/CommentsClient.cs +++ b/Src/Notion.Client/Api/Comments/Create/CommentsClient.cs @@ -4,7 +4,7 @@ namespace Notion.Client { public partial class CommentsClient { - public async Task Create(CreateCommentParameters parameters) + public async Task CreateAsync(CreateCommentParameters parameters) { var body = (ICreateCommentsBodyParameters)parameters; diff --git a/Src/Notion.Client/Api/Comments/ICommentsClient.cs b/Src/Notion.Client/Api/Comments/ICommentsClient.cs index 8ec81348..1b89dcd7 100644 --- a/Src/Notion.Client/Api/Comments/ICommentsClient.cs +++ b/Src/Notion.Client/Api/Comments/ICommentsClient.cs @@ -4,6 +4,8 @@ namespace Notion.Client { public interface ICommentsClient { - Task Create(CreateCommentParameters createCommentParameters); + Task CreateAsync(CreateCommentParameters createCommentParameters); + + Task RetrieveAsync(RetrieveCommentsParameters parameters); } } diff --git a/Src/Notion.Client/Api/Comments/Retrieve/CommentsClient.cs b/Src/Notion.Client/Api/Comments/Retrieve/CommentsClient.cs index eb1546ab..22964c5f 100644 --- a/Src/Notion.Client/Api/Comments/Retrieve/CommentsClient.cs +++ b/Src/Notion.Client/Api/Comments/Retrieve/CommentsClient.cs @@ -7,7 +7,7 @@ namespace Notion.Client public partial class CommentsClient { [SuppressMessage("ReSharper", "UnusedMember.Global")] - public async Task Retrieve(RetrieveCommentsParameters parameters) + public async Task RetrieveAsync(RetrieveCommentsParameters parameters) { var qp = (IRetrieveCommentsQueryParameters)parameters; diff --git a/Src/Notion.Client/Api/Pages/IPagesClient.cs b/Src/Notion.Client/Api/Pages/IPagesClient.cs index f6b8f94f..755b385f 100644 --- a/Src/Notion.Client/Api/Pages/IPagesClient.cs +++ b/Src/Notion.Client/Api/Pages/IPagesClient.cs @@ -57,7 +57,7 @@ Task UpdatePropertiesAsync( /// /// /// - Task RetrievePagePropertyItem( + Task RetrievePagePropertyItemAsync( RetrievePropertyItemParameters retrievePropertyItemParameters); } } diff --git a/Src/Notion.Client/Api/Pages/PagesClient.cs b/Src/Notion.Client/Api/Pages/PagesClient.cs index 91c59a64..43fe143e 100644 --- a/Src/Notion.Client/Api/Pages/PagesClient.cs +++ b/Src/Notion.Client/Api/Pages/PagesClient.cs @@ -54,7 +54,7 @@ public async Task RetrieveAsync(string pageId) return await _client.GetAsync(url); } - public async Task RetrievePagePropertyItem( + public async Task RetrievePagePropertyItemAsync( RetrievePropertyItemParameters retrievePropertyItemParameters) { var pathParameters = (IRetrievePropertyItemPathParameters)retrievePropertyItemParameters; diff --git a/Test/Notion.IntegrationTests/CommentsClientTests.cs b/Test/Notion.IntegrationTests/CommentsClientTests.cs index efc91a44..35a8b87d 100644 --- a/Test/Notion.IntegrationTests/CommentsClientTests.cs +++ b/Test/Notion.IntegrationTests/CommentsClientTests.cs @@ -43,7 +43,7 @@ public async Task ShouldCreatePageComment() ); // Act - var response = await _client.Comments.Create(parameters); + var response = await _client.Comments.CreateAsync(parameters); // Arrange @@ -64,7 +64,7 @@ public async Task ShouldCreatePageComment() public async Task ShouldCreateADiscussionComment() { // Arrange - var comment = await _client.Comments.Create( + var comment = await _client.Comments.CreateAsync( CreateCommentParameters.CreatePageComment( new ParentPageInput { PageId = _page.Id }, new List @@ -75,7 +75,7 @@ public async Task ShouldCreateADiscussionComment() ); // Act - var response = await _client.Comments.Create( + var response = await _client.Comments.CreateAsync( CreateCommentParameters.CreateDiscussionComment( comment.DiscussionId, new List diff --git a/Test/Notion.IntegrationTests/IPageClientTests.cs b/Test/Notion.IntegrationTests/IPageClientTests.cs index fb3dafaa..16051f42 100644 --- a/Test/Notion.IntegrationTests/IPageClientTests.cs +++ b/Test/Notion.IntegrationTests/IPageClientTests.cs @@ -47,7 +47,7 @@ public async Task CreateAsync_CreatesANewPage() var pageProperty = page.Properties["Name"].Should().BeOfType().Subject; var titleProperty - = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItem( + = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItemAsync( new RetrievePropertyItemParameters { PageId = page.Id, @@ -87,7 +87,7 @@ public async Task Bug_unable_to_create_page_with_select_property() var pageProperty = page.Properties["Name"].Should().BeOfType().Subject; var titleProperty - = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItem( + = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItemAsync( new RetrievePropertyItemParameters { PageId = page.Id, @@ -116,7 +116,7 @@ public async Task Test_RetrievePagePropertyItemAsync() var page = await _client.Pages.CreateAsync(pagesCreateParameters); - var property = await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters + var property = await _client.Pages.RetrievePagePropertyItemAsync(new RetrievePropertyItemParameters { PageId = page.Id, PropertyId = "title" @@ -185,11 +185,13 @@ public async Task Test_UpdatePageProperty_with_date_as_null() var page = await _client.Pages.CreateAsync(pagesCreateParameters); - var setDate = (DatePropertyItem)await _client.Pages.RetrievePagePropertyItem(new RetrievePropertyItemParameters - { - PageId = page.Id, - PropertyId = page.Properties[DatePropertyName].Id - }); + var setDate = (DatePropertyItem)await _client.Pages.RetrievePagePropertyItemAsync( + new RetrievePropertyItemParameters + { + PageId = page.Id, + PropertyId = page.Properties[DatePropertyName].Id + } + ); setDate?.Date?.Start.Should().Be(Convert.ToDateTime("2020-12-08T12:00:00Z")); @@ -201,7 +203,7 @@ public async Task Test_UpdatePageProperty_with_date_as_null() var updatedPage = await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Properties = testProps }); - var verifyDate = (DatePropertyItem)await _client.Pages.RetrievePagePropertyItem( + var verifyDate = (DatePropertyItem)await _client.Pages.RetrievePagePropertyItemAsync( new RetrievePropertyItemParameters { PageId = page.Id, @@ -236,7 +238,7 @@ public async Task Bug_Unable_To_Parse_NumberPropertyItem() var pageParent = Assert.IsType(page.Parent); Assert.Equal(_databaseId, pageParent.DatabaseId); - var titleProperty = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItem( + var titleProperty = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItemAsync( new RetrievePropertyItemParameters { PageId = page.Id, @@ -245,7 +247,7 @@ public async Task Bug_Unable_To_Parse_NumberPropertyItem() Assert.Equal("Test Page Title", titleProperty.Results.First().As().Title.PlainText); - var numberProperty = (NumberPropertyItem)await _client.Pages.RetrievePagePropertyItem( + var numberProperty = (NumberPropertyItem)await _client.Pages.RetrievePagePropertyItemAsync( new RetrievePropertyItemParameters { PageId = page.Id, diff --git a/Test/Notion.UnitTests/DatabasesClientTests.cs b/Test/Notion.UnitTests/DatabasesClientTests.cs index 326bd55a..fc06ebc7 100644 --- a/Test/Notion.UnitTests/DatabasesClientTests.cs +++ b/Test/Notion.UnitTests/DatabasesClientTests.cs @@ -490,7 +490,7 @@ var jsonData "{\"object\":\"property_item\",\"id\":\"JwY^\",\"type\":\"formula\",\"formula\":{\"type\":\"date\",\"date\":{\"start\":\"2021-06-28\",\"end\":null}}}") ); - var formulaPropertyValue = (FormulaPropertyItem)await _pagesClient.RetrievePagePropertyItem( + var formulaPropertyValue = (FormulaPropertyItem)await _pagesClient.RetrievePagePropertyItemAsync( new RetrievePropertyItemParameters { PageId = page.Id, diff --git a/Test/Notion.UnitTests/PagesClientTests.cs b/Test/Notion.UnitTests/PagesClientTests.cs index 87c32dae..adbb9443 100644 --- a/Test/Notion.UnitTests/PagesClientTests.cs +++ b/Test/Notion.UnitTests/PagesClientTests.cs @@ -110,7 +110,7 @@ public async Task UpdatePropertiesAsync() page.Properties.Should().HaveCount(2); var updatedProperty = page.Properties.First(x => x.Key == "In stock"); - var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItem( + var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItemAsync( new RetrievePropertyItemParameters { PageId = page.Id, @@ -176,7 +176,7 @@ public async Task UpdatePageAsync() page.Properties.Should().HaveCount(2); var updatedProperty = page.Properties.First(x => x.Key == "In stock"); - var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItem( + var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItemAsync( new RetrievePropertyItemParameters { PageId = page.Id, @@ -225,7 +225,7 @@ public async Task ArchivePageAsync() page.Properties.Should().HaveCount(2); var updatedProperty = page.Properties.First(x => x.Key == "In stock"); - var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItem( + var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItemAsync( new RetrievePropertyItemParameters { PageId = page.Id, From 2b2189fd679a963a406eb8b88394d9fced04b886 Mon Sep 17 00:00:00 2001 From: sotiriszogos Date: Sat, 8 Oct 2022 19:29:42 +0300 Subject: [PATCH 122/216] Fixing typo issues --- .../UpdateBlocks/HeadingThreeeUpdateBlock.cs | 2 +- .../PropertySchema/RelationPropertySchema.cs | 4 ++-- .../PropertySchema/RelationUpdatePropertySchema.cs | 4 ++-- Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs | 2 +- Src/Notion.Client/Models/Blocks/IBlock.cs | 2 +- Src/Notion.Client/Models/Blocks/IColumnChildrenBlock.cs | 4 ++-- Src/Notion.Client/Models/Blocks/TemplateBlock.cs | 2 +- Test/Notion.IntegrationTests/IBlocksClientTests.cs | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/HeadingThreeeUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/HeadingThreeeUpdateBlock.cs index 353d1a98..d2eb4861 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/HeadingThreeeUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/HeadingThreeeUpdateBlock.cs @@ -4,7 +4,7 @@ namespace Notion.Client { - public class HeadingThreeeUpdateBlock : UpdateBlock + public class HeadingThreeUpdateBlock : UpdateBlock { [JsonProperty("heading_3")] [SuppressMessage("ReSharper", "InconsistentNaming")] diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/RelationPropertySchema.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/RelationPropertySchema.cs index bee17690..fa6a3249 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/RelationPropertySchema.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/RelationPropertySchema.cs @@ -14,10 +14,10 @@ public class RelationInfo public Guid DatabaseId { get; set; } [JsonProperty("synced_property_id")] - public string SynchedPropertyId { get; set; } + public string SyncedPropertyId { get; set; } [JsonProperty("synced_property_name")] - public string SynchedPropertyName { get; set; } + public string SyncedPropertyName { get; set; } } } } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/RelationUpdatePropertySchema.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/RelationUpdatePropertySchema.cs index 1565cd4a..4f6a74a3 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/RelationUpdatePropertySchema.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/RelationUpdatePropertySchema.cs @@ -14,10 +14,10 @@ public class RelationInfo public Guid DatabaseId { get; set; } [JsonProperty("synced_property_id")] - public string SynchedPropertyId { get; set; } + public string SyncedPropertyId { get; set; } [JsonProperty("synced_property_name")] - public string SynchedPropertyName { get; set; } + public string SyncedPropertyName { get; set; } } } } diff --git a/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs b/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs index c6abc213..deada7de 100644 --- a/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs +++ b/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs @@ -5,7 +5,7 @@ namespace Notion.Client { - public class HeadingThreeeBlock : Block, IColumnChildrenBlock, INonColumnBlock + public class HeadingThreeBlock : Block, IColumnChildrenBlock, INonColumnBlock { [JsonProperty("heading_3")] [SuppressMessage("ReSharper", "InconsistentNaming")] diff --git a/Src/Notion.Client/Models/Blocks/IBlock.cs b/Src/Notion.Client/Models/Blocks/IBlock.cs index fcf5364d..df625cf6 100644 --- a/Src/Notion.Client/Models/Blocks/IBlock.cs +++ b/Src/Notion.Client/Models/Blocks/IBlock.cs @@ -21,7 +21,7 @@ namespace Notion.Client [JsonSubtypes.KnownSubTypeAttribute(typeof(FileBlock), BlockType.File)] [JsonSubtypes.KnownSubTypeAttribute(typeof(HeadingOneBlock), BlockType.Heading_1)] [JsonSubtypes.KnownSubTypeAttribute(typeof(HeadingTwoBlock), BlockType.Heading_2)] - [JsonSubtypes.KnownSubTypeAttribute(typeof(HeadingThreeeBlock), BlockType.Heading_3)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(HeadingThreeBlock), BlockType.Heading_3)] [JsonSubtypes.KnownSubTypeAttribute(typeof(ImageBlock), BlockType.Image)] [JsonSubtypes.KnownSubTypeAttribute(typeof(LinkPreviewBlock), BlockType.LinkPreview)] [JsonSubtypes.KnownSubTypeAttribute(typeof(LinkToPageBlock), BlockType.LinkToPage)] diff --git a/Src/Notion.Client/Models/Blocks/IColumnChildrenBlock.cs b/Src/Notion.Client/Models/Blocks/IColumnChildrenBlock.cs index 8c1e1446..769487c8 100644 --- a/Src/Notion.Client/Models/Blocks/IColumnChildrenBlock.cs +++ b/Src/Notion.Client/Models/Blocks/IColumnChildrenBlock.cs @@ -1,6 +1,6 @@ namespace Notion.Client { - public interface ITemplateChildrendBlock : IBlock + public interface ITemplateChildrenBlock : IBlock { } @@ -8,7 +8,7 @@ public interface ISyncedBlockChildren : IBlock { } - public interface IColumnChildrenBlock : ITemplateChildrendBlock, ISyncedBlockChildren + public interface IColumnChildrenBlock : ITemplateChildrenBlock, ISyncedBlockChildren { } diff --git a/Src/Notion.Client/Models/Blocks/TemplateBlock.cs b/Src/Notion.Client/Models/Blocks/TemplateBlock.cs index 705eaac3..867e7c85 100644 --- a/Src/Notion.Client/Models/Blocks/TemplateBlock.cs +++ b/Src/Notion.Client/Models/Blocks/TemplateBlock.cs @@ -16,7 +16,7 @@ public class Data public IEnumerable RichText { get; set; } [JsonProperty("children")] - public IEnumerable Children { get; set; } + public IEnumerable Children { get; set; } } } } diff --git a/Test/Notion.IntegrationTests/IBlocksClientTests.cs b/Test/Notion.IntegrationTests/IBlocksClientTests.cs index 34459f01..51e32072 100644 --- a/Test/Notion.IntegrationTests/IBlocksClientTests.cs +++ b/Test/Notion.IntegrationTests/IBlocksClientTests.cs @@ -370,7 +370,7 @@ private static IEnumerable BlockData() { new RichTextText { Text = new Text { Content = "Test Template" } } }, - Children = new List + Children = new List { new EmbedBlock { From 36efddc5b1374bb082a03ad644c38b3043591662 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 8 Dec 2022 15:27:30 +0000 Subject: [PATCH 123/216] Bump Newtonsoft.Json from 13.0.1 to 13.0.2 in /Src/Notion.Client Bumps [Newtonsoft.Json](https://github.com/JamesNK/Newtonsoft.Json) from 13.0.1 to 13.0.2. - [Release notes](https://github.com/JamesNK/Newtonsoft.Json/releases) - [Commits](https://github.com/JamesNK/Newtonsoft.Json/compare/13.0.1...13.0.2) --- updated-dependencies: - dependency-name: Newtonsoft.Json dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- Src/Notion.Client/Notion.Client.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/Notion.Client/Notion.Client.csproj b/Src/Notion.Client/Notion.Client.csproj index 048db729..981fd1f7 100644 --- a/Src/Notion.Client/Notion.Client.csproj +++ b/Src/Notion.Client/Notion.Client.csproj @@ -19,7 +19,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + From bcd89906f7eaa57fb11b1c3cfd4bf14f61e14ca7 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Sat, 31 Dec 2022 21:28:47 +0530 Subject: [PATCH 124/216] Clean up integration tests --- .../CommentsClientTests.cs | 22 ++---- .../IBlocksClientTests.cs | 59 ++++++---------- .../IPageClientTests.cs | 67 ++++++++----------- .../IntegrationTestBase.cs | 24 +++++++ .../PageWithPageParentTests.cs | 63 +++++++++++++++++ 5 files changed, 143 insertions(+), 92 deletions(-) create mode 100644 Test/Notion.IntegrationTests/IntegrationTestBase.cs create mode 100644 Test/Notion.IntegrationTests/PageWithPageParentTests.cs diff --git a/Test/Notion.IntegrationTests/CommentsClientTests.cs b/Test/Notion.IntegrationTests/CommentsClientTests.cs index 35a8b87d..f2a84d21 100644 --- a/Test/Notion.IntegrationTests/CommentsClientTests.cs +++ b/Test/Notion.IntegrationTests/CommentsClientTests.cs @@ -7,30 +7,22 @@ namespace Notion.IntegrationTests; -public class CommentsClientTests : IDisposable +public class CommentsClientTests : IntegrationTestBase, IDisposable { - private readonly INotionClient _client; private readonly Page _page; public CommentsClientTests() { - var options = new ClientOptions { AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN") }; - - _client = NotionClientFactory.Create(options); - - var pageParentId = Environment.GetEnvironmentVariable("NOTION_PAGE_PARENT_ID") ?? - throw new InvalidOperationException("Page parent id is required."); - - _page = _client.Pages.CreateAsync( + _page = Client.Pages.CreateAsync( PagesCreateParametersBuilder.Create( - new ParentPageInput { PageId = pageParentId } + new ParentPageInput { PageId = ParentPageId } ).Build() ).Result; } public void Dispose() { - _client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters { Archived = true }).Wait(); + Client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters { Archived = true }).Wait(); } [Fact] @@ -43,7 +35,7 @@ public async Task ShouldCreatePageComment() ); // Act - var response = await _client.Comments.CreateAsync(parameters); + var response = await Client.Comments.CreateAsync(parameters); // Arrange @@ -64,7 +56,7 @@ public async Task ShouldCreatePageComment() public async Task ShouldCreateADiscussionComment() { // Arrange - var comment = await _client.Comments.CreateAsync( + var comment = await Client.Comments.CreateAsync( CreateCommentParameters.CreatePageComment( new ParentPageInput { PageId = _page.Id }, new List @@ -75,7 +67,7 @@ public async Task ShouldCreateADiscussionComment() ); // Act - var response = await _client.Comments.CreateAsync( + var response = await Client.Comments.CreateAsync( CreateCommentParameters.CreateDiscussionComment( comment.DiscussionId, new List diff --git a/Test/Notion.IntegrationTests/IBlocksClientTests.cs b/Test/Notion.IntegrationTests/IBlocksClientTests.cs index 51e32072..9aed7872 100644 --- a/Test/Notion.IntegrationTests/IBlocksClientTests.cs +++ b/Test/Notion.IntegrationTests/IBlocksClientTests.cs @@ -8,29 +8,18 @@ namespace Notion.IntegrationTests; -public class IBlocksClientTests +public class IBlocksClientTests : IntegrationTestBase { - private readonly INotionClient _client; - - public IBlocksClientTests() - { - var options = new ClientOptions { AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN") }; - - _client = NotionClientFactory.Create(options); - } - [Fact] public async Task AppendChildrenAsync_AppendsBlocksGivenBlocks() { - var pageParentId = "3c357473a28149a488c010d2b245a589"; - - var page = await _client.Pages.CreateAsync( + var page = await Client.Pages.CreateAsync( PagesCreateParametersBuilder.Create( - new ParentPageInput { PageId = pageParentId } + new ParentPageInput { PageId = ParentPageId } ).Build() ); - var blocks = await _client.Blocks.AppendChildrenAsync( + var blocks = await Client.Blocks.AppendChildrenAsync( page.Id, new BlocksAppendChildrenParameters { @@ -56,21 +45,19 @@ public async Task AppendChildrenAsync_AppendsBlocksGivenBlocks() blocks.Results.Should().HaveCount(4); // cleanup - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); + await Client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); } [Fact] public async Task UpdateBlockAsync_UpdatesGivenBlock() { - var pageParentId = "3c357473a28149a488c010d2b245a589"; - - var page = await _client.Pages.CreateAsync( + var page = await Client.Pages.CreateAsync( PagesCreateParametersBuilder.Create( - new ParentPageInput { PageId = pageParentId } + new ParentPageInput { PageId = ParentPageId } ).Build() ); - var blocks = await _client.Blocks.AppendChildrenAsync( + var blocks = await Client.Blocks.AppendChildrenAsync( page.Id, new BlocksAppendChildrenParameters { @@ -79,27 +66,25 @@ public async Task UpdateBlockAsync_UpdatesGivenBlock() ); var blockId = blocks.Results.First().Id; - await _client.Blocks.UpdateAsync(blockId, new BreadcrumbUpdateBlock()); + await Client.Blocks.UpdateAsync(blockId, new BreadcrumbUpdateBlock()); - blocks = await _client.Blocks.RetrieveChildrenAsync(page.Id); + blocks = await Client.Blocks.RetrieveChildrenAsync(page.Id); blocks.Results.Should().HaveCount(1); // cleanup - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); + await Client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); } [Fact] public async Task DeleteAsync_DeleteBlockWithGivenId() { - var pageParentId = "3c357473a28149a488c010d2b245a589"; - - var page = await _client.Pages.CreateAsync( + var page = await Client.Pages.CreateAsync( PagesCreateParametersBuilder.Create( - new ParentPageInput { PageId = pageParentId } + new ParentPageInput { PageId = ParentPageId } ).Build() ); - var blocks = await _client.Blocks.AppendChildrenAsync( + var blocks = await Client.Blocks.AppendChildrenAsync( page.Id, new BlocksAppendChildrenParameters { @@ -114,30 +99,28 @@ public async Task DeleteAsync_DeleteBlockWithGivenId() blocks.Results.Should().HaveCount(2); // cleanup - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); + await Client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); } [Theory] [MemberData(nameof(BlockData))] public async Task UpdateAsync_UpdatesGivenBlock(IBlock block, IUpdateBlock updateBlock, Action assert) { - var pageParentId = "3c357473a28149a488c010d2b245a589"; - - var page = await _client.Pages.CreateAsync( + var page = await Client.Pages.CreateAsync( PagesCreateParametersBuilder.Create( - new ParentPageInput { PageId = pageParentId } + new ParentPageInput { PageId = ParentPageId } ).Build() ); - var blocks = await _client.Blocks.AppendChildrenAsync( + var blocks = await Client.Blocks.AppendChildrenAsync( page.Id, new BlocksAppendChildrenParameters { Children = new List { block } } ); var blockId = blocks.Results.First().Id; - await _client.Blocks.UpdateAsync(blockId, updateBlock); + await Client.Blocks.UpdateAsync(blockId, updateBlock); - blocks = await _client.Blocks.RetrieveChildrenAsync(page.Id); + blocks = await Client.Blocks.RetrieveChildrenAsync(page.Id); blocks.Results.Should().HaveCount(1); var updatedBlock = blocks.Results.First(); @@ -145,7 +128,7 @@ public async Task UpdateAsync_UpdatesGivenBlock(IBlock block, IUpdateBlock updat assert.Invoke(updatedBlock); // cleanup - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); + await Client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); } private static IEnumerable BlockData() diff --git a/Test/Notion.IntegrationTests/IPageClientTests.cs b/Test/Notion.IntegrationTests/IPageClientTests.cs index 16051f42..a0f51d71 100644 --- a/Test/Notion.IntegrationTests/IPageClientTests.cs +++ b/Test/Notion.IntegrationTests/IPageClientTests.cs @@ -8,24 +8,13 @@ namespace Notion.IntegrationTests; -public class IPageClientTests +public class IPageClientTests : IntegrationTestBase { - private readonly INotionClient _client; - private readonly string _databaseId; - - public IPageClientTests() - { - var options = new ClientOptions { AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN") }; - - _client = NotionClientFactory.Create(options); - _databaseId = Environment.GetEnvironmentVariable("DATABASE_ID") ?? "f86f2262-0751-40f2-8f63-e3f7a3c39fcb"; - } - [Fact] public async Task CreateAsync_CreatesANewPage() { var pagesCreateParameters = PagesCreateParametersBuilder - .Create(new DatabaseParentInput { DatabaseId = _databaseId }) + .Create(new DatabaseParentInput { DatabaseId = ParentDatabaseId }) .AddProperty("Name", new TitlePropertyValue { @@ -36,18 +25,18 @@ public async Task CreateAsync_CreatesANewPage() }) .Build(); - var page = await _client.Pages.CreateAsync(pagesCreateParameters); + var page = await Client.Pages.CreateAsync(pagesCreateParameters); page.Should().NotBeNull(); page.Parent.Should().BeOfType().Which - .DatabaseId.Should().Be(_databaseId); + .DatabaseId.Should().Be(ParentDatabaseId); page.Properties.Should().ContainKey("Name"); var pageProperty = page.Properties["Name"].Should().BeOfType().Subject; var titleProperty - = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItemAsync( + = (ListPropertyItem)await Client.Pages.RetrievePagePropertyItemAsync( new RetrievePropertyItemParameters { PageId = page.Id, @@ -56,14 +45,14 @@ var titleProperty titleProperty.Results.First().As().Title.PlainText.Should().Be("Test Page Title"); - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); + await Client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); } [Fact] public async Task Bug_unable_to_create_page_with_select_property() { var pagesCreateParameters = PagesCreateParametersBuilder - .Create(new DatabaseParentInput { DatabaseId = _databaseId }) + .Create(new DatabaseParentInput { DatabaseId = ParentDatabaseId }) .AddProperty("Name", new TitlePropertyValue { @@ -76,18 +65,18 @@ public async Task Bug_unable_to_create_page_with_select_property() new SelectPropertyValue { Select = new SelectOption { Id = "dfbfbe65-6f67-4876-9f75-699124334d06" } }) .Build(); - var page = await _client.Pages.CreateAsync(pagesCreateParameters); + var page = await Client.Pages.CreateAsync(pagesCreateParameters); page.Should().NotBeNull(); page.Parent.Should().BeOfType().Which - .DatabaseId.Should().Be(_databaseId); + .DatabaseId.Should().Be(ParentDatabaseId); page.Properties.Should().ContainKey("Name"); var pageProperty = page.Properties["Name"].Should().BeOfType().Subject; var titleProperty - = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItemAsync( + = (ListPropertyItem)await Client.Pages.RetrievePagePropertyItemAsync( new RetrievePropertyItemParameters { PageId = page.Id, @@ -96,14 +85,14 @@ var titleProperty titleProperty.Results.First().As().Title.PlainText.Should().Be("Test Page Title"); - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); + await Client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); } [Fact] public async Task Test_RetrievePagePropertyItemAsync() { var pagesCreateParameters = PagesCreateParametersBuilder - .Create(new DatabaseParentInput { DatabaseId = _databaseId }) + .Create(new DatabaseParentInput { DatabaseId = ParentDatabaseId }) .AddProperty("Name", new TitlePropertyValue { @@ -114,9 +103,9 @@ public async Task Test_RetrievePagePropertyItemAsync() }) .Build(); - var page = await _client.Pages.CreateAsync(pagesCreateParameters); + var page = await Client.Pages.CreateAsync(pagesCreateParameters); - var property = await _client.Pages.RetrievePagePropertyItemAsync(new RetrievePropertyItemParameters + var property = await Client.Pages.RetrievePagePropertyItemAsync(new RetrievePropertyItemParameters { PageId = page.Id, PropertyId = "title" @@ -138,7 +127,7 @@ public async Task Test_RetrievePagePropertyItemAsync() }); // cleanup - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); + await Client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); } [Fact] @@ -161,7 +150,7 @@ public async Task Test_UpdatePageProperty_with_date_as_null() }; var pagesCreateParameters = PagesCreateParametersBuilder - .Create(new DatabaseParentInput { DatabaseId = _databaseId }) + .Create(new DatabaseParentInput { DatabaseId = ParentDatabaseId }) .AddProperty("Name", new TitlePropertyValue { @@ -181,11 +170,11 @@ public async Task Test_UpdatePageProperty_with_date_as_null() }) .Build(); - await _client.Databases.UpdateAsync(_databaseId, updateDatabaseParameters); + await Client.Databases.UpdateAsync(ParentDatabaseId, updateDatabaseParameters); - var page = await _client.Pages.CreateAsync(pagesCreateParameters); + var page = await Client.Pages.CreateAsync(pagesCreateParameters); - var setDate = (DatePropertyItem)await _client.Pages.RetrievePagePropertyItemAsync( + var setDate = (DatePropertyItem)await Client.Pages.RetrievePagePropertyItemAsync( new RetrievePropertyItemParameters { PageId = page.Id, @@ -201,9 +190,9 @@ public async Task Test_UpdatePageProperty_with_date_as_null() testProps.Add(DatePropertyName, new DatePropertyValue { Date = null }); var updatedPage = - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Properties = testProps }); + await Client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Properties = testProps }); - var verifyDate = (DatePropertyItem)await _client.Pages.RetrievePagePropertyItemAsync( + var verifyDate = (DatePropertyItem)await Client.Pages.RetrievePagePropertyItemAsync( new RetrievePropertyItemParameters { PageId = page.Id, @@ -213,7 +202,7 @@ public async Task Test_UpdatePageProperty_with_date_as_null() verifyDate?.Date.Should().BeNull(); //cleanup - await _client.Blocks.DeleteAsync(page.Id); + await Client.Blocks.DeleteAsync(page.Id); } [Fact] @@ -221,7 +210,7 @@ public async Task Bug_Unable_To_Parse_NumberPropertyItem() { // Arrange var pagesCreateParameters = PagesCreateParametersBuilder - .Create(new DatabaseParentInput { DatabaseId = _databaseId }).AddProperty("Name", + .Create(new DatabaseParentInput { DatabaseId = ParentDatabaseId }).AddProperty("Name", new TitlePropertyValue { Title = new List @@ -231,14 +220,14 @@ public async Task Bug_Unable_To_Parse_NumberPropertyItem() }).AddProperty("Number", new NumberPropertyValue { Number = 200.00 }).Build(); // Act - var page = await _client.Pages.CreateAsync(pagesCreateParameters); + var page = await Client.Pages.CreateAsync(pagesCreateParameters); // Assert Assert.NotNull(page); var pageParent = Assert.IsType(page.Parent); - Assert.Equal(_databaseId, pageParent.DatabaseId); + Assert.Equal(ParentDatabaseId, pageParent.DatabaseId); - var titleProperty = (ListPropertyItem)await _client.Pages.RetrievePagePropertyItemAsync( + var titleProperty = (ListPropertyItem)await Client.Pages.RetrievePagePropertyItemAsync( new RetrievePropertyItemParameters { PageId = page.Id, @@ -247,7 +236,7 @@ public async Task Bug_Unable_To_Parse_NumberPropertyItem() Assert.Equal("Test Page Title", titleProperty.Results.First().As().Title.PlainText); - var numberProperty = (NumberPropertyItem)await _client.Pages.RetrievePagePropertyItemAsync( + var numberProperty = (NumberPropertyItem)await Client.Pages.RetrievePagePropertyItemAsync( new RetrievePropertyItemParameters { PageId = page.Id, @@ -256,6 +245,6 @@ public async Task Bug_Unable_To_Parse_NumberPropertyItem() Assert.Equal(200.00, numberProperty.Number); - await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); + await Client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); } } diff --git a/Test/Notion.IntegrationTests/IntegrationTestBase.cs b/Test/Notion.IntegrationTests/IntegrationTestBase.cs new file mode 100644 index 00000000..31836c32 --- /dev/null +++ b/Test/Notion.IntegrationTests/IntegrationTestBase.cs @@ -0,0 +1,24 @@ +using System; +using Notion.Client; + +namespace Notion.IntegrationTests; + +public abstract class IntegrationTestBase +{ + protected readonly INotionClient Client; + protected readonly string ParentPageId; + protected readonly string ParentDatabaseId; + + protected IntegrationTestBase() + { + var options = new ClientOptions { AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN") }; + + Client = NotionClientFactory.Create(options); + + ParentPageId = Environment.GetEnvironmentVariable("NOTION_PARENT_PAGE_ID") + ?? throw new InvalidOperationException("Parent page id is required."); + + ParentDatabaseId = Environment.GetEnvironmentVariable("NOTION_PARENT_DATABASE_ID") + ?? throw new InvalidOperationException("Parent database id is required."); + } +} diff --git a/Test/Notion.IntegrationTests/PageWithPageParentTests.cs b/Test/Notion.IntegrationTests/PageWithPageParentTests.cs new file mode 100644 index 00000000..cca3356b --- /dev/null +++ b/Test/Notion.IntegrationTests/PageWithPageParentTests.cs @@ -0,0 +1,63 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using FluentAssertions; +using Notion.Client; +using Xunit; + +namespace Notion.IntegrationTests; + +public class PageWithPageParentTests : IntegrationTestBase +{ + [Fact] + public async Task Update_Title_Of_Page() + { + // Arrange + var pagesCreateParameters = PagesCreateParametersBuilder + .Create(new ParentPageInput() { PageId = ParentPageId }) + .AddProperty("title", + new TitlePropertyValue + { + Title = new List + { + new RichTextTextInput { Text = new Text { Content = "Test Page Title" } } + } + }).Build(); + + var page = await Client.Pages.CreateAsync(pagesCreateParameters); + + var updatePage = new PagesUpdateParameters() + { + Properties = new Dictionary + { + { + "title", + new TitlePropertyValue() + { + Title = new List + { + new RichTextText { Text = new Text() { Content = "Page Title Updated" } } + } + } + } + } + }; + + // Act + var updatedPage = await Client.Pages.UpdateAsync(page.Id, updatePage); + + // Assert + var titleProperty = (ListPropertyItem)await Client.Pages.RetrievePagePropertyItemAsync( + new RetrievePropertyItemParameters + { + PageId = updatedPage.Id, + PropertyId = updatedPage.Properties["title"].Id + } + ); + + Assert.Equal("Page Title Updated", titleProperty.Results.First().As().Title.PlainText); + + // Clean Up + await Client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); + } +} From 798f6782046db15480380ef12fa4edee338b5153 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Tue, 24 Jan 2023 17:30:14 +0530 Subject: [PATCH 125/216] 347 fix table block children property type --- Src/Notion.Client/Models/Blocks/TableBlock.cs | 9 ++- .../IBlocksClientTests.cs | 81 ++++++++++++++----- 2 files changed, 65 insertions(+), 25 deletions(-) diff --git a/Src/Notion.Client/Models/Blocks/TableBlock.cs b/Src/Notion.Client/Models/Blocks/TableBlock.cs index cf41440c..80fe72bc 100644 --- a/Src/Notion.Client/Models/Blocks/TableBlock.cs +++ b/Src/Notion.Client/Models/Blocks/TableBlock.cs @@ -1,15 +1,16 @@ -using Newtonsoft.Json; +using System.Collections.Generic; +using Newtonsoft.Json; namespace Notion.Client { public class TableBlock : Block, IColumnChildrenBlock, INonColumnBlock { [JsonProperty("table")] - public TableInfo Table { get; set; } + public Info Table { get; set; } public override BlockType Type => BlockType.Table; - public class TableInfo + public class Info { [JsonProperty("table_width")] public int TableWidth { get; set; } @@ -21,7 +22,7 @@ public class TableInfo public bool HasRowHeader { get; set; } [JsonProperty("children")] - public TableRowBlock Children { get; set; } + public IEnumerable Children { get; set; } } } } diff --git a/Test/Notion.IntegrationTests/IBlocksClientTests.cs b/Test/Notion.IntegrationTests/IBlocksClientTests.cs index 9aed7872..6f10189c 100644 --- a/Test/Notion.IntegrationTests/IBlocksClientTests.cs +++ b/Test/Notion.IntegrationTests/IBlocksClientTests.cs @@ -104,7 +104,8 @@ public async Task DeleteAsync_DeleteBlockWithGivenId() [Theory] [MemberData(nameof(BlockData))] - public async Task UpdateAsync_UpdatesGivenBlock(IBlock block, IUpdateBlock updateBlock, Action assert) + public async Task UpdateAsync_UpdatesGivenBlock( + IBlock block, IUpdateBlock updateBlock, Action assert) { var page = await Client.Pages.CreateAsync( PagesCreateParametersBuilder.Create( @@ -125,7 +126,7 @@ public async Task UpdateAsync_UpdatesGivenBlock(IBlock block, IUpdateBlock updat var updatedBlock = blocks.Results.First(); - assert.Invoke(updatedBlock); + assert.Invoke(updatedBlock, Client); // cleanup await Client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); @@ -159,7 +160,7 @@ private static IEnumerable BlockData() } } }, - new Action(block => + new Action((block, client) => { var updatedBlock = (BookmarkBlock)block; Assert.Equal("https://github.com/notion-dotnet/notion-sdk-net", updatedBlock.Bookmark.Url); @@ -170,7 +171,7 @@ private static IEnumerable BlockData() { new EquationBlock { Equation = new EquationBlock.Info { Expression = "e=mc^3" } }, new EquationUpdateBlock { Equation = new EquationUpdateBlock.Info { Expression = "e=mc^2" } }, - new Action(block => + new Action((block, client) => { var updatedBlock = (EquationBlock)block; Assert.Equal("e=mc^2", updatedBlock.Equation.Expression); @@ -207,10 +208,10 @@ private static IEnumerable BlockData() } } }, - new Action(block => + new Action((block, client) => { block.Should().NotBeNull(); - + block.Should().BeOfType().Subject .Audio.Should().BeOfType().Subject .External.Url.Should().Be("https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3"); @@ -219,7 +220,7 @@ private static IEnumerable BlockData() new object[] { new TableOfContentsBlock { TableOfContents = new TableOfContentsBlock.Data() }, - new TableOfContentsUpdateBlock(), new Action(block => + new TableOfContentsUpdateBlock(), new Action((block, client) => { Assert.NotNull(block); _ = Assert.IsType(block); @@ -247,11 +248,11 @@ private static IEnumerable BlockData() } } }, - new Action(block => + new Action((block, client) => { Assert.NotNull(block); var calloutBlock = Assert.IsType(block); - + Assert.Equal("Test 2", calloutBlock.Callout.RichText.OfType().First().Text.Content); }) }, @@ -277,11 +278,11 @@ private static IEnumerable BlockData() } } }, - new Action(block => + new Action((block, client) => { Assert.NotNull(block); var quoteBlock = Assert.IsType(block); - + Assert.Equal("Test 2", quoteBlock.Quote.RichText.OfType().First().Text.Content); }) }, @@ -308,12 +309,12 @@ private static IEnumerable BlockData() } } }, - new Action(block => + new Action((block, client) => { Assert.NotNull(block); var imageBlock = Assert.IsType(block); var imageFile = Assert.IsType(imageBlock.Image); - + Assert.Equal("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", imageFile.External.Url); }) @@ -334,11 +335,11 @@ private static IEnumerable BlockData() Url = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg" } }, - new Action(block => + new Action((block, client) => { Assert.NotNull(block); var embedBlock = Assert.IsType(block); - + Assert.Equal("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", embedBlock.Embed.Url); }) @@ -376,14 +377,14 @@ private static IEnumerable BlockData() } } }, - new Action(block => + new Action((block, client) => { Assert.NotNull(block); var templateBlock = Assert.IsType(block); - + Assert.Single(templateBlock.Template.RichText); Assert.Null(templateBlock.Template.Children); - + Assert.Equal("Test Template 2", templateBlock.Template.RichText.OfType().First().Text.Content); }) @@ -402,17 +403,55 @@ private static IEnumerable BlockData() { LinkToPage = new ParentPageInput { PageId = "3c357473a28149a488c010d2b245a589" } }, - new Action(block => + new Action((block, client) => { Assert.NotNull(block); var linkToPageBlock = Assert.IsType(block); - + var pageParent = Assert.IsType(linkToPageBlock.LinkToPage); - + // TODO: Currently the api doesn't allow to update the link_to_page block type // This will change to updated ID once api start to support Assert.Equal(Guid.Parse("533578e3edf14c0a91a9da6b09bac3ee"), Guid.Parse(pageParent.PageId)); }) + }, + new object[] + { + new TableBlock + { + Table = new TableBlock.Info + { + TableWidth = 1, + Children = new[] + { + new TableRowBlock + { + TableRow = new TableRowBlock.Info + { + Cells = new[] + { + new[] { new RichTextText { Text = new Text { Content = "Data" } } } + } + } + } + } + } + }, + new TableUpdateBlock { Table = new TableUpdateBlock.Info { HasColumnHeader = false } }, + new Action((block, client) => + { + var tableBlock = block.Should().NotBeNull().And.BeOfType().Subject; + tableBlock.HasChildren.Should().BeTrue(); + + var children = client.Blocks.RetrieveChildrenAsync(tableBlock.Id).GetAwaiter().GetResult(); + + children.Results.Should().ContainSingle() + .Subject.Should().BeOfType() + .Subject.TableRow.Cells.Should().ContainSingle() + .Subject.Should().ContainSingle() + .Subject.Should().BeOfType() + .Subject.Text.Content.Should().Be("Data"); + }) } }; } From 13954003a13cddecd9744e2b9e9e444761c26cfc Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Tue, 24 Jan 2023 18:58:53 +0530 Subject: [PATCH 126/216] respect null value set by user for SelectPropertyValue.Select property --- .../PropertyValue/SelectPropertyValue.cs | 2 +- .../IPageClientTests.cs | 94 +++++++++++++++++++ 2 files changed, 95 insertions(+), 1 deletion(-) diff --git a/Src/Notion.Client/Models/PropertyValue/SelectPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/SelectPropertyValue.cs index 74c94c82..63d333d9 100644 --- a/Src/Notion.Client/Models/PropertyValue/SelectPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/SelectPropertyValue.cs @@ -9,7 +9,7 @@ public class SelectPropertyValue : PropertyValue { public override PropertyValueType Type => PropertyValueType.Select; - [JsonProperty("select")] + [JsonProperty("select", NullValueHandling = NullValueHandling.Include)] public SelectOption Select { get; set; } } } diff --git a/Test/Notion.IntegrationTests/IPageClientTests.cs b/Test/Notion.IntegrationTests/IPageClientTests.cs index a0f51d71..f0833be5 100644 --- a/Test/Notion.IntegrationTests/IPageClientTests.cs +++ b/Test/Notion.IntegrationTests/IPageClientTests.cs @@ -247,4 +247,98 @@ public async Task Bug_Unable_To_Parse_NumberPropertyItem() await Client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); } + + [Fact] + public async Task Bug_exception_when_attempting_to_set_select_property_to_nothing() + { + // Arrange + var databaseCreateRequest = new DatabasesCreateParameters + { + Title = + new List + { + new RichTextTextInput() { Text = new Text { Content = "Test Database" } } + }, + Parent = new ParentPageInput() { PageId = ParentPageId }, + Properties = new Dictionary + { + { + "title", new TitlePropertySchema + { + Title = new Dictionary() + } + }, + { + "Colors1", + new SelectPropertySchema + { + Select = new OptionWrapper + { + Options = new List + { + new() { Name = "Red" }, + new() { Name = "Green" }, + new() { Name = "Blue" } + } + } + } + }, + { + "Colors2", + new SelectPropertySchema + { + Select = new OptionWrapper + { + Options = new List + { + new() { Name = "Red" }, + new() { Name = "Green" }, + new() { Name = "Blue" } + } + } + } + }, + } + }; + + var database = await Client.Databases.CreateAsync(databaseCreateRequest); + + var pagesCreateParameters = PagesCreateParametersBuilder + .Create(new DatabaseParentInput { DatabaseId = database.Id }) + .AddProperty("title", + new TitlePropertyValue + { + Title = new List + { + new RichTextTextInput { Text = new Text { Content = "Test" } } + } + }) + .AddProperty("Colors1", new SelectPropertyValue { Select = new SelectOption { Name = "Red" } }) + .AddProperty("Colors2", new SelectPropertyValue { Select = new SelectOption { Name = "Green" } }) + .Build(); + + // Act + var page = await Client.Pages.CreateAsync(pagesCreateParameters); + + var updatePageRequest = new PagesUpdateParameters + { + Properties = new Dictionary + { + { "Colors1", new SelectPropertyValue { Select = new SelectOption { Name = "Blue" } } }, + { "Colors2", new SelectPropertyValue { Select = null } } + } + }; + + var updatedPage = await Client.Pages.UpdateAsync(page.Id, updatePageRequest); + + // Assert + page.Properties["Colors1"].As().Select.Name.Should().Be("Red"); + page.Properties["Colors2"].As().Select.Name.Should().Be("Green"); + + updatedPage.Properties["Colors1"].As().Select.Name.Should().Be("Blue"); + updatedPage.Properties["Colors2"].As().Select.Should().BeNull(); + + await Client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); + await Client.Databases.UpdateAsync(database.Id, new DatabasesUpdateParameters { Archived = true }); + } } From 19934deed2088d0e7ffed29a4686a7b49e368810 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Tue, 24 Jan 2023 19:18:52 +0530 Subject: [PATCH 127/216] update version prefix to 4.1.0 --- Src/Notion.Client/Notion.Client.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/Notion.Client/Notion.Client.csproj b/Src/Notion.Client/Notion.Client.csproj index 981fd1f7..4a614c64 100644 --- a/Src/Notion.Client/Notion.Client.csproj +++ b/Src/Notion.Client/Notion.Client.csproj @@ -1,7 +1,7 @@  - 4.0.0-preview + 4.1.0-preview netstandard2.0 9.0 From 1b3a00ce48299dc56e7ce602fcf974ca133f58d4 Mon Sep 17 00:00:00 2001 From: Herman Schoenfeld Date: Sun, 12 Mar 2023 01:27:56 +1000 Subject: [PATCH 128/216] Fix serialization exception on sync blocks --- Src/Notion.Client/Models/Blocks/IBlock.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Src/Notion.Client/Models/Blocks/IBlock.cs b/Src/Notion.Client/Models/Blocks/IBlock.cs index df625cf6..bbe5d6e6 100644 --- a/Src/Notion.Client/Models/Blocks/IBlock.cs +++ b/Src/Notion.Client/Models/Blocks/IBlock.cs @@ -29,6 +29,7 @@ namespace Notion.Client [JsonSubtypes.KnownSubTypeAttribute(typeof(ParagraphBlock), BlockType.Paragraph)] [JsonSubtypes.KnownSubTypeAttribute(typeof(PDFBlock), BlockType.PDF)] [JsonSubtypes.KnownSubTypeAttribute(typeof(QuoteBlock), BlockType.Quote)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(UnsupportedBlock), BlockType.SyncedBlock)] [JsonSubtypes.KnownSubTypeAttribute(typeof(TableBlock), BlockType.Table)] [JsonSubtypes.KnownSubTypeAttribute(typeof(TableRowBlock), BlockType.TableRow)] [JsonSubtypes.KnownSubTypeAttribute(typeof(TableOfContentsBlock), BlockType.TableOfContents)] From 6cfcbcf1e797f613d719fb407fa52516c43ed1f9 Mon Sep 17 00:00:00 2001 From: Herman Schoenfeld Date: Mon, 13 Mar 2023 02:11:01 +1000 Subject: [PATCH 129/216] Fix heading blocks to support toggles --- Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs | 5 +++-- .../Blocks/{HeadingThreeeBlock.cs => HeadingThreeBlock.cs} | 5 +++-- Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) rename Src/Notion.Client/Models/Blocks/{HeadingThreeeBlock.cs => HeadingThreeBlock.cs} (88%) diff --git a/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs b/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs index b0753122..1e8474a4 100644 --- a/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs +++ b/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs @@ -13,8 +13,6 @@ public class HeadingOneBlock : Block, IColumnChildrenBlock, INonColumnBlock public override BlockType Type => BlockType.Heading_1; - public override bool HasChildren => false; - public class Info { [JsonProperty("rich_text")] @@ -23,6 +21,9 @@ public class Info [JsonProperty("color")] [JsonConverter(typeof(StringEnumConverter))] public Color? Color { get; set; } + + [JsonProperty("is_toggleable")] + public bool IsToggleable { get; set; } } } } diff --git a/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs b/Src/Notion.Client/Models/Blocks/HeadingThreeBlock.cs similarity index 88% rename from Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs rename to Src/Notion.Client/Models/Blocks/HeadingThreeBlock.cs index deada7de..e300a511 100644 --- a/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs +++ b/Src/Notion.Client/Models/Blocks/HeadingThreeBlock.cs @@ -13,8 +13,6 @@ public class HeadingThreeBlock : Block, IColumnChildrenBlock, INonColumnBlock public override BlockType Type => BlockType.Heading_3; - public override bool HasChildren => false; - public class Info { [JsonProperty("rich_text")] @@ -23,6 +21,9 @@ public class Info [JsonProperty("color")] [JsonConverter(typeof(StringEnumConverter))] public Color? Color { get; set; } + + [JsonProperty("is_toggleable")] + public bool IsToggleable { get; set; } } } } diff --git a/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs b/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs index f5ffd7ea..3be849a8 100644 --- a/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs +++ b/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs @@ -13,8 +13,6 @@ public class HeadingTwoBlock : Block, IColumnChildrenBlock, INonColumnBlock public override BlockType Type => BlockType.Heading_2; - public override bool HasChildren => false; - public class Info { [JsonProperty("rich_text")] @@ -23,6 +21,9 @@ public class Info [JsonProperty("color")] [JsonConverter(typeof(StringEnumConverter))] public Color? Color { get; set; } + + [JsonProperty("is_toggleable")] + public bool IsToggleable { get; set; } } } } From 1c929fcba203a904b24710e01f0ace4b07b7800d Mon Sep 17 00:00:00 2001 From: romain vergnory Date: Wed, 17 May 2023 11:22:19 +0200 Subject: [PATCH 130/216] feat : Make calls cancellable --- Src/Notion.Client/Api/Blocks/BlocksClient.cs | 21 ++++++++++--------- Src/Notion.Client/Api/Blocks/IBlocksClient.cs | 13 ++++++------ .../Api/Comments/Create/CommentsClient.cs | 8 ++++--- .../Api/Comments/ICommentsClient.cs | 5 +++-- .../Api/Comments/Retrieve/CommentsClient.cs | 6 ++++-- .../Api/Databases/DatabasesClient.cs | 19 +++++++++-------- .../Api/Databases/IDatabasesClient.cs | 11 +++++----- Src/Notion.Client/Api/Pages/IPagesClient.cs | 11 +++++----- Src/Notion.Client/Api/Pages/PagesClient.cs | 21 ++++++++++--------- Src/Notion.Client/Api/Search/ISearchClient.cs | 3 ++- Src/Notion.Client/Api/Search/SearchClient.cs | 7 ++++--- Src/Notion.Client/Api/Users/IUsersClient.cs | 9 ++++---- Src/Notion.Client/Api/Users/UsersClient.cs | 15 ++++++------- 13 files changed, 82 insertions(+), 67 deletions(-) diff --git a/Src/Notion.Client/Api/Blocks/BlocksClient.cs b/Src/Notion.Client/Api/Blocks/BlocksClient.cs index 1282a346..068ce969 100644 --- a/Src/Notion.Client/Api/Blocks/BlocksClient.cs +++ b/Src/Notion.Client/Api/Blocks/BlocksClient.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; using static Notion.Client.ApiEndpoints; @@ -16,7 +17,7 @@ public BlocksClient(IRestClient client) public async Task> RetrieveChildrenAsync( string blockId, - BlocksRetrieveChildrenParameters parameters = null) + BlocksRetrieveChildrenParameters parameters = null, CancellationToken cancellationToken = default) { if (string.IsNullOrWhiteSpace(blockId)) { @@ -33,12 +34,12 @@ public async Task> RetrieveChildrenAsync( { "page_size", queryParameters?.PageSize?.ToString() } }; - return await _client.GetAsync>(url, queryParams); + return await _client.GetAsync>(url, queryParams, cancellationToken: cancellationToken); } public async Task> AppendChildrenAsync( string blockId, - BlocksAppendChildrenParameters parameters = null) + BlocksAppendChildrenParameters parameters = null, CancellationToken cancellationToken = default) { if (string.IsNullOrWhiteSpace(blockId)) { @@ -49,10 +50,10 @@ public async Task> AppendChildrenAsync( var body = (IBlocksAppendChildrenBodyParameters)parameters; - return await _client.PatchAsync>(url, body); + return await _client.PatchAsync>(url, body, cancellationToken: cancellationToken); } - public async Task RetrieveAsync(string blockId) + public async Task RetrieveAsync(string blockId, CancellationToken cancellationToken = default) { if (string.IsNullOrWhiteSpace(blockId)) { @@ -61,10 +62,10 @@ public async Task RetrieveAsync(string blockId) var url = BlocksApiUrls.Retrieve(blockId); - return await _client.GetAsync(url); + return await _client.GetAsync(url, cancellationToken: cancellationToken); } - public async Task UpdateAsync(string blockId, IUpdateBlock updateBlock) + public async Task UpdateAsync(string blockId, IUpdateBlock updateBlock, CancellationToken cancellationToken = default) { if (string.IsNullOrWhiteSpace(blockId)) { @@ -73,10 +74,10 @@ public async Task UpdateAsync(string blockId, IUpdateBlock updateBlock) var url = BlocksApiUrls.Update(blockId); - return await _client.PatchAsync(url, updateBlock); + return await _client.PatchAsync(url, updateBlock, cancellationToken: cancellationToken); } - public async Task DeleteAsync(string blockId) + public async Task DeleteAsync(string blockId, CancellationToken cancellationToken = default) { if (string.IsNullOrWhiteSpace(blockId)) { @@ -85,7 +86,7 @@ public async Task DeleteAsync(string blockId) var url = BlocksApiUrls.Delete(blockId); - await _client.DeleteAsync(url); + await _client.DeleteAsync(url, cancellationToken: cancellationToken); } } } diff --git a/Src/Notion.Client/Api/Blocks/IBlocksClient.cs b/Src/Notion.Client/Api/Blocks/IBlocksClient.cs index f45611b7..252a218d 100644 --- a/Src/Notion.Client/Api/Blocks/IBlocksClient.cs +++ b/Src/Notion.Client/Api/Blocks/IBlocksClient.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System.Threading; +using System.Threading.Tasks; namespace Notion.Client { @@ -9,7 +10,7 @@ public interface IBlocksClient /// /// /// Block - Task RetrieveAsync(string blockId); + Task RetrieveAsync(string blockId, CancellationToken cancellationToken = default); /// /// Updates the content for the specified block_id based on the block type. @@ -17,11 +18,11 @@ public interface IBlocksClient /// /// /// Block - Task UpdateAsync(string blockId, IUpdateBlock updateBlock); + Task UpdateAsync(string blockId, IUpdateBlock updateBlock, CancellationToken cancellationToken = default); Task> RetrieveChildrenAsync( string blockId, - BlocksRetrieveChildrenParameters parameters = null); + BlocksRetrieveChildrenParameters parameters = null, CancellationToken cancellationToken = default); /// /// Creates and appends new children blocks to the parent block_id specified. @@ -31,12 +32,12 @@ Task> RetrieveChildrenAsync( /// A paginated list of newly created first level children block objects. Task> AppendChildrenAsync( string blockId, - BlocksAppendChildrenParameters parameters = null); + BlocksAppendChildrenParameters parameters = null, CancellationToken cancellationToken = default); /// /// Sets a Block object, including page blocks, to archived: true using the ID specified. /// /// Identifier for a Notion block - Task DeleteAsync(string blockId); + Task DeleteAsync(string blockId, CancellationToken cancellationToken = default); } } diff --git a/Src/Notion.Client/Api/Comments/Create/CommentsClient.cs b/Src/Notion.Client/Api/Comments/Create/CommentsClient.cs index cb3b9bd1..ac2244ea 100644 --- a/Src/Notion.Client/Api/Comments/Create/CommentsClient.cs +++ b/Src/Notion.Client/Api/Comments/Create/CommentsClient.cs @@ -1,16 +1,18 @@ -using System.Threading.Tasks; +using System.Threading; +using System.Threading.Tasks; namespace Notion.Client { public partial class CommentsClient { - public async Task CreateAsync(CreateCommentParameters parameters) + public async Task CreateAsync(CreateCommentParameters parameters, CancellationToken cancellationToken = default) { var body = (ICreateCommentsBodyParameters)parameters; return await _client.PostAsync( ApiEndpoints.CommentsApiUrls.Create(), - body + body, + cancellationToken: cancellationToken ); } } diff --git a/Src/Notion.Client/Api/Comments/ICommentsClient.cs b/Src/Notion.Client/Api/Comments/ICommentsClient.cs index 98ec3faf..7b7af943 100644 --- a/Src/Notion.Client/Api/Comments/ICommentsClient.cs +++ b/Src/Notion.Client/Api/Comments/ICommentsClient.cs @@ -1,11 +1,12 @@ +using System.Threading; using System.Threading.Tasks; namespace Notion.Client { public interface ICommentsClient { - Task CreateAsync(CreateCommentParameters createCommentParameters); + Task CreateAsync(CreateCommentParameters createCommentParameters, CancellationToken cancellationToken = default); - Task RetrieveAsync(RetrieveCommentsParameters parameters); + Task RetrieveAsync(RetrieveCommentsParameters parameters, CancellationToken cancellationToken = default); } } diff --git a/Src/Notion.Client/Api/Comments/Retrieve/CommentsClient.cs b/Src/Notion.Client/Api/Comments/Retrieve/CommentsClient.cs index 22964c5f..45c64f00 100644 --- a/Src/Notion.Client/Api/Comments/Retrieve/CommentsClient.cs +++ b/Src/Notion.Client/Api/Comments/Retrieve/CommentsClient.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; +using System.Threading; using System.Threading.Tasks; namespace Notion.Client @@ -7,7 +8,7 @@ namespace Notion.Client public partial class CommentsClient { [SuppressMessage("ReSharper", "UnusedMember.Global")] - public async Task RetrieveAsync(RetrieveCommentsParameters parameters) + public async Task RetrieveAsync(RetrieveCommentsParameters parameters, CancellationToken cancellationToken = default) { var qp = (IRetrieveCommentsQueryParameters)parameters; @@ -20,7 +21,8 @@ public async Task RetrieveAsync(RetrieveCommentsParame return await _client.GetAsync( ApiEndpoints.CommentsApiUrls.Retrieve(), - queryParams + queryParams, + cancellationToken: cancellationToken ); } } diff --git a/Src/Notion.Client/Api/Databases/DatabasesClient.cs b/Src/Notion.Client/Api/Databases/DatabasesClient.cs index 5157dee9..4412b8bb 100644 --- a/Src/Notion.Client/Api/Databases/DatabasesClient.cs +++ b/Src/Notion.Client/Api/Databases/DatabasesClient.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System.Threading; +using System.Threading.Tasks; using static Notion.Client.ApiEndpoints; namespace Notion.Client @@ -12,32 +13,32 @@ public DatabasesClient(IRestClient client) _client = client; } - public async Task RetrieveAsync(string databaseId) + public async Task RetrieveAsync(string databaseId, CancellationToken cancellationToken = default) { - return await _client.GetAsync(DatabasesApiUrls.Retrieve(databaseId)); + return await _client.GetAsync(DatabasesApiUrls.Retrieve(databaseId), cancellationToken: cancellationToken); } public async Task> QueryAsync( string databaseId, - DatabasesQueryParameters databasesQueryParameters) + DatabasesQueryParameters databasesQueryParameters, CancellationToken cancellationToken = default) { var body = (IDatabaseQueryBodyParameters)databasesQueryParameters; - return await _client.PostAsync>(DatabasesApiUrls.Query(databaseId), body); + return await _client.PostAsync>(DatabasesApiUrls.Query(databaseId), body, cancellationToken: cancellationToken); } - public async Task CreateAsync(DatabasesCreateParameters databasesCreateParameters) + public async Task CreateAsync(DatabasesCreateParameters databasesCreateParameters, CancellationToken cancellationToken = default) { var body = (IDatabasesCreateBodyParameters)databasesCreateParameters; - return await _client.PostAsync(DatabasesApiUrls.Create, body); + return await _client.PostAsync(DatabasesApiUrls.Create, body, cancellationToken: cancellationToken); } - public async Task UpdateAsync(string databaseId, DatabasesUpdateParameters databasesUpdateParameters) + public async Task UpdateAsync(string databaseId, DatabasesUpdateParameters databasesUpdateParameters, CancellationToken cancellationToken = default) { var body = (IDatabasesUpdateBodyParameters)databasesUpdateParameters; - return await _client.PatchAsync(DatabasesApiUrls.Update(databaseId), body); + return await _client.PatchAsync(DatabasesApiUrls.Update(databaseId), body, cancellationToken: cancellationToken); } } } diff --git a/Src/Notion.Client/Api/Databases/IDatabasesClient.cs b/Src/Notion.Client/Api/Databases/IDatabasesClient.cs index 9c245ce3..c7e1c21a 100644 --- a/Src/Notion.Client/Api/Databases/IDatabasesClient.cs +++ b/Src/Notion.Client/Api/Databases/IDatabasesClient.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System.Threading; +using System.Threading.Tasks; namespace Notion.Client { @@ -11,7 +12,7 @@ public interface IDatabasesClient /// /// /// - Task RetrieveAsync(string databaseId); + Task RetrieveAsync(string databaseId, CancellationToken cancellationToken = default); /// /// Gets a list of Pages contained in the database, filtered and ordered according to the @@ -23,7 +24,7 @@ public interface IDatabasesClient /// /// /// - Task> QueryAsync(string databaseId, DatabasesQueryParameters databasesQueryParameters); + Task> QueryAsync(string databaseId, DatabasesQueryParameters databasesQueryParameters, CancellationToken cancellationToken = default); /// /// Creates a database as a subpage in the specified parent page, with the specified properties schema. @@ -32,7 +33,7 @@ public interface IDatabasesClient /// /// /// - Task CreateAsync(DatabasesCreateParameters databasesCreateParameters); + Task CreateAsync(DatabasesCreateParameters databasesCreateParameters, CancellationToken cancellationToken = default); /// /// Updates an existing database as specified by the parameters. @@ -42,6 +43,6 @@ public interface IDatabasesClient /// /// /// - Task UpdateAsync(string databaseId, DatabasesUpdateParameters databasesUpdateParameters); + Task UpdateAsync(string databaseId, DatabasesUpdateParameters databasesUpdateParameters, CancellationToken cancellationToken = default); } } diff --git a/Src/Notion.Client/Api/Pages/IPagesClient.cs b/Src/Notion.Client/Api/Pages/IPagesClient.cs index 755b385f..8dc8f5ce 100644 --- a/Src/Notion.Client/Api/Pages/IPagesClient.cs +++ b/Src/Notion.Client/Api/Pages/IPagesClient.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; namespace Notion.Client @@ -15,7 +16,7 @@ public interface IPagesClient /// /// Create page parameters /// Created object. - Task CreateAsync(PagesCreateParameters pagesCreateParameters); + Task CreateAsync(PagesCreateParameters pagesCreateParameters, CancellationToken cancellationToken = default); /// /// Retrieves a Page object using the ID specified. @@ -24,7 +25,7 @@ public interface IPagesClient /// /// /// - Task RetrieveAsync(string pageId); + Task RetrieveAsync(string pageId, CancellationToken cancellationToken = default); /// /// Updates page property values for the specified page. @@ -38,7 +39,7 @@ public interface IPagesClient /// Updated object Task UpdatePropertiesAsync( string pageId, - IDictionary updatedProperties); + IDictionary updatedProperties, CancellationToken cancellationToken = default); /// /// Updates page property values for the specified page. @@ -47,7 +48,7 @@ Task UpdatePropertiesAsync( /// Identifier for a Notion page /// Update property parameters /// Updated object - Task UpdateAsync(string pageId, PagesUpdateParameters pagesUpdateParameters); + Task UpdateAsync(string pageId, PagesUpdateParameters pagesUpdateParameters, CancellationToken cancellationToken = default); /// /// Retrieves a property_item object for a given pageId and propertyId. Depending on the property type, the object @@ -58,6 +59,6 @@ Task UpdatePropertiesAsync( /// /// Task RetrievePagePropertyItemAsync( - RetrievePropertyItemParameters retrievePropertyItemParameters); + RetrievePropertyItemParameters retrievePropertyItemParameters, CancellationToken cancellationToken = default); } } diff --git a/Src/Notion.Client/Api/Pages/PagesClient.cs b/Src/Notion.Client/Api/Pages/PagesClient.cs index 43fe143e..76b3e41a 100644 --- a/Src/Notion.Client/Api/Pages/PagesClient.cs +++ b/Src/Notion.Client/Api/Pages/PagesClient.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; +using System.Threading; using System.Threading.Tasks; using static Notion.Client.ApiEndpoints; @@ -25,7 +26,7 @@ public PagesClient(IRestClient client) /// /// Create page parameters /// Created page. - public async Task CreateAsync(PagesCreateParameters pagesCreateParameters) + public async Task CreateAsync(PagesCreateParameters pagesCreateParameters, CancellationToken cancellationToken = default) { if (pagesCreateParameters is null) { @@ -44,18 +45,18 @@ public async Task CreateAsync(PagesCreateParameters pagesCreateParameters) throw new ArgumentNullException(nameof(bodyParameters.Properties), "Properties are required!"); } - return await _client.PostAsync(PagesApiUrls.Create(), bodyParameters); + return await _client.PostAsync(PagesApiUrls.Create(), bodyParameters, cancellationToken: cancellationToken); } - public async Task RetrieveAsync(string pageId) + public async Task RetrieveAsync(string pageId, CancellationToken cancellationToken = default) { var url = PagesApiUrls.Retrieve(pageId); - return await _client.GetAsync(url); + return await _client.GetAsync(url, cancellationToken: cancellationToken); } public async Task RetrievePagePropertyItemAsync( - RetrievePropertyItemParameters retrievePropertyItemParameters) + RetrievePropertyItemParameters retrievePropertyItemParameters, CancellationToken cancellationToken = default) { var pathParameters = (IRetrievePropertyItemPathParameters)retrievePropertyItemParameters; var queryParameters = (IRetrievePropertyQueryParameters)retrievePropertyItemParameters; @@ -68,27 +69,27 @@ public async Task RetrievePagePropertyItemAsync( { "page_size", queryParameters?.PageSize?.ToString() } }; - return await _client.GetAsync(url, queryParams); + return await _client.GetAsync(url, queryParams, cancellationToken: cancellationToken); } - public async Task UpdateAsync(string pageId, PagesUpdateParameters pagesUpdateParameters) + public async Task UpdateAsync(string pageId, PagesUpdateParameters pagesUpdateParameters, CancellationToken cancellationToken = default) { var url = PagesApiUrls.Update(pageId); var body = (IPagesUpdateBodyParameters)pagesUpdateParameters; - return await _client.PatchAsync(url, body); + return await _client.PatchAsync(url, body, cancellationToken: cancellationToken); } [Obsolete("This method is obsolete. Use UpdateAsync instead. This API will be removed in future release")] public async Task UpdatePropertiesAsync( string pageId, - IDictionary updatedProperties) + IDictionary updatedProperties, CancellationToken cancellationToken = default) { var url = PagesApiUrls.UpdateProperties(pageId); var body = new UpdatePropertiesParameters { Properties = updatedProperties }; - return await _client.PatchAsync(url, body); + return await _client.PatchAsync(url, body, cancellationToken: cancellationToken); } [SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Local")] diff --git a/Src/Notion.Client/Api/Search/ISearchClient.cs b/Src/Notion.Client/Api/Search/ISearchClient.cs index 835c14e4..a1e05990 100644 --- a/Src/Notion.Client/Api/Search/ISearchClient.cs +++ b/Src/Notion.Client/Api/Search/ISearchClient.cs @@ -1,4 +1,5 @@ using System.Diagnostics.CodeAnalysis; +using System.Threading; using System.Threading.Tasks; namespace Notion.Client @@ -14,6 +15,6 @@ public interface ISearchClient /// /// /// - Task> SearchAsync(SearchParameters parameters); + Task> SearchAsync(SearchParameters parameters, CancellationToken cancellationToken = default); } } diff --git a/Src/Notion.Client/Api/Search/SearchClient.cs b/Src/Notion.Client/Api/Search/SearchClient.cs index bd73acfc..cebe6aa3 100644 --- a/Src/Notion.Client/Api/Search/SearchClient.cs +++ b/Src/Notion.Client/Api/Search/SearchClient.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System.Threading; +using System.Threading.Tasks; using static Notion.Client.ApiEndpoints; namespace Notion.Client @@ -12,13 +13,13 @@ public SearchClient(IRestClient client) _client = client; } - public async Task> SearchAsync(SearchParameters parameters) + public async Task> SearchAsync(SearchParameters parameters, CancellationToken cancellationToken = default) { var url = SearchApiUrls.Search(); var body = (ISearchBodyParameters)parameters; - return await _client.PostAsync>(url, body); + return await _client.PostAsync>(url, body, cancellationToken: cancellationToken); } } } diff --git a/Src/Notion.Client/Api/Users/IUsersClient.cs b/Src/Notion.Client/Api/Users/IUsersClient.cs index 69981022..dc86ce12 100644 --- a/Src/Notion.Client/Api/Users/IUsersClient.cs +++ b/Src/Notion.Client/Api/Users/IUsersClient.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System.Threading; +using System.Threading.Tasks; namespace Notion.Client { @@ -11,7 +12,7 @@ public interface IUsersClient /// /// /// - Task RetrieveAsync(string userId); + Task RetrieveAsync(string userId, CancellationToken cancellationToken = default); /// /// Returns a paginated list of Users for the workspace. @@ -20,7 +21,7 @@ public interface IUsersClient /// /// /// - Task> ListAsync(); + Task> ListAsync(CancellationToken cancellationToken = default); /// /// Retrieves the bot User associated with the API token provided in the authorization header. @@ -29,6 +30,6 @@ public interface IUsersClient /// object of type bot having an owner field with information about the person who authorized /// the integration. /// - Task MeAsync(); + Task MeAsync(CancellationToken cancellationToken = default); } } diff --git a/Src/Notion.Client/Api/Users/UsersClient.cs b/Src/Notion.Client/Api/Users/UsersClient.cs index 957ac45e..66c18d3d 100644 --- a/Src/Notion.Client/Api/Users/UsersClient.cs +++ b/Src/Notion.Client/Api/Users/UsersClient.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System.Threading; +using System.Threading.Tasks; using static Notion.Client.ApiEndpoints; namespace Notion.Client @@ -12,14 +13,14 @@ public UsersClient(IRestClient client) _client = client; } - public async Task RetrieveAsync(string userId) + public async Task RetrieveAsync(string userId, CancellationToken cancellationToken = default) { - return await _client.GetAsync(UsersApiUrls.Retrieve(userId)); + return await _client.GetAsync(UsersApiUrls.Retrieve(userId), cancellationToken: cancellationToken); } - public async Task> ListAsync() + public async Task> ListAsync(CancellationToken cancellationToken = default) { - return await _client.GetAsync>(UsersApiUrls.List()); + return await _client.GetAsync>(UsersApiUrls.List(), cancellationToken: cancellationToken); } /// @@ -29,9 +30,9 @@ public async Task> ListAsync() /// User object of type bot having an owner field with information about the person who authorized the /// integration. /// - public async Task MeAsync() + public async Task MeAsync(CancellationToken cancellationToken = default) { - return await _client.GetAsync(UsersApiUrls.Me()); + return await _client.GetAsync(UsersApiUrls.Me(), cancellationToken: cancellationToken); } } } From aec461478f451050a7e1bd1161d8035fb8b330a5 Mon Sep 17 00:00:00 2001 From: romain vergnory Date: Wed, 17 May 2023 18:37:16 +0200 Subject: [PATCH 131/216] fix : syncedblock could not be deserialized --- Src/Notion.Client/Models/Blocks/IBlock.cs | 1 + Test/Notion.UnitTests/BlocksClientTests.cs | 2 +- .../blocks/RetrieveBlockChildrenResponse.json | 27 +++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/Src/Notion.Client/Models/Blocks/IBlock.cs b/Src/Notion.Client/Models/Blocks/IBlock.cs index df625cf6..24d6a12a 100644 --- a/Src/Notion.Client/Models/Blocks/IBlock.cs +++ b/Src/Notion.Client/Models/Blocks/IBlock.cs @@ -29,6 +29,7 @@ namespace Notion.Client [JsonSubtypes.KnownSubTypeAttribute(typeof(ParagraphBlock), BlockType.Paragraph)] [JsonSubtypes.KnownSubTypeAttribute(typeof(PDFBlock), BlockType.PDF)] [JsonSubtypes.KnownSubTypeAttribute(typeof(QuoteBlock), BlockType.Quote)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(SyncedBlockBlock), BlockType.SyncedBlock)] [JsonSubtypes.KnownSubTypeAttribute(typeof(TableBlock), BlockType.Table)] [JsonSubtypes.KnownSubTypeAttribute(typeof(TableRowBlock), BlockType.TableRow)] [JsonSubtypes.KnownSubTypeAttribute(typeof(TableOfContentsBlock), BlockType.TableOfContents)] diff --git a/Test/Notion.UnitTests/BlocksClientTests.cs b/Test/Notion.UnitTests/BlocksClientTests.cs index 5d436b97..0d6b2c01 100644 --- a/Test/Notion.UnitTests/BlocksClientTests.cs +++ b/Test/Notion.UnitTests/BlocksClientTests.cs @@ -38,7 +38,7 @@ public async Task RetrieveBlockChildren() // Assert var children = childrenResult.Results; - children.Should().HaveCount(8); + children.Should().HaveCount(9); } [Fact] diff --git a/Test/Notion.UnitTests/data/blocks/RetrieveBlockChildrenResponse.json b/Test/Notion.UnitTests/data/blocks/RetrieveBlockChildrenResponse.json index 649185e7..7b0ae104 100644 --- a/Test/Notion.UnitTests/data/blocks/RetrieveBlockChildrenResponse.json +++ b/Test/Notion.UnitTests/data/blocks/RetrieveBlockChildrenResponse.json @@ -155,6 +155,33 @@ "expiry_time": "2022-05-11T17:55:32.613Z" } } + }, + { + "object": "block", + "id": "570d1df0-56c9-42f7-b8b8-5315323f82de", + "parent": { + "type": "page_id", + "page_id": "9b02f058-bd87-46c2-95d2-7496fb9075bb" + }, + "created_time": "2023-02-03T13:59:00.000Z", + "last_edited_time": "2023-02-03T13:59:00.000Z", + "created_by": { + "object": "user", + "id": "92e803ec-193c-4bcd-b28e-88365858d562" + }, + "last_edited_by": { + "object": "user", + "id": "92e803ec-193c-4bcd-b28e-88365858d562" + }, + "has_children": true, + "archived": false, + "type": "synced_block", + "synced_block": { + "synced_from": { + "type": "block_id", + "block_id": "d2f7e3f3-c553-410d-a5f9-dfc0c335b169" + } + } } ], "next_cursor": null, From 06ea4f40cf5172e32632ed63a0ec2c4f1a989dd8 Mon Sep 17 00:00:00 2001 From: Herman Schoenfeld Date: Thu, 18 May 2023 10:44:55 +1000 Subject: [PATCH 132/216] Fixed synced block serialization (#1) Fix synced block serialization --- Src/Notion.Client/Models/Blocks/IBlock.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/Notion.Client/Models/Blocks/IBlock.cs b/Src/Notion.Client/Models/Blocks/IBlock.cs index bbe5d6e6..24d6a12a 100644 --- a/Src/Notion.Client/Models/Blocks/IBlock.cs +++ b/Src/Notion.Client/Models/Blocks/IBlock.cs @@ -29,7 +29,7 @@ namespace Notion.Client [JsonSubtypes.KnownSubTypeAttribute(typeof(ParagraphBlock), BlockType.Paragraph)] [JsonSubtypes.KnownSubTypeAttribute(typeof(PDFBlock), BlockType.PDF)] [JsonSubtypes.KnownSubTypeAttribute(typeof(QuoteBlock), BlockType.Quote)] - [JsonSubtypes.KnownSubTypeAttribute(typeof(UnsupportedBlock), BlockType.SyncedBlock)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(SyncedBlockBlock), BlockType.SyncedBlock)] [JsonSubtypes.KnownSubTypeAttribute(typeof(TableBlock), BlockType.Table)] [JsonSubtypes.KnownSubTypeAttribute(typeof(TableRowBlock), BlockType.TableRow)] [JsonSubtypes.KnownSubTypeAttribute(typeof(TableOfContentsBlock), BlockType.TableOfContents)] From c4b52ee8e2fe56886eb8638b9ed3ec3a11012938 Mon Sep 17 00:00:00 2001 From: RandomUser14 Date: Mon, 17 Jul 2023 12:19:41 +0200 Subject: [PATCH 133/216] fix: UniqueId property support --- .../Models/Database/Properties/Property.cs | 1 + .../Models/Database/Properties/PropertyType.cs | 5 ++++- .../Database/Properties/UniqueIdProperty.cs | 15 +++++++++++++++ Test/Notion.UnitTests/PropertyTests.cs | 2 ++ 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 Src/Notion.Client/Models/Database/Properties/UniqueIdProperty.cs diff --git a/Src/Notion.Client/Models/Database/Properties/Property.cs b/Src/Notion.Client/Models/Database/Properties/Property.cs index 163b7ef0..fa0dac50 100644 --- a/Src/Notion.Client/Models/Database/Properties/Property.cs +++ b/Src/Notion.Client/Models/Database/Properties/Property.cs @@ -25,6 +25,7 @@ namespace Notion.Client [JsonSubtypes.KnownSubTypeAttribute(typeof(StatusProperty), PropertyType.Status)] [JsonSubtypes.KnownSubTypeAttribute(typeof(TitleProperty), PropertyType.Title)] [JsonSubtypes.KnownSubTypeAttribute(typeof(UrlProperty), PropertyType.Url)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(UniqueIdProperty), PropertyType.UniqueId)] public class Property { [JsonProperty("id")] diff --git a/Src/Notion.Client/Models/Database/Properties/PropertyType.cs b/Src/Notion.Client/Models/Database/Properties/PropertyType.cs index e4db339a..1d53b2a8 100644 --- a/Src/Notion.Client/Models/Database/Properties/PropertyType.cs +++ b/Src/Notion.Client/Models/Database/Properties/PropertyType.cs @@ -67,6 +67,9 @@ public enum PropertyType LastEditedTime, [EnumMember(Value = "status")] - Status + Status, + + [EnumMember(Value = "unique_id")] + UniqueId, } } diff --git a/Src/Notion.Client/Models/Database/Properties/UniqueIdProperty.cs b/Src/Notion.Client/Models/Database/Properties/UniqueIdProperty.cs new file mode 100644 index 00000000..8b56b462 --- /dev/null +++ b/Src/Notion.Client/Models/Database/Properties/UniqueIdProperty.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class UniqueIdProperty : Property + { + public override PropertyType Type => PropertyType.UniqueId; + + [JsonProperty("unique_id")] + public Dictionary UniqueId { get; set; } + } +} + diff --git a/Test/Notion.UnitTests/PropertyTests.cs b/Test/Notion.UnitTests/PropertyTests.cs index 07949131..fc748413 100644 --- a/Test/Notion.UnitTests/PropertyTests.cs +++ b/Test/Notion.UnitTests/PropertyTests.cs @@ -26,6 +26,7 @@ public class PropertyTests [InlineData(typeof(SelectProperty), PropertyType.Select)] [InlineData(typeof(TitleProperty), PropertyType.Title)] [InlineData(typeof(UrlProperty), PropertyType.Url)] + [InlineData(typeof(UniqueIdProperty), PropertyType.UniqueId)] public void TestPropertyType(Type type, PropertyType expectedPropertyType) { var typeInstance = (Property)Activator.CreateInstance(type); @@ -54,6 +55,7 @@ public void TestPropertyType(Type type, PropertyType expectedPropertyType) [InlineData(typeof(SelectProperty), "select")] [InlineData(typeof(TitleProperty), "title")] [InlineData(typeof(UrlProperty), "url")] + [InlineData(typeof(UniqueIdProperty), "unique_id")] public void TestPropertyTypeText(Type type, string expectedPropertyType) { var typeInstance = (Property)Activator.CreateInstance(type); From a298ec89837f3f786de6e41640d1ef74d6db100e Mon Sep 17 00:00:00 2001 From: RandomUser14 Date: Mon, 17 Jul 2023 13:17:08 +0200 Subject: [PATCH 134/216] fix: Unique Id property parsing --- .../Models/PropertyValue/PropertyValue.cs | 1 + .../Models/PropertyValue/PropertyValueType.cs | 5 +++- .../PropertyValue/UniqueIdPropertyValue.cs | 29 +++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 Src/Notion.Client/Models/PropertyValue/UniqueIdPropertyValue.cs diff --git a/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs index c423be82..5f7a6b05 100644 --- a/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs @@ -29,6 +29,7 @@ namespace Notion.Client [JsonSubtypes.KnownSubTypeAttribute(typeof(StatusPropertyValue), PropertyValueType.Status)] [JsonSubtypes.KnownSubTypeAttribute(typeof(TitlePropertyValue), PropertyValueType.Title)] [JsonSubtypes.KnownSubTypeAttribute(typeof(UrlPropertyValue), PropertyValueType.Url)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(UniqueIdPropertyValue), PropertyValueType.UniqueId)] [SuppressMessage("ReSharper", "UnusedMember.Global")] [SuppressMessage("ReSharper", "UnassignedGetOnlyAutoProperty")] public class PropertyValue diff --git a/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs b/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs index 96ddaf77..ca6759c0 100644 --- a/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs +++ b/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs @@ -70,6 +70,9 @@ public enum PropertyValueType LastEditedBy, [EnumMember(Value = "status")] - Status + Status, + + [EnumMember(Value = "unique_id")] + UniqueId, } } diff --git a/Src/Notion.Client/Models/PropertyValue/UniqueIdPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/UniqueIdPropertyValue.cs new file mode 100644 index 00000000..716d9cce --- /dev/null +++ b/Src/Notion.Client/Models/PropertyValue/UniqueIdPropertyValue.cs @@ -0,0 +1,29 @@ +using System; +using Newtonsoft.Json; + +namespace Notion.Client +{ + /// + /// Unique Id property value object. + /// + public class UniqueIdPropertyValue : PropertyValue + { + public override PropertyValueType Type => PropertyValueType.UniqueId; + + /// + /// Unique Id property of database item + /// + [JsonProperty("unique_id")] + public UniqueIdValue UniqueId { get; set; } + } + + public class UniqueIdValue + { + [JsonProperty("prefix")] + public string Prefix { get; set; } + + [JsonProperty("number")] + public double? Number { get; set; } + } +} + From 366c5a408fde510940e211781d90bf2975f11fce Mon Sep 17 00:00:00 2001 From: Dmitry Fomenko Date: Thu, 7 Sep 2023 14:29:40 +0300 Subject: [PATCH 135/216] Fix Timestamp property value --- .../Models/Filters/TimestampLastEditedTimeFilter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/Notion.Client/Models/Filters/TimestampLastEditedTimeFilter.cs b/Src/Notion.Client/Models/Filters/TimestampLastEditedTimeFilter.cs index 695183cc..1cd22974 100644 --- a/Src/Notion.Client/Models/Filters/TimestampLastEditedTimeFilter.cs +++ b/Src/Notion.Client/Models/Filters/TimestampLastEditedTimeFilter.cs @@ -39,7 +39,7 @@ public TimestampLastEditedTimeFilter( } [JsonProperty("timestamp")] - public string Timestamp => "last_modified_time"; + public string Timestamp => "last_edited_time"; [JsonProperty("last_edited_time")] public DateFilter.Condition LastEditedTime { get; set; } From b3f859134b4e5f82a2739bbcd4db8c9e18d923fc Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 17 Sep 2023 03:09:52 +0530 Subject: [PATCH 136/216] Add support to pagination query params to List Users --- Src/Notion.Client/Api/Users/IUsersClient.cs | 6 ++++ .../Users/List/Request/ListUsersParameters.cs | 13 ++++++++ .../Api/Users/List/UsersClient.cs | 30 +++++++++++++++++++ Src/Notion.Client/Api/Users/UsersClient.cs | 2 +- 4 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 Src/Notion.Client/Api/Users/List/Request/ListUsersParameters.cs create mode 100644 Src/Notion.Client/Api/Users/List/UsersClient.cs diff --git a/Src/Notion.Client/Api/Users/IUsersClient.cs b/Src/Notion.Client/Api/Users/IUsersClient.cs index dc86ce12..0f9f18ac 100644 --- a/Src/Notion.Client/Api/Users/IUsersClient.cs +++ b/Src/Notion.Client/Api/Users/IUsersClient.cs @@ -1,5 +1,6 @@ using System.Threading; using System.Threading.Tasks; +using Notion.Client.List.Request; namespace Notion.Client { @@ -23,6 +24,11 @@ public interface IUsersClient /// Task> ListAsync(CancellationToken cancellationToken = default); + Task> ListAsync( + ListUsersParameters listUsersParameters, + CancellationToken cancellationToken = default + ); + /// /// Retrieves the bot User associated with the API token provided in the authorization header. /// diff --git a/Src/Notion.Client/Api/Users/List/Request/ListUsersParameters.cs b/Src/Notion.Client/Api/Users/List/Request/ListUsersParameters.cs new file mode 100644 index 00000000..046a0c5b --- /dev/null +++ b/Src/Notion.Client/Api/Users/List/Request/ListUsersParameters.cs @@ -0,0 +1,13 @@ +namespace Notion.Client.List.Request +{ + public interface IListUsersQueryParameters : IPaginationParameters + { + } + + public class ListUsersParameters : IListUsersQueryParameters + { + public string StartCursor { get; set; } + + public int? PageSize { get; set; } + } +} diff --git a/Src/Notion.Client/Api/Users/List/UsersClient.cs b/Src/Notion.Client/Api/Users/List/UsersClient.cs new file mode 100644 index 00000000..57c40ea3 --- /dev/null +++ b/Src/Notion.Client/Api/Users/List/UsersClient.cs @@ -0,0 +1,30 @@ +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using Notion.Client.List.Request; + +namespace Notion.Client +{ + public partial class UsersClient + { + public async Task> ListAsync( + ListUsersParameters listUsersParameters, + CancellationToken cancellationToken = default + ) + { + var queryParameters = (IListUsersQueryParameters)listUsersParameters; + + var queryParams = new Dictionary + { + { "start_cursor", queryParameters?.StartCursor }, + { "page_size", queryParameters?.PageSize?.ToString() } + }; + + return await _client.GetAsync>( + ApiEndpoints.UsersApiUrls.List(), + queryParams, + cancellationToken: cancellationToken + ); + } + } +} diff --git a/Src/Notion.Client/Api/Users/UsersClient.cs b/Src/Notion.Client/Api/Users/UsersClient.cs index 66c18d3d..f40299ee 100644 --- a/Src/Notion.Client/Api/Users/UsersClient.cs +++ b/Src/Notion.Client/Api/Users/UsersClient.cs @@ -4,7 +4,7 @@ namespace Notion.Client { - public class UsersClient : IUsersClient + public partial class UsersClient : IUsersClient { private readonly IRestClient _client; From 2c2b9f3404497fef17ca7cd5a8d18d882932ba44 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 17 Sep 2023 03:10:20 +0530 Subject: [PATCH 137/216] Run dotnet format --- .../Models/Database/Properties/PropertyType.cs | 2 +- .../Database/Properties/UniqueIdProperty.cs | 5 ++--- .../PropertyValue/UniqueIdPropertyValue.cs | 3 +-- .../IBlocksClientTests.cs | 16 ++++++++-------- Test/Notion.IntegrationTests/IPageClientTests.cs | 4 ++-- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/Src/Notion.Client/Models/Database/Properties/PropertyType.cs b/Src/Notion.Client/Models/Database/Properties/PropertyType.cs index 1d53b2a8..6391308c 100644 --- a/Src/Notion.Client/Models/Database/Properties/PropertyType.cs +++ b/Src/Notion.Client/Models/Database/Properties/PropertyType.cs @@ -70,6 +70,6 @@ public enum PropertyType Status, [EnumMember(Value = "unique_id")] - UniqueId, + UniqueId, } } diff --git a/Src/Notion.Client/Models/Database/Properties/UniqueIdProperty.cs b/Src/Notion.Client/Models/Database/Properties/UniqueIdProperty.cs index 8b56b462..4a9e9d5d 100644 --- a/Src/Notion.Client/Models/Database/Properties/UniqueIdProperty.cs +++ b/Src/Notion.Client/Models/Database/Properties/UniqueIdProperty.cs @@ -1,9 +1,8 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using Newtonsoft.Json; namespace Notion.Client -{ +{ public class UniqueIdProperty : Property { public override PropertyType Type => PropertyType.UniqueId; diff --git a/Src/Notion.Client/Models/PropertyValue/UniqueIdPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/UniqueIdPropertyValue.cs index 716d9cce..0ce1c704 100644 --- a/Src/Notion.Client/Models/PropertyValue/UniqueIdPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/UniqueIdPropertyValue.cs @@ -1,5 +1,4 @@ -using System; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Notion.Client { diff --git a/Test/Notion.IntegrationTests/IBlocksClientTests.cs b/Test/Notion.IntegrationTests/IBlocksClientTests.cs index 6f10189c..3f616cfa 100644 --- a/Test/Notion.IntegrationTests/IBlocksClientTests.cs +++ b/Test/Notion.IntegrationTests/IBlocksClientTests.cs @@ -211,7 +211,7 @@ private static IEnumerable BlockData() new Action((block, client) => { block.Should().NotBeNull(); - + block.Should().BeOfType().Subject .Audio.Should().BeOfType().Subject .External.Url.Should().Be("https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3"); @@ -252,7 +252,7 @@ private static IEnumerable BlockData() { Assert.NotNull(block); var calloutBlock = Assert.IsType(block); - + Assert.Equal("Test 2", calloutBlock.Callout.RichText.OfType().First().Text.Content); }) }, @@ -282,7 +282,7 @@ private static IEnumerable BlockData() { Assert.NotNull(block); var quoteBlock = Assert.IsType(block); - + Assert.Equal("Test 2", quoteBlock.Quote.RichText.OfType().First().Text.Content); }) }, @@ -314,7 +314,7 @@ private static IEnumerable BlockData() Assert.NotNull(block); var imageBlock = Assert.IsType(block); var imageFile = Assert.IsType(imageBlock.Image); - + Assert.Equal("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", imageFile.External.Url); }) @@ -339,7 +339,7 @@ private static IEnumerable BlockData() { Assert.NotNull(block); var embedBlock = Assert.IsType(block); - + Assert.Equal("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg", embedBlock.Embed.Url); }) @@ -381,10 +381,10 @@ private static IEnumerable BlockData() { Assert.NotNull(block); var templateBlock = Assert.IsType(block); - + Assert.Single(templateBlock.Template.RichText); Assert.Null(templateBlock.Template.Children); - + Assert.Equal("Test Template 2", templateBlock.Template.RichText.OfType().First().Text.Content); }) @@ -407,7 +407,7 @@ private static IEnumerable BlockData() { Assert.NotNull(block); var linkToPageBlock = Assert.IsType(block); - + var pageParent = Assert.IsType(linkToPageBlock.LinkToPage); // TODO: Currently the api doesn't allow to update the link_to_page block type diff --git a/Test/Notion.IntegrationTests/IPageClientTests.cs b/Test/Notion.IntegrationTests/IPageClientTests.cs index f0833be5..84ac493e 100644 --- a/Test/Notion.IntegrationTests/IPageClientTests.cs +++ b/Test/Notion.IntegrationTests/IPageClientTests.cs @@ -330,11 +330,11 @@ public async Task Bug_exception_when_attempting_to_set_select_property_to_nothin }; var updatedPage = await Client.Pages.UpdateAsync(page.Id, updatePageRequest); - + // Assert page.Properties["Colors1"].As().Select.Name.Should().Be("Red"); page.Properties["Colors2"].As().Select.Name.Should().Be("Green"); - + updatedPage.Properties["Colors1"].As().Select.Name.Should().Be("Blue"); updatedPage.Properties["Colors2"].As().Select.Should().BeNull(); From 2eff28f78263de0ee8c9c6b433cb600ee1c21a46 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 17 Sep 2023 03:32:04 +0530 Subject: [PATCH 138/216] Add support for Verification Property --- .../Models/PropertyValue/PropertyValue.cs | 1 + .../Models/PropertyValue/PropertyValueType.cs | 3 ++ .../VerificationPropertyValue.cs | 39 +++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 Src/Notion.Client/Models/PropertyValue/VerificationPropertyValue.cs diff --git a/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs index 5f7a6b05..a74b11da 100644 --- a/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs @@ -30,6 +30,7 @@ namespace Notion.Client [JsonSubtypes.KnownSubTypeAttribute(typeof(TitlePropertyValue), PropertyValueType.Title)] [JsonSubtypes.KnownSubTypeAttribute(typeof(UrlPropertyValue), PropertyValueType.Url)] [JsonSubtypes.KnownSubTypeAttribute(typeof(UniqueIdPropertyValue), PropertyValueType.UniqueId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(VerificationPropertyValue), PropertyValueType.Verification)] [SuppressMessage("ReSharper", "UnusedMember.Global")] [SuppressMessage("ReSharper", "UnassignedGetOnlyAutoProperty")] public class PropertyValue diff --git a/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs b/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs index ca6759c0..d77a564c 100644 --- a/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs +++ b/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs @@ -74,5 +74,8 @@ public enum PropertyValueType [EnumMember(Value = "unique_id")] UniqueId, + + [EnumMember(Value = "verification")] + Verification, } } diff --git a/Src/Notion.Client/Models/PropertyValue/VerificationPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/VerificationPropertyValue.cs new file mode 100644 index 00000000..8cdb9bae --- /dev/null +++ b/Src/Notion.Client/Models/PropertyValue/VerificationPropertyValue.cs @@ -0,0 +1,39 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + /// + /// Verification property value. + /// + public class VerificationPropertyValue : PropertyValue + { + public override PropertyValueType Type => PropertyValueType.Verification; + + /// + /// Object containing verification type-specific data. + /// + [JsonProperty("verification")] + public Info Verification { get; set; } + + public class Info + { + /// + /// The state of verification. Possible values are "verified" and "unverified". + /// + [JsonProperty("state")] + public string State { get; set; } + + /// + /// Describes the user who verified this page. + /// + [JsonProperty("verified_by")] + public User VerifiedBy { get; set; } + + /// + /// Date verification property values contain a date property value. + /// + [JsonProperty("date")] + public Date Date { get; set; } + } + } +} From 0c2df505fc82d807f0295dece0a930cf6252a3b1 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 17 Sep 2023 03:40:33 +0530 Subject: [PATCH 139/216] Add new notion api error codes --- Src/Notion.Client/NotionAPIErrorCode.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Src/Notion.Client/NotionAPIErrorCode.cs b/Src/Notion.Client/NotionAPIErrorCode.cs index 1dc822bd..e0264ae7 100644 --- a/Src/Notion.Client/NotionAPIErrorCode.cs +++ b/Src/Notion.Client/NotionAPIErrorCode.cs @@ -15,6 +15,9 @@ public enum NotionAPIErrorCode [EnumMember(Value = "invalid_request")] InvalidRequest, + [EnumMember(Value = "invalid_grant")] + InvalidGrant, + [EnumMember(Value = "validation_error")] ValidationError, @@ -40,6 +43,12 @@ public enum NotionAPIErrorCode InternalServerError, [EnumMember(Value = "service_unavailable")] - ServiceUnavailable + ServiceUnavailable, + + [EnumMember(Value = "database_connection_unavailable")] + DatabaseConnectionUnavailable, + + [EnumMember(Value = "gateway_timeout")] + GetewayTimeout } } From 9a393508a6c04e6b01f2828f72daefb5b80f4f80 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 17 Sep 2023 03:47:01 +0530 Subject: [PATCH 140/216] Add public_url on Page and Database --- Src/Notion.Client/Models/Database/Database.cs | 6 ++++++ Src/Notion.Client/Models/Page/Page.cs | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/Src/Notion.Client/Models/Database/Database.cs b/Src/Notion.Client/Models/Database/Database.cs index 33da29b7..f83d3316 100644 --- a/Src/Notion.Client/Models/Database/Database.cs +++ b/Src/Notion.Client/Models/Database/Database.cs @@ -52,5 +52,11 @@ public class Database : IObject, IObjectModificationData public PartialUser CreatedBy { get; set; } public PartialUser LastEditedBy { get; set; } + + /// + /// The public page URL if the page has been published to the web. Otherwise, null. + /// + [JsonProperty("public_url")] + public string PublicUrl { get; set; } } } diff --git a/Src/Notion.Client/Models/Page/Page.cs b/Src/Notion.Client/Models/Page/Page.cs index 996bdd46..cd81c411 100644 --- a/Src/Notion.Client/Models/Page/Page.cs +++ b/Src/Notion.Client/Models/Page/Page.cs @@ -67,5 +67,11 @@ public class Page : IObject, IObjectModificationData public PartialUser CreatedBy { get; set; } public PartialUser LastEditedBy { get; set; } + + /// + /// The public page URL if the page has been published to the web. Otherwise, null. + /// + [JsonProperty("public_url")] + public string PublicUrl { get; set; } } } From 6ee3e6364780704f4bf29aa2c6d43c2d528a921c Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 17 Sep 2023 03:51:39 +0530 Subject: [PATCH 141/216] A support for `after` parameter to the Append block children API --- .../Blocks/RequestParams/BlocksAppendChildrenParameters.cs | 2 ++ .../RequestParams/IBlocksAppendChildrenBodyParameters.cs | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksAppendChildrenParameters.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksAppendChildrenParameters.cs index e78899bb..0d5574dd 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksAppendChildrenParameters.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksAppendChildrenParameters.cs @@ -5,5 +5,7 @@ namespace Notion.Client public class BlocksAppendChildrenParameters : IBlocksAppendChildrenBodyParameters { public IEnumerable Children { get; set; } + + public string After { get; set; } } } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/IBlocksAppendChildrenBodyParameters.cs b/Src/Notion.Client/Api/Blocks/RequestParams/IBlocksAppendChildrenBodyParameters.cs index bdd4d324..ef1321aa 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/IBlocksAppendChildrenBodyParameters.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/IBlocksAppendChildrenBodyParameters.cs @@ -8,5 +8,11 @@ public interface IBlocksAppendChildrenBodyParameters { [JsonProperty("children")] IEnumerable Children { get; set; } + + /// + /// The ID of the existing block that the new block should be appended after. + /// + [JsonProperty("after")] + public string After { get; set; } } } From 0029cf791ffeb90a44757bec610fe3b5019baac3 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 17 Sep 2023 04:15:58 +0530 Subject: [PATCH 142/216] Add support for filter_properties in Database query api query params --- .../Api/Databases/DatabasesClient.cs | 15 +++++++++++++-- .../RequestParams/DatabasesQueryParameters.cs | 4 +++- .../IDatabaseQueryQueryParameters.cs | 11 +++++++++++ Src/Notion.Client/RestClient/IRestClient.cs | 2 +- Src/Notion.Client/RestClient/RestClient.cs | 6 +++--- Src/Notion.Client/http/QueryHelpers.cs | 2 +- 6 files changed, 32 insertions(+), 8 deletions(-) create mode 100644 Src/Notion.Client/Api/Databases/RequestParams/IDatabaseQueryQueryParameters.cs diff --git a/Src/Notion.Client/Api/Databases/DatabasesClient.cs b/Src/Notion.Client/Api/Databases/DatabasesClient.cs index 4412b8bb..ca6a1bef 100644 --- a/Src/Notion.Client/Api/Databases/DatabasesClient.cs +++ b/Src/Notion.Client/Api/Databases/DatabasesClient.cs @@ -1,4 +1,6 @@ -using System.Threading; +using System.Collections.Generic; +using System.Linq; +using System.Threading; using System.Threading.Tasks; using static Notion.Client.ApiEndpoints; @@ -23,8 +25,17 @@ public async Task> QueryAsync( DatabasesQueryParameters databasesQueryParameters, CancellationToken cancellationToken = default) { var body = (IDatabaseQueryBodyParameters)databasesQueryParameters; + var queryParameters = (IDatabaseQueryQueryParameters)databasesQueryParameters; - return await _client.PostAsync>(DatabasesApiUrls.Query(databaseId), body, cancellationToken: cancellationToken); + var queryParams = queryParameters.FilterProperties? + .Select(x => new KeyValuePair("filter_properties", x)); + + return await _client.PostAsync>( + DatabasesApiUrls.Query(databaseId), + body, + queryParams, + cancellationToken: cancellationToken + ); } public async Task CreateAsync(DatabasesCreateParameters databasesCreateParameters, CancellationToken cancellationToken = default) diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesQueryParameters.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesQueryParameters.cs index 51bd8a06..2c2bb030 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesQueryParameters.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesQueryParameters.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - public class DatabasesQueryParameters : IDatabaseQueryBodyParameters + public class DatabasesQueryParameters : IDatabaseQueryBodyParameters, IDatabaseQueryQueryParameters { public Filter Filter { get; set; } @@ -11,5 +11,7 @@ public class DatabasesQueryParameters : IDatabaseQueryBodyParameters public string StartCursor { get; set; } public int? PageSize { get; set; } + + public List FilterProperties { get; set; } } } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/IDatabaseQueryQueryParameters.cs b/Src/Notion.Client/Api/Databases/RequestParams/IDatabaseQueryQueryParameters.cs new file mode 100644 index 00000000..f8ba1f41 --- /dev/null +++ b/Src/Notion.Client/Api/Databases/RequestParams/IDatabaseQueryQueryParameters.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public interface IDatabaseQueryQueryParameters + { + [JsonProperty("filter_properties")] + List FilterProperties { get; set; } + } +} diff --git a/Src/Notion.Client/RestClient/IRestClient.cs b/Src/Notion.Client/RestClient/IRestClient.cs index 7abb8553..b8ffe5b3 100644 --- a/Src/Notion.Client/RestClient/IRestClient.cs +++ b/Src/Notion.Client/RestClient/IRestClient.cs @@ -17,7 +17,7 @@ Task GetAsync( Task PostAsync( string uri, object body, - IDictionary queryParams = null, + IEnumerable> queryParams = null, IDictionary headers = null, JsonSerializerSettings serializerSettings = null, CancellationToken cancellationToken = default); diff --git a/Src/Notion.Client/RestClient/RestClient.cs b/Src/Notion.Client/RestClient/RestClient.cs index 307fcd7a..e64f187d 100644 --- a/Src/Notion.Client/RestClient/RestClient.cs +++ b/Src/Notion.Client/RestClient/RestClient.cs @@ -45,7 +45,7 @@ public async Task GetAsync( public async Task PostAsync( string uri, object body, - IDictionary queryParams = null, + IEnumerable> queryParams = null, IDictionary headers = null, JsonSerializerSettings serializerSettings = null, CancellationToken cancellationToken = default) @@ -125,7 +125,7 @@ private static async Task BuildException(HttpResponseMessage response private async Task SendAsync( string requestUri, HttpMethod httpMethod, - IDictionary queryParams = null, + IEnumerable> queryParams = null, IDictionary headers = null, Action attachContent = null, CancellationToken cancellationToken = default) @@ -176,7 +176,7 @@ private void EnsureHttpClient() _httpClient.BaseAddress = new Uri(_options.BaseUrl); } - private static string AddQueryString(string uri, IDictionary queryParams) + private static string AddQueryString(string uri, IEnumerable> queryParams) { return queryParams == null ? uri : QueryHelpers.AddQueryString(uri, queryParams); } diff --git a/Src/Notion.Client/http/QueryHelpers.cs b/Src/Notion.Client/http/QueryHelpers.cs index 530536f3..60de4e7b 100644 --- a/Src/Notion.Client/http/QueryHelpers.cs +++ b/Src/Notion.Client/http/QueryHelpers.cs @@ -45,7 +45,7 @@ public static string AddQueryString(string uri, IDictionary quer return AddQueryString(uri, (IEnumerable>)queryParams); } - private static string AddQueryString( + public static string AddQueryString( string uri, IEnumerable> queryParams) { From 0882a76051b8382af007f4967f20d969f1309ad0 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 17 Sep 2023 04:40:33 +0530 Subject: [PATCH 143/216] NotionApiRateLimitException to expose Retry-After value --- Src/Notion.Client/NotionApiException.cs | 17 ++++++++++++++++- Src/Notion.Client/RestClient/RestClient.cs | 11 +++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Src/Notion.Client/NotionApiException.cs b/Src/Notion.Client/NotionApiException.cs index d11fea6f..3e5d2b5b 100644 --- a/Src/Notion.Client/NotionApiException.cs +++ b/Src/Notion.Client/NotionApiException.cs @@ -5,7 +5,7 @@ namespace Notion.Client { [SuppressMessage("ReSharper", "MemberCanBePrivate.Global")] - public sealed class NotionApiException : Exception + public class NotionApiException : Exception { public NotionApiException(HttpStatusCode statusCode, NotionAPIErrorCode? notionAPIErrorCode, string message) : this(statusCode, notionAPIErrorCode, message, null) @@ -29,4 +29,19 @@ private NotionApiException( public HttpStatusCode StatusCode { get; } } + + public sealed class NotionApiRateLimitException : NotionApiException + { + public TimeSpan? RetryAfter { get; } + + public NotionApiRateLimitException( + HttpStatusCode statusCode, + NotionAPIErrorCode? notionAPIErrorCode, + string message, + TimeSpan? retryAfter) + : base(statusCode, notionAPIErrorCode, message) + { + RetryAfter = retryAfter; + } + } } diff --git a/Src/Notion.Client/RestClient/RestClient.cs b/Src/Notion.Client/RestClient/RestClient.cs index 307fcd7a..a16e314e 100644 --- a/Src/Notion.Client/RestClient/RestClient.cs +++ b/Src/Notion.Client/RestClient/RestClient.cs @@ -112,6 +112,17 @@ private static async Task BuildException(HttpResponseMessage response try { errorResponse = JsonConvert.DeserializeObject(errorBody); + + if (errorResponse.ErrorCode == NotionAPIErrorCode.RateLimited) + { + var retryAfter = response.Headers.RetryAfter.Delta; + return new NotionApiRateLimitException( + response.StatusCode, + errorResponse.ErrorCode, + errorResponse.Message, + retryAfter + ); + } } catch (Exception ex) { From 5188eb4683532e07ca570bbb9bccfa2a2b2e07a9 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 17 Sep 2023 04:54:54 +0530 Subject: [PATCH 144/216] Resolve Code Factor warning --- Src/Notion.Client/NotionApiException.cs | 20 +++++------------ .../NotionApiRateLimitException.cs | 22 +++++++++++++++++++ 2 files changed, 27 insertions(+), 15 deletions(-) create mode 100644 Src/Notion.Client/NotionApiRateLimitException.cs diff --git a/Src/Notion.Client/NotionApiException.cs b/Src/Notion.Client/NotionApiException.cs index 3e5d2b5b..cf62f1b6 100644 --- a/Src/Notion.Client/NotionApiException.cs +++ b/Src/Notion.Client/NotionApiException.cs @@ -21,6 +21,11 @@ private NotionApiException( NotionAPIErrorCode = notionAPIErrorCode; StatusCode = statusCode; + InitializeData(); + } + + private void InitializeData() + { Data.Add("StatusCode", StatusCode); Data.Add("NotionApiErrorCode", NotionAPIErrorCode); } @@ -29,19 +34,4 @@ private NotionApiException( public HttpStatusCode StatusCode { get; } } - - public sealed class NotionApiRateLimitException : NotionApiException - { - public TimeSpan? RetryAfter { get; } - - public NotionApiRateLimitException( - HttpStatusCode statusCode, - NotionAPIErrorCode? notionAPIErrorCode, - string message, - TimeSpan? retryAfter) - : base(statusCode, notionAPIErrorCode, message) - { - RetryAfter = retryAfter; - } - } } diff --git a/Src/Notion.Client/NotionApiRateLimitException.cs b/Src/Notion.Client/NotionApiRateLimitException.cs new file mode 100644 index 00000000..c10cce2d --- /dev/null +++ b/Src/Notion.Client/NotionApiRateLimitException.cs @@ -0,0 +1,22 @@ +using System; +using System.Net; + +namespace Notion.Client +{ + public sealed class NotionApiRateLimitException : NotionApiException + { + public TimeSpan? RetryAfter { get; } + + public NotionApiRateLimitException( + HttpStatusCode statusCode, + NotionAPIErrorCode? notionAPIErrorCode, + string message, + TimeSpan? retryAfter) + : base(statusCode, notionAPIErrorCode, message) + { + RetryAfter = retryAfter; + + Data.Add("RetryAfter", retryAfter); + } + } +} From 9c433dafa1b50ab23b77bb41c3b53e63f2412754 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 17 Sep 2023 05:12:51 +0530 Subject: [PATCH 145/216] Change VersionPrefix 4.2.0-preview --- Src/Notion.Client/Notion.Client.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/Notion.Client/Notion.Client.csproj b/Src/Notion.Client/Notion.Client.csproj index 4a614c64..c7e96e08 100644 --- a/Src/Notion.Client/Notion.Client.csproj +++ b/Src/Notion.Client/Notion.Client.csproj @@ -1,7 +1,7 @@  - 4.1.0-preview + 4.2.0-preview netstandard2.0 9.0 From 95d0b6895d0382574196c0c4c6d066d3830a20bf Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Fri, 13 Oct 2023 00:17:46 +0530 Subject: [PATCH 146/216] Integrate release drafter (#389) * Add release drafter workflow * Add release drafter configuration --- .github/release-drafter.yml | 16 +++++++++++ .github/workflows/release-drafter.yml | 41 +++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 .github/release-drafter.yml create mode 100644 .github/workflows/release-drafter.yml diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml new file mode 100644 index 00000000..f42ffd37 --- /dev/null +++ b/.github/release-drafter.yml @@ -0,0 +1,16 @@ +categories: + - title: '🚀 Features' + labels: + - 'feature' + - 'enhancement' + - title: '🐛 Bug Fixes' + labels: + - 'fix' + - 'bugfix' + - 'bug' + - title: '🧰 Maintenance' + label: 'chore' +template: | + ## Changes + + $CHANGES \ No newline at end of file diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml new file mode 100644 index 00000000..4eed5a56 --- /dev/null +++ b/.github/workflows/release-drafter.yml @@ -0,0 +1,41 @@ +name: Release Drafter + +on: + push: + # branches to consider in the event; optional, defaults to all + branches: + - main + # pull_request event is required only for autolabeler + pull_request: + # Only following types are handled by the action, but one can default to all as well + types: [opened, reopened, synchronize] + # pull_request_target event is required for autolabeler to support PRs from forks + pull_request_target: + types: [opened, reopened, synchronize] + +permissions: + contents: read + +jobs: + update_release_draft: + permissions: + # write permission is required to create a github release + contents: write + # write permission is required for autolabeler + # otherwise, read permission is required at least + pull-requests: write + runs-on: ubuntu-latest + steps: + # (Optional) GitHub Enterprise requires GHE_HOST variable set + #- name: Set GHE_HOST + # run: | + # echo "GHE_HOST=${GITHUB_SERVER_URL##https:\/\/}" >> $GITHUB_ENV + + # Drafts your next Release notes as Pull Requests are merged into "master" + - uses: release-drafter/release-drafter@v5.21.1 + # (Optional) specify config name to use, relative to .github/. Default: release-drafter.yml + # with: + # config-name: my-config.yml + # disable-autolabeler: true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file From 5ec0c9586f084e4aa3d145059f07310c96dd7a90 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Fri, 13 Oct 2023 14:54:51 +0530 Subject: [PATCH 147/216] Add interface for Wiki database --- Src/Notion.Client/Models/Database/Database.cs | 2 +- Src/Notion.Client/Models/Database/IWikiDatabase.cs | 13 +++++++++++++ Src/Notion.Client/Models/Page/Page.cs | 2 +- 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 Src/Notion.Client/Models/Database/IWikiDatabase.cs diff --git a/Src/Notion.Client/Models/Database/Database.cs b/Src/Notion.Client/Models/Database/Database.cs index f83d3316..c5a46ed6 100644 --- a/Src/Notion.Client/Models/Database/Database.cs +++ b/Src/Notion.Client/Models/Database/Database.cs @@ -4,7 +4,7 @@ namespace Notion.Client { - public class Database : IObject, IObjectModificationData + public class Database : IObject, IObjectModificationData, IWikiDatabase { [JsonProperty("title")] public List Title { get; set; } diff --git a/Src/Notion.Client/Models/Database/IWikiDatabase.cs b/Src/Notion.Client/Models/Database/IWikiDatabase.cs new file mode 100644 index 00000000..ac7a798b --- /dev/null +++ b/Src/Notion.Client/Models/Database/IWikiDatabase.cs @@ -0,0 +1,13 @@ +using JsonSubTypes; +using Newtonsoft.Json; + +namespace Notion.Client +{ + [JsonConverter(typeof(JsonSubtypes), "object")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(Page), ObjectType.Page)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(Database), ObjectType.Database)] + public interface IWikiDatabase : IObject + { + + } +} diff --git a/Src/Notion.Client/Models/Page/Page.cs b/Src/Notion.Client/Models/Page/Page.cs index cd81c411..c6bcfae1 100644 --- a/Src/Notion.Client/Models/Page/Page.cs +++ b/Src/Notion.Client/Models/Page/Page.cs @@ -4,7 +4,7 @@ namespace Notion.Client { - public class Page : IObject, IObjectModificationData + public class Page : IObject, IObjectModificationData, IWikiDatabase { /// /// The parent of this page. Can be a database, page, or workspace. From 28132edb7827cccd936b61911b0a51b38136dff7 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Fri, 13 Oct 2023 14:57:30 +0530 Subject: [PATCH 148/216] Update Query database endpoint to return both Page and Database --- .../Api/Databases/DatabasesClient.cs | 24 ++-------------- .../Api/Databases/IDatabasesClient.cs | 2 +- .../Api/Databases/Query/DatabasesClient.cs | 28 +++++++++++++++++++ .../Request}/DatabasesQueryParameters.cs | 0 .../Request}/IDatabaseQueryBodyParameters.cs | 0 .../Request}/IDatabaseQueryQueryParameters.cs | 0 .../Query/Response/DatabaseQueryResponse.cs | 7 +++++ Test/Notion.UnitTests/DatabasesClientTests.cs | 6 ++-- 8 files changed, 42 insertions(+), 25 deletions(-) create mode 100644 Src/Notion.Client/Api/Databases/Query/DatabasesClient.cs rename Src/Notion.Client/Api/Databases/{RequestParams => Query/Request}/DatabasesQueryParameters.cs (100%) rename Src/Notion.Client/Api/Databases/{RequestParams => Query/Request}/IDatabaseQueryBodyParameters.cs (100%) rename Src/Notion.Client/Api/Databases/{RequestParams => Query/Request}/IDatabaseQueryQueryParameters.cs (100%) create mode 100644 Src/Notion.Client/Api/Databases/Query/Response/DatabaseQueryResponse.cs diff --git a/Src/Notion.Client/Api/Databases/DatabasesClient.cs b/Src/Notion.Client/Api/Databases/DatabasesClient.cs index ca6a1bef..673ee122 100644 --- a/Src/Notion.Client/Api/Databases/DatabasesClient.cs +++ b/Src/Notion.Client/Api/Databases/DatabasesClient.cs @@ -1,12 +1,10 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading; +using System.Threading; using System.Threading.Tasks; using static Notion.Client.ApiEndpoints; namespace Notion.Client { - public class DatabasesClient : IDatabasesClient + public sealed partial class DatabasesClient : IDatabasesClient { private readonly IRestClient _client; @@ -20,24 +18,6 @@ public async Task RetrieveAsync(string databaseId, CancellationToken c return await _client.GetAsync(DatabasesApiUrls.Retrieve(databaseId), cancellationToken: cancellationToken); } - public async Task> QueryAsync( - string databaseId, - DatabasesQueryParameters databasesQueryParameters, CancellationToken cancellationToken = default) - { - var body = (IDatabaseQueryBodyParameters)databasesQueryParameters; - var queryParameters = (IDatabaseQueryQueryParameters)databasesQueryParameters; - - var queryParams = queryParameters.FilterProperties? - .Select(x => new KeyValuePair("filter_properties", x)); - - return await _client.PostAsync>( - DatabasesApiUrls.Query(databaseId), - body, - queryParams, - cancellationToken: cancellationToken - ); - } - public async Task CreateAsync(DatabasesCreateParameters databasesCreateParameters, CancellationToken cancellationToken = default) { var body = (IDatabasesCreateBodyParameters)databasesCreateParameters; diff --git a/Src/Notion.Client/Api/Databases/IDatabasesClient.cs b/Src/Notion.Client/Api/Databases/IDatabasesClient.cs index c7e1c21a..98df1273 100644 --- a/Src/Notion.Client/Api/Databases/IDatabasesClient.cs +++ b/Src/Notion.Client/Api/Databases/IDatabasesClient.cs @@ -24,7 +24,7 @@ public interface IDatabasesClient /// /// /// - Task> QueryAsync(string databaseId, DatabasesQueryParameters databasesQueryParameters, CancellationToken cancellationToken = default); + Task QueryAsync(string databaseId, DatabasesQueryParameters databasesQueryParameters, CancellationToken cancellationToken = default); /// /// Creates a database as a subpage in the specified parent page, with the specified properties schema. diff --git a/Src/Notion.Client/Api/Databases/Query/DatabasesClient.cs b/Src/Notion.Client/Api/Databases/Query/DatabasesClient.cs new file mode 100644 index 00000000..2d0c62be --- /dev/null +++ b/Src/Notion.Client/Api/Databases/Query/DatabasesClient.cs @@ -0,0 +1,28 @@ +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; + +namespace Notion.Client +{ + public sealed partial class DatabasesClient + { + public async Task QueryAsync( + string databaseId, + DatabasesQueryParameters databasesQueryParameters, CancellationToken cancellationToken = default) + { + var body = (IDatabaseQueryBodyParameters)databasesQueryParameters; + var queryParameters = (IDatabaseQueryQueryParameters)databasesQueryParameters; + + var queryParams = queryParameters.FilterProperties? + .Select(x => new KeyValuePair("filter_properties", x)); + + return await _client.PostAsync( + ApiEndpoints.DatabasesApiUrls.Query(databaseId), + body, + queryParams, + cancellationToken: cancellationToken + ); + } + } +} diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesQueryParameters.cs b/Src/Notion.Client/Api/Databases/Query/Request/DatabasesQueryParameters.cs similarity index 100% rename from Src/Notion.Client/Api/Databases/RequestParams/DatabasesQueryParameters.cs rename to Src/Notion.Client/Api/Databases/Query/Request/DatabasesQueryParameters.cs diff --git a/Src/Notion.Client/Api/Databases/RequestParams/IDatabaseQueryBodyParameters.cs b/Src/Notion.Client/Api/Databases/Query/Request/IDatabaseQueryBodyParameters.cs similarity index 100% rename from Src/Notion.Client/Api/Databases/RequestParams/IDatabaseQueryBodyParameters.cs rename to Src/Notion.Client/Api/Databases/Query/Request/IDatabaseQueryBodyParameters.cs diff --git a/Src/Notion.Client/Api/Databases/RequestParams/IDatabaseQueryQueryParameters.cs b/Src/Notion.Client/Api/Databases/Query/Request/IDatabaseQueryQueryParameters.cs similarity index 100% rename from Src/Notion.Client/Api/Databases/RequestParams/IDatabaseQueryQueryParameters.cs rename to Src/Notion.Client/Api/Databases/Query/Request/IDatabaseQueryQueryParameters.cs diff --git a/Src/Notion.Client/Api/Databases/Query/Response/DatabaseQueryResponse.cs b/Src/Notion.Client/Api/Databases/Query/Response/DatabaseQueryResponse.cs new file mode 100644 index 00000000..73968c38 --- /dev/null +++ b/Src/Notion.Client/Api/Databases/Query/Response/DatabaseQueryResponse.cs @@ -0,0 +1,7 @@ +namespace Notion.Client +{ + // ReSharper disable once ClassNeverInstantiated.Global + public class DatabaseQueryResponse : PaginatedList + { + } +} diff --git a/Test/Notion.UnitTests/DatabasesClientTests.cs b/Test/Notion.UnitTests/DatabasesClientTests.cs index fc06ebc7..3bd047a7 100644 --- a/Test/Notion.UnitTests/DatabasesClientTests.cs +++ b/Test/Notion.UnitTests/DatabasesClientTests.cs @@ -64,8 +64,9 @@ public async Task QueryAsync() pagesPaginatedList.Results.Should().ContainSingle(); - foreach (var page in pagesPaginatedList.Results) + foreach (var iWikiDatabase in pagesPaginatedList.Results) { + var page = (Page)iWikiDatabase; page.Parent.Should().BeAssignableTo(); page.Object.Should().Be(ObjectType.Page); } @@ -476,8 +477,9 @@ var jsonData pagesPaginatedList.Results.Should().ContainSingle(); - foreach (var page in pagesPaginatedList.Results) + foreach (var iWikiDatabase in pagesPaginatedList.Results) { + var page = (Page)iWikiDatabase; page.Parent.Should().BeAssignableTo(); page.Object.Should().Be(ObjectType.Page); From 770c4e59ccba465f8f9ed1e129323ab6f9aeca77 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Fri, 13 Oct 2023 14:57:52 +0530 Subject: [PATCH 149/216] Add integration test for Query database api --- .../DatabasesClientTests.cs | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 Test/Notion.IntegrationTests/DatabasesClientTests.cs diff --git a/Test/Notion.IntegrationTests/DatabasesClientTests.cs b/Test/Notion.IntegrationTests/DatabasesClientTests.cs new file mode 100644 index 00000000..069f5be8 --- /dev/null +++ b/Test/Notion.IntegrationTests/DatabasesClientTests.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Notion.Client; +using Xunit; + +namespace Notion.IntegrationTests; + +public class DatabasesClientTests : IntegrationTestBase, IDisposable +{ + private readonly Page _page; + + public DatabasesClientTests() + { + _page = Client.Pages.CreateAsync( + PagesCreateParametersBuilder.Create( + new ParentPageInput { PageId = ParentPageId } + ).Build() + ).Result; + } + + public void Dispose() + { + Client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters { Archived = true }).Wait(); + } + + [Fact] + public async Task QueryDatabase() + { + // Arrange + var createdDatabase = await CreateDatabaseWithAPageAsync(); + + + // Act + var response = await Client.Databases.QueryAsync(createdDatabase.Id, new DatabasesQueryParameters()); + + // Assert + Assert.NotNull(response.Results); + Assert.Single(response.Results); + var page = response.Results.Cast().First(); + var title = page.Properties["Name"] as TitlePropertyValue; + Assert.Equal("Test Title", (title!.Title.Cast().First()).Text.Content); + } + + private async Task CreateDatabaseWithAPageAsync() + { + var createDbRequest = new DatabasesCreateParameters + { + Title = new List + { + new RichTextTextInput + { + Text = new Text + { + Content = "Test List", + Link = null + } + } + }, + Properties = new Dictionary + { + { "Name", new TitlePropertySchema { Title = new Dictionary() } }, + }, + Parent = new ParentPageInput { PageId = _page.Id } + }; + + var createdDatabase = await Client.Databases.CreateAsync(createDbRequest); + + var pagesCreateParameters = PagesCreateParametersBuilder + .Create(new DatabaseParentInput { DatabaseId = createdDatabase.Id }) + .AddProperty("Name", + new TitlePropertyValue + { + Title = new List + { + new RichTextText { Text = new Text { Content = "Test Title" } } + } + }) + .Build(); + + await Client.Pages.CreateAsync(pagesCreateParameters); + + return createdDatabase; + } +} From 8236df37f5bfd444f4efc27d0755a8e438efd5b0 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Fri, 13 Oct 2023 15:02:19 +0530 Subject: [PATCH 150/216] Resolve code factor violations --- Src/Notion.Client/Models/Database/IWikiDatabase.cs | 1 - Test/Notion.IntegrationTests/DatabasesClientTests.cs | 1 - 2 files changed, 2 deletions(-) diff --git a/Src/Notion.Client/Models/Database/IWikiDatabase.cs b/Src/Notion.Client/Models/Database/IWikiDatabase.cs index ac7a798b..59969175 100644 --- a/Src/Notion.Client/Models/Database/IWikiDatabase.cs +++ b/Src/Notion.Client/Models/Database/IWikiDatabase.cs @@ -8,6 +8,5 @@ namespace Notion.Client [JsonSubtypes.KnownSubTypeAttribute(typeof(Database), ObjectType.Database)] public interface IWikiDatabase : IObject { - } } diff --git a/Test/Notion.IntegrationTests/DatabasesClientTests.cs b/Test/Notion.IntegrationTests/DatabasesClientTests.cs index 069f5be8..e2255339 100644 --- a/Test/Notion.IntegrationTests/DatabasesClientTests.cs +++ b/Test/Notion.IntegrationTests/DatabasesClientTests.cs @@ -31,7 +31,6 @@ public async Task QueryDatabase() // Arrange var createdDatabase = await CreateDatabaseWithAPageAsync(); - // Act var response = await Client.Databases.QueryAsync(createdDatabase.Id, new DatabasesQueryParameters()); From c932a4264b89c0e402f0a1755d93069eab07fafb Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Fri, 13 Oct 2023 16:14:41 +0530 Subject: [PATCH 151/216] Add support for create token endpoint --- Src/Notion.Client/Api/ApiEndpoints.cs | 5 +++ .../Authentication/AuthenticationClient.cs | 12 +++++++ .../CreateToken/AuthenticationClient.cs | 21 +++++++++++ .../CreateToken/Request/CreateTokenRequest.cs | 13 +++++++ .../CreateToken/Request/ExternalAccount.cs | 22 ++++++++++++ .../Request/ICreateTokenBodyParameters.cs | 35 +++++++++++++++++++ .../Response/CreateTokenResponse.cs | 31 ++++++++++++++++ .../Authentication/IAuthenticationClient.cs | 22 ++++++++++++ Src/Notion.Client/NotionClient.cs | 8 ++++- Src/Notion.Client/NotionClientFactory.cs | 5 +-- 10 files changed, 171 insertions(+), 3 deletions(-) create mode 100644 Src/Notion.Client/Api/Authentication/AuthenticationClient.cs create mode 100644 Src/Notion.Client/Api/Authentication/CreateToken/AuthenticationClient.cs create mode 100644 Src/Notion.Client/Api/Authentication/CreateToken/Request/CreateTokenRequest.cs create mode 100644 Src/Notion.Client/Api/Authentication/CreateToken/Request/ExternalAccount.cs create mode 100644 Src/Notion.Client/Api/Authentication/CreateToken/Request/ICreateTokenBodyParameters.cs create mode 100644 Src/Notion.Client/Api/Authentication/CreateToken/Response/CreateTokenResponse.cs create mode 100644 Src/Notion.Client/Api/Authentication/IAuthenticationClient.cs diff --git a/Src/Notion.Client/Api/ApiEndpoints.cs b/Src/Notion.Client/Api/ApiEndpoints.cs index a6434683..4ed80bb1 100644 --- a/Src/Notion.Client/Api/ApiEndpoints.cs +++ b/Src/Notion.Client/Api/ApiEndpoints.cs @@ -131,5 +131,10 @@ public static string Create() return "/v1/comments"; } } + + public static class AuthenticationUrls + { + public static string CreateToken() => "/v1/oauth/token"; + } } } diff --git a/Src/Notion.Client/Api/Authentication/AuthenticationClient.cs b/Src/Notion.Client/Api/Authentication/AuthenticationClient.cs new file mode 100644 index 00000000..ab141200 --- /dev/null +++ b/Src/Notion.Client/Api/Authentication/AuthenticationClient.cs @@ -0,0 +1,12 @@ +namespace Notion.Client +{ + public sealed partial class AuthenticationClient : IAuthenticationClient + { + private readonly IRestClient _client; + + public AuthenticationClient(IRestClient restClient) + { + _client = restClient; + } + } +} diff --git a/Src/Notion.Client/Api/Authentication/CreateToken/AuthenticationClient.cs b/Src/Notion.Client/Api/Authentication/CreateToken/AuthenticationClient.cs new file mode 100644 index 00000000..23632632 --- /dev/null +++ b/Src/Notion.Client/Api/Authentication/CreateToken/AuthenticationClient.cs @@ -0,0 +1,21 @@ +using System.Threading; +using System.Threading.Tasks; + +namespace Notion.Client +{ + public sealed partial class AuthenticationClient + { + public async Task CreateTokenAsync( + CreateTokenRequest createTokenRequest, + CancellationToken cancellationToken = default) + { + var body = (ICreateTokenBodyParameters)createTokenRequest; + + return await _client.PostAsync( + ApiEndpoints.AuthenticationUrls.CreateToken(), + body, + cancellationToken: cancellationToken + ); + } + } +} diff --git a/Src/Notion.Client/Api/Authentication/CreateToken/Request/CreateTokenRequest.cs b/Src/Notion.Client/Api/Authentication/CreateToken/Request/CreateTokenRequest.cs new file mode 100644 index 00000000..3fe8ffde --- /dev/null +++ b/Src/Notion.Client/Api/Authentication/CreateToken/Request/CreateTokenRequest.cs @@ -0,0 +1,13 @@ +namespace Notion.Client +{ + public class CreateTokenRequest : ICreateTokenBodyParameters + { + public string GrantType => "authorization_code"; + + public string Code { get; set; } + + public string RedirectUri { get; set; } + + public ExternalAccount ExternalAccount { get; set; } + } +} diff --git a/Src/Notion.Client/Api/Authentication/CreateToken/Request/ExternalAccount.cs b/Src/Notion.Client/Api/Authentication/CreateToken/Request/ExternalAccount.cs new file mode 100644 index 00000000..432d709f --- /dev/null +++ b/Src/Notion.Client/Api/Authentication/CreateToken/Request/ExternalAccount.cs @@ -0,0 +1,22 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + /// + /// External account info + /// + public class ExternalAccount + { + /// + /// External account key + /// + [JsonProperty("key")] + public string Key { get; set; } + + /// + /// External account name + /// + [JsonProperty("name")] + public string Name { get; set; } + } +} diff --git a/Src/Notion.Client/Api/Authentication/CreateToken/Request/ICreateTokenBodyParameters.cs b/Src/Notion.Client/Api/Authentication/CreateToken/Request/ICreateTokenBodyParameters.cs new file mode 100644 index 00000000..e896e71a --- /dev/null +++ b/Src/Notion.Client/Api/Authentication/CreateToken/Request/ICreateTokenBodyParameters.cs @@ -0,0 +1,35 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public interface ICreateTokenBodyParameters + { + /// + /// A constant string: "authorization_code". + /// + [JsonProperty("grant_type")] + string GrantType { get; } + + /// + /// A unique random code that Notion generates to authenticate with your service, + /// generated when a user initiates the OAuth flow. + /// + [JsonProperty("code")] + string Code { get; set; } + + /// + /// The "redirect_uri" that was provided in the OAuth Domain & URI section + /// of the integration's Authorization settings. Do not include this field if a + /// "redirect_uri" query param was not included in the Authorization URL + /// provided to users. In most cases, this field is required. + /// + [JsonProperty("redirect_uri")] + string RedirectUri { get; set; } + + /// + /// External account details + /// + [JsonProperty("external_account")] + ExternalAccount ExternalAccount { get; set; } + } +} diff --git a/Src/Notion.Client/Api/Authentication/CreateToken/Response/CreateTokenResponse.cs b/Src/Notion.Client/Api/Authentication/CreateToken/Response/CreateTokenResponse.cs new file mode 100644 index 00000000..fbbe7a7a --- /dev/null +++ b/Src/Notion.Client/Api/Authentication/CreateToken/Response/CreateTokenResponse.cs @@ -0,0 +1,31 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class CreateTokenResponse + { + [JsonProperty("access_token")] + public string AccessToken { get; set; } + + [JsonProperty("token_type")] + public string TokenType { get; set; } = "bearer"; + + [JsonProperty("bot_id")] + public string BotId { get; set; } + + [JsonProperty("duplicated_template_id")] + public string DuplicatedTemplateId { get; set; } + + [JsonProperty("owner")] + public IBotOwner Owner { get; set; } + + [JsonProperty("workspace_icon")] + public string WorkspaceIcon { get; set; } + + [JsonProperty("workspace_id")] + public string WorkspaceId { get; set; } + + [JsonProperty("workspace_name")] + public string WorkspaceName { get; set; } + } +} diff --git a/Src/Notion.Client/Api/Authentication/IAuthenticationClient.cs b/Src/Notion.Client/Api/Authentication/IAuthenticationClient.cs new file mode 100644 index 00000000..0b4ebeb8 --- /dev/null +++ b/Src/Notion.Client/Api/Authentication/IAuthenticationClient.cs @@ -0,0 +1,22 @@ +using System.Threading; +using System.Threading.Tasks; + +namespace Notion.Client +{ + /// + /// Authentication client + /// + public interface IAuthenticationClient + { + /// + /// Creates an access token that a third-party service can use to authenticate with Notion. + /// + /// + /// + /// + Task CreateTokenAsync( + CreateTokenRequest createTokenRequest, + CancellationToken cancellationToken = default + ); + } +} diff --git a/Src/Notion.Client/NotionClient.cs b/Src/Notion.Client/NotionClient.cs index ca0c1334..2fc6f479 100644 --- a/Src/Notion.Client/NotionClient.cs +++ b/Src/Notion.Client/NotionClient.cs @@ -5,6 +5,8 @@ namespace Notion.Client [SuppressMessage("ReSharper", "UnusedMemberInSuper.Global")] public interface INotionClient { + IAuthenticationClient AuthenticationClient { get; } + IUsersClient Users { get; } IDatabasesClient Databases { get; } @@ -29,7 +31,8 @@ public NotionClient( IPagesClient pages, ISearchClient search, ICommentsClient comments, - IBlocksClient blocks) + IBlocksClient blocks, + IAuthenticationClient authenticationClient) { RestClient = restClient; Users = users; @@ -38,8 +41,11 @@ public NotionClient( Search = search; Comments = comments; Blocks = blocks; + AuthenticationClient = authenticationClient; } + public IAuthenticationClient AuthenticationClient { get; } + public IUsersClient Users { get; } public IDatabasesClient Databases { get; } diff --git a/Src/Notion.Client/NotionClientFactory.cs b/Src/Notion.Client/NotionClientFactory.cs index e82ba2de..e66f0781 100644 --- a/Src/Notion.Client/NotionClientFactory.cs +++ b/Src/Notion.Client/NotionClientFactory.cs @@ -12,8 +12,9 @@ public static NotionClient Create(ClientOptions options) , new DatabasesClient(restClient) , new PagesClient(restClient) , new SearchClient(restClient) - , blocks: new BlocksClient(restClient) - , comments: new CommentsClient(restClient) + , new CommentsClient(restClient) + , new BlocksClient(restClient) + , new AuthenticationClient(restClient) ); } } From 68ddcd1b22e6296825e52fbcb602319ae65b98c6 Mon Sep 17 00:00:00 2001 From: Kashif Soofi Date: Fri, 13 Oct 2023 12:30:37 +0100 Subject: [PATCH 152/216] #390: Add missing property in paginated response --- Src/Notion.Client/Models/PaginatedList.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Src/Notion.Client/Models/PaginatedList.cs b/Src/Notion.Client/Models/PaginatedList.cs index e126125a..d0b1107f 100644 --- a/Src/Notion.Client/Models/PaginatedList.cs +++ b/Src/Notion.Client/Models/PaginatedList.cs @@ -25,5 +25,8 @@ public class PaginatedList [JsonProperty("next_cursor")] public string NextCursor { get; set; } + + [JsonProperty("type")] + public string Type { get; set; } } } From 9ada4418e846c53c0978ef585687fa26a5abf9e7 Mon Sep 17 00:00:00 2001 From: Kashif Soofi Date: Fri, 13 Oct 2023 20:20:08 +0100 Subject: [PATCH 153/216] #390: Remove Type from RetrieveCommentsResponse --- Src/Notion.Client/Api/Comments/Retrieve/Response/Comments.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/Src/Notion.Client/Api/Comments/Retrieve/Response/Comments.cs b/Src/Notion.Client/Api/Comments/Retrieve/Response/Comments.cs index c89182a5..8b3b43b3 100644 --- a/Src/Notion.Client/Api/Comments/Retrieve/Response/Comments.cs +++ b/Src/Notion.Client/Api/Comments/Retrieve/Response/Comments.cs @@ -5,9 +5,6 @@ namespace Notion.Client { public class RetrieveCommentsResponse : PaginatedList { - [JsonProperty("type")] - public string Type { get; set; } - [JsonProperty("comment")] public Dictionary Comment { get; set; } } From e66a83fa422a4298344788bba9b805ccc276aa93 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sat, 14 Oct 2023 23:03:37 +0530 Subject: [PATCH 154/216] Add block property in paginated block children response --- Src/Notion.Client/Api/Blocks/BlocksClient.cs | 24 +------------ Src/Notion.Client/Api/Blocks/IBlocksClient.cs | 19 +++++++--- .../BlocksRetrieveChildrenParameters.cs | 9 ----- .../IBlocksRetrieveChildrenQueryParameters.cs | 6 ---- .../Blocks/RetrieveChildren/BlocksClient.cs | 36 +++++++++++++++++++ .../Request/BlockRetrieveChildrenRequest.cs | 13 +++++++ .../IBlockRetrieveChildrenPathParameters.cs | 7 ++++ .../IBlockRetrieveChildrenQueryParameters.cs | 6 ++++ .../Response/RetrieveChildrenResponse.cs | 11 ++++++ .../IBlocksClientTests.cs | 14 ++++++-- Test/Notion.UnitTests/BlocksClientTests.cs | 5 ++- 11 files changed, 104 insertions(+), 46 deletions(-) delete mode 100644 Src/Notion.Client/Api/Blocks/RequestParams/BlocksRetrieveChildrenParameters.cs delete mode 100644 Src/Notion.Client/Api/Blocks/RequestParams/IBlocksRetrieveChildrenQueryParameters.cs create mode 100644 Src/Notion.Client/Api/Blocks/RetrieveChildren/BlocksClient.cs create mode 100644 Src/Notion.Client/Api/Blocks/RetrieveChildren/Request/BlockRetrieveChildrenRequest.cs create mode 100644 Src/Notion.Client/Api/Blocks/RetrieveChildren/Request/IBlockRetrieveChildrenPathParameters.cs create mode 100644 Src/Notion.Client/Api/Blocks/RetrieveChildren/Request/IBlockRetrieveChildrenQueryParameters.cs create mode 100644 Src/Notion.Client/Api/Blocks/RetrieveChildren/Response/RetrieveChildrenResponse.cs diff --git a/Src/Notion.Client/Api/Blocks/BlocksClient.cs b/Src/Notion.Client/Api/Blocks/BlocksClient.cs index 068ce969..2c82457f 100644 --- a/Src/Notion.Client/Api/Blocks/BlocksClient.cs +++ b/Src/Notion.Client/Api/Blocks/BlocksClient.cs @@ -6,7 +6,7 @@ namespace Notion.Client { - public class BlocksClient : IBlocksClient + public sealed partial class BlocksClient : IBlocksClient { private readonly IRestClient _client; @@ -15,28 +15,6 @@ public BlocksClient(IRestClient client) _client = client; } - public async Task> RetrieveChildrenAsync( - string blockId, - BlocksRetrieveChildrenParameters parameters = null, CancellationToken cancellationToken = default) - { - if (string.IsNullOrWhiteSpace(blockId)) - { - throw new ArgumentNullException(nameof(blockId)); - } - - var url = BlocksApiUrls.RetrieveChildren(blockId); - - var queryParameters = (IBlocksRetrieveChildrenQueryParameters)parameters; - - var queryParams = new Dictionary - { - { "start_cursor", queryParameters?.StartCursor }, - { "page_size", queryParameters?.PageSize?.ToString() } - }; - - return await _client.GetAsync>(url, queryParams, cancellationToken: cancellationToken); - } - public async Task> AppendChildrenAsync( string blockId, BlocksAppendChildrenParameters parameters = null, CancellationToken cancellationToken = default) diff --git a/Src/Notion.Client/Api/Blocks/IBlocksClient.cs b/Src/Notion.Client/Api/Blocks/IBlocksClient.cs index 252a218d..59dac072 100644 --- a/Src/Notion.Client/Api/Blocks/IBlocksClient.cs +++ b/Src/Notion.Client/Api/Blocks/IBlocksClient.cs @@ -18,11 +18,22 @@ public interface IBlocksClient /// /// /// Block - Task UpdateAsync(string blockId, IUpdateBlock updateBlock, CancellationToken cancellationToken = default); + Task UpdateAsync(string blockId, IUpdateBlock updateBlock, + CancellationToken cancellationToken = default); - Task> RetrieveChildrenAsync( - string blockId, - BlocksRetrieveChildrenParameters parameters = null, CancellationToken cancellationToken = default); + /// + /// Returns a paginated array of child block objects contained in the block using the ID specified. + ///
+ /// In order to receive a complete representation of a block, you may need to recursively retrieve the + /// block children of child blocks. + ///
+ /// + /// + /// + Task RetrieveChildrenAsync( + BlockRetrieveChildrenRequest request, + CancellationToken cancellationToken = default + ); /// /// Creates and appends new children blocks to the parent block_id specified. diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksRetrieveChildrenParameters.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksRetrieveChildrenParameters.cs deleted file mode 100644 index 30f9c17d..00000000 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksRetrieveChildrenParameters.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Notion.Client -{ - public class BlocksRetrieveChildrenParameters : IBlocksRetrieveChildrenQueryParameters - { - public string StartCursor { get; set; } - - public int? PageSize { get; set; } - } -} diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/IBlocksRetrieveChildrenQueryParameters.cs b/Src/Notion.Client/Api/Blocks/RequestParams/IBlocksRetrieveChildrenQueryParameters.cs deleted file mode 100644 index 5c85e06a..00000000 --- a/Src/Notion.Client/Api/Blocks/RequestParams/IBlocksRetrieveChildrenQueryParameters.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Notion.Client -{ - public interface IBlocksRetrieveChildrenQueryParameters : IPaginationParameters - { - } -} diff --git a/Src/Notion.Client/Api/Blocks/RetrieveChildren/BlocksClient.cs b/Src/Notion.Client/Api/Blocks/RetrieveChildren/BlocksClient.cs new file mode 100644 index 00000000..c91f5c6d --- /dev/null +++ b/Src/Notion.Client/Api/Blocks/RetrieveChildren/BlocksClient.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +namespace Notion.Client +{ + public sealed partial class BlocksClient + { + public async Task RetrieveChildrenAsync( + BlockRetrieveChildrenRequest request, + CancellationToken cancellationToken = default) + { + if (string.IsNullOrWhiteSpace(request.BlockId)) + { + throw new ArgumentNullException(nameof(request.BlockId)); + } + + var url = ApiEndpoints.BlocksApiUrls.RetrieveChildren(request.BlockId); + + var queryParameters = (IBlockRetrieveChildrenQueryParameters)request; + + var queryParams = new Dictionary + { + { "start_cursor", queryParameters?.StartCursor }, + { "page_size", queryParameters?.PageSize?.ToString() } + }; + + return await _client.GetAsync( + url, + queryParams, + cancellationToken: cancellationToken + ); + } + } +} diff --git a/Src/Notion.Client/Api/Blocks/RetrieveChildren/Request/BlockRetrieveChildrenRequest.cs b/Src/Notion.Client/Api/Blocks/RetrieveChildren/Request/BlockRetrieveChildrenRequest.cs new file mode 100644 index 00000000..c0e87f3e --- /dev/null +++ b/Src/Notion.Client/Api/Blocks/RetrieveChildren/Request/BlockRetrieveChildrenRequest.cs @@ -0,0 +1,13 @@ +namespace Notion.Client +{ + public class BlockRetrieveChildrenRequest : + IBlockRetrieveChildrenQueryParameters, + IBlockRetrieveChildrenPathParameters + { + public string StartCursor { get; set; } + + public int? PageSize { get; set; } + + public string BlockId { get; set; } + } +} diff --git a/Src/Notion.Client/Api/Blocks/RetrieveChildren/Request/IBlockRetrieveChildrenPathParameters.cs b/Src/Notion.Client/Api/Blocks/RetrieveChildren/Request/IBlockRetrieveChildrenPathParameters.cs new file mode 100644 index 00000000..c23c2e90 --- /dev/null +++ b/Src/Notion.Client/Api/Blocks/RetrieveChildren/Request/IBlockRetrieveChildrenPathParameters.cs @@ -0,0 +1,7 @@ +namespace Notion.Client +{ + public interface IBlockRetrieveChildrenPathParameters + { + public string BlockId { get; set; } + } +} diff --git a/Src/Notion.Client/Api/Blocks/RetrieveChildren/Request/IBlockRetrieveChildrenQueryParameters.cs b/Src/Notion.Client/Api/Blocks/RetrieveChildren/Request/IBlockRetrieveChildrenQueryParameters.cs new file mode 100644 index 00000000..68c7de32 --- /dev/null +++ b/Src/Notion.Client/Api/Blocks/RetrieveChildren/Request/IBlockRetrieveChildrenQueryParameters.cs @@ -0,0 +1,6 @@ +namespace Notion.Client +{ + public interface IBlockRetrieveChildrenQueryParameters : IPaginationParameters + { + } +} diff --git a/Src/Notion.Client/Api/Blocks/RetrieveChildren/Response/RetrieveChildrenResponse.cs b/Src/Notion.Client/Api/Blocks/RetrieveChildren/Response/RetrieveChildrenResponse.cs new file mode 100644 index 00000000..0b34619f --- /dev/null +++ b/Src/Notion.Client/Api/Blocks/RetrieveChildren/Response/RetrieveChildrenResponse.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class RetrieveChildrenResponse : PaginatedList + { + [JsonProperty("block")] + public Dictionary Block { get; set; } + } +} diff --git a/Test/Notion.IntegrationTests/IBlocksClientTests.cs b/Test/Notion.IntegrationTests/IBlocksClientTests.cs index 3f616cfa..9435060c 100644 --- a/Test/Notion.IntegrationTests/IBlocksClientTests.cs +++ b/Test/Notion.IntegrationTests/IBlocksClientTests.cs @@ -68,7 +68,10 @@ public async Task UpdateBlockAsync_UpdatesGivenBlock() var blockId = blocks.Results.First().Id; await Client.Blocks.UpdateAsync(blockId, new BreadcrumbUpdateBlock()); - blocks = await Client.Blocks.RetrieveChildrenAsync(page.Id); + blocks = await Client.Blocks.RetrieveChildrenAsync(new BlockRetrieveChildrenRequest + { + BlockId = page.Id + }); blocks.Results.Should().HaveCount(1); // cleanup @@ -121,7 +124,10 @@ public async Task UpdateAsync_UpdatesGivenBlock( var blockId = blocks.Results.First().Id; await Client.Blocks.UpdateAsync(blockId, updateBlock); - blocks = await Client.Blocks.RetrieveChildrenAsync(page.Id); + blocks = await Client.Blocks.RetrieveChildrenAsync(new BlockRetrieveChildrenRequest + { + BlockId = page.Id + }); blocks.Results.Should().HaveCount(1); var updatedBlock = blocks.Results.First(); @@ -443,7 +449,9 @@ private static IEnumerable BlockData() var tableBlock = block.Should().NotBeNull().And.BeOfType().Subject; tableBlock.HasChildren.Should().BeTrue(); - var children = client.Blocks.RetrieveChildrenAsync(tableBlock.Id).GetAwaiter().GetResult(); + var children = client.Blocks.RetrieveChildrenAsync(new BlockRetrieveChildrenRequest{ + BlockId = tableBlock.Id + }).GetAwaiter().GetResult(); children.Results.Should().ContainSingle() .Subject.Should().BeOfType() diff --git a/Test/Notion.UnitTests/BlocksClientTests.cs b/Test/Notion.UnitTests/BlocksClientTests.cs index 0d6b2c01..a1432050 100644 --- a/Test/Notion.UnitTests/BlocksClientTests.cs +++ b/Test/Notion.UnitTests/BlocksClientTests.cs @@ -34,7 +34,10 @@ public async Task RetrieveBlockChildren() ); // Act - var childrenResult = await _client.RetrieveChildrenAsync(blockId, new BlocksRetrieveChildrenParameters()); + var childrenResult = await _client.RetrieveChildrenAsync(new BlockRetrieveChildrenRequest + { + BlockId = blockId + }); // Assert var children = childrenResult.Results; From 0d3f322fcf802f7b21ebc53e207693db1ac1288a Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sat, 14 Oct 2023 23:37:33 +0530 Subject: [PATCH 155/216] Add block property in Append children api response --- .../Api/Blocks/AppendChildren/BlocksClient.cs | 25 ++++++++++++++++ .../Request/BlockAppendChildrenRequest.cs} | 4 ++- .../IBlockAppendChildrenBodyParameters.cs} | 2 +- .../IBlockAppendChildrenPathParameters.cs | 7 +++++ .../Response/AppendChildrenResponse.cs | 11 +++++++ Src/Notion.Client/Api/Blocks/BlocksClient.cs | 16 ---------- Src/Notion.Client/Api/Blocks/IBlocksClient.cs | 11 +++---- .../IBlocksClientTests.cs | 29 ++++++++++--------- Test/Notion.UnitTests/BlocksClientTests.cs | 5 ++-- 9 files changed, 72 insertions(+), 38 deletions(-) create mode 100644 Src/Notion.Client/Api/Blocks/AppendChildren/BlocksClient.cs rename Src/Notion.Client/Api/Blocks/{RequestParams/BlocksAppendChildrenParameters.cs => AppendChildren/Request/BlockAppendChildrenRequest.cs} (52%) rename Src/Notion.Client/Api/Blocks/{RequestParams/IBlocksAppendChildrenBodyParameters.cs => AppendChildren/Request/IBlockAppendChildrenBodyParameters.cs} (88%) create mode 100644 Src/Notion.Client/Api/Blocks/AppendChildren/Request/IBlockAppendChildrenPathParameters.cs create mode 100644 Src/Notion.Client/Api/Blocks/AppendChildren/Response/AppendChildrenResponse.cs diff --git a/Src/Notion.Client/Api/Blocks/AppendChildren/BlocksClient.cs b/Src/Notion.Client/Api/Blocks/AppendChildren/BlocksClient.cs new file mode 100644 index 00000000..66d9e1ea --- /dev/null +++ b/Src/Notion.Client/Api/Blocks/AppendChildren/BlocksClient.cs @@ -0,0 +1,25 @@ +using System; +using System.Threading; +using System.Threading.Tasks; + +namespace Notion.Client +{ + public sealed partial class BlocksClient + { + public async Task AppendChildrenAsync( + BlockAppendChildrenRequest request, + CancellationToken cancellationToken = default) + { + if (string.IsNullOrWhiteSpace(request.BlockId)) + { + throw new ArgumentNullException(nameof(request.BlockId)); + } + + var url = ApiEndpoints.BlocksApiUrls.AppendChildren(request.BlockId); + + var body = (IBlockAppendChildrenBodyParameters)request; + + return await _client.PatchAsync(url, body, cancellationToken: cancellationToken); + } + } +} diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksAppendChildrenParameters.cs b/Src/Notion.Client/Api/Blocks/AppendChildren/Request/BlockAppendChildrenRequest.cs similarity index 52% rename from Src/Notion.Client/Api/Blocks/RequestParams/BlocksAppendChildrenParameters.cs rename to Src/Notion.Client/Api/Blocks/AppendChildren/Request/BlockAppendChildrenRequest.cs index 0d5574dd..580d164a 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksAppendChildrenParameters.cs +++ b/Src/Notion.Client/Api/Blocks/AppendChildren/Request/BlockAppendChildrenRequest.cs @@ -2,10 +2,12 @@ namespace Notion.Client { - public class BlocksAppendChildrenParameters : IBlocksAppendChildrenBodyParameters + public class BlockAppendChildrenRequest : IBlockAppendChildrenBodyParameters, IBlockAppendChildrenPathParameters { public IEnumerable Children { get; set; } public string After { get; set; } + + public string BlockId { get; set; } } } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/IBlocksAppendChildrenBodyParameters.cs b/Src/Notion.Client/Api/Blocks/AppendChildren/Request/IBlockAppendChildrenBodyParameters.cs similarity index 88% rename from Src/Notion.Client/Api/Blocks/RequestParams/IBlocksAppendChildrenBodyParameters.cs rename to Src/Notion.Client/Api/Blocks/AppendChildren/Request/IBlockAppendChildrenBodyParameters.cs index ef1321aa..3d8650aa 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/IBlocksAppendChildrenBodyParameters.cs +++ b/Src/Notion.Client/Api/Blocks/AppendChildren/Request/IBlockAppendChildrenBodyParameters.cs @@ -4,7 +4,7 @@ namespace Notion.Client { // TODO: need an input version of Block - public interface IBlocksAppendChildrenBodyParameters + public interface IBlockAppendChildrenBodyParameters { [JsonProperty("children")] IEnumerable Children { get; set; } diff --git a/Src/Notion.Client/Api/Blocks/AppendChildren/Request/IBlockAppendChildrenPathParameters.cs b/Src/Notion.Client/Api/Blocks/AppendChildren/Request/IBlockAppendChildrenPathParameters.cs new file mode 100644 index 00000000..350382f6 --- /dev/null +++ b/Src/Notion.Client/Api/Blocks/AppendChildren/Request/IBlockAppendChildrenPathParameters.cs @@ -0,0 +1,7 @@ +namespace Notion.Client +{ + public interface IBlockAppendChildrenPathParameters + { + public string BlockId { get; set; } + } +} diff --git a/Src/Notion.Client/Api/Blocks/AppendChildren/Response/AppendChildrenResponse.cs b/Src/Notion.Client/Api/Blocks/AppendChildren/Response/AppendChildrenResponse.cs new file mode 100644 index 00000000..88e04ad5 --- /dev/null +++ b/Src/Notion.Client/Api/Blocks/AppendChildren/Response/AppendChildrenResponse.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class AppendChildrenResponse : PaginatedList + { + [JsonProperty("block")] + public Dictionary Block { get; set; } + } +} diff --git a/Src/Notion.Client/Api/Blocks/BlocksClient.cs b/Src/Notion.Client/Api/Blocks/BlocksClient.cs index 2c82457f..92713a78 100644 --- a/Src/Notion.Client/Api/Blocks/BlocksClient.cs +++ b/Src/Notion.Client/Api/Blocks/BlocksClient.cs @@ -15,22 +15,6 @@ public BlocksClient(IRestClient client) _client = client; } - public async Task> AppendChildrenAsync( - string blockId, - BlocksAppendChildrenParameters parameters = null, CancellationToken cancellationToken = default) - { - if (string.IsNullOrWhiteSpace(blockId)) - { - throw new ArgumentNullException(nameof(blockId)); - } - - var url = BlocksApiUrls.AppendChildren(blockId); - - var body = (IBlocksAppendChildrenBodyParameters)parameters; - - return await _client.PatchAsync>(url, body, cancellationToken: cancellationToken); - } - public async Task RetrieveAsync(string blockId, CancellationToken cancellationToken = default) { if (string.IsNullOrWhiteSpace(blockId)) diff --git a/Src/Notion.Client/Api/Blocks/IBlocksClient.cs b/Src/Notion.Client/Api/Blocks/IBlocksClient.cs index 59dac072..fec1b9f5 100644 --- a/Src/Notion.Client/Api/Blocks/IBlocksClient.cs +++ b/Src/Notion.Client/Api/Blocks/IBlocksClient.cs @@ -38,12 +38,13 @@ Task RetrieveChildrenAsync( /// /// Creates and appends new children blocks to the parent block_id specified. /// - /// Identifier for a block - /// + /// + /// /// A paginated list of newly created first level children block objects. - Task> AppendChildrenAsync( - string blockId, - BlocksAppendChildrenParameters parameters = null, CancellationToken cancellationToken = default); + Task AppendChildrenAsync( + BlockAppendChildrenRequest request, + CancellationToken cancellationToken = default + ); /// /// Sets a Block object, including page blocks, to archived: true using the ID specified. diff --git a/Test/Notion.IntegrationTests/IBlocksClientTests.cs b/Test/Notion.IntegrationTests/IBlocksClientTests.cs index 9435060c..24e28da7 100644 --- a/Test/Notion.IntegrationTests/IBlocksClientTests.cs +++ b/Test/Notion.IntegrationTests/IBlocksClientTests.cs @@ -20,9 +20,9 @@ public async Task AppendChildrenAsync_AppendsBlocksGivenBlocks() ); var blocks = await Client.Blocks.AppendChildrenAsync( - page.Id, - new BlocksAppendChildrenParameters + new BlockAppendChildrenRequest { + BlockId = page.Id, Children = new List { new BreadcrumbBlock { Breadcrumb = new BreadcrumbBlock.Data() }, @@ -58,9 +58,9 @@ public async Task UpdateBlockAsync_UpdatesGivenBlock() ); var blocks = await Client.Blocks.AppendChildrenAsync( - page.Id, - new BlocksAppendChildrenParameters + new BlockAppendChildrenRequest { + BlockId = page.Id, Children = new List { new BreadcrumbBlock { Breadcrumb = new BreadcrumbBlock.Data() } } } ); @@ -68,11 +68,11 @@ public async Task UpdateBlockAsync_UpdatesGivenBlock() var blockId = blocks.Results.First().Id; await Client.Blocks.UpdateAsync(blockId, new BreadcrumbUpdateBlock()); - blocks = await Client.Blocks.RetrieveChildrenAsync(new BlockRetrieveChildrenRequest + var updatedBlocks = await Client.Blocks.RetrieveChildrenAsync(new BlockRetrieveChildrenRequest { BlockId = page.Id }); - blocks.Results.Should().HaveCount(1); + updatedBlocks.Results.Should().HaveCount(1); // cleanup await Client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); @@ -88,9 +88,9 @@ public async Task DeleteAsync_DeleteBlockWithGivenId() ); var blocks = await Client.Blocks.AppendChildrenAsync( - page.Id, - new BlocksAppendChildrenParameters + new BlockAppendChildrenRequest { + BlockId = page.Id, Children = new List { new DividerBlock { Divider = new DividerBlock.Data() }, @@ -117,20 +117,23 @@ public async Task UpdateAsync_UpdatesGivenBlock( ); var blocks = await Client.Blocks.AppendChildrenAsync( - page.Id, - new BlocksAppendChildrenParameters { Children = new List { block } } + new BlockAppendChildrenRequest + { + BlockId = page.Id, + Children = new List { block } + } ); var blockId = blocks.Results.First().Id; await Client.Blocks.UpdateAsync(blockId, updateBlock); - blocks = await Client.Blocks.RetrieveChildrenAsync(new BlockRetrieveChildrenRequest + var updatedBlocks = await Client.Blocks.RetrieveChildrenAsync(new BlockRetrieveChildrenRequest { BlockId = page.Id }); - blocks.Results.Should().HaveCount(1); + updatedBlocks.Results.Should().HaveCount(1); - var updatedBlock = blocks.Results.First(); + var updatedBlock = updatedBlocks.Results.First(); assert.Invoke(updatedBlock, Client); diff --git a/Test/Notion.UnitTests/BlocksClientTests.cs b/Test/Notion.UnitTests/BlocksClientTests.cs index a1432050..600e0bf4 100644 --- a/Test/Notion.UnitTests/BlocksClientTests.cs +++ b/Test/Notion.UnitTests/BlocksClientTests.cs @@ -60,8 +60,9 @@ public async Task AppendBlockChildren() .WithBody(jsonData) ); - var parameters = new BlocksAppendChildrenParameters + var request = new BlockAppendChildrenRequest { + BlockId = blockId, Children = new List { new HeadingTwoBlock @@ -100,7 +101,7 @@ public async Task AppendBlockChildren() }; // Act - var blocksResult = await _client.AppendChildrenAsync(blockId, parameters); + var blocksResult = await _client.AppendChildrenAsync(request); // Assert var blocks = blocksResult.Results; From 37a7125afac4c5b16a64d8126a3980b2e142e4fe Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sat, 14 Oct 2023 23:40:07 +0530 Subject: [PATCH 156/216] Add database property in DatabaseQuery response --- .../Api/Databases/Query/Response/DatabaseQueryResponse.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Src/Notion.Client/Api/Databases/Query/Response/DatabaseQueryResponse.cs b/Src/Notion.Client/Api/Databases/Query/Response/DatabaseQueryResponse.cs index 73968c38..5b7c9ec6 100644 --- a/Src/Notion.Client/Api/Databases/Query/Response/DatabaseQueryResponse.cs +++ b/Src/Notion.Client/Api/Databases/Query/Response/DatabaseQueryResponse.cs @@ -1,7 +1,12 @@ -namespace Notion.Client +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client { // ReSharper disable once ClassNeverInstantiated.Global public class DatabaseQueryResponse : PaginatedList { + [JsonProperty("database")] + public Dictionary Database { get; set; } } } From 063723dd96d5120ec7b53a5a99644407494b35a9 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sat, 14 Oct 2023 23:51:17 +0530 Subject: [PATCH 157/216] Add PageOrDatabase property in search response --- Src/Notion.Client/Api/Search/ISearchClient.cs | 8 ++++++-- .../{Parameters => Request}/ISearchBodyParameters.cs | 0 .../Search/{Parameters => Request}/SearchDirection.cs | 0 .../Search/{Parameters => Request}/SearchFilter.cs | 0 .../{Parameters => Request}/SearchObjectType.cs | 0 .../SearchParameters.cs => Request/SearchRequest.cs} | 2 +- .../Api/Search/{Parameters => Request}/SearchSort.cs | 0 .../Api/Search/Response/SearchResponse.cs | 11 +++++++++++ Src/Notion.Client/Api/Search/SearchClient.cs | 10 ++++++---- Test/Notion.UnitTests/SearchClientTest.cs | 2 +- 10 files changed, 25 insertions(+), 8 deletions(-) rename Src/Notion.Client/Api/Search/{Parameters => Request}/ISearchBodyParameters.cs (100%) rename Src/Notion.Client/Api/Search/{Parameters => Request}/SearchDirection.cs (100%) rename Src/Notion.Client/Api/Search/{Parameters => Request}/SearchFilter.cs (100%) rename Src/Notion.Client/Api/Search/{Parameters => Request}/SearchObjectType.cs (100%) rename Src/Notion.Client/Api/Search/{Parameters/SearchParameters.cs => Request/SearchRequest.cs} (82%) rename Src/Notion.Client/Api/Search/{Parameters => Request}/SearchSort.cs (100%) create mode 100644 Src/Notion.Client/Api/Search/Response/SearchResponse.cs diff --git a/Src/Notion.Client/Api/Search/ISearchClient.cs b/Src/Notion.Client/Api/Search/ISearchClient.cs index a1e05990..accee1e1 100644 --- a/Src/Notion.Client/Api/Search/ISearchClient.cs +++ b/Src/Notion.Client/Api/Search/ISearchClient.cs @@ -11,10 +11,14 @@ public interface ISearchClient /// Searches all original pages, databases, and child pages/databases that are shared with the integration. /// It will not return linked databases, since these duplicate their source databases. /// - /// Search filters and body parameters + /// Search filters and body parameters + /// /// /// /// - Task> SearchAsync(SearchParameters parameters, CancellationToken cancellationToken = default); + Task SearchAsync( + SearchRequest request, + CancellationToken cancellationToken = default + ); } } diff --git a/Src/Notion.Client/Api/Search/Parameters/ISearchBodyParameters.cs b/Src/Notion.Client/Api/Search/Request/ISearchBodyParameters.cs similarity index 100% rename from Src/Notion.Client/Api/Search/Parameters/ISearchBodyParameters.cs rename to Src/Notion.Client/Api/Search/Request/ISearchBodyParameters.cs diff --git a/Src/Notion.Client/Api/Search/Parameters/SearchDirection.cs b/Src/Notion.Client/Api/Search/Request/SearchDirection.cs similarity index 100% rename from Src/Notion.Client/Api/Search/Parameters/SearchDirection.cs rename to Src/Notion.Client/Api/Search/Request/SearchDirection.cs diff --git a/Src/Notion.Client/Api/Search/Parameters/SearchFilter.cs b/Src/Notion.Client/Api/Search/Request/SearchFilter.cs similarity index 100% rename from Src/Notion.Client/Api/Search/Parameters/SearchFilter.cs rename to Src/Notion.Client/Api/Search/Request/SearchFilter.cs diff --git a/Src/Notion.Client/Api/Search/Parameters/SearchObjectType.cs b/Src/Notion.Client/Api/Search/Request/SearchObjectType.cs similarity index 100% rename from Src/Notion.Client/Api/Search/Parameters/SearchObjectType.cs rename to Src/Notion.Client/Api/Search/Request/SearchObjectType.cs diff --git a/Src/Notion.Client/Api/Search/Parameters/SearchParameters.cs b/Src/Notion.Client/Api/Search/Request/SearchRequest.cs similarity index 82% rename from Src/Notion.Client/Api/Search/Parameters/SearchParameters.cs rename to Src/Notion.Client/Api/Search/Request/SearchRequest.cs index e1c8ced8..a9ac887f 100644 --- a/Src/Notion.Client/Api/Search/Parameters/SearchParameters.cs +++ b/Src/Notion.Client/Api/Search/Request/SearchRequest.cs @@ -1,6 +1,6 @@ namespace Notion.Client { - public class SearchParameters : ISearchBodyParameters + public class SearchRequest : ISearchBodyParameters { public string Query { get; set; } diff --git a/Src/Notion.Client/Api/Search/Parameters/SearchSort.cs b/Src/Notion.Client/Api/Search/Request/SearchSort.cs similarity index 100% rename from Src/Notion.Client/Api/Search/Parameters/SearchSort.cs rename to Src/Notion.Client/Api/Search/Request/SearchSort.cs diff --git a/Src/Notion.Client/Api/Search/Response/SearchResponse.cs b/Src/Notion.Client/Api/Search/Response/SearchResponse.cs new file mode 100644 index 00000000..2be0e2f1 --- /dev/null +++ b/Src/Notion.Client/Api/Search/Response/SearchResponse.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class SearchResponse : PaginatedList + { + [JsonProperty("page_or_database")] + public Dictionary PageOrDatabase { get; set; } + } +} diff --git a/Src/Notion.Client/Api/Search/SearchClient.cs b/Src/Notion.Client/Api/Search/SearchClient.cs index cebe6aa3..492e0940 100644 --- a/Src/Notion.Client/Api/Search/SearchClient.cs +++ b/Src/Notion.Client/Api/Search/SearchClient.cs @@ -4,7 +4,7 @@ namespace Notion.Client { - public class SearchClient : ISearchClient + public sealed class SearchClient : ISearchClient { private readonly IRestClient _client; @@ -13,13 +13,15 @@ public SearchClient(IRestClient client) _client = client; } - public async Task> SearchAsync(SearchParameters parameters, CancellationToken cancellationToken = default) + public async Task SearchAsync( + SearchRequest request, + CancellationToken cancellationToken = default) { var url = SearchApiUrls.Search(); - var body = (ISearchBodyParameters)parameters; + var body = (ISearchBodyParameters)request; - return await _client.PostAsync>(url, body, cancellationToken: cancellationToken); + return await _client.PostAsync(url, body, cancellationToken: cancellationToken); } } } diff --git a/Test/Notion.UnitTests/SearchClientTest.cs b/Test/Notion.UnitTests/SearchClientTest.cs index 63fb4a94..35765cef 100644 --- a/Test/Notion.UnitTests/SearchClientTest.cs +++ b/Test/Notion.UnitTests/SearchClientTest.cs @@ -30,7 +30,7 @@ public async Task Search() .WithBody(jsonData) ); - var searchParameters = new SearchParameters + var searchParameters = new SearchRequest { Query = "External tasks", Sort = new SearchSort From 535b161fc2d39cae5758a9de0955aa0532722565 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 15 Oct 2023 00:03:34 +0530 Subject: [PATCH 158/216] Add User property to ListUsers response --- Src/Notion.Client/Api/Users/IUsersClient.cs | 18 ++++++++++++++---- ...tUsersParameters.cs => ListUsersRequest.cs} | 2 +- .../Users/List/Response/ListUsersResponse.cs | 11 +++++++++++ .../Api/Users/List/UsersClient.cs | 16 ++++++++++++---- Src/Notion.Client/Api/Users/UsersClient.cs | 5 ----- 5 files changed, 38 insertions(+), 14 deletions(-) rename Src/Notion.Client/Api/Users/List/Request/{ListUsersParameters.cs => ListUsersRequest.cs} (78%) create mode 100644 Src/Notion.Client/Api/Users/List/Response/ListUsersResponse.cs diff --git a/Src/Notion.Client/Api/Users/IUsersClient.cs b/Src/Notion.Client/Api/Users/IUsersClient.cs index 0f9f18ac..bc0c3d8a 100644 --- a/Src/Notion.Client/Api/Users/IUsersClient.cs +++ b/Src/Notion.Client/Api/Users/IUsersClient.cs @@ -19,13 +19,23 @@ public interface IUsersClient /// Returns a paginated list of Users for the workspace. /// The response may contain fewer than page_size of results. /// + /// /// - /// + /// /// - Task> ListAsync(CancellationToken cancellationToken = default); + Task ListAsync(CancellationToken cancellationToken = default); - Task> ListAsync( - ListUsersParameters listUsersParameters, + /// + /// Returns a paginated list of Users for the workspace. + /// The response may contain fewer than page_size of results. + /// + /// + /// + /// + /// + /// + Task ListAsync( + ListUsersRequest listUsersRequest, CancellationToken cancellationToken = default ); diff --git a/Src/Notion.Client/Api/Users/List/Request/ListUsersParameters.cs b/Src/Notion.Client/Api/Users/List/Request/ListUsersRequest.cs similarity index 78% rename from Src/Notion.Client/Api/Users/List/Request/ListUsersParameters.cs rename to Src/Notion.Client/Api/Users/List/Request/ListUsersRequest.cs index 046a0c5b..f3684d09 100644 --- a/Src/Notion.Client/Api/Users/List/Request/ListUsersParameters.cs +++ b/Src/Notion.Client/Api/Users/List/Request/ListUsersRequest.cs @@ -4,7 +4,7 @@ public interface IListUsersQueryParameters : IPaginationParameters { } - public class ListUsersParameters : IListUsersQueryParameters + public class ListUsersRequest : IListUsersQueryParameters { public string StartCursor { get; set; } diff --git a/Src/Notion.Client/Api/Users/List/Response/ListUsersResponse.cs b/Src/Notion.Client/Api/Users/List/Response/ListUsersResponse.cs new file mode 100644 index 00000000..2d30237f --- /dev/null +++ b/Src/Notion.Client/Api/Users/List/Response/ListUsersResponse.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class ListUsersResponse : PaginatedList + { + [JsonProperty("user")] + public Dictionary User { get; set; } + } +} diff --git a/Src/Notion.Client/Api/Users/List/UsersClient.cs b/Src/Notion.Client/Api/Users/List/UsersClient.cs index 57c40ea3..ce13633a 100644 --- a/Src/Notion.Client/Api/Users/List/UsersClient.cs +++ b/Src/Notion.Client/Api/Users/List/UsersClient.cs @@ -7,12 +7,20 @@ namespace Notion.Client { public partial class UsersClient { - public async Task> ListAsync( - ListUsersParameters listUsersParameters, + public async Task ListAsync(CancellationToken cancellationToken = default) + { + return await _client.GetAsync( + ApiEndpoints.UsersApiUrls.List(), + cancellationToken: cancellationToken + ); + } + + public async Task ListAsync( + ListUsersRequest listUsersRequest, CancellationToken cancellationToken = default ) { - var queryParameters = (IListUsersQueryParameters)listUsersParameters; + var queryParameters = (IListUsersQueryParameters)listUsersRequest; var queryParams = new Dictionary { @@ -20,7 +28,7 @@ public async Task> ListAsync( { "page_size", queryParameters?.PageSize?.ToString() } }; - return await _client.GetAsync>( + return await _client.GetAsync( ApiEndpoints.UsersApiUrls.List(), queryParams, cancellationToken: cancellationToken diff --git a/Src/Notion.Client/Api/Users/UsersClient.cs b/Src/Notion.Client/Api/Users/UsersClient.cs index f40299ee..24681b53 100644 --- a/Src/Notion.Client/Api/Users/UsersClient.cs +++ b/Src/Notion.Client/Api/Users/UsersClient.cs @@ -18,11 +18,6 @@ public async Task RetrieveAsync(string userId, CancellationToken cancellat return await _client.GetAsync(UsersApiUrls.Retrieve(userId), cancellationToken: cancellationToken); } - public async Task> ListAsync(CancellationToken cancellationToken = default) - { - return await _client.GetAsync>(UsersApiUrls.List(), cancellationToken: cancellationToken); - } - /// /// Retrieves the bot User associated with the API token provided in the authorization header. /// From bb2f97e679379f2e6c3d588b3e4441e82e391b40 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 15 Oct 2023 04:12:06 +0530 Subject: [PATCH 159/216] Add wrapper class to avoid sending block id as part of request body --- .../Api/Blocks/AppendChildren/BlocksClient.cs | 2 +- .../Request/IBlockAppendChildrenBodyParameters.cs | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Src/Notion.Client/Api/Blocks/AppendChildren/BlocksClient.cs b/Src/Notion.Client/Api/Blocks/AppendChildren/BlocksClient.cs index 66d9e1ea..50ce3c61 100644 --- a/Src/Notion.Client/Api/Blocks/AppendChildren/BlocksClient.cs +++ b/Src/Notion.Client/Api/Blocks/AppendChildren/BlocksClient.cs @@ -17,7 +17,7 @@ public async Task AppendChildrenAsync( var url = ApiEndpoints.BlocksApiUrls.AppendChildren(request.BlockId); - var body = (IBlockAppendChildrenBodyParameters)request; + var body = new BlockAppendChildrenBodyParameters(request); return await _client.PatchAsync(url, body, cancellationToken: cancellationToken); } diff --git a/Src/Notion.Client/Api/Blocks/AppendChildren/Request/IBlockAppendChildrenBodyParameters.cs b/Src/Notion.Client/Api/Blocks/AppendChildren/Request/IBlockAppendChildrenBodyParameters.cs index 3d8650aa..b476c089 100644 --- a/Src/Notion.Client/Api/Blocks/AppendChildren/Request/IBlockAppendChildrenBodyParameters.cs +++ b/Src/Notion.Client/Api/Blocks/AppendChildren/Request/IBlockAppendChildrenBodyParameters.cs @@ -15,4 +15,17 @@ public interface IBlockAppendChildrenBodyParameters [JsonProperty("after")] public string After { get; set; } } + + internal class BlockAppendChildrenBodyParameters : IBlockAppendChildrenBodyParameters + { + public IEnumerable Children { get; set; } + + public string After { get; set; } + + public BlockAppendChildrenBodyParameters(BlockAppendChildrenRequest request) + { + Children = request.Children; + After = request.After; + } + } } From 2c94a50422f77d949567b6ca41bca0dcff1eb06c Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 15 Oct 2023 02:44:05 +0530 Subject: [PATCH 160/216] Adjust CommentsClient Tests --- Test/Notion.IntegrationTests/CommentsClientTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Test/Notion.IntegrationTests/CommentsClientTests.cs b/Test/Notion.IntegrationTests/CommentsClientTests.cs index f2a84d21..0eb56bea 100644 --- a/Test/Notion.IntegrationTests/CommentsClientTests.cs +++ b/Test/Notion.IntegrationTests/CommentsClientTests.cs @@ -78,7 +78,7 @@ public async Task ShouldCreateADiscussionComment() ); // Arrange - Assert.Null(response.Parent); + Assert.NotNull(response.Parent); Assert.NotNull(response.Id); Assert.Equal(comment.DiscussionId, response.DiscussionId); From 8a0d469febfec2b521808ee4b9171b150ef775ed Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 15 Oct 2023 02:44:34 +0530 Subject: [PATCH 161/216] Adjust PageClient tests --- ...IPageClientTests.cs => PageClientTests.cs} | 157 +++++++++++------- 1 file changed, 100 insertions(+), 57 deletions(-) rename Test/Notion.IntegrationTests/{IPageClientTests.cs => PageClientTests.cs} (71%) diff --git a/Test/Notion.IntegrationTests/IPageClientTests.cs b/Test/Notion.IntegrationTests/PageClientTests.cs similarity index 71% rename from Test/Notion.IntegrationTests/IPageClientTests.cs rename to Test/Notion.IntegrationTests/PageClientTests.cs index 84ac493e..1e697c59 100644 --- a/Test/Notion.IntegrationTests/IPageClientTests.cs +++ b/Test/Notion.IntegrationTests/PageClientTests.cs @@ -8,13 +8,69 @@ namespace Notion.IntegrationTests; -public class IPageClientTests : IntegrationTestBase +public class PageClientTests : IntegrationTestBase, IDisposable { + private readonly Page _page; + private readonly Database _database; + + public PageClientTests() + { + // Create a page + _page = Client.Pages.CreateAsync( + PagesCreateParametersBuilder.Create( + new ParentPageInput { PageId = ParentPageId } + ).Build() + ).Result; + + // Create a database + var createDbRequest = new DatabasesCreateParameters + { + Title = new List + { + new RichTextTextInput + { + Text = new Text + { + Content = "Test List", + Link = null + } + } + }, + Properties = new Dictionary + { + { "Name", new TitlePropertySchema { Title = new Dictionary() } }, + { + "TestSelect", + new SelectPropertySchema + { + Select = new OptionWrapper + { + Options = new List + { + new() { Name = "Red" }, + new() { Name = "Blue" } + } + } + } + }, + { "Number", new NumberPropertySchema { Number = new Number { Format = "number" } } } + }, + Parent = new ParentPageInput { PageId = _page.Id } + }; + + _database = Client.Databases.CreateAsync(createDbRequest).GetAwaiter().GetResult(); + } + + public void Dispose() + { + Client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters { Archived = true }).GetAwaiter().GetResult(); + } + [Fact] public async Task CreateAsync_CreatesANewPage() { var pagesCreateParameters = PagesCreateParametersBuilder - .Create(new DatabaseParentInput { DatabaseId = ParentDatabaseId }) + .Create(new DatabaseParentInput { DatabaseId = _database.Id }) .AddProperty("Name", new TitlePropertyValue { @@ -30,10 +86,10 @@ public async Task CreateAsync_CreatesANewPage() page.Should().NotBeNull(); page.Parent.Should().BeOfType().Which - .DatabaseId.Should().Be(ParentDatabaseId); + .DatabaseId.Should().Be(_database.Id); page.Properties.Should().ContainKey("Name"); - var pageProperty = page.Properties["Name"].Should().BeOfType().Subject; + var pageProperty = page.Properties["Name"].Should().BeOfType().Subject; var titleProperty = (ListPropertyItem)await Client.Pages.RetrievePagePropertyItemAsync( @@ -44,15 +100,14 @@ var titleProperty }); titleProperty.Results.First().As().Title.PlainText.Should().Be("Test Page Title"); - - await Client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); } [Fact] public async Task Bug_unable_to_create_page_with_select_property() { + // Arrange var pagesCreateParameters = PagesCreateParametersBuilder - .Create(new DatabaseParentInput { DatabaseId = ParentDatabaseId }) + .Create(new DatabaseParentInput { DatabaseId = _database.Id }) .AddProperty("Name", new TitlePropertyValue { @@ -62,37 +117,33 @@ public async Task Bug_unable_to_create_page_with_select_property() } }) .AddProperty("TestSelect", - new SelectPropertyValue { Select = new SelectOption { Id = "dfbfbe65-6f67-4876-9f75-699124334d06" } }) + new SelectPropertyValue { Select = new SelectOption { Name = "Blue" } }) .Build(); + // Act var page = await Client.Pages.CreateAsync(pagesCreateParameters); + // Asserts page.Should().NotBeNull(); page.Parent.Should().BeOfType().Which - .DatabaseId.Should().Be(ParentDatabaseId); + .DatabaseId.Should().Be(_database.Id); page.Properties.Should().ContainKey("Name"); - var pageProperty = page.Properties["Name"].Should().BeOfType().Subject; - - var titleProperty - = (ListPropertyItem)await Client.Pages.RetrievePagePropertyItemAsync( - new RetrievePropertyItemParameters - { - PageId = page.Id, - PropertyId = pageProperty.Id - }); - - titleProperty.Results.First().As().Title.PlainText.Should().Be("Test Page Title"); + var titlePropertyValue = page.Properties["Name"].Should().BeOfType().Subject; + titlePropertyValue.Title.First().PlainText.Should().Be("Test Page Title"); - await Client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); + page.Properties.Should().ContainKey("TestSelect"); + var selectPropertyValue = page.Properties["TestSelect"].Should().BeOfType().Subject; + selectPropertyValue.Select.Name.Should().Be("Blue"); } [Fact] public async Task Test_RetrievePagePropertyItemAsync() { + // Arrange var pagesCreateParameters = PagesCreateParametersBuilder - .Create(new DatabaseParentInput { DatabaseId = ParentDatabaseId }) + .Create(new DatabaseParentInput { DatabaseId = _database.Id }) .AddProperty("Name", new TitlePropertyValue { @@ -105,12 +156,14 @@ public async Task Test_RetrievePagePropertyItemAsync() var page = await Client.Pages.CreateAsync(pagesCreateParameters); + // Act var property = await Client.Pages.RetrievePagePropertyItemAsync(new RetrievePropertyItemParameters { PageId = page.Id, PropertyId = "title" }); + // Assert property.Should().NotBeNull(); property.Should().BeOfType(); @@ -125,16 +178,14 @@ public async Task Test_RetrievePagePropertyItemAsync() titleProperty.Title.PlainText.Should().Be("Test Page Title"); }); - - // cleanup - await Client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); } [Fact] public async Task Test_UpdatePageProperty_with_date_as_null() { - // setup - add property to db and create a page with the property having a date + // Arrange + // Add property Date property to database const string DatePropertyName = "Test Date Property"; var updateDatabaseParameters = new DatabasesUpdateParameters @@ -149,8 +200,9 @@ public async Task Test_UpdatePageProperty_with_date_as_null() } }; + // Create a page with the property having a date var pagesCreateParameters = PagesCreateParametersBuilder - .Create(new DatabaseParentInput { DatabaseId = ParentDatabaseId }) + .Create(new DatabaseParentInput { DatabaseId = _database.Id }) .AddProperty("Name", new TitlePropertyValue { @@ -170,10 +222,11 @@ public async Task Test_UpdatePageProperty_with_date_as_null() }) .Build(); - await Client.Databases.UpdateAsync(ParentDatabaseId, updateDatabaseParameters); + await Client.Databases.UpdateAsync(_database.Id, updateDatabaseParameters); var page = await Client.Pages.CreateAsync(pagesCreateParameters); + // Act var setDate = (DatePropertyItem)await Client.Pages.RetrievePagePropertyItemAsync( new RetrievePropertyItemParameters { @@ -182,27 +235,28 @@ public async Task Test_UpdatePageProperty_with_date_as_null() } ); + // Assert setDate?.Date?.Start.Should().Be(Convert.ToDateTime("2020-12-08T12:00:00Z")); - // verify - IDictionary testProps = new Dictionary(); - - testProps.Add(DatePropertyName, new DatePropertyValue { Date = null }); + var pageUpdateParameters = new PagesUpdateParameters + { + Properties = new Dictionary + { + { DatePropertyName, new DatePropertyValue { Date = null } } + } + }; - var updatedPage = - await Client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Properties = testProps }); + var updatedPage = await Client.Pages.UpdateAsync(page.Id, pageUpdateParameters); var verifyDate = (DatePropertyItem)await Client.Pages.RetrievePagePropertyItemAsync( new RetrievePropertyItemParameters { PageId = page.Id, PropertyId = updatedPage.Properties[DatePropertyName].Id - }); + } + ); verifyDate?.Date.Should().BeNull(); - - //cleanup - await Client.Blocks.DeleteAsync(page.Id); } [Fact] @@ -210,14 +264,16 @@ public async Task Bug_Unable_To_Parse_NumberPropertyItem() { // Arrange var pagesCreateParameters = PagesCreateParametersBuilder - .Create(new DatabaseParentInput { DatabaseId = ParentDatabaseId }).AddProperty("Name", + .Create(new DatabaseParentInput { DatabaseId = _database.Id }) + .AddProperty("Name", new TitlePropertyValue { Title = new List { new RichTextText { Text = new Text { Content = "Test Page Title" } } } - }).AddProperty("Number", new NumberPropertyValue { Number = 200.00 }).Build(); + }) + .AddProperty("Number", new NumberPropertyValue { Number = 200.00 }).Build(); // Act var page = await Client.Pages.CreateAsync(pagesCreateParameters); @@ -225,7 +281,7 @@ public async Task Bug_Unable_To_Parse_NumberPropertyItem() // Assert Assert.NotNull(page); var pageParent = Assert.IsType(page.Parent); - Assert.Equal(ParentDatabaseId, pageParent.DatabaseId); + Assert.Equal(_database.Id, pageParent.DatabaseId); var titleProperty = (ListPropertyItem)await Client.Pages.RetrievePagePropertyItemAsync( new RetrievePropertyItemParameters @@ -244,8 +300,6 @@ public async Task Bug_Unable_To_Parse_NumberPropertyItem() }); Assert.Equal(200.00, numberProperty.Number); - - await Client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); } [Fact] @@ -255,19 +309,11 @@ public async Task Bug_exception_when_attempting_to_set_select_property_to_nothin var databaseCreateRequest = new DatabasesCreateParameters { Title = - new List - { - new RichTextTextInput() { Text = new Text { Content = "Test Database" } } - }, - Parent = new ParentPageInput() { PageId = ParentPageId }, + new List { new RichTextTextInput { Text = new Text { Content = "Test Database" } } }, + Parent = new ParentPageInput() { PageId = _page.Id }, Properties = new Dictionary { - { - "title", new TitlePropertySchema - { - Title = new Dictionary() - } - }, + { "title", new TitlePropertySchema { Title = new Dictionary() } }, { "Colors1", new SelectPropertySchema @@ -337,8 +383,5 @@ public async Task Bug_exception_when_attempting_to_set_select_property_to_nothin updatedPage.Properties["Colors1"].As().Select.Name.Should().Be("Blue"); updatedPage.Properties["Colors2"].As().Select.Should().BeNull(); - - await Client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); - await Client.Databases.UpdateAsync(database.Id, new DatabasesUpdateParameters { Archived = true }); } } From 0813c026ae7b126ee24632e34e5a789efefa090b Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 15 Oct 2023 02:52:58 +0530 Subject: [PATCH 162/216] Make use of IAsyncDisposable in PageWithPageParent test --- .../PageWithPageParentTests.cs | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/Test/Notion.IntegrationTests/PageWithPageParentTests.cs b/Test/Notion.IntegrationTests/PageWithPageParentTests.cs index cca3356b..3d31e94d 100644 --- a/Test/Notion.IntegrationTests/PageWithPageParentTests.cs +++ b/Test/Notion.IntegrationTests/PageWithPageParentTests.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using FluentAssertions; @@ -7,12 +8,12 @@ namespace Notion.IntegrationTests; -public class PageWithPageParentTests : IntegrationTestBase +public class PageWithPageParentTests : IntegrationTestBase, IAsyncDisposable { - [Fact] - public async Task Update_Title_Of_Page() + private readonly Page _page; + + public PageWithPageParentTests() { - // Arrange var pagesCreateParameters = PagesCreateParametersBuilder .Create(new ParentPageInput() { PageId = ParentPageId }) .AddProperty("title", @@ -24,8 +25,13 @@ public async Task Update_Title_Of_Page() } }).Build(); - var page = await Client.Pages.CreateAsync(pagesCreateParameters); + _page = Client.Pages.CreateAsync(pagesCreateParameters).GetAwaiter().GetResult(); + } + [Fact] + public async Task Update_Title_Of_Page() + { + // Arrange var updatePage = new PagesUpdateParameters() { Properties = new Dictionary @@ -44,7 +50,7 @@ public async Task Update_Title_Of_Page() }; // Act - var updatedPage = await Client.Pages.UpdateAsync(page.Id, updatePage); + var updatedPage = await Client.Pages.UpdateAsync(_page.Id, updatePage); // Assert var titleProperty = (ListPropertyItem)await Client.Pages.RetrievePagePropertyItemAsync( @@ -55,9 +61,11 @@ public async Task Update_Title_Of_Page() } ); - Assert.Equal("Page Title Updated", titleProperty.Results.First().As().Title.PlainText); + titleProperty.Results.First().As().Title.PlainText.Should().Be("Page Title Updated"); + } - // Clean Up - await Client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); + public async ValueTask DisposeAsync() + { + await Client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters { Archived = true }); } } From 66d75a4fa8bff78b5e4b67a4e4a6a699ef18c7ae Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 15 Oct 2023 03:01:19 +0530 Subject: [PATCH 163/216] User IAsyncDisposable in PageClient tests --- Test/Notion.IntegrationTests/PageClientTests.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Test/Notion.IntegrationTests/PageClientTests.cs b/Test/Notion.IntegrationTests/PageClientTests.cs index 1e697c59..d2843dc4 100644 --- a/Test/Notion.IntegrationTests/PageClientTests.cs +++ b/Test/Notion.IntegrationTests/PageClientTests.cs @@ -8,7 +8,7 @@ namespace Notion.IntegrationTests; -public class PageClientTests : IntegrationTestBase, IDisposable +public class PageClientTests : IntegrationTestBase, IAsyncDisposable { private readonly Page _page; private readonly Database _database; @@ -20,7 +20,7 @@ public PageClientTests() PagesCreateParametersBuilder.Create( new ParentPageInput { PageId = ParentPageId } ).Build() - ).Result; + ).GetAwaiter().GetResult(); // Create a database var createDbRequest = new DatabasesCreateParameters @@ -61,9 +61,9 @@ public PageClientTests() _database = Client.Databases.CreateAsync(createDbRequest).GetAwaiter().GetResult(); } - public void Dispose() + public async ValueTask DisposeAsync() { - Client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters { Archived = true }).GetAwaiter().GetResult(); + await Client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters { Archived = true }); } [Fact] From 5231ed1c40c21f43aa89ce0b43b7262e3d7d9c0f Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 15 Oct 2023 03:03:07 +0530 Subject: [PATCH 164/216] Use IAsyncDisposable in Comments client tests --- Test/Notion.IntegrationTests/CommentsClientTests.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Test/Notion.IntegrationTests/CommentsClientTests.cs b/Test/Notion.IntegrationTests/CommentsClientTests.cs index 0eb56bea..5a6de044 100644 --- a/Test/Notion.IntegrationTests/CommentsClientTests.cs +++ b/Test/Notion.IntegrationTests/CommentsClientTests.cs @@ -7,7 +7,7 @@ namespace Notion.IntegrationTests; -public class CommentsClientTests : IntegrationTestBase, IDisposable +public class CommentsClientTests : IntegrationTestBase, IAsyncDisposable { private readonly Page _page; @@ -17,12 +17,12 @@ public CommentsClientTests() PagesCreateParametersBuilder.Create( new ParentPageInput { PageId = ParentPageId } ).Build() - ).Result; + ).GetAwaiter().GetResult(); } - public void Dispose() + public async ValueTask DisposeAsync() { - Client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters { Archived = true }).Wait(); + await Client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters { Archived = true }); } [Fact] From f5db1489c22e846d606775270dbcd3ffb7feb8ac Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 15 Oct 2023 03:09:00 +0530 Subject: [PATCH 165/216] Use IAsyncDisposable in Databases Client tests * use fluent assertions --- .../DatabasesClientTests.cs | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Test/Notion.IntegrationTests/DatabasesClientTests.cs b/Test/Notion.IntegrationTests/DatabasesClientTests.cs index e2255339..cbdfb652 100644 --- a/Test/Notion.IntegrationTests/DatabasesClientTests.cs +++ b/Test/Notion.IntegrationTests/DatabasesClientTests.cs @@ -2,12 +2,13 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using FluentAssertions; using Notion.Client; using Xunit; namespace Notion.IntegrationTests; -public class DatabasesClientTests : IntegrationTestBase, IDisposable +public class DatabasesClientTests : IntegrationTestBase, IAsyncDisposable { private readonly Page _page; @@ -17,12 +18,12 @@ public DatabasesClientTests() PagesCreateParametersBuilder.Create( new ParentPageInput { PageId = ParentPageId } ).Build() - ).Result; + ).GetAwaiter().GetResult(); } - public void Dispose() + public async ValueTask DisposeAsync() { - Client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters { Archived = true }).Wait(); + await Client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters { Archived = true }); } [Fact] @@ -35,11 +36,12 @@ public async Task QueryDatabase() var response = await Client.Databases.QueryAsync(createdDatabase.Id, new DatabasesQueryParameters()); // Assert - Assert.NotNull(response.Results); - Assert.Single(response.Results); - var page = response.Results.Cast().First(); - var title = page.Properties["Name"] as TitlePropertyValue; - Assert.Equal("Test Title", (title!.Title.Cast().First()).Text.Content); + response.Results.Should().NotBeNull(); + var page = response.Results.Should().ContainSingle().Subject.As(); + + page.Properties["Name"].As() + .Title.Cast().First() + .Text.Content.Should().Be("Test Title"); } private async Task CreateDatabaseWithAPageAsync() From 50a7b66a51edf6aefd48d47fdb4a844974c1116c Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 15 Oct 2023 04:21:19 +0530 Subject: [PATCH 166/216] Adjust Breaking BlocksClients tests --- ...cksClientTests.cs => BlocksClientTests.cs} | 58 +++---------------- 1 file changed, 7 insertions(+), 51 deletions(-) rename Test/Notion.IntegrationTests/{IBlocksClientTests.cs => BlocksClientTests.cs} (89%) diff --git a/Test/Notion.IntegrationTests/IBlocksClientTests.cs b/Test/Notion.IntegrationTests/BlocksClientTests.cs similarity index 89% rename from Test/Notion.IntegrationTests/IBlocksClientTests.cs rename to Test/Notion.IntegrationTests/BlocksClientTests.cs index 24e28da7..9b09ec3f 100644 --- a/Test/Notion.IntegrationTests/IBlocksClientTests.cs +++ b/Test/Notion.IntegrationTests/BlocksClientTests.cs @@ -188,12 +188,13 @@ private static IEnumerable BlockData() }, new object[] { - new DividerBlock { Divider = new DividerBlock.Data() }, new DividerUpdateBlock(), new Action( - block => - { - Assert.NotNull(block); - _ = Assert.IsType(block); - }) + new DividerBlock { Divider = new DividerBlock.Data() }, + new DividerUpdateBlock(), + new Action((block, client) => + { + Assert.NotNull(block); + _ = Assert.IsType(block); + }) }, new object[] { @@ -354,51 +355,6 @@ private static IEnumerable BlockData() }) }, new object[] - { - new TemplateBlock - { - Template = new TemplateBlock.Data - { - RichText = new List - { - new RichTextText { Text = new Text { Content = "Test Template" } } - }, - Children = new List - { - new EmbedBlock - { - Embed = new EmbedBlock.Info - { - Url - = "https://zephoria.com/wp-content/uploads/2014/08/online-community.jpg" - } - } - } - } - }, - new TemplateUpdateBlock - { - Template = new TemplateUpdateBlock.Info - { - RichText = new List - { - new RichTextTextInput { Text = new Text { Content = "Test Template 2" } } - } - } - }, - new Action((block, client) => - { - Assert.NotNull(block); - var templateBlock = Assert.IsType(block); - - Assert.Single(templateBlock.Template.RichText); - Assert.Null(templateBlock.Template.Children); - - Assert.Equal("Test Template 2", - templateBlock.Template.RichText.OfType().First().Text.Content); - }) - }, - new object[] { new LinkToPageBlock { From 3b4324befb554d858383e102fde4b4e0f0f905d7 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 15 Oct 2023 04:28:20 +0530 Subject: [PATCH 167/216] Use IAsyncLifetime to initialize and cleanup common resources --- .../BlocksClientTests.cs | 81 +++++++------------ 1 file changed, 29 insertions(+), 52 deletions(-) diff --git a/Test/Notion.IntegrationTests/BlocksClientTests.cs b/Test/Notion.IntegrationTests/BlocksClientTests.cs index 9b09ec3f..71d853b6 100644 --- a/Test/Notion.IntegrationTests/BlocksClientTests.cs +++ b/Test/Notion.IntegrationTests/BlocksClientTests.cs @@ -8,21 +8,31 @@ namespace Notion.IntegrationTests; -public class IBlocksClientTests : IntegrationTestBase +public class IBlocksClientTests : IntegrationTestBase, IAsyncLifetime { - [Fact] - public async Task AppendChildrenAsync_AppendsBlocksGivenBlocks() + private Page _page = null!; + + public async Task InitializeAsync() { - var page = await Client.Pages.CreateAsync( + _page = await Client.Pages.CreateAsync( PagesCreateParametersBuilder.Create( new ParentPageInput { PageId = ParentPageId } ).Build() ); + } + public async Task DisposeAsync() + { + await Client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters { Archived = true }); + } + + [Fact] + public async Task AppendChildrenAsync_AppendsBlocksGivenBlocks() + { var blocks = await Client.Blocks.AppendChildrenAsync( new BlockAppendChildrenRequest { - BlockId = page.Id, + BlockId = _page.Id, Children = new List { new BreadcrumbBlock { Breadcrumb = new BreadcrumbBlock.Data() }, @@ -43,24 +53,15 @@ public async Task AppendChildrenAsync_AppendsBlocksGivenBlocks() ); blocks.Results.Should().HaveCount(4); - - // cleanup - await Client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); } [Fact] public async Task UpdateBlockAsync_UpdatesGivenBlock() { - var page = await Client.Pages.CreateAsync( - PagesCreateParametersBuilder.Create( - new ParentPageInput { PageId = ParentPageId } - ).Build() - ); - var blocks = await Client.Blocks.AppendChildrenAsync( new BlockAppendChildrenRequest { - BlockId = page.Id, + BlockId = _page.Id, Children = new List { new BreadcrumbBlock { Breadcrumb = new BreadcrumbBlock.Data() } } } ); @@ -68,29 +69,19 @@ public async Task UpdateBlockAsync_UpdatesGivenBlock() var blockId = blocks.Results.First().Id; await Client.Blocks.UpdateAsync(blockId, new BreadcrumbUpdateBlock()); - var updatedBlocks = await Client.Blocks.RetrieveChildrenAsync(new BlockRetrieveChildrenRequest - { - BlockId = page.Id - }); - updatedBlocks.Results.Should().HaveCount(1); + var updatedBlocks = + await Client.Blocks.RetrieveChildrenAsync(new BlockRetrieveChildrenRequest { BlockId = _page.Id }); - // cleanup - await Client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); + updatedBlocks.Results.Should().HaveCount(1); } [Fact] public async Task DeleteAsync_DeleteBlockWithGivenId() { - var page = await Client.Pages.CreateAsync( - PagesCreateParametersBuilder.Create( - new ParentPageInput { PageId = ParentPageId } - ).Build() - ); - var blocks = await Client.Blocks.AppendChildrenAsync( new BlockAppendChildrenRequest { - BlockId = page.Id, + BlockId = _page.Id, Children = new List { new DividerBlock { Divider = new DividerBlock.Data() }, @@ -100,9 +91,6 @@ public async Task DeleteAsync_DeleteBlockWithGivenId() ); blocks.Results.Should().HaveCount(2); - - // cleanup - await Client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); } [Theory] @@ -110,16 +98,10 @@ public async Task DeleteAsync_DeleteBlockWithGivenId() public async Task UpdateAsync_UpdatesGivenBlock( IBlock block, IUpdateBlock updateBlock, Action assert) { - var page = await Client.Pages.CreateAsync( - PagesCreateParametersBuilder.Create( - new ParentPageInput { PageId = ParentPageId } - ).Build() - ); - var blocks = await Client.Blocks.AppendChildrenAsync( new BlockAppendChildrenRequest { - BlockId = page.Id, + BlockId = _page.Id, Children = new List { block } } ); @@ -127,18 +109,14 @@ public async Task UpdateAsync_UpdatesGivenBlock( var blockId = blocks.Results.First().Id; await Client.Blocks.UpdateAsync(blockId, updateBlock); - var updatedBlocks = await Client.Blocks.RetrieveChildrenAsync(new BlockRetrieveChildrenRequest - { - BlockId = page.Id - }); + var updatedBlocks = + await Client.Blocks.RetrieveChildrenAsync(new BlockRetrieveChildrenRequest { BlockId = _page.Id }); + updatedBlocks.Results.Should().HaveCount(1); var updatedBlock = updatedBlocks.Results.First(); assert.Invoke(updatedBlock, Client); - - // cleanup - await Client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); } private static IEnumerable BlockData() @@ -188,8 +166,7 @@ private static IEnumerable BlockData() }, new object[] { - new DividerBlock { Divider = new DividerBlock.Data() }, - new DividerUpdateBlock(), + new DividerBlock { Divider = new DividerBlock.Data() }, new DividerUpdateBlock(), new Action((block, client) => { Assert.NotNull(block); @@ -374,7 +351,7 @@ private static IEnumerable BlockData() var linkToPageBlock = Assert.IsType(block); var pageParent = Assert.IsType(linkToPageBlock.LinkToPage); - + // TODO: Currently the api doesn't allow to update the link_to_page block type // This will change to updated ID once api start to support Assert.Equal(Guid.Parse("533578e3edf14c0a91a9da6b09bac3ee"), Guid.Parse(pageParent.PageId)); @@ -408,9 +385,9 @@ private static IEnumerable BlockData() var tableBlock = block.Should().NotBeNull().And.BeOfType().Subject; tableBlock.HasChildren.Should().BeTrue(); - var children = client.Blocks.RetrieveChildrenAsync(new BlockRetrieveChildrenRequest{ - BlockId = tableBlock.Id - }).GetAwaiter().GetResult(); + var children = client.Blocks + .RetrieveChildrenAsync(new BlockRetrieveChildrenRequest { BlockId = tableBlock.Id }) + .GetAwaiter().GetResult(); children.Results.Should().ContainSingle() .Subject.Should().BeOfType() From c79531a165be24a7400c2ca74ec28506f6361a79 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 15 Oct 2023 04:30:48 +0530 Subject: [PATCH 168/216] Discard unused lambda args --- .../Notion.IntegrationTests/BlocksClientTests.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Test/Notion.IntegrationTests/BlocksClientTests.cs b/Test/Notion.IntegrationTests/BlocksClientTests.cs index 71d853b6..4db78d85 100644 --- a/Test/Notion.IntegrationTests/BlocksClientTests.cs +++ b/Test/Notion.IntegrationTests/BlocksClientTests.cs @@ -147,7 +147,7 @@ private static IEnumerable BlockData() } } }, - new Action((block, client) => + new Action((block, _) => { var updatedBlock = (BookmarkBlock)block; Assert.Equal("https://github.com/notion-dotnet/notion-sdk-net", updatedBlock.Bookmark.Url); @@ -158,7 +158,7 @@ private static IEnumerable BlockData() { new EquationBlock { Equation = new EquationBlock.Info { Expression = "e=mc^3" } }, new EquationUpdateBlock { Equation = new EquationUpdateBlock.Info { Expression = "e=mc^2" } }, - new Action((block, client) => + new Action((block, _) => { var updatedBlock = (EquationBlock)block; Assert.Equal("e=mc^2", updatedBlock.Equation.Expression); @@ -195,7 +195,7 @@ private static IEnumerable BlockData() } } }, - new Action((block, client) => + new Action((block, _) => { block.Should().NotBeNull(); @@ -235,7 +235,7 @@ private static IEnumerable BlockData() } } }, - new Action((block, client) => + new Action((block, _) => { Assert.NotNull(block); var calloutBlock = Assert.IsType(block); @@ -265,7 +265,7 @@ private static IEnumerable BlockData() } } }, - new Action((block, client) => + new Action((block, _) => { Assert.NotNull(block); var quoteBlock = Assert.IsType(block); @@ -296,7 +296,7 @@ private static IEnumerable BlockData() } } }, - new Action((block, client) => + new Action((block, _) => { Assert.NotNull(block); var imageBlock = Assert.IsType(block); @@ -322,7 +322,7 @@ private static IEnumerable BlockData() Url = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg" } }, - new Action((block, client) => + new Action((block, _) => { Assert.NotNull(block); var embedBlock = Assert.IsType(block); @@ -345,7 +345,7 @@ private static IEnumerable BlockData() { LinkToPage = new ParentPageInput { PageId = "3c357473a28149a488c010d2b245a589" } }, - new Action((block, client) => + new Action((block, _) => { Assert.NotNull(block); var linkToPageBlock = Assert.IsType(block); From 88135e48942a9c7b0fabbc1366666785933acaaa Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 15 Oct 2023 04:33:02 +0530 Subject: [PATCH 169/216] Use IAsyncLifetime in CommentsClient Tests --- .../CommentsClientTests.cs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Test/Notion.IntegrationTests/CommentsClientTests.cs b/Test/Notion.IntegrationTests/CommentsClientTests.cs index 5a6de044..1655fc71 100644 --- a/Test/Notion.IntegrationTests/CommentsClientTests.cs +++ b/Test/Notion.IntegrationTests/CommentsClientTests.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Notion.Client; @@ -7,20 +6,20 @@ namespace Notion.IntegrationTests; -public class CommentsClientTests : IntegrationTestBase, IAsyncDisposable +public class CommentsClientTests : IntegrationTestBase, IAsyncLifetime { - private readonly Page _page; + private Page _page = null!; - public CommentsClientTests() + public async Task InitializeAsync() { - _page = Client.Pages.CreateAsync( + _page = await Client.Pages.CreateAsync( PagesCreateParametersBuilder.Create( new ParentPageInput { PageId = ParentPageId } ).Build() - ).GetAwaiter().GetResult(); + ); } - public async ValueTask DisposeAsync() + public async Task DisposeAsync() { await Client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters { Archived = true }); } From f6e8feb4c0e8c17ff134ecdf23d61dc0ff86abe7 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 15 Oct 2023 04:34:38 +0530 Subject: [PATCH 170/216] User IAsyncLifeTIme in DatabasesClient tests --- .../DatabasesClientTests.cs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Test/Notion.IntegrationTests/DatabasesClientTests.cs b/Test/Notion.IntegrationTests/DatabasesClientTests.cs index cbdfb652..c5c7082b 100644 --- a/Test/Notion.IntegrationTests/DatabasesClientTests.cs +++ b/Test/Notion.IntegrationTests/DatabasesClientTests.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using FluentAssertions; @@ -8,20 +7,20 @@ namespace Notion.IntegrationTests; -public class DatabasesClientTests : IntegrationTestBase, IAsyncDisposable +public class DatabasesClientTests : IntegrationTestBase, IAsyncLifetime { - private readonly Page _page; + private Page _page = null!; - public DatabasesClientTests() + public async Task InitializeAsync() { - _page = Client.Pages.CreateAsync( + _page = await Client.Pages.CreateAsync( PagesCreateParametersBuilder.Create( new ParentPageInput { PageId = ParentPageId } ).Build() - ).GetAwaiter().GetResult(); + ); } - public async ValueTask DisposeAsync() + public async Task DisposeAsync() { await Client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters { Archived = true }); } From 889fa12412b52f158f342af7ef7499603753b42a Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 15 Oct 2023 04:36:41 +0530 Subject: [PATCH 171/216] Use IAsyncLifetime in PageClient tests --- Test/Notion.IntegrationTests/PageClientTests.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Test/Notion.IntegrationTests/PageClientTests.cs b/Test/Notion.IntegrationTests/PageClientTests.cs index d2843dc4..2e4153eb 100644 --- a/Test/Notion.IntegrationTests/PageClientTests.cs +++ b/Test/Notion.IntegrationTests/PageClientTests.cs @@ -8,19 +8,19 @@ namespace Notion.IntegrationTests; -public class PageClientTests : IntegrationTestBase, IAsyncDisposable +public class PageClientTests : IntegrationTestBase, IAsyncLifetime { - private readonly Page _page; - private readonly Database _database; + private Page _page = null!; + private Database _database = null!; - public PageClientTests() + public async Task InitializeAsync() { // Create a page - _page = Client.Pages.CreateAsync( + _page = await Client.Pages.CreateAsync( PagesCreateParametersBuilder.Create( new ParentPageInput { PageId = ParentPageId } ).Build() - ).GetAwaiter().GetResult(); + ); // Create a database var createDbRequest = new DatabasesCreateParameters @@ -58,10 +58,10 @@ public PageClientTests() Parent = new ParentPageInput { PageId = _page.Id } }; - _database = Client.Databases.CreateAsync(createDbRequest).GetAwaiter().GetResult(); + _database = await Client.Databases.CreateAsync(createDbRequest); } - public async ValueTask DisposeAsync() + public async Task DisposeAsync() { await Client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters { Archived = true }); } From f1c0a228313131b4e963d18d8d6722248996bf77 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 15 Oct 2023 04:38:26 +0530 Subject: [PATCH 172/216] User IAsyncLifetime in PageWithPageParent tests --- .../PageWithPageParentTests.cs | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/Test/Notion.IntegrationTests/PageWithPageParentTests.cs b/Test/Notion.IntegrationTests/PageWithPageParentTests.cs index 3d31e94d..5f398dc7 100644 --- a/Test/Notion.IntegrationTests/PageWithPageParentTests.cs +++ b/Test/Notion.IntegrationTests/PageWithPageParentTests.cs @@ -1,5 +1,4 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using FluentAssertions; @@ -8,11 +7,11 @@ namespace Notion.IntegrationTests; -public class PageWithPageParentTests : IntegrationTestBase, IAsyncDisposable +public class PageWithPageParentTests : IntegrationTestBase, IAsyncLifetime { - private readonly Page _page; + private Page _page = null!; - public PageWithPageParentTests() + public async Task InitializeAsync() { var pagesCreateParameters = PagesCreateParametersBuilder .Create(new ParentPageInput() { PageId = ParentPageId }) @@ -25,7 +24,12 @@ public PageWithPageParentTests() } }).Build(); - _page = Client.Pages.CreateAsync(pagesCreateParameters).GetAwaiter().GetResult(); + _page = await Client.Pages.CreateAsync(pagesCreateParameters); + } + + public async Task DisposeAsync() + { + await Client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters { Archived = true }); } [Fact] @@ -63,9 +67,4 @@ public async Task Update_Title_Of_Page() titleProperty.Results.First().As().Title.PlainText.Should().Be("Page Title Updated"); } - - public async ValueTask DisposeAsync() - { - await Client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters { Archived = true }); - } } From 8d574d66407f301c0f0c6dce72a5ca04c52969ff Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 15 Oct 2023 01:43:23 +0530 Subject: [PATCH 173/216] Add Block object request models --- .../Blocks/Request/AudioBlockRequest.cs | 12 +++++++ .../Blocks/Request/BlockObjectRequest.cs | 28 +++++++++++++++++ .../Blocks/Request/BookmarkBlockRequest.cs | 22 +++++++++++++ .../Blocks/Request/BreadcrumbBlockRequest.cs | 16 ++++++++++ .../Request/BulletedListItemBlockRequest.cs | 27 ++++++++++++++++ .../Blocks/Request/CalloutBlockRequest.cs | 30 ++++++++++++++++++ .../Request/ChildDatabaseBlockRequest.cs | 18 +++++++++++ .../Blocks/Request/ChildPageBlockRequest.cs | 18 +++++++++++ .../Models/Blocks/Request/CodeBlockRequest.cs | 25 +++++++++++++++ .../Blocks/Request/ColumnBlockRequest.cs | 19 ++++++++++++ .../Blocks/Request/ColumnListBlockRequest.cs | 19 ++++++++++++ .../Blocks/Request/DividerBlockRequest.cs | 16 ++++++++++ .../Blocks/Request/EmbedBlockRequest.cs | 22 +++++++++++++ .../Blocks/Request/EquationBlockRequest.cs | 18 +++++++++++ .../Models/Blocks/Request/FileBlockRequest.cs | 12 +++++++ .../Blocks/Request/HeadingOneBlockRequest.cs | 29 +++++++++++++++++ .../Request/HeadingThreeBlockRequest.cs | 29 +++++++++++++++++ .../Blocks/Request/HeadingTwoBlockRequest.cs | 29 +++++++++++++++++ .../Blocks/Request/IBlockObjectRequest.cs | 19 ++++++++++++ .../Request/IColumnChildrenBlockRequest.cs | 18 +++++++++++ .../Blocks/Request/ImageBlockRequest.cs | 12 +++++++ .../Blocks/Request/LinkPreviewBlockRequest.cs | 18 +++++++++++ .../Blocks/Request/LinkToPageBlockRequest.cs | 12 +++++++ .../Request/NumberedListItemBlockRequest.cs | 27 ++++++++++++++++ .../Models/Blocks/Request/PDFBlockRequest.cs | 14 +++++++++ .../Blocks/Request/ParagraphBlockRequest.cs | 27 ++++++++++++++++ .../Blocks/Request/QuoteBlockRequest.cs | 27 ++++++++++++++++ .../Blocks/Request/SyncedBlockBlockRequest.cs | 31 +++++++++++++++++++ .../Blocks/Request/TableBlockRequest.cs | 28 +++++++++++++++++ .../Request/TableOfContentsBlockRequest.cs | 20 ++++++++++++ .../Blocks/Request/TableRowBlockRequest.cs | 19 ++++++++++++ .../Blocks/Request/TemplateBlockRequest.cs | 22 +++++++++++++ .../Models/Blocks/Request/ToDoBlockRequest.cs | 30 ++++++++++++++++++ .../Blocks/Request/ToggleBlockRequest.cs | 27 ++++++++++++++++ .../Blocks/Request/VideoBlockRequest.cs | 12 +++++++ 35 files changed, 752 insertions(+) create mode 100644 Src/Notion.Client/Models/Blocks/Request/AudioBlockRequest.cs create mode 100644 Src/Notion.Client/Models/Blocks/Request/BlockObjectRequest.cs create mode 100644 Src/Notion.Client/Models/Blocks/Request/BookmarkBlockRequest.cs create mode 100644 Src/Notion.Client/Models/Blocks/Request/BreadcrumbBlockRequest.cs create mode 100644 Src/Notion.Client/Models/Blocks/Request/BulletedListItemBlockRequest.cs create mode 100644 Src/Notion.Client/Models/Blocks/Request/CalloutBlockRequest.cs create mode 100644 Src/Notion.Client/Models/Blocks/Request/ChildDatabaseBlockRequest.cs create mode 100644 Src/Notion.Client/Models/Blocks/Request/ChildPageBlockRequest.cs create mode 100644 Src/Notion.Client/Models/Blocks/Request/CodeBlockRequest.cs create mode 100644 Src/Notion.Client/Models/Blocks/Request/ColumnBlockRequest.cs create mode 100644 Src/Notion.Client/Models/Blocks/Request/ColumnListBlockRequest.cs create mode 100644 Src/Notion.Client/Models/Blocks/Request/DividerBlockRequest.cs create mode 100644 Src/Notion.Client/Models/Blocks/Request/EmbedBlockRequest.cs create mode 100644 Src/Notion.Client/Models/Blocks/Request/EquationBlockRequest.cs create mode 100644 Src/Notion.Client/Models/Blocks/Request/FileBlockRequest.cs create mode 100644 Src/Notion.Client/Models/Blocks/Request/HeadingOneBlockRequest.cs create mode 100644 Src/Notion.Client/Models/Blocks/Request/HeadingThreeBlockRequest.cs create mode 100644 Src/Notion.Client/Models/Blocks/Request/HeadingTwoBlockRequest.cs create mode 100644 Src/Notion.Client/Models/Blocks/Request/IBlockObjectRequest.cs create mode 100644 Src/Notion.Client/Models/Blocks/Request/IColumnChildrenBlockRequest.cs create mode 100644 Src/Notion.Client/Models/Blocks/Request/ImageBlockRequest.cs create mode 100644 Src/Notion.Client/Models/Blocks/Request/LinkPreviewBlockRequest.cs create mode 100644 Src/Notion.Client/Models/Blocks/Request/LinkToPageBlockRequest.cs create mode 100644 Src/Notion.Client/Models/Blocks/Request/NumberedListItemBlockRequest.cs create mode 100644 Src/Notion.Client/Models/Blocks/Request/PDFBlockRequest.cs create mode 100644 Src/Notion.Client/Models/Blocks/Request/ParagraphBlockRequest.cs create mode 100644 Src/Notion.Client/Models/Blocks/Request/QuoteBlockRequest.cs create mode 100644 Src/Notion.Client/Models/Blocks/Request/SyncedBlockBlockRequest.cs create mode 100644 Src/Notion.Client/Models/Blocks/Request/TableBlockRequest.cs create mode 100644 Src/Notion.Client/Models/Blocks/Request/TableOfContentsBlockRequest.cs create mode 100644 Src/Notion.Client/Models/Blocks/Request/TableRowBlockRequest.cs create mode 100644 Src/Notion.Client/Models/Blocks/Request/TemplateBlockRequest.cs create mode 100644 Src/Notion.Client/Models/Blocks/Request/ToDoBlockRequest.cs create mode 100644 Src/Notion.Client/Models/Blocks/Request/ToggleBlockRequest.cs create mode 100644 Src/Notion.Client/Models/Blocks/Request/VideoBlockRequest.cs diff --git a/Src/Notion.Client/Models/Blocks/Request/AudioBlockRequest.cs b/Src/Notion.Client/Models/Blocks/Request/AudioBlockRequest.cs new file mode 100644 index 00000000..8378574e --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/Request/AudioBlockRequest.cs @@ -0,0 +1,12 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class AudioBlockRequest : BlockObjectRequest, IColumnChildrenBlockRequest, INonColumnBlockRequest + { + [JsonProperty("audio")] + public FileObject Audio { get; set; } + + public override BlockType Type => BlockType.Audio; + } +} diff --git a/Src/Notion.Client/Models/Blocks/Request/BlockObjectRequest.cs b/Src/Notion.Client/Models/Blocks/Request/BlockObjectRequest.cs new file mode 100644 index 00000000..a3eb3182 --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/Request/BlockObjectRequest.cs @@ -0,0 +1,28 @@ +using System; + +namespace Notion.Client +{ + public abstract class BlockObjectRequest : IBlockObjectRequest + { + public ObjectType Object => ObjectType.Block; + + public string Id { get; set; } + + public virtual BlockType Type { get; set; } + + public DateTime CreatedTime { get; set; } + + public DateTime LastEditedTime { get; set; } + + public virtual bool HasChildren { get; set; } + + public PartialUser CreatedBy { get; set; } + + public PartialUser LastEditedBy { get; set; } + + /// + /// Information about the block's parent. + /// + public IBlockParent Parent { get; set; } + } +} diff --git a/Src/Notion.Client/Models/Blocks/Request/BookmarkBlockRequest.cs b/Src/Notion.Client/Models/Blocks/Request/BookmarkBlockRequest.cs new file mode 100644 index 00000000..0c7c0be2 --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/Request/BookmarkBlockRequest.cs @@ -0,0 +1,22 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class BookmarkBlockRequest : BlockObjectRequest, IColumnChildrenBlockRequest, INonColumnBlockRequest + { + [JsonProperty("bookmark")] + public Info Bookmark { get; set; } + + public override BlockType Type => BlockType.Bookmark; + + public class Info + { + [JsonProperty("url")] + public string Url { get; set; } + + [JsonProperty("caption")] + public IEnumerable Caption { get; set; } + } + } +} diff --git a/Src/Notion.Client/Models/Blocks/Request/BreadcrumbBlockRequest.cs b/Src/Notion.Client/Models/Blocks/Request/BreadcrumbBlockRequest.cs new file mode 100644 index 00000000..f6039456 --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/Request/BreadcrumbBlockRequest.cs @@ -0,0 +1,16 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class BreadcrumbBlockRequest : BlockObjectRequest, IColumnChildrenBlockRequest, INonColumnBlockRequest + { + [JsonProperty("breadcrumb")] + public Data Breadcrumb { get; set; } + + public override BlockType Type => BlockType.Breadcrumb; + + public class Data + { + } + } +} diff --git a/Src/Notion.Client/Models/Blocks/Request/BulletedListItemBlockRequest.cs b/Src/Notion.Client/Models/Blocks/Request/BulletedListItemBlockRequest.cs new file mode 100644 index 00000000..0aa8a183 --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/Request/BulletedListItemBlockRequest.cs @@ -0,0 +1,27 @@ +using System.Collections.Generic; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace Notion.Client +{ + public class BulletedListItemBlockRequest : BlockObjectRequest, IColumnChildrenBlockRequest, INonColumnBlockRequest + { + [JsonProperty("bulleted_list_item")] + public Info BulletedListItem { get; set; } + + public override BlockType Type => BlockType.BulletedListItem; + + public class Info + { + [JsonProperty("rich_text")] + public IEnumerable RichText { get; set; } + + [JsonProperty("color")] + [JsonConverter(typeof(StringEnumConverter))] + public Color? Color { get; set; } + + [JsonProperty("children")] + public IEnumerable Children { get; set; } + } + } +} diff --git a/Src/Notion.Client/Models/Blocks/Request/CalloutBlockRequest.cs b/Src/Notion.Client/Models/Blocks/Request/CalloutBlockRequest.cs new file mode 100644 index 00000000..b8a56823 --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/Request/CalloutBlockRequest.cs @@ -0,0 +1,30 @@ +using System.Collections.Generic; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace Notion.Client +{ + public class CalloutBlockRequest : BlockObjectRequest, IColumnChildrenBlockRequest, INonColumnBlockRequest + { + [JsonProperty("callout")] + public Info Callout { get; set; } + + public override BlockType Type => BlockType.Callout; + + public class Info + { + [JsonProperty("rich_text")] + public IEnumerable RichText { get; set; } + + [JsonProperty("icon")] + public IPageIcon Icon { get; set; } + + [JsonProperty("color")] + [JsonConverter(typeof(StringEnumConverter))] + public Color? Color { get; set; } + + [JsonProperty("children")] + public IEnumerable Children { get; set; } + } + } +} diff --git a/Src/Notion.Client/Models/Blocks/Request/ChildDatabaseBlockRequest.cs b/Src/Notion.Client/Models/Blocks/Request/ChildDatabaseBlockRequest.cs new file mode 100644 index 00000000..34ff9387 --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/Request/ChildDatabaseBlockRequest.cs @@ -0,0 +1,18 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class ChildDatabaseBlockRequest : BlockObjectRequest, IColumnChildrenBlockRequest, INonColumnBlockRequest + { + [JsonProperty("child_database")] + public Info ChildDatabase { get; set; } + + public override BlockType Type => BlockType.ChildDatabase; + + public class Info + { + [JsonProperty("title")] + public string Title { get; set; } + } + } +} diff --git a/Src/Notion.Client/Models/Blocks/Request/ChildPageBlockRequest.cs b/Src/Notion.Client/Models/Blocks/Request/ChildPageBlockRequest.cs new file mode 100644 index 00000000..43213b77 --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/Request/ChildPageBlockRequest.cs @@ -0,0 +1,18 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class ChildPageBlockRequest : BlockObjectRequest, IColumnChildrenBlockRequest, INonColumnBlockRequest + { + [JsonProperty("child_page")] + public Info ChildPage { get; set; } + + public override BlockType Type => BlockType.ChildPage; + + public class Info + { + [JsonProperty("title")] + public string Title { get; set; } + } + } +} diff --git a/Src/Notion.Client/Models/Blocks/Request/CodeBlockRequest.cs b/Src/Notion.Client/Models/Blocks/Request/CodeBlockRequest.cs new file mode 100644 index 00000000..732e3208 --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/Request/CodeBlockRequest.cs @@ -0,0 +1,25 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class CodeBlockRequest : BlockObjectRequest, IColumnChildrenBlockRequest, INonColumnBlockRequest + { + [JsonProperty("code")] + public Info Code { get; set; } + + public override BlockType Type => BlockType.Code; + + public class Info + { + [JsonProperty("rich_text")] + public IEnumerable RichText { get; set; } + + [JsonProperty("language")] + public string Language { get; set; } + + [JsonProperty("caption")] + public IEnumerable Caption { get; set; } + } + } +} diff --git a/Src/Notion.Client/Models/Blocks/Request/ColumnBlockRequest.cs b/Src/Notion.Client/Models/Blocks/Request/ColumnBlockRequest.cs new file mode 100644 index 00000000..c4136294 --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/Request/ColumnBlockRequest.cs @@ -0,0 +1,19 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class ColumnBlockRequest : BlockObjectRequest + { + public override BlockType Type => BlockType.Column; + + [JsonProperty("column")] + public Info Column { get; set; } + + public class Info + { + [JsonProperty("children")] + public IEnumerable Children { get; set; } + } + } +} diff --git a/Src/Notion.Client/Models/Blocks/Request/ColumnListBlockRequest.cs b/Src/Notion.Client/Models/Blocks/Request/ColumnListBlockRequest.cs new file mode 100644 index 00000000..431acf8e --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/Request/ColumnListBlockRequest.cs @@ -0,0 +1,19 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class ColumnListBlockRequest : BlockObjectRequest, INonColumnBlockRequest + { + [JsonProperty("column_list")] + public Info ColumnList { get; set; } + + public override BlockType Type => BlockType.ColumnList; + + public class Info + { + [JsonProperty("children")] + public IEnumerable Children { get; set; } + } + } +} diff --git a/Src/Notion.Client/Models/Blocks/Request/DividerBlockRequest.cs b/Src/Notion.Client/Models/Blocks/Request/DividerBlockRequest.cs new file mode 100644 index 00000000..49c81059 --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/Request/DividerBlockRequest.cs @@ -0,0 +1,16 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class DividerBlockRequest : BlockObjectRequest, IColumnChildrenBlockRequest, INonColumnBlockRequest + { + [JsonProperty("divider")] + public Data Divider { get; set; } + + public override BlockType Type => BlockType.Divider; + + public class Data + { + } + } +} diff --git a/Src/Notion.Client/Models/Blocks/Request/EmbedBlockRequest.cs b/Src/Notion.Client/Models/Blocks/Request/EmbedBlockRequest.cs new file mode 100644 index 00000000..81cb2339 --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/Request/EmbedBlockRequest.cs @@ -0,0 +1,22 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class EmbedBlockRequest : BlockObjectRequest, IColumnChildrenBlockRequest, INonColumnBlockRequest + { + [JsonProperty("embed")] + public Info Embed { get; set; } + + public override BlockType Type => BlockType.Embed; + + public class Info + { + [JsonProperty("url")] + public string Url { get; set; } + + [JsonProperty("caption")] + public IEnumerable Caption { get; set; } + } + } +} diff --git a/Src/Notion.Client/Models/Blocks/Request/EquationBlockRequest.cs b/Src/Notion.Client/Models/Blocks/Request/EquationBlockRequest.cs new file mode 100644 index 00000000..5c2ddb8a --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/Request/EquationBlockRequest.cs @@ -0,0 +1,18 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class EquationBlockRequest : BlockObjectRequest, IColumnChildrenBlockRequest, INonColumnBlockRequest + { + [JsonProperty("equation")] + public Info Equation { get; set; } + + public override BlockType Type => BlockType.Equation; + + public class Info + { + [JsonProperty("expression")] + public string Expression { get; set; } + } + } +} diff --git a/Src/Notion.Client/Models/Blocks/Request/FileBlockRequest.cs b/Src/Notion.Client/Models/Blocks/Request/FileBlockRequest.cs new file mode 100644 index 00000000..0539c41c --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/Request/FileBlockRequest.cs @@ -0,0 +1,12 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class FileBlockRequest : BlockObjectRequest, IColumnChildrenBlockRequest, INonColumnBlockRequest + { + [JsonProperty("file")] + public FileObject File { get; set; } + + public override BlockType Type => BlockType.File; + } +} diff --git a/Src/Notion.Client/Models/Blocks/Request/HeadingOneBlockRequest.cs b/Src/Notion.Client/Models/Blocks/Request/HeadingOneBlockRequest.cs new file mode 100644 index 00000000..dd91451a --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/Request/HeadingOneBlockRequest.cs @@ -0,0 +1,29 @@ +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace Notion.Client +{ + public class HeadingOneBlockRequest : BlockObjectRequest, IColumnChildrenBlockRequest, INonColumnBlockRequest + { + [JsonProperty("heading_1")] + [SuppressMessage("ReSharper", "InconsistentNaming")] + public Info Heading_1 { get; set; } + + public override BlockType Type => BlockType.Heading_1; + + public class Info + { + [JsonProperty("rich_text")] + public IEnumerable RichText { get; set; } + + [JsonProperty("color")] + [JsonConverter(typeof(StringEnumConverter))] + public Color? Color { get; set; } + + [JsonProperty("is_toggleable")] + public bool IsToggleable { get; set; } + } + } +} diff --git a/Src/Notion.Client/Models/Blocks/Request/HeadingThreeBlockRequest.cs b/Src/Notion.Client/Models/Blocks/Request/HeadingThreeBlockRequest.cs new file mode 100644 index 00000000..9b78c80e --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/Request/HeadingThreeBlockRequest.cs @@ -0,0 +1,29 @@ +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace Notion.Client +{ + public class HeadingThreeBlockRequest : BlockObjectRequest, IColumnChildrenBlockRequest, INonColumnBlockRequest + { + [JsonProperty("heading_3")] + [SuppressMessage("ReSharper", "InconsistentNaming")] + public Info Heading_3 { get; set; } + + public override BlockType Type => BlockType.Heading_3; + + public class Info + { + [JsonProperty("rich_text")] + public IEnumerable RichText { get; set; } + + [JsonProperty("color")] + [JsonConverter(typeof(StringEnumConverter))] + public Color? Color { get; set; } + + [JsonProperty("is_toggleable")] + public bool IsToggleable { get; set; } + } + } +} diff --git a/Src/Notion.Client/Models/Blocks/Request/HeadingTwoBlockRequest.cs b/Src/Notion.Client/Models/Blocks/Request/HeadingTwoBlockRequest.cs new file mode 100644 index 00000000..dfdeb9dd --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/Request/HeadingTwoBlockRequest.cs @@ -0,0 +1,29 @@ +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace Notion.Client +{ + public class HeadingTwoBlockRequest : BlockObjectRequest, IColumnChildrenBlockRequest, INonColumnBlockRequest + { + [JsonProperty("heading_2")] + [SuppressMessage("ReSharper", "InconsistentNaming")] + public Info Heading_2 { get; set; } + + public override BlockType Type => BlockType.Heading_2; + + public class Info + { + [JsonProperty("rich_text")] + public IEnumerable RichText { get; set; } + + [JsonProperty("color")] + [JsonConverter(typeof(StringEnumConverter))] + public Color? Color { get; set; } + + [JsonProperty("is_toggleable")] + public bool IsToggleable { get; set; } + } + } +} diff --git a/Src/Notion.Client/Models/Blocks/Request/IBlockObjectRequest.cs b/Src/Notion.Client/Models/Blocks/Request/IBlockObjectRequest.cs new file mode 100644 index 00000000..b3fbaf55 --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/Request/IBlockObjectRequest.cs @@ -0,0 +1,19 @@ +using JsonSubTypes; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace Notion.Client +{ + public interface IBlockObjectRequest : IObject, IObjectModificationData + { + [JsonProperty("type")] + [JsonConverter(typeof(StringEnumConverter))] + BlockType Type { get; } + + [JsonProperty("has_children")] + bool HasChildren { get; set; } + + [JsonProperty("parent")] + IBlockParent Parent { get; set; } + } +} diff --git a/Src/Notion.Client/Models/Blocks/Request/IColumnChildrenBlockRequest.cs b/Src/Notion.Client/Models/Blocks/Request/IColumnChildrenBlockRequest.cs new file mode 100644 index 00000000..54e08fab --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/Request/IColumnChildrenBlockRequest.cs @@ -0,0 +1,18 @@ +namespace Notion.Client +{ + public interface ITemplateChildrenBlockRequest : IBlockObjectRequest + { + } + + public interface ISyncedBlockChildrenRequest : IBlockObjectRequest + { + } + + public interface IColumnChildrenBlockRequest : ITemplateChildrenBlockRequest, ISyncedBlockChildrenRequest + { + } + + public interface INonColumnBlockRequest : IBlockObjectRequest + { + } +} diff --git a/Src/Notion.Client/Models/Blocks/Request/ImageBlockRequest.cs b/Src/Notion.Client/Models/Blocks/Request/ImageBlockRequest.cs new file mode 100644 index 00000000..d3ec252b --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/Request/ImageBlockRequest.cs @@ -0,0 +1,12 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class ImageBlockRequest : BlockObjectRequest, IColumnChildrenBlockRequest, INonColumnBlockRequest + { + [JsonProperty("image")] + public FileObject Image { get; set; } + + public override BlockType Type => BlockType.Image; + } +} diff --git a/Src/Notion.Client/Models/Blocks/Request/LinkPreviewBlockRequest.cs b/Src/Notion.Client/Models/Blocks/Request/LinkPreviewBlockRequest.cs new file mode 100644 index 00000000..11a47592 --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/Request/LinkPreviewBlockRequest.cs @@ -0,0 +1,18 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class LinkPreviewBlockRequest : BlockObjectRequest, IColumnChildrenBlockRequest, INonColumnBlockRequest + { + [JsonProperty("link_preview")] + public Data LinkPreview { get; set; } + + public override BlockType Type => BlockType.LinkPreview; + + public class Data + { + [JsonProperty("url")] + public string Url { get; set; } + } + } +} diff --git a/Src/Notion.Client/Models/Blocks/Request/LinkToPageBlockRequest.cs b/Src/Notion.Client/Models/Blocks/Request/LinkToPageBlockRequest.cs new file mode 100644 index 00000000..ec182df5 --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/Request/LinkToPageBlockRequest.cs @@ -0,0 +1,12 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class LinkToPageBlockRequest : BlockObjectRequest, IColumnChildrenBlockRequest, INonColumnBlockRequest + { + [JsonProperty("link_to_page")] + public IPageParent LinkToPage { get; set; } + + public override BlockType Type => BlockType.LinkToPage; + } +} diff --git a/Src/Notion.Client/Models/Blocks/Request/NumberedListItemBlockRequest.cs b/Src/Notion.Client/Models/Blocks/Request/NumberedListItemBlockRequest.cs new file mode 100644 index 00000000..87342c1d --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/Request/NumberedListItemBlockRequest.cs @@ -0,0 +1,27 @@ +using System.Collections.Generic; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace Notion.Client +{ + public class NumberedListItemBlockRequest : BlockObjectRequest, IColumnChildrenBlockRequest, INonColumnBlockRequest + { + [JsonProperty("numbered_list_item")] + public Info NumberedListItem { get; set; } + + public override BlockType Type => BlockType.NumberedListItem; + + public class Info + { + [JsonProperty("rich_text")] + public IEnumerable RichText { get; set; } + + [JsonProperty("color")] + [JsonConverter(typeof(StringEnumConverter))] + public Color? Color { get; set; } + + [JsonProperty("children")] + public IEnumerable Children { get; set; } + } + } +} diff --git a/Src/Notion.Client/Models/Blocks/Request/PDFBlockRequest.cs b/Src/Notion.Client/Models/Blocks/Request/PDFBlockRequest.cs new file mode 100644 index 00000000..5590000d --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/Request/PDFBlockRequest.cs @@ -0,0 +1,14 @@ +using System.Diagnostics.CodeAnalysis; +using Newtonsoft.Json; + +namespace Notion.Client +{ + [SuppressMessage("ReSharper", "InconsistentNaming")] + public class PDFBlockRequest : BlockObjectRequest, IColumnChildrenBlockRequest, INonColumnBlockRequest + { + [JsonProperty("pdf")] + public FileObject PDF { get; set; } + + public override BlockType Type => BlockType.PDF; + } +} diff --git a/Src/Notion.Client/Models/Blocks/Request/ParagraphBlockRequest.cs b/Src/Notion.Client/Models/Blocks/Request/ParagraphBlockRequest.cs new file mode 100644 index 00000000..8e8dfa51 --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/Request/ParagraphBlockRequest.cs @@ -0,0 +1,27 @@ +using System.Collections.Generic; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace Notion.Client +{ + public class ParagraphBlockRequest : Block, IColumnChildrenBlockRequest, INonColumnBlockRequest + { + [JsonProperty("paragraph")] + public Info Paragraph { get; set; } + + public override BlockType Type => BlockType.Paragraph; + + public class Info + { + [JsonProperty("rich_text")] + public IEnumerable RichText { get; set; } + + [JsonProperty("color")] + [JsonConverter(typeof(StringEnumConverter))] + public Color? Color { get; set; } + + [JsonProperty("children")] + public IEnumerable Children { get; set; } + } + } +} diff --git a/Src/Notion.Client/Models/Blocks/Request/QuoteBlockRequest.cs b/Src/Notion.Client/Models/Blocks/Request/QuoteBlockRequest.cs new file mode 100644 index 00000000..3acd3130 --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/Request/QuoteBlockRequest.cs @@ -0,0 +1,27 @@ +using System.Collections.Generic; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace Notion.Client +{ + public class QuoteBlockRequest : BlockObjectRequest, IColumnChildrenBlockRequest, INonColumnBlockRequest + { + [JsonProperty("quote")] + public Info Quote { get; set; } + + public override BlockType Type => BlockType.Quote; + + public class Info + { + [JsonProperty("rich_text")] + public IEnumerable RichText { get; set; } + + [JsonProperty("color")] + [JsonConverter(typeof(StringEnumConverter))] + public Color? Color { get; set; } + + [JsonProperty("children")] + public IEnumerable Children { get; set; } + } + } +} diff --git a/Src/Notion.Client/Models/Blocks/Request/SyncedBlockBlockRequest.cs b/Src/Notion.Client/Models/Blocks/Request/SyncedBlockBlockRequest.cs new file mode 100644 index 00000000..5338e5bb --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/Request/SyncedBlockBlockRequest.cs @@ -0,0 +1,31 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class SyncedBlockBlockRequest : BlockObjectRequest, IColumnChildrenBlockRequest, INonColumnBlockRequest + { + [JsonProperty("synced_block")] + public Data SyncedBlock { get; set; } + + public override BlockType Type => BlockType.SyncedBlock; + + public class Data + { + [JsonProperty("synced_from")] + public SyncedFromBlockId SyncedFrom { get; set; } + + [JsonProperty("children")] + public IEnumerable Children { get; set; } + + public class SyncedFromBlockId + { + [JsonProperty("type")] + public string Type { get; set; } + + [JsonProperty("block_id")] + public string BlockId { get; set; } + } + } + } +} diff --git a/Src/Notion.Client/Models/Blocks/Request/TableBlockRequest.cs b/Src/Notion.Client/Models/Blocks/Request/TableBlockRequest.cs new file mode 100644 index 00000000..1e966182 --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/Request/TableBlockRequest.cs @@ -0,0 +1,28 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class TableBlockRequest : BlockObjectRequest, IColumnChildrenBlockRequest, INonColumnBlockRequest + { + [JsonProperty("table")] + public Info Table { get; set; } + + public override BlockType Type => BlockType.Table; + + public class Info + { + [JsonProperty("table_width")] + public int TableWidth { get; set; } + + [JsonProperty("has_column_header")] + public bool HasColumnHeader { get; set; } + + [JsonProperty("has_row_header")] + public bool HasRowHeader { get; set; } + + [JsonProperty("children")] + public IEnumerable Children { get; set; } + } + } +} diff --git a/Src/Notion.Client/Models/Blocks/Request/TableOfContentsBlockRequest.cs b/Src/Notion.Client/Models/Blocks/Request/TableOfContentsBlockRequest.cs new file mode 100644 index 00000000..2aef499d --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/Request/TableOfContentsBlockRequest.cs @@ -0,0 +1,20 @@ +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace Notion.Client +{ + public class TableOfContentsBlockRequest : BlockObjectRequest, IColumnChildrenBlockRequest, INonColumnBlockRequest + { + [JsonProperty("table_of_contents")] + public Data TableOfContents { get; set; } + + public override BlockType Type => BlockType.TableOfContents; + + public class Data + { + [JsonProperty("color")] + [JsonConverter(typeof(StringEnumConverter))] + public Color? Color { get; set; } + } + } +} diff --git a/Src/Notion.Client/Models/Blocks/Request/TableRowBlockRequest.cs b/Src/Notion.Client/Models/Blocks/Request/TableRowBlockRequest.cs new file mode 100644 index 00000000..ead85b33 --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/Request/TableRowBlockRequest.cs @@ -0,0 +1,19 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class TableRowBlockRequest : BlockObjectRequest, IColumnChildrenBlockRequest, INonColumnBlockRequest + { + [JsonProperty("table_row")] + public Info TableRow { get; set; } + + public override BlockType Type => BlockType.TableRow; + + public class Info + { + [JsonProperty("cells")] + public IEnumerable> Cells { get; set; } + } + } +} diff --git a/Src/Notion.Client/Models/Blocks/Request/TemplateBlockRequest.cs b/Src/Notion.Client/Models/Blocks/Request/TemplateBlockRequest.cs new file mode 100644 index 00000000..04c161d2 --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/Request/TemplateBlockRequest.cs @@ -0,0 +1,22 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class TemplateBlockRequest : BlockObjectRequest, IColumnChildrenBlockRequest, INonColumnBlockRequest + { + [JsonProperty("template")] + public Data Template { get; set; } + + public override BlockType Type => BlockType.Template; + + public class Data + { + [JsonProperty("rich_text")] + public IEnumerable RichText { get; set; } + + [JsonProperty("children")] + public IEnumerable Children { get; set; } + } + } +} diff --git a/Src/Notion.Client/Models/Blocks/Request/ToDoBlockRequest.cs b/Src/Notion.Client/Models/Blocks/Request/ToDoBlockRequest.cs new file mode 100644 index 00000000..ed7b09c3 --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/Request/ToDoBlockRequest.cs @@ -0,0 +1,30 @@ +using System.Collections.Generic; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace Notion.Client +{ + public class ToDoBlockRequest : BlockObjectRequest, IColumnChildrenBlockRequest, INonColumnBlockRequest + { + [JsonProperty("to_do")] + public Info ToDo { get; set; } + + public override BlockType Type => BlockType.ToDo; + + public class Info + { + [JsonProperty("rich_text")] + public IEnumerable RichText { get; set; } + + [JsonProperty("checked")] + public bool IsChecked { get; set; } + + [JsonProperty("color")] + [JsonConverter(typeof(StringEnumConverter))] + public Color? Color { get; set; } + + [JsonProperty("children")] + public IEnumerable Children { get; set; } + } + } +} diff --git a/Src/Notion.Client/Models/Blocks/Request/ToggleBlockRequest.cs b/Src/Notion.Client/Models/Blocks/Request/ToggleBlockRequest.cs new file mode 100644 index 00000000..fbbbcd37 --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/Request/ToggleBlockRequest.cs @@ -0,0 +1,27 @@ +using System.Collections.Generic; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +namespace Notion.Client +{ + public class ToggleBlockRequest : BlockObjectRequest, IColumnChildrenBlockRequest, INonColumnBlockRequest + { + [JsonProperty("toggle")] + public Info Toggle { get; set; } + + public override BlockType Type => BlockType.Toggle; + + public class Info + { + [JsonProperty("rich_text")] + public IEnumerable RichText { get; set; } + + [JsonProperty("color")] + [JsonConverter(typeof(StringEnumConverter))] + public Color? Color { get; set; } + + [JsonProperty("children")] + public IEnumerable Children { get; set; } + } + } +} diff --git a/Src/Notion.Client/Models/Blocks/Request/VideoBlockRequest.cs b/Src/Notion.Client/Models/Blocks/Request/VideoBlockRequest.cs new file mode 100644 index 00000000..238b2d26 --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/Request/VideoBlockRequest.cs @@ -0,0 +1,12 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class VideoBlockRequest : BlockObjectRequest, IColumnChildrenBlockRequest, INonColumnBlockRequest + { + [JsonProperty("video")] + public FileObject Video { get; set; } + + public override BlockType Type => BlockType.Video; + } +} From f5f69be7cf24497ce59f8a166cb47d5a1543790f Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 15 Oct 2023 01:53:05 +0530 Subject: [PATCH 174/216] Use IBlockObjectRequest in Block Append Children api --- .../Request/BlockAppendChildrenRequest.cs | 2 +- .../IBlockAppendChildrenBodyParameters.cs | 5 +- .../BlocksClientTests.cs | 63 ++++++++++--------- Test/Notion.UnitTests/BlocksClientTests.cs | 10 +-- 4 files changed, 41 insertions(+), 39 deletions(-) diff --git a/Src/Notion.Client/Api/Blocks/AppendChildren/Request/BlockAppendChildrenRequest.cs b/Src/Notion.Client/Api/Blocks/AppendChildren/Request/BlockAppendChildrenRequest.cs index 580d164a..8a5a9cde 100644 --- a/Src/Notion.Client/Api/Blocks/AppendChildren/Request/BlockAppendChildrenRequest.cs +++ b/Src/Notion.Client/Api/Blocks/AppendChildren/Request/BlockAppendChildrenRequest.cs @@ -4,7 +4,7 @@ namespace Notion.Client { public class BlockAppendChildrenRequest : IBlockAppendChildrenBodyParameters, IBlockAppendChildrenPathParameters { - public IEnumerable Children { get; set; } + public IEnumerable Children { get; set; } public string After { get; set; } diff --git a/Src/Notion.Client/Api/Blocks/AppendChildren/Request/IBlockAppendChildrenBodyParameters.cs b/Src/Notion.Client/Api/Blocks/AppendChildren/Request/IBlockAppendChildrenBodyParameters.cs index b476c089..ea6cef37 100644 --- a/Src/Notion.Client/Api/Blocks/AppendChildren/Request/IBlockAppendChildrenBodyParameters.cs +++ b/Src/Notion.Client/Api/Blocks/AppendChildren/Request/IBlockAppendChildrenBodyParameters.cs @@ -3,11 +3,10 @@ namespace Notion.Client { - // TODO: need an input version of Block public interface IBlockAppendChildrenBodyParameters { [JsonProperty("children")] - IEnumerable Children { get; set; } + IEnumerable Children { get; set; } /// /// The ID of the existing block that the new block should be appended after. @@ -18,7 +17,7 @@ public interface IBlockAppendChildrenBodyParameters internal class BlockAppendChildrenBodyParameters : IBlockAppendChildrenBodyParameters { - public IEnumerable Children { get; set; } + public IEnumerable Children { get; set; } public string After { get; set; } diff --git a/Test/Notion.IntegrationTests/BlocksClientTests.cs b/Test/Notion.IntegrationTests/BlocksClientTests.cs index 4db78d85..284ac009 100644 --- a/Test/Notion.IntegrationTests/BlocksClientTests.cs +++ b/Test/Notion.IntegrationTests/BlocksClientTests.cs @@ -33,14 +33,14 @@ public async Task AppendChildrenAsync_AppendsBlocksGivenBlocks() new BlockAppendChildrenRequest { BlockId = _page.Id, - Children = new List + Children = new List { - new BreadcrumbBlock { Breadcrumb = new BreadcrumbBlock.Data() }, - new DividerBlock { Divider = new DividerBlock.Data() }, - new TableOfContentsBlock { TableOfContents = new TableOfContentsBlock.Data() }, - new CalloutBlock + new BreadcrumbBlockRequest { Breadcrumb = new BreadcrumbBlockRequest.Data() }, + new DividerBlockRequest { Divider = new DividerBlockRequest.Data() }, + new TableOfContentsBlockRequest { TableOfContents = new TableOfContentsBlockRequest.Data() }, + new CalloutBlockRequest { - Callout = new CalloutBlock.Info + Callout = new CalloutBlockRequest.Info { RichText = new List { @@ -62,7 +62,10 @@ public async Task UpdateBlockAsync_UpdatesGivenBlock() new BlockAppendChildrenRequest { BlockId = _page.Id, - Children = new List { new BreadcrumbBlock { Breadcrumb = new BreadcrumbBlock.Data() } } + Children = new List + { + new BreadcrumbBlockRequest { Breadcrumb = new BreadcrumbBlockRequest.Data() } + } } ); @@ -82,10 +85,10 @@ public async Task DeleteAsync_DeleteBlockWithGivenId() new BlockAppendChildrenRequest { BlockId = _page.Id, - Children = new List + Children = new List { - new DividerBlock { Divider = new DividerBlock.Data() }, - new TableOfContentsBlock { TableOfContents = new TableOfContentsBlock.Data() } + new DividerBlockRequest { Divider = new DividerBlockRequest.Data() }, + new TableOfContentsBlockRequest { TableOfContents = new TableOfContentsBlockRequest.Data() } } } ); @@ -96,13 +99,13 @@ public async Task DeleteAsync_DeleteBlockWithGivenId() [Theory] [MemberData(nameof(BlockData))] public async Task UpdateAsync_UpdatesGivenBlock( - IBlock block, IUpdateBlock updateBlock, Action assert) + IBlockObjectRequest block, IUpdateBlock updateBlock, Action assert) { var blocks = await Client.Blocks.AppendChildrenAsync( new BlockAppendChildrenRequest { BlockId = _page.Id, - Children = new List { block } + Children = new List { block } } ); @@ -125,9 +128,9 @@ private static IEnumerable BlockData() { new object[] { - new BookmarkBlock + new BookmarkBlockRequest { - Bookmark = new BookmarkBlock.Info + Bookmark = new BookmarkBlockRequest.Info { Url = "https://developers.notion.com/reference/rich-text", Caption = new List @@ -156,7 +159,7 @@ private static IEnumerable BlockData() }, new object[] { - new EquationBlock { Equation = new EquationBlock.Info { Expression = "e=mc^3" } }, + new EquationBlockRequest { Equation = new EquationBlockRequest.Info { Expression = "e=mc^3" } }, new EquationUpdateBlock { Equation = new EquationUpdateBlock.Info { Expression = "e=mc^2" } }, new Action((block, _) => { @@ -166,7 +169,7 @@ private static IEnumerable BlockData() }, new object[] { - new DividerBlock { Divider = new DividerBlock.Data() }, new DividerUpdateBlock(), + new DividerBlockRequest { Divider = new DividerBlockRequest.Data() }, new DividerUpdateBlock(), new Action((block, client) => { Assert.NotNull(block); @@ -175,7 +178,7 @@ private static IEnumerable BlockData() }, new object[] { - new AudioBlock + new AudioBlockRequest { Audio = new ExternalFile { @@ -206,7 +209,7 @@ private static IEnumerable BlockData() }, new object[] { - new TableOfContentsBlock { TableOfContents = new TableOfContentsBlock.Data() }, + new TableOfContentsBlockRequest { TableOfContents = new TableOfContentsBlockRequest.Data() }, new TableOfContentsUpdateBlock(), new Action((block, client) => { Assert.NotNull(block); @@ -215,9 +218,9 @@ private static IEnumerable BlockData() }, new object[] { - new CalloutBlock + new CalloutBlockRequest { - Callout = new CalloutBlock.Info + Callout = new CalloutBlockRequest.Info { RichText = new List { @@ -245,9 +248,9 @@ private static IEnumerable BlockData() }, new object[] { - new QuoteBlock + new QuoteBlockRequest { - Quote = new QuoteBlock.Info + Quote = new QuoteBlockRequest.Info { RichText = new List { @@ -275,7 +278,7 @@ private static IEnumerable BlockData() }, new object[] { - new ImageBlock + new ImageBlockRequest { Image = new ExternalFile { @@ -308,9 +311,9 @@ private static IEnumerable BlockData() }, new object[] { - new EmbedBlock + new EmbedBlockRequest { - Embed = new EmbedBlock.Info + Embed = new EmbedBlockRequest.Info { Url = "https://zephoria.com/wp-content/uploads/2014/08/online-community.jpg" } @@ -333,7 +336,7 @@ private static IEnumerable BlockData() }, new object[] { - new LinkToPageBlock + new LinkToPageBlockRequest { LinkToPage = new PageParent { @@ -359,16 +362,16 @@ private static IEnumerable BlockData() }, new object[] { - new TableBlock + new TableBlockRequest { - Table = new TableBlock.Info + Table = new TableBlockRequest.Info { TableWidth = 1, Children = new[] { - new TableRowBlock + new TableRowBlockRequest { - TableRow = new TableRowBlock.Info + TableRow = new TableRowBlockRequest.Info { Cells = new[] { diff --git a/Test/Notion.UnitTests/BlocksClientTests.cs b/Test/Notion.UnitTests/BlocksClientTests.cs index 600e0bf4..6dd1656b 100644 --- a/Test/Notion.UnitTests/BlocksClientTests.cs +++ b/Test/Notion.UnitTests/BlocksClientTests.cs @@ -63,11 +63,11 @@ public async Task AppendBlockChildren() var request = new BlockAppendChildrenRequest { BlockId = blockId, - Children = new List + Children = new List { - new HeadingTwoBlock + new HeadingTwoBlockRequest { - Heading_2 = new HeadingTwoBlock.Info + Heading_2 = new HeadingTwoBlockRequest.Info { RichText = new List { @@ -75,9 +75,9 @@ public async Task AppendBlockChildren() } } }, - new ParagraphBlock + new ParagraphBlockRequest { - Paragraph = new ParagraphBlock.Info + Paragraph = new ParagraphBlockRequest.Info { RichText = new List { From 09ff9194a934ed2b24ffed7cbaac130cad9fae5d Mon Sep 17 00:00:00 2001 From: Gehongyan Date: Wed, 8 Nov 2023 18:00:03 +0800 Subject: [PATCH 175/216] Fix broken database relation request parameters. --- .../PropertySchema/RelationPropertySchema.cs | 17 ++--------------- .../RelationUpdatePropertySchema.cs | 17 ++--------------- 2 files changed, 4 insertions(+), 30 deletions(-) diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/RelationPropertySchema.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/RelationPropertySchema.cs index fa6a3249..4c278ac2 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/RelationPropertySchema.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/PropertySchema/RelationPropertySchema.cs @@ -1,23 +1,10 @@ -using System; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Notion.Client { public class RelationPropertySchema : IPropertySchema { [JsonProperty("relation")] - public RelationInfo Relation { get; set; } - - public class RelationInfo - { - [JsonProperty("database_id")] - public Guid DatabaseId { get; set; } - - [JsonProperty("synced_property_id")] - public string SyncedPropertyId { get; set; } - - [JsonProperty("synced_property_name")] - public string SyncedPropertyName { get; set; } - } + public RelationData Relation { get; set; } } } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/RelationUpdatePropertySchema.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/RelationUpdatePropertySchema.cs index 4f6a74a3..25f65cd4 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/RelationUpdatePropertySchema.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/PropertySchema/RelationUpdatePropertySchema.cs @@ -1,23 +1,10 @@ -using System; -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Notion.Client { public class RelationUpdatePropertySchema : UpdatePropertySchema { [JsonProperty("relation")] - public RelationInfo Relation { get; set; } - - public class RelationInfo - { - [JsonProperty("database_id")] - public Guid DatabaseId { get; set; } - - [JsonProperty("synced_property_id")] - public string SyncedPropertyId { get; set; } - - [JsonProperty("synced_property_name")] - public string SyncedPropertyName { get; set; } - } + public RelationData Relation { get; set; } } } From 59fd00540c0e0c1cdb619e6704bf04dbd86c4cd7 Mon Sep 17 00:00:00 2001 From: "boris.kuzmanov" Date: Sat, 27 Apr 2024 14:47:47 +0200 Subject: [PATCH 176/216] Change GetewayTimeout to GatewayTimeout (typo fix) --- Src/Notion.Client/NotionAPIErrorCode.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/Notion.Client/NotionAPIErrorCode.cs b/Src/Notion.Client/NotionAPIErrorCode.cs index e0264ae7..97984f98 100644 --- a/Src/Notion.Client/NotionAPIErrorCode.cs +++ b/Src/Notion.Client/NotionAPIErrorCode.cs @@ -49,6 +49,6 @@ public enum NotionAPIErrorCode DatabaseConnectionUnavailable, [EnumMember(Value = "gateway_timeout")] - GetewayTimeout + GatewayTimeout } } From b85a175fad43b4c65d1baa35d4af4030b0a5b4f6 Mon Sep 17 00:00:00 2001 From: "boris.kuzmanov" Date: Sun, 28 Apr 2024 13:37:54 +0200 Subject: [PATCH 177/216] Add name property to FileObject --- Src/Notion.Client/Models/File/FileObject.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Src/Notion.Client/Models/File/FileObject.cs b/Src/Notion.Client/Models/File/FileObject.cs index 9ed206de..2c219a1b 100644 --- a/Src/Notion.Client/Models/File/FileObject.cs +++ b/Src/Notion.Client/Models/File/FileObject.cs @@ -11,6 +11,9 @@ public abstract class FileObject : IPageIcon { [JsonProperty("caption")] public IEnumerable Caption { get; set; } + + [JsonProperty("name")] + public string Name { get; set; } [JsonProperty("type")] public virtual string Type { get; set; } From 09937b69db43e1b8e8abe2bd2023972297261fa8 Mon Sep 17 00:00:00 2001 From: "boris.kuzmanov" Date: Sun, 28 Apr 2024 14:24:30 +0200 Subject: [PATCH 178/216] Run lint --- Src/Notion.Client/Models/File/FileObject.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/Notion.Client/Models/File/FileObject.cs b/Src/Notion.Client/Models/File/FileObject.cs index 2c219a1b..aa7aed1b 100644 --- a/Src/Notion.Client/Models/File/FileObject.cs +++ b/Src/Notion.Client/Models/File/FileObject.cs @@ -11,7 +11,7 @@ public abstract class FileObject : IPageIcon { [JsonProperty("caption")] public IEnumerable Caption { get; set; } - + [JsonProperty("name")] public string Name { get; set; } From 08ed291c0d27ca02ce02f8a7d5b9d2c31032dad7 Mon Sep 17 00:00:00 2001 From: kosaku-hayashi Date: Sun, 14 Jul 2024 14:57:47 +0900 Subject: [PATCH 179/216] Removed 'archived' property and added 'in_trash' property. --- Src/Notion.Client/Api/Blocks/IBlocksClient.cs | 2 +- .../UpdateBlocks/BookmarkUpdateBlock.cs | 2 +- .../UpdateBlocks/BreadcrumbUpdateBlock.cs | 2 +- .../UpdateBlocks/DividerUpdateBlock.cs | 2 +- .../UpdateBlocks/IUpdateBlock.cs | 4 ++-- .../UpdateBlocks/TableOfContentsUpdateBlock.cs | 2 +- .../UpdateBlocks/UpdateBlock.cs | 2 +- .../DatabasesUpdateParameters.cs | 2 +- .../IDatabasesUpdateBodyParameters.cs | 4 ++-- .../IPagesUpdateBodyParameters.cs | 4 ++-- .../RequestParams/PagesUpdateParameters.cs | 4 ++-- Src/Notion.Client/Models/Blocks/Block.cs | 2 ++ Src/Notion.Client/Models/Blocks/IBlock.cs | 3 +++ Src/Notion.Client/Models/Database/Database.cs | 7 ++----- Src/Notion.Client/Models/Page/Page.cs | 6 +++--- .../BlocksClientTests.cs | 2 +- .../CommentsClientTests.cs | 2 +- .../DatabasesClientTests.cs | 2 +- .../Notion.IntegrationTests/PageClientTests.cs | 2 +- .../PageWithPageParentTests.cs | 2 +- Test/Notion.UnitTests/BlocksClientTests.cs | 1 + Test/Notion.UnitTests/Notion.UnitTests.csproj | 2 +- Test/Notion.UnitTests/PagesClientTests.cs | 14 +++++++------- Test/Notion.UnitTests/SearchClientTest.cs | 2 +- .../blocks/AppendBlockChildrenResponse.json | 1 + .../blocks/RetrieveBlockChildrenResponse.json | 18 +++++++++--------- .../data/blocks/RetrieveBlockResponse.json | 1 + .../data/blocks/UpdateBlockResponse.json | 1 + .../databases/DatabaseRetrieveResponse.json | 1 + .../data/databases/DatabasesQueryResponse.json | 2 +- ...yncDateFormulaValueReturnsNullResponse.json | 2 +- .../data/pages/CreatePageResponse.json | 2 +- ...ageObjectShouldHaveUrlPropertyResponse.json | 2 +- ...ageResponse.json => TrashPageResponse.json} | 2 +- .../pages/UpdatePagePropertiesResponse.json | 2 +- .../data/search/SearchResponse.json | 3 ++- 36 files changed, 61 insertions(+), 53 deletions(-) rename Test/Notion.UnitTests/data/pages/{ArchivePageResponse.json => TrashPageResponse.json} (97%) diff --git a/Src/Notion.Client/Api/Blocks/IBlocksClient.cs b/Src/Notion.Client/Api/Blocks/IBlocksClient.cs index fec1b9f5..c5a64e59 100644 --- a/Src/Notion.Client/Api/Blocks/IBlocksClient.cs +++ b/Src/Notion.Client/Api/Blocks/IBlocksClient.cs @@ -47,7 +47,7 @@ Task AppendChildrenAsync( ); /// - /// Sets a Block object, including page blocks, to archived: true using the ID specified. + /// Moves a Block object, including page blocks, to the trash: true using the ID specified. /// /// Identifier for a Notion block Task DeleteAsync(string blockId, CancellationToken cancellationToken = default); diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BookmarkUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BookmarkUpdateBlock.cs index 612b6dda..b147c587 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BookmarkUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BookmarkUpdateBlock.cs @@ -8,7 +8,7 @@ public class BookmarkUpdateBlock : IUpdateBlock [JsonProperty("bookmark")] public Info Bookmark { get; set; } - public bool Archived { get; set; } + public bool InTrash { get; set; } public class Info { diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BreadcrumbUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BreadcrumbUpdateBlock.cs index a90f6966..260eca82 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BreadcrumbUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BreadcrumbUpdateBlock.cs @@ -12,7 +12,7 @@ public BreadcrumbUpdateBlock() [JsonProperty("breadcrumb")] public Info Breadcrumb { get; set; } - public bool Archived { get; set; } + public bool InTrash { get; set; } public class Info { diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/DividerUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/DividerUpdateBlock.cs index 79f332f0..62b83451 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/DividerUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/DividerUpdateBlock.cs @@ -12,7 +12,7 @@ public DividerUpdateBlock() [JsonProperty("divider")] public Info Divider { get; set; } - public bool Archived { get; set; } + public bool InTrash { get; set; } public class Info { diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/IUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/IUpdateBlock.cs index ba93fe29..5b1de4be 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/IUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/IUpdateBlock.cs @@ -4,7 +4,7 @@ namespace Notion.Client { public interface IUpdateBlock { - [JsonProperty("archived")] - bool Archived { get; set; } + [JsonProperty("in_trash")] + bool InTrash { get; set; } } } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableOfContentsUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableOfContentsUpdateBlock.cs index bef1f278..2e4adff9 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableOfContentsUpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/TableOfContentsUpdateBlock.cs @@ -12,7 +12,7 @@ public TableOfContentsUpdateBlock() [JsonProperty("table_of_contents")] public Info TableOfContents { get; set; } - public bool Archived { get; set; } + public bool InTrash { get; set; } public class Info { diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/UpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/UpdateBlock.cs index d0321e52..14704cb2 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/UpdateBlock.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/UpdateBlock.cs @@ -2,6 +2,6 @@ { public abstract class UpdateBlock : IUpdateBlock { - public bool Archived { get; set; } + public bool InTrash { get; set; } } } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs index 41da2d17..5147a6b0 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/DatabasesUpdateParameters.cs @@ -12,7 +12,7 @@ public class DatabasesUpdateParameters : IDatabasesUpdateBodyParameters public FileObject Cover { get; set; } - public bool Archived { get; set; } + public bool InTrash { get; set; } public bool? IsInline { get; set; } diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/IDatabasesUpdateBodyParameters.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/IDatabasesUpdateBodyParameters.cs index b1dc419a..f37df431 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/IDatabasesUpdateBodyParameters.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesUpdateParameters/IDatabasesUpdateBodyParameters.cs @@ -17,8 +17,8 @@ public interface IDatabasesUpdateBodyParameters [JsonProperty("cover")] FileObject Cover { get; set; } - [JsonProperty("archived")] - bool Archived { get; set; } + [JsonProperty("in_trash")] + bool InTrash { get; set; } [JsonProperty("is_inline")] bool? IsInline { get; set; } diff --git a/Src/Notion.Client/Api/Pages/RequestParams/IPagesUpdateBodyParameters.cs b/Src/Notion.Client/Api/Pages/RequestParams/IPagesUpdateBodyParameters.cs index b37dd1fd..b7ea1ea6 100644 --- a/Src/Notion.Client/Api/Pages/RequestParams/IPagesUpdateBodyParameters.cs +++ b/Src/Notion.Client/Api/Pages/RequestParams/IPagesUpdateBodyParameters.cs @@ -5,8 +5,8 @@ namespace Notion.Client { public interface IPagesUpdateBodyParameters { - [JsonProperty("archived")] - bool Archived { get; set; } + [JsonProperty("in_trash")] + bool InTrash { get; set; } [JsonProperty("properties")] IDictionary Properties { get; set; } diff --git a/Src/Notion.Client/Api/Pages/RequestParams/PagesUpdateParameters.cs b/Src/Notion.Client/Api/Pages/RequestParams/PagesUpdateParameters.cs index 742ef8dd..6845f27b 100644 --- a/Src/Notion.Client/Api/Pages/RequestParams/PagesUpdateParameters.cs +++ b/Src/Notion.Client/Api/Pages/RequestParams/PagesUpdateParameters.cs @@ -11,8 +11,8 @@ public class PagesUpdateParameters : IPagesUpdateBodyParameters [JsonProperty("cover")] public FileObject Cover { get; set; } - [JsonProperty("archived")] - public bool Archived { get; set; } + [JsonProperty("in_trash")] + public bool InTrash { get; set; } [JsonProperty("properties")] public IDictionary Properties { get; set; } diff --git a/Src/Notion.Client/Models/Blocks/Block.cs b/Src/Notion.Client/Models/Blocks/Block.cs index 883399df..fa1ef612 100644 --- a/Src/Notion.Client/Models/Blocks/Block.cs +++ b/Src/Notion.Client/Models/Blocks/Block.cs @@ -16,6 +16,8 @@ public abstract class Block : IBlock public virtual bool HasChildren { get; set; } + public bool InTrash { get; set; } + public PartialUser CreatedBy { get; set; } public PartialUser LastEditedBy { get; set; } diff --git a/Src/Notion.Client/Models/Blocks/IBlock.cs b/Src/Notion.Client/Models/Blocks/IBlock.cs index 24d6a12a..b06a3646 100644 --- a/Src/Notion.Client/Models/Blocks/IBlock.cs +++ b/Src/Notion.Client/Models/Blocks/IBlock.cs @@ -47,6 +47,9 @@ public interface IBlock : IObject, IObjectModificationData [JsonProperty("has_children")] bool HasChildren { get; set; } + [JsonProperty("in_trash")] + bool InTrash { get; set; } + [JsonProperty("parent")] IBlockParent Parent { get; set; } } diff --git a/Src/Notion.Client/Models/Database/Database.cs b/Src/Notion.Client/Models/Database/Database.cs index c5a46ed6..be288ea0 100644 --- a/Src/Notion.Client/Models/Database/Database.cs +++ b/Src/Notion.Client/Models/Database/Database.cs @@ -27,11 +27,8 @@ public class Database : IObject, IObjectModificationData, IWikiDatabase [JsonProperty("url")] public string Url { get; set; } - /// - /// The archived status of the database. - /// - [JsonProperty("archived")] - public bool Archived { get; set; } + [JsonProperty("in_trash")] + public bool InTrash { get; set; } [JsonProperty("is_inline")] public bool IsInline { get; set; } diff --git a/Src/Notion.Client/Models/Page/Page.cs b/Src/Notion.Client/Models/Page/Page.cs index c6bcfae1..fe4eb0de 100644 --- a/Src/Notion.Client/Models/Page/Page.cs +++ b/Src/Notion.Client/Models/Page/Page.cs @@ -13,10 +13,10 @@ public class Page : IObject, IObjectModificationData, IWikiDatabase public IPageParent Parent { get; set; } /// - /// The archived status of the page. + /// Indicates whether the page is currently in the trash. /// - [JsonProperty("archived")] - public bool IsArchived { get; set; } + [JsonProperty("in_trash")] + public bool InTrash { get; set; } /// /// Property values of this page. diff --git a/Test/Notion.IntegrationTests/BlocksClientTests.cs b/Test/Notion.IntegrationTests/BlocksClientTests.cs index 284ac009..5c8e4618 100644 --- a/Test/Notion.IntegrationTests/BlocksClientTests.cs +++ b/Test/Notion.IntegrationTests/BlocksClientTests.cs @@ -23,7 +23,7 @@ public async Task InitializeAsync() public async Task DisposeAsync() { - await Client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters { Archived = true }); + await Client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters { InTrash = true }); } [Fact] diff --git a/Test/Notion.IntegrationTests/CommentsClientTests.cs b/Test/Notion.IntegrationTests/CommentsClientTests.cs index 1655fc71..fac1fce1 100644 --- a/Test/Notion.IntegrationTests/CommentsClientTests.cs +++ b/Test/Notion.IntegrationTests/CommentsClientTests.cs @@ -21,7 +21,7 @@ public async Task InitializeAsync() public async Task DisposeAsync() { - await Client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters { Archived = true }); + await Client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters { InTrash = true }); } [Fact] diff --git a/Test/Notion.IntegrationTests/DatabasesClientTests.cs b/Test/Notion.IntegrationTests/DatabasesClientTests.cs index c5c7082b..31b611f1 100644 --- a/Test/Notion.IntegrationTests/DatabasesClientTests.cs +++ b/Test/Notion.IntegrationTests/DatabasesClientTests.cs @@ -22,7 +22,7 @@ public async Task InitializeAsync() public async Task DisposeAsync() { - await Client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters { Archived = true }); + await Client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters { InTrash = true }); } [Fact] diff --git a/Test/Notion.IntegrationTests/PageClientTests.cs b/Test/Notion.IntegrationTests/PageClientTests.cs index 2e4153eb..21adbd5b 100644 --- a/Test/Notion.IntegrationTests/PageClientTests.cs +++ b/Test/Notion.IntegrationTests/PageClientTests.cs @@ -63,7 +63,7 @@ public async Task InitializeAsync() public async Task DisposeAsync() { - await Client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters { Archived = true }); + await Client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters { InTrash = true }); } [Fact] diff --git a/Test/Notion.IntegrationTests/PageWithPageParentTests.cs b/Test/Notion.IntegrationTests/PageWithPageParentTests.cs index 5f398dc7..3c6d3c6c 100644 --- a/Test/Notion.IntegrationTests/PageWithPageParentTests.cs +++ b/Test/Notion.IntegrationTests/PageWithPageParentTests.cs @@ -29,7 +29,7 @@ public async Task InitializeAsync() public async Task DisposeAsync() { - await Client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters { Archived = true }); + await Client.Pages.UpdateAsync(_page.Id, new PagesUpdateParameters { InTrash = true }); } [Fact] diff --git a/Test/Notion.UnitTests/BlocksClientTests.cs b/Test/Notion.UnitTests/BlocksClientTests.cs index 6dd1656b..e2cc8603 100644 --- a/Test/Notion.UnitTests/BlocksClientTests.cs +++ b/Test/Notion.UnitTests/BlocksClientTests.cs @@ -184,6 +184,7 @@ public async Task UpdateAsync() block.Id.Should().Be(blockId); block.HasChildren.Should().BeFalse(); + block.InTrash.Should().BeFalse(); block.Type.Should().Be(BlockType.ToDo); var todoBlock = (ToDoBlock)block; diff --git a/Test/Notion.UnitTests/Notion.UnitTests.csproj b/Test/Notion.UnitTests/Notion.UnitTests.csproj index 30ff0791..588ddc54 100644 --- a/Test/Notion.UnitTests/Notion.UnitTests.csproj +++ b/Test/Notion.UnitTests/Notion.UnitTests.csproj @@ -51,7 +51,7 @@ Always - + Always diff --git a/Test/Notion.UnitTests/PagesClientTests.cs b/Test/Notion.UnitTests/PagesClientTests.cs index adbb9443..9541f62e 100644 --- a/Test/Notion.UnitTests/PagesClientTests.cs +++ b/Test/Notion.UnitTests/PagesClientTests.cs @@ -39,7 +39,7 @@ public async Task RetrieveAsync() page.Id.Should().Be(pageId); page.Parent.Type.Should().Be(ParentType.DatabaseId); ((DatabaseParent)page.Parent).DatabaseId.Should().Be("48f8fee9-cd79-4180-bc2f-ec0398253067"); - page.IsArchived.Should().BeFalse(); + page.InTrash.Should().BeFalse(); } [Fact] @@ -72,7 +72,7 @@ public async Task CreateAsync() page.Url.Should().NotBeNullOrEmpty(); page.Properties.Should().HaveCount(1); page.Properties.First().Key.Should().Be("Name"); - page.IsArchived.Should().BeFalse(); + page.InTrash.Should().BeFalse(); page.Parent.Should().NotBeNull(); ((DatabaseParent)page.Parent).DatabaseId.Should().Be("3c357473-a281-49a4-88c0-10d2b245a589"); } @@ -172,7 +172,7 @@ public async Task UpdatePageAsync() var page = await _client.UpdateAsync(pageId, pagesUpdateParameters); page.Id.Should().Be(pageId); - page.IsArchived.Should().BeFalse(); + page.InTrash.Should().BeFalse(); page.Properties.Should().HaveCount(2); var updatedProperty = page.Properties.First(x => x.Key == "In stock"); @@ -187,14 +187,14 @@ public async Task UpdatePageAsync() } [Fact] - public async Task ArchivePageAsync() + public async Task TrashPageAsync() { var pageId = "251d2b5f-268c-4de2-afe9-c71ff92ca95c"; var propertyId = "{>U;"; var path = ApiEndpoints.PagesApiUrls.UpdateProperties(pageId); - var jsonData = await File.ReadAllTextAsync("data/pages/ArchivePageResponse.json"); + var jsonData = await File.ReadAllTextAsync("data/pages/TrashPageResponse.json"); Server.Given(CreatePatchRequestBuilder(path)) .RespondWith( @@ -211,7 +211,7 @@ public async Task ArchivePageAsync() var pagesUpdateParameters = new PagesUpdateParameters { - Archived = true, + InTrash = true, Properties = new Dictionary { { "In stock", new CheckboxPropertyValue { Checkbox = true } } @@ -221,7 +221,7 @@ public async Task ArchivePageAsync() var page = await _client.UpdateAsync(pageId, pagesUpdateParameters); page.Id.Should().Be(pageId); - page.IsArchived.Should().BeTrue(); + page.InTrash.Should().BeTrue(); page.Properties.Should().HaveCount(2); var updatedProperty = page.Properties.First(x => x.Key == "In stock"); diff --git a/Test/Notion.UnitTests/SearchClientTest.cs b/Test/Notion.UnitTests/SearchClientTest.cs index 35765cef..a5a477cb 100644 --- a/Test/Notion.UnitTests/SearchClientTest.cs +++ b/Test/Notion.UnitTests/SearchClientTest.cs @@ -59,7 +59,7 @@ public async Task Search() obj.Object.Should().Be(ObjectType.Page); var page = (Page)obj; - page.IsArchived.Should().BeFalse(); + page.InTrash.Should().BeFalse(); page.Properties.Should().HaveCount(1); page.Parent.Should().BeAssignableTo(); ((DatabaseParent)page.Parent).DatabaseId.Should().Be("e6c6f8ff-c70e-4970-91ba-98f03e0d7fc6"); diff --git a/Test/Notion.UnitTests/data/blocks/AppendBlockChildrenResponse.json b/Test/Notion.UnitTests/data/blocks/AppendBlockChildrenResponse.json index 32612405..13966312 100644 --- a/Test/Notion.UnitTests/data/blocks/AppendBlockChildrenResponse.json +++ b/Test/Notion.UnitTests/data/blocks/AppendBlockChildrenResponse.json @@ -7,6 +7,7 @@ "created_time": "2021-03-16T16:31:00.000Z", "last_edited_time": "2021-03-16T16:32:00.000Z", "has_children": false, + "in_trash" : false, "type": "heading_2", "heading_2": { "rich_text": [ diff --git a/Test/Notion.UnitTests/data/blocks/RetrieveBlockChildrenResponse.json b/Test/Notion.UnitTests/data/blocks/RetrieveBlockChildrenResponse.json index 7b0ae104..b16dfc35 100644 --- a/Test/Notion.UnitTests/data/blocks/RetrieveBlockChildrenResponse.json +++ b/Test/Notion.UnitTests/data/blocks/RetrieveBlockChildrenResponse.json @@ -7,7 +7,7 @@ "created_time": "2021-05-29T16:22:00.000Z", "last_edited_time": "2021-05-29T16:22:00.000Z", "has_children": false, - "archived": false, + "in_trash": false, "type": "paragraph", "paragraph": { "rich_text": [] @@ -19,7 +19,7 @@ "created_time": "2021-05-30T09:25:00.000Z", "last_edited_time": "2021-05-30T09:25:00.000Z", "has_children": false, - "archived": false, + "in_trash": false, "type": "heading_2", "heading_2": { "rich_text": [ @@ -49,7 +49,7 @@ "created_time": "2021-05-30T09:36:00.000Z", "last_edited_time": "2021-05-30T09:36:00.000Z", "has_children": false, - "archived": false, + "in_trash": false, "type": "heading_2", "heading_2": { "rich_text": [ @@ -79,7 +79,7 @@ "created_time": "2021-08-18T21:12:00.000Z", "last_edited_time": "2021-08-18T21:12:00.000Z", "has_children": false, - "archived": false, + "in_trash": false, "type": "paragraph", "paragraph": { "rich_text": [] @@ -91,7 +91,7 @@ "created_time": "2021-08-18T23:00:00.000Z", "last_edited_time": "2021-08-18T23:00:00.000Z", "has_children": false, - "archived": false, + "in_trash": false, "type": "child_page", "child_page": { "title": "" @@ -103,7 +103,7 @@ "created_time": "2021-08-18T23:00:00.000Z", "last_edited_time": "2021-08-18T23:00:00.000Z", "has_children": false, - "archived": false, + "in_trash": false, "type": "child_page", "child_page": { "title": "" @@ -115,7 +115,7 @@ "created_time": "2021-09-09T05:22:00.000Z", "last_edited_time": "2021-09-09T05:22:00.000Z", "has_children": false, - "archived": false, + "in_trash": false, "type": "paragraph", "paragraph": { "rich_text": [] @@ -127,7 +127,7 @@ "created_time": "2022-05-03T13:28:00.000Z", "last_edited_time": "2022-05-03T13:29:00.000Z", "has_children": false, - "archived": false, + "in_trash": false, "type": "image", "image": { "caption": [ @@ -174,7 +174,7 @@ "id": "92e803ec-193c-4bcd-b28e-88365858d562" }, "has_children": true, - "archived": false, + "in_trash": false, "type": "synced_block", "synced_block": { "synced_from": { diff --git a/Test/Notion.UnitTests/data/blocks/RetrieveBlockResponse.json b/Test/Notion.UnitTests/data/blocks/RetrieveBlockResponse.json index 9c7deabe..6df6ddb2 100644 --- a/Test/Notion.UnitTests/data/blocks/RetrieveBlockResponse.json +++ b/Test/Notion.UnitTests/data/blocks/RetrieveBlockResponse.json @@ -4,6 +4,7 @@ "created_time": "2021-03-16T16:31:00.000Z", "last_edited_time": "2021-03-16T16:32:00.000Z", "has_children": false, + "in_trash" : false, "type": "to_do", "to_do": { "rich_text": [ diff --git a/Test/Notion.UnitTests/data/blocks/UpdateBlockResponse.json b/Test/Notion.UnitTests/data/blocks/UpdateBlockResponse.json index 497aba34..c2d3a2c4 100644 --- a/Test/Notion.UnitTests/data/blocks/UpdateBlockResponse.json +++ b/Test/Notion.UnitTests/data/blocks/UpdateBlockResponse.json @@ -4,6 +4,7 @@ "created_time": "2021-03-16T16:31:00.000Z", "last_edited_time": "2021-03-16T16:32:00.000Z", "has_children": false, + "in_trash" : false, "type": "to_do", "to_do": { "rich_text": [ diff --git a/Test/Notion.UnitTests/data/databases/DatabaseRetrieveResponse.json b/Test/Notion.UnitTests/data/databases/DatabaseRetrieveResponse.json index 9b5cf45f..5849bb88 100644 --- a/Test/Notion.UnitTests/data/databases/DatabaseRetrieveResponse.json +++ b/Test/Notion.UnitTests/data/databases/DatabaseRetrieveResponse.json @@ -33,6 +33,7 @@ } }, "url": "https://www.notion.so/668d797c76fa49349b05ad288df2d136", + "in_trash" : false, "properties": { "Tags": { "id": "YG~h", diff --git a/Test/Notion.UnitTests/data/databases/DatabasesQueryResponse.json b/Test/Notion.UnitTests/data/databases/DatabasesQueryResponse.json index 27e70234..cf1b1f01 100644 --- a/Test/Notion.UnitTests/data/databases/DatabasesQueryResponse.json +++ b/Test/Notion.UnitTests/data/databases/DatabasesQueryResponse.json @@ -10,7 +10,7 @@ "type": "database_id", "database_id": "897e5a76-ae52-4b48-9fdf-e71f5945d1af" }, - "archived": false, + "in_trash": false, "url": "https://www.notion.so/2e01e904febd43a0ad028eedb903a82c", "properties": { "Recipes": { diff --git a/Test/Notion.UnitTests/data/databases/Fix123QueryAsyncDateFormulaValueReturnsNullResponse.json b/Test/Notion.UnitTests/data/databases/Fix123QueryAsyncDateFormulaValueReturnsNullResponse.json index 8c1b95c0..00159d76 100644 --- a/Test/Notion.UnitTests/data/databases/Fix123QueryAsyncDateFormulaValueReturnsNullResponse.json +++ b/Test/Notion.UnitTests/data/databases/Fix123QueryAsyncDateFormulaValueReturnsNullResponse.json @@ -12,7 +12,7 @@ "type": "database_id", "database_id": "f86f2262-0751-40f2-8f63-e3f7a3c39fcb" }, - "archived": false, + "in_trash": false, "properties": { "Column": { "id": "B[\\E", diff --git a/Test/Notion.UnitTests/data/pages/CreatePageResponse.json b/Test/Notion.UnitTests/data/pages/CreatePageResponse.json index 89f0e58e..a801949b 100644 --- a/Test/Notion.UnitTests/data/pages/CreatePageResponse.json +++ b/Test/Notion.UnitTests/data/pages/CreatePageResponse.json @@ -3,7 +3,7 @@ "id": "251d2b5f-268c-4de2-afe9-c71ff92ca95c", "created_time": "2020-03-17T19:10:04.968Z", "last_edited_time": "2020-03-17T21:49:37.913Z", - "archived": false, + "in_trash": false, "url": "https://www.notion.so/Test-251d2b5f268c4de2afe9c71ff92ca95c", "properties": { "Name": { diff --git a/Test/Notion.UnitTests/data/pages/PageObjectShouldHaveUrlPropertyResponse.json b/Test/Notion.UnitTests/data/pages/PageObjectShouldHaveUrlPropertyResponse.json index 8f9d45ab..bf5ba373 100644 --- a/Test/Notion.UnitTests/data/pages/PageObjectShouldHaveUrlPropertyResponse.json +++ b/Test/Notion.UnitTests/data/pages/PageObjectShouldHaveUrlPropertyResponse.json @@ -7,7 +7,7 @@ "type": "database_id", "database_id": "48f8fee9-cd79-4180-bc2f-ec0398253067" }, - "archived": false, + "in_trash": false, "url": "https://www.notion.so/Avocado-251d2b5f268c4de2afe9c71ff92ca95c", "properties": { "Name": { diff --git a/Test/Notion.UnitTests/data/pages/ArchivePageResponse.json b/Test/Notion.UnitTests/data/pages/TrashPageResponse.json similarity index 97% rename from Test/Notion.UnitTests/data/pages/ArchivePageResponse.json rename to Test/Notion.UnitTests/data/pages/TrashPageResponse.json index 2f9af7c6..0c61a3c9 100644 --- a/Test/Notion.UnitTests/data/pages/ArchivePageResponse.json +++ b/Test/Notion.UnitTests/data/pages/TrashPageResponse.json @@ -3,7 +3,7 @@ "id": "251d2b5f-268c-4de2-afe9-c71ff92ca95c", "created_time": "2020-03-17T19:10:04.968Z", "last_edited_time": "2020-03-17T21:49:37.913Z", - "archived": true, + "in_trash": true, "url": "https://www.notion.so/Test-251d2b5f268c4de2afe9c71ff92ca95c", "properties": { "In stock": { diff --git a/Test/Notion.UnitTests/data/pages/UpdatePagePropertiesResponse.json b/Test/Notion.UnitTests/data/pages/UpdatePagePropertiesResponse.json index 12076368..70cc2164 100644 --- a/Test/Notion.UnitTests/data/pages/UpdatePagePropertiesResponse.json +++ b/Test/Notion.UnitTests/data/pages/UpdatePagePropertiesResponse.json @@ -3,7 +3,7 @@ "id": "251d2b5f-268c-4de2-afe9-c71ff92ca95c", "created_time": "2020-03-17T19:10:04.968Z", "last_edited_time": "2020-03-17T21:49:37.913Z", - "archived": false, + "in_trash": false, "url": "https://www.notion.so/Test-251d2b5f268c4de2afe9c71ff92ca95c", "properties": { "In stock": { diff --git a/Test/Notion.UnitTests/data/search/SearchResponse.json b/Test/Notion.UnitTests/data/search/SearchResponse.json index 107adcb3..53defa57 100644 --- a/Test/Notion.UnitTests/data/search/SearchResponse.json +++ b/Test/Notion.UnitTests/data/search/SearchResponse.json @@ -4,6 +4,7 @@ "object": "list", "results": [ { + "in_trash": false, "created_time": "2021-04-22T22:23:26.080Z", "id": "e6c6f8ff-c70e-4970-91ba-98f03e0d7fc6", "last_edited_time": "2021-04-23T04:21:00.000Z", @@ -43,7 +44,7 @@ ] }, { - "archived": false, + "in_trash": false, "created_time": "2021-04-23T04:21:00.000Z", "id": "4f555b50-3a9b-49cb-924c-3746f4ca5522", "last_edited_time": "2021-04-23T04:21:00.000Z", From 609e04dc8b9ef3969d3c214af95e5ddaf18e8b13 Mon Sep 17 00:00:00 2001 From: kosaku-hayashi Date: Sun, 14 Jul 2024 17:01:31 +0900 Subject: [PATCH 180/216] Added support for button properties. --- .../Database/Properties/ButtonProperty.cs | 16 ++++++++++++++++ .../Models/Database/Properties/Property.cs | 1 + .../Models/Database/Properties/PropertyType.cs | 3 +++ .../Models/PropertyValue/ButtonPropertyValue.cs | 17 +++++++++++++++++ .../Models/PropertyValue/PropertyValue.cs | 1 + .../Models/PropertyValue/PropertyValueType.cs | 3 +++ Test/Notion.UnitTests/PagesClientTests.cs | 2 +- Test/Notion.UnitTests/PropertyTests.cs | 2 ++ .../databases/DatabaseRetrieveResponse.json | 6 ++++++ .../data/databases/DatabasesListResponse.json | 6 ++++++ .../data/databases/DatabasesQueryResponse.json | 5 +++++ .../data/pages/TrashPageResponse.json | 5 +++++ 12 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 Src/Notion.Client/Models/Database/Properties/ButtonProperty.cs create mode 100644 Src/Notion.Client/Models/PropertyValue/ButtonPropertyValue.cs diff --git a/Src/Notion.Client/Models/Database/Properties/ButtonProperty.cs b/Src/Notion.Client/Models/Database/Properties/ButtonProperty.cs new file mode 100644 index 00000000..983138e2 --- /dev/null +++ b/Src/Notion.Client/Models/Database/Properties/ButtonProperty.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; +using System.Threading.Tasks; + +namespace Notion.Client +{ + public class ButtonProperty : Property + { + public override PropertyType Type => PropertyType.Button; + + [JsonProperty("button")] + public Dictionary Button { get; set; } + } +} diff --git a/Src/Notion.Client/Models/Database/Properties/Property.cs b/Src/Notion.Client/Models/Database/Properties/Property.cs index fa0dac50..6392bbaf 100644 --- a/Src/Notion.Client/Models/Database/Properties/Property.cs +++ b/Src/Notion.Client/Models/Database/Properties/Property.cs @@ -26,6 +26,7 @@ namespace Notion.Client [JsonSubtypes.KnownSubTypeAttribute(typeof(TitleProperty), PropertyType.Title)] [JsonSubtypes.KnownSubTypeAttribute(typeof(UrlProperty), PropertyType.Url)] [JsonSubtypes.KnownSubTypeAttribute(typeof(UniqueIdProperty), PropertyType.UniqueId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ButtonProperty), PropertyType.Button)] public class Property { [JsonProperty("id")] diff --git a/Src/Notion.Client/Models/Database/Properties/PropertyType.cs b/Src/Notion.Client/Models/Database/Properties/PropertyType.cs index 6391308c..206f9fe2 100644 --- a/Src/Notion.Client/Models/Database/Properties/PropertyType.cs +++ b/Src/Notion.Client/Models/Database/Properties/PropertyType.cs @@ -71,5 +71,8 @@ public enum PropertyType [EnumMember(Value = "unique_id")] UniqueId, + + [EnumMember(Value = "button")] + Button, } } diff --git a/Src/Notion.Client/Models/PropertyValue/ButtonPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/ButtonPropertyValue.cs new file mode 100644 index 00000000..61ae9fc4 --- /dev/null +++ b/Src/Notion.Client/Models/PropertyValue/ButtonPropertyValue.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class ButtonPropertyValue : PropertyValue + { + public override PropertyValueType Type => PropertyValueType.Button; + + [JsonProperty("button")] + public ButtonValue Button { get; set; } + + public class ButtonValue { } + } +} diff --git a/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs index a74b11da..e1289046 100644 --- a/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/PropertyValue.cs @@ -30,6 +30,7 @@ namespace Notion.Client [JsonSubtypes.KnownSubTypeAttribute(typeof(TitlePropertyValue), PropertyValueType.Title)] [JsonSubtypes.KnownSubTypeAttribute(typeof(UrlPropertyValue), PropertyValueType.Url)] [JsonSubtypes.KnownSubTypeAttribute(typeof(UniqueIdPropertyValue), PropertyValueType.UniqueId)] + [JsonSubtypes.KnownSubTypeAttribute(typeof(ButtonPropertyValue), PropertyValueType.Button)] [JsonSubtypes.KnownSubTypeAttribute(typeof(VerificationPropertyValue), PropertyValueType.Verification)] [SuppressMessage("ReSharper", "UnusedMember.Global")] [SuppressMessage("ReSharper", "UnassignedGetOnlyAutoProperty")] diff --git a/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs b/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs index d77a564c..574138e9 100644 --- a/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs +++ b/Src/Notion.Client/Models/PropertyValue/PropertyValueType.cs @@ -77,5 +77,8 @@ public enum PropertyValueType [EnumMember(Value = "verification")] Verification, + + [EnumMember(Value = "button")] + Button, } } diff --git a/Test/Notion.UnitTests/PagesClientTests.cs b/Test/Notion.UnitTests/PagesClientTests.cs index 9541f62e..4dc75380 100644 --- a/Test/Notion.UnitTests/PagesClientTests.cs +++ b/Test/Notion.UnitTests/PagesClientTests.cs @@ -222,7 +222,7 @@ public async Task TrashPageAsync() page.Id.Should().Be(pageId); page.InTrash.Should().BeTrue(); - page.Properties.Should().HaveCount(2); + page.Properties.Should().HaveCount(3); var updatedProperty = page.Properties.First(x => x.Key == "In stock"); var checkboxPropertyValue = (CheckboxPropertyItem)await _client.RetrievePagePropertyItemAsync( diff --git a/Test/Notion.UnitTests/PropertyTests.cs b/Test/Notion.UnitTests/PropertyTests.cs index fc748413..55f6d1c1 100644 --- a/Test/Notion.UnitTests/PropertyTests.cs +++ b/Test/Notion.UnitTests/PropertyTests.cs @@ -27,6 +27,7 @@ public class PropertyTests [InlineData(typeof(TitleProperty), PropertyType.Title)] [InlineData(typeof(UrlProperty), PropertyType.Url)] [InlineData(typeof(UniqueIdProperty), PropertyType.UniqueId)] + [InlineData(typeof(ButtonProperty),PropertyType.Button)] public void TestPropertyType(Type type, PropertyType expectedPropertyType) { var typeInstance = (Property)Activator.CreateInstance(type); @@ -56,6 +57,7 @@ public void TestPropertyType(Type type, PropertyType expectedPropertyType) [InlineData(typeof(TitleProperty), "title")] [InlineData(typeof(UrlProperty), "url")] [InlineData(typeof(UniqueIdProperty), "unique_id")] + [InlineData(typeof(ButtonProperty), "button")] public void TestPropertyTypeText(Type type, string expectedPropertyType) { var typeInstance = (Property)Activator.CreateInstance(type); diff --git a/Test/Notion.UnitTests/data/databases/DatabaseRetrieveResponse.json b/Test/Notion.UnitTests/data/databases/DatabaseRetrieveResponse.json index 5849bb88..9e1acfb0 100644 --- a/Test/Notion.UnitTests/data/databases/DatabaseRetrieveResponse.json +++ b/Test/Notion.UnitTests/data/databases/DatabaseRetrieveResponse.json @@ -90,6 +90,12 @@ } } }, + "SimpleButton": { + "id":"_ri%7C", + "name":"SimpleButton", + "type":"button", + "button": {} + }, "Name": { "id": "title", "name": "Name", diff --git a/Test/Notion.UnitTests/data/databases/DatabasesListResponse.json b/Test/Notion.UnitTests/data/databases/DatabasesListResponse.json index 713c0736..ad0e5497 100644 --- a/Test/Notion.UnitTests/data/databases/DatabasesListResponse.json +++ b/Test/Notion.UnitTests/data/databases/DatabasesListResponse.json @@ -81,6 +81,12 @@ } } }, + "SimpleButton": { + "id":"_ri%7C", + "name":"SimpleButton", + "type":"button", + "button": {} + }, "Name": { "id": "title", "name": "Name", diff --git a/Test/Notion.UnitTests/data/databases/DatabasesQueryResponse.json b/Test/Notion.UnitTests/data/databases/DatabasesQueryResponse.json index cf1b1f01..d291a5b2 100644 --- a/Test/Notion.UnitTests/data/databases/DatabasesQueryResponse.json +++ b/Test/Notion.UnitTests/data/databases/DatabasesQueryResponse.json @@ -45,6 +45,11 @@ "id": "{>U;", "type": "checkbox", "checkbox": false + }, + "Add Page Button": { + "id":"_ri%7C", + "type":"button", + "button": {} } } } diff --git a/Test/Notion.UnitTests/data/pages/TrashPageResponse.json b/Test/Notion.UnitTests/data/pages/TrashPageResponse.json index 0c61a3c9..add1f546 100644 --- a/Test/Notion.UnitTests/data/pages/TrashPageResponse.json +++ b/Test/Notion.UnitTests/data/pages/TrashPageResponse.json @@ -11,6 +11,11 @@ "type": "checkbox", "checkbox": true }, + "Add Page Button": { + "id":"_ri%7C", + "type":"button", + "button": {} + }, "Name": { "id": "title", "type": "title", From 0459c906c0c4f92fec3da8da930cdc74f9c81f44 Mon Sep 17 00:00:00 2001 From: kosaku-hayashi Date: Tue, 16 Jul 2024 14:28:46 +0900 Subject: [PATCH 181/216] Support "bad_gateway" error code --- Src/Notion.Client/NotionAPIErrorCode.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Src/Notion.Client/NotionAPIErrorCode.cs b/Src/Notion.Client/NotionAPIErrorCode.cs index e0264ae7..260c25b5 100644 --- a/Src/Notion.Client/NotionAPIErrorCode.cs +++ b/Src/Notion.Client/NotionAPIErrorCode.cs @@ -42,6 +42,9 @@ public enum NotionAPIErrorCode [EnumMember(Value = "internal_server_error")] InternalServerError, + [EnumMember(Value = "bad_gateway")] + BadGateway, + [EnumMember(Value = "service_unavailable")] ServiceUnavailable, From 54f5fd32330b903afff7cc65eeecd51832e060e6 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Wed, 30 Oct 2024 12:28:05 +0530 Subject: [PATCH 182/216] Use DateTimeOffset instead of DateTime for DatePropertyValue --- .../Models/PropertyValue/DatePropertyValue.cs | 7 ++- .../PageClientTests.cs | 61 ++++++++++++++++++- 2 files changed, 63 insertions(+), 5 deletions(-) diff --git a/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs index 22715b2e..7467936b 100644 --- a/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs @@ -1,5 +1,6 @@ using System; using Newtonsoft.Json; +using Newtonsoft.Json.Converters; namespace Notion.Client { @@ -26,13 +27,15 @@ public class Date /// Start date with optional time. /// [JsonProperty("start")] - public DateTime? Start { get; set; } + [JsonConverter(typeof(IsoDateTimeConverter))] + public DateTimeOffset? Start { get; set; } /// /// End date with optional time. /// [JsonProperty("end")] - public DateTime? End { get; set; } + [JsonConverter(typeof(IsoDateTimeConverter))] + public DateTimeOffset? End { get; set; } /// /// Optional time zone information for start and end. Possible values are extracted from the IANA database and they are diff --git a/Test/Notion.IntegrationTests/PageClientTests.cs b/Test/Notion.IntegrationTests/PageClientTests.cs index 21adbd5b..31678d73 100644 --- a/Test/Notion.IntegrationTests/PageClientTests.cs +++ b/Test/Notion.IntegrationTests/PageClientTests.cs @@ -216,8 +216,8 @@ public async Task Test_UpdatePageProperty_with_date_as_null() { Date = new Date { - Start = Convert.ToDateTime("2020-12-08T12:00:00Z"), - End = Convert.ToDateTime("2025-12-08T12:00:00Z") + Start = DateTimeOffset.Parse("2024-06-26T00:00:00.000+01:00"), + End = DateTimeOffset.Parse("2025-12-08").Date } }) .Build(); @@ -236,7 +236,8 @@ public async Task Test_UpdatePageProperty_with_date_as_null() ); // Assert - setDate?.Date?.Start.Should().Be(Convert.ToDateTime("2020-12-08T12:00:00Z")); + setDate?.Date?.Start.Should().Be(DateTimeOffset.Parse("2024-06-26T00:00:00.000+01:00")); + setDate?.Date?.End.Should().Be(DateTimeOffset.Parse("2025-12-08T00:00:00.000+01:00")); var pageUpdateParameters = new PagesUpdateParameters { @@ -384,4 +385,58 @@ public async Task Bug_exception_when_attempting_to_set_select_property_to_nothin updatedPage.Properties["Colors1"].As().Select.Name.Should().Be("Blue"); updatedPage.Properties["Colors2"].As().Select.Should().BeNull(); } + + [Fact] + public async Task Verify_date_property_is_parsed_correctly_in_mention_object() + { + var pageRequest = PagesCreateParametersBuilder + .Create(new DatabaseParentInput { DatabaseId = _database.Id }) + .AddProperty("Name", + new TitlePropertyValue + { + Title = new List + { + new RichTextMention() + { + Mention = new Mention() + { + Page = new ObjectId() + { + Id = _page.Id, + }, + Date = new DatePropertyValue() + { + Date = new Date() + { + Start = DateTime.UtcNow + } + } + } + } + } + }) + .Build(); + + var page = await Client.Pages.CreateAsync(pageRequest); + + page.Should().NotBeNull(); + + page.Parent.Should().BeOfType().Which + .DatabaseId.Should().Be(_database.Id); + + page.Properties.Should().ContainKey("Name"); + var pageProperty = page.Properties["Name"].Should().BeOfType().Subject; + + var titleProperty = (ListPropertyItem)await Client.Pages.RetrievePagePropertyItemAsync( + new RetrievePropertyItemParameters + { + PageId = page.Id, + PropertyId = pageProperty.Id + }); + + titleProperty.Results.First() + .As() + .Title.As() + .Mention.Date.Date.Should().NotBeNull(); + } } From 8fc28489095a964fe306228bd780640b8c973a95 Mon Sep 17 00:00:00 2001 From: Marian Zagoruiko Date: Mon, 13 Jan 2025 12:59:57 +0200 Subject: [PATCH 183/216] fix: allow setting properties to null --- .gitignore | 2 ++ Src/Notion.Client/Models/PropertyValue/EmailPropertyValue.cs | 2 +- Src/Notion.Client/Models/PropertyValue/NumberPropertyValue.cs | 2 +- .../Models/PropertyValue/PhoneNumberPropertyValue.cs | 2 +- Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs | 2 +- Src/Notion.Client/Models/PropertyValue/UrlPropertyValue.cs | 2 +- 6 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index c6d337c2..5072687a 100644 --- a/.gitignore +++ b/.gitignore @@ -354,3 +354,5 @@ MigrationBackup/ # Rider .idea/ + +.DS_Store diff --git a/Src/Notion.Client/Models/PropertyValue/EmailPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/EmailPropertyValue.cs index 5a8e2c7a..a8ac4806 100644 --- a/Src/Notion.Client/Models/PropertyValue/EmailPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/EmailPropertyValue.cs @@ -12,7 +12,7 @@ public class EmailPropertyValue : PropertyValue /// /// Describes an email address. /// - [JsonProperty("email")] + [JsonProperty("email", NullValueHandling = NullValueHandling.Include)] public string Email { get; set; } } } diff --git a/Src/Notion.Client/Models/PropertyValue/NumberPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/NumberPropertyValue.cs index 15f9c768..a709e4f5 100644 --- a/Src/Notion.Client/Models/PropertyValue/NumberPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/NumberPropertyValue.cs @@ -12,7 +12,7 @@ public class NumberPropertyValue : PropertyValue /// /// Value of number /// - [JsonProperty("number")] + [JsonProperty("number", NullValueHandling = NullValueHandling.Include)] public double? Number { get; set; } } } diff --git a/Src/Notion.Client/Models/PropertyValue/PhoneNumberPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/PhoneNumberPropertyValue.cs index 79a24dac..f7c37a19 100644 --- a/Src/Notion.Client/Models/PropertyValue/PhoneNumberPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/PhoneNumberPropertyValue.cs @@ -12,7 +12,7 @@ public class PhoneNumberPropertyValue : PropertyValue /// /// Phone number value /// - [JsonProperty("phone_number")] + [JsonProperty("phone_number", NullValueHandling = NullValueHandling.Include)] public string PhoneNumber { get; set; } } } diff --git a/Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs index 29a64ef7..921ff810 100644 --- a/Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/StatusPropertyValue.cs @@ -47,7 +47,7 @@ public enum StatusColor public override PropertyValueType Type => PropertyValueType.Status; - [JsonProperty("status")] + [JsonProperty("status", NullValueHandling = NullValueHandling.Include)] public Data Status { get; set; } public class Data diff --git a/Src/Notion.Client/Models/PropertyValue/UrlPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/UrlPropertyValue.cs index 5fc8f8bb..91b5f71c 100644 --- a/Src/Notion.Client/Models/PropertyValue/UrlPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/UrlPropertyValue.cs @@ -12,7 +12,7 @@ public class UrlPropertyValue : PropertyValue /// /// Describes a web address /// - [JsonProperty("url")] + [JsonProperty("url", NullValueHandling = NullValueHandling.Include)] public string Url { get; set; } } } From 34ecf9d7f706a53f453be34ddb9ccfb44b4a3b7f Mon Sep 17 00:00:00 2001 From: Gehongyan Date: Sat, 22 Feb 2025 11:22:16 +0800 Subject: [PATCH 184/216] Add UpdateDatabaseRelationProperties Test --- .../DatabasesClientTests.cs | 63 ++++++++++++++++++- 1 file changed, 60 insertions(+), 3 deletions(-) diff --git a/Test/Notion.IntegrationTests/DatabasesClientTests.cs b/Test/Notion.IntegrationTests/DatabasesClientTests.cs index 31b611f1..d5278519 100644 --- a/Test/Notion.IntegrationTests/DatabasesClientTests.cs +++ b/Test/Notion.IntegrationTests/DatabasesClientTests.cs @@ -29,7 +29,7 @@ public async Task DisposeAsync() public async Task QueryDatabase() { // Arrange - var createdDatabase = await CreateDatabaseWithAPageAsync(); + var createdDatabase = await CreateDatabaseWithAPageAsync("Test List"); // Act var response = await Client.Databases.QueryAsync(createdDatabase.Id, new DatabasesQueryParameters()); @@ -43,7 +43,64 @@ public async Task QueryDatabase() .Text.Content.Should().Be("Test Title"); } - private async Task CreateDatabaseWithAPageAsync() + [Fact] + public async Task UpdateDatabaseRelationProperties() + { + // Arrange + var createdSourceDatabase = await CreateDatabaseWithAPageAsync("Test Relation Source"); + var createdDestinationDatabase = await CreateDatabaseWithAPageAsync("Test Relation Destination"); + + // Act + var response = await Client.Databases.UpdateAsync(createdDestinationDatabase.Id, + new DatabasesUpdateParameters + { + Properties = new Dictionary + { + { + "Single Relation", + new RelationUpdatePropertySchema + { + Relation = new SinglePropertyRelation + { + DatabaseId = createdSourceDatabase.Id, + SingleProperty = new Dictionary() + } + } + }, + { + "Dual Relation", + new RelationUpdatePropertySchema + { + Relation = new DualPropertyRelation + { + DatabaseId = createdSourceDatabase.Id, + DualProperty = new DualPropertyRelation.Data() + } + } + } + } + }); + + // Assert + response.Properties.Should().NotBeNull(); + + response.Properties.Should().ContainKey("Single Relation"); + var singleRelation = response.Properties["Single Relation"].As().Relation; + singleRelation.Should().BeEquivalentTo( + new SinglePropertyRelation + { + DatabaseId = createdSourceDatabase.Id, + SingleProperty = new Dictionary() + }); + + response.Properties.Should().ContainKey("Dual Relation"); + var dualRelation = response.Properties["Dual Relation"].As().Relation; + dualRelation.DatabaseId.Should().Be(createdSourceDatabase.Id); + dualRelation.Type.Should().Be(RelationType.Dual); + dualRelation.Should().BeOfType(); + } + + private async Task CreateDatabaseWithAPageAsync(string databaseName) { var createDbRequest = new DatabasesCreateParameters { @@ -53,7 +110,7 @@ private async Task CreateDatabaseWithAPageAsync() { Text = new Text { - Content = "Test List", + Content = databaseName, Link = null } } From cff7585c8aac2e09aacb66ccbfe306ba5f71bf03 Mon Sep 17 00:00:00 2001 From: Marian Zagoruiko Date: Wed, 15 Jan 2025 13:50:27 +0200 Subject: [PATCH 185/216] feat: include time option for dates --- .../Models/PropertyValue/DatePropertyValue.cs | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs index 7467936b..7d785212 100644 --- a/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs @@ -21,6 +21,7 @@ public class DatePropertyValue : PropertyValue /// /// Date value object. /// + [JsonConverter(typeof(DateCustomConverter))] public class Date { /// @@ -43,5 +44,94 @@ public class Date /// [JsonProperty("time_zone")] public string TimeZone { get; set; } + + /// + /// Whether to include time + /// + public bool IncludeTime { get; set; } = true; + } + + public class DateJsonObject + { + [JsonProperty("start")] + public string Start { get; set; } + + [JsonProperty("end")] + public string End { get; set; } + + [JsonProperty("time_zone")] + public string TimeZone { get; set; } + } + + public class DateCustomConverter : JsonConverter + { + public override Date ReadJson(JsonReader reader, Type objectType, Date existingValue, bool hasExistingValue, + JsonSerializer serializer) + { + var jsonObject = serializer.Deserialize(reader); + + if (jsonObject == null) + { + return null; + } + + var date = new Date + { + Start = ParseDateTime(jsonObject.Start, out bool includeTime), + End = ParseDateTime(jsonObject.End, out _), + TimeZone = jsonObject.TimeZone, + IncludeTime = includeTime, + }; + + return date; + } + + public override void WriteJson(JsonWriter writer, Date value, JsonSerializer serializer) + { + if (value is null) + { + writer.WriteNull(); + + return; + } + + writer.WriteStartObject(); + + if (value.Start.HasValue) + { + string startFormat = value.IncludeTime ? "yyyy-MM-ddTHH:mm:ss" : "yyyy-MM-dd"; + writer.WritePropertyName("start"); + writer.WriteValue(value.Start.Value.ToString(startFormat)); + } + + if (value.End.HasValue) + { + string endFormat = value.IncludeTime ? "yyyy-MM-ddTHH:mm:ss" : "yyyy-MM-dd"; + writer.WritePropertyName("end"); + writer.WriteValue(value.End.Value.ToString(endFormat)); + } + + if (!string.IsNullOrEmpty(value.TimeZone)) + { + writer.WritePropertyName("time_zone"); + writer.WriteValue(value.TimeZone); + } + + writer.WriteEndObject(); + } + + private static DateTime? ParseDateTime(string dateTimeString, out bool includeTime) + { + includeTime = false; + + if (string.IsNullOrEmpty(dateTimeString)) + { + return null; + } + + includeTime = dateTimeString.Contains("T") || dateTimeString.Contains(" "); + + return DateTimeOffset.Parse(dateTimeString).UtcDateTime; + } } } From f41327e34abf0529a18006581580ec7005738f03 Mon Sep 17 00:00:00 2001 From: Marian Zagoruiko Date: Fri, 17 Jan 2025 18:10:12 +0200 Subject: [PATCH 186/216] feat: rollup date parsing --- Src/Notion.Client/Models/PropertyValue/RollupPropertyValue.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/Notion.Client/Models/PropertyValue/RollupPropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/RollupPropertyValue.cs index 2eb104fb..92020c61 100644 --- a/Src/Notion.Client/Models/PropertyValue/RollupPropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/RollupPropertyValue.cs @@ -35,7 +35,7 @@ public class RollupValue /// Date rollup property values contain a date property value. /// [JsonProperty("date")] - public DatePropertyValue Date { get; set; } + public Date Date { get; set; } /// /// Array rollup property values contain an array of element objects. From 954c042c057a0c6fc5b3a2debad938fb40424f37 Mon Sep 17 00:00:00 2001 From: Marian Zagoruiko Date: Fri, 28 Mar 2025 10:06:16 +0200 Subject: [PATCH 187/216] fix: custom emoji support --- Src/Notion.Client/Models/CustomEmoji.cs | 16 ++++++++++++++++ Src/Notion.Client/Models/CustomEmojiObject.cs | 13 +++++++++++++ Src/Notion.Client/Models/Page/IPageIcon.cs | 1 + 3 files changed, 30 insertions(+) create mode 100644 Src/Notion.Client/Models/CustomEmoji.cs create mode 100644 Src/Notion.Client/Models/CustomEmojiObject.cs diff --git a/Src/Notion.Client/Models/CustomEmoji.cs b/Src/Notion.Client/Models/CustomEmoji.cs new file mode 100644 index 00000000..0f7a4c48 --- /dev/null +++ b/Src/Notion.Client/Models/CustomEmoji.cs @@ -0,0 +1,16 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class CustomEmoji + { + [JsonProperty("id")] + public string Id { get; set; } + + [JsonProperty("name")] + public string Name { get; set; } + + [JsonProperty("url")] + public string Url { get; set; } + } +} diff --git a/Src/Notion.Client/Models/CustomEmojiObject.cs b/Src/Notion.Client/Models/CustomEmojiObject.cs new file mode 100644 index 00000000..1faa4d74 --- /dev/null +++ b/Src/Notion.Client/Models/CustomEmojiObject.cs @@ -0,0 +1,13 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class CustomEmojiObject : IPageIcon + { + [JsonProperty("custom_emoji")] + public CustomEmoji CustomEmoji { get; set; } + + [JsonProperty("type")] + public string Type { get; set; } + } +} diff --git a/Src/Notion.Client/Models/Page/IPageIcon.cs b/Src/Notion.Client/Models/Page/IPageIcon.cs index b9ebea56..5d692185 100644 --- a/Src/Notion.Client/Models/Page/IPageIcon.cs +++ b/Src/Notion.Client/Models/Page/IPageIcon.cs @@ -5,6 +5,7 @@ namespace Notion.Client { [JsonConverter(typeof(JsonSubtypes), "type")] [JsonSubtypes.KnownSubTypeAttribute(typeof(EmojiObject), "emoji")] + [JsonSubtypes.KnownSubTypeAttribute(typeof(CustomEmojiObject), "custom_emoji")] [JsonSubtypes.KnownSubTypeAttribute(typeof(FileObject), "file")] [JsonSubtypes.KnownSubTypeAttribute(typeof(FileObject), "external")] public interface IPageIcon From 8ee7f0fd923e55406aa88a12bdd94409c8bf2c3e Mon Sep 17 00:00:00 2001 From: Marian Zagoruiko Date: Fri, 28 Mar 2025 10:28:28 +0200 Subject: [PATCH 188/216] fix: linter --- .../PropertyValue/DateCustomConverter.cs | 77 +++++++++++++++++ .../Models/PropertyValue/DateJsonObject.cs | 16 ++++ .../Models/PropertyValue/DatePropertyValue.cs | 84 ------------------- 3 files changed, 93 insertions(+), 84 deletions(-) create mode 100644 Src/Notion.Client/Models/PropertyValue/DateCustomConverter.cs create mode 100644 Src/Notion.Client/Models/PropertyValue/DateJsonObject.cs diff --git a/Src/Notion.Client/Models/PropertyValue/DateCustomConverter.cs b/Src/Notion.Client/Models/PropertyValue/DateCustomConverter.cs new file mode 100644 index 00000000..6823c303 --- /dev/null +++ b/Src/Notion.Client/Models/PropertyValue/DateCustomConverter.cs @@ -0,0 +1,77 @@ +using System; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class DateCustomConverter : JsonConverter + { + public override Date ReadJson(JsonReader reader, Type objectType, Date existingValue, bool hasExistingValue, + JsonSerializer serializer) + { + var jsonObject = serializer.Deserialize(reader); + + if (jsonObject == null) + { + return null; + } + + var date = new Date + { + Start = ParseDateTime(jsonObject.Start, out bool includeTime), + End = ParseDateTime(jsonObject.End, out _), + TimeZone = jsonObject.TimeZone, + IncludeTime = includeTime, + }; + + return date; + } + + public override void WriteJson(JsonWriter writer, Date value, JsonSerializer serializer) + { + if (value is null) + { + writer.WriteNull(); + + return; + } + + writer.WriteStartObject(); + + if (value.Start.HasValue) + { + string startFormat = value.IncludeTime ? "yyyy-MM-ddTHH:mm:ss" : "yyyy-MM-dd"; + writer.WritePropertyName("start"); + writer.WriteValue(value.Start.Value.ToString(startFormat)); + } + + if (value.End.HasValue) + { + string endFormat = value.IncludeTime ? "yyyy-MM-ddTHH:mm:ss" : "yyyy-MM-dd"; + writer.WritePropertyName("end"); + writer.WriteValue(value.End.Value.ToString(endFormat)); + } + + if (!string.IsNullOrEmpty(value.TimeZone)) + { + writer.WritePropertyName("time_zone"); + writer.WriteValue(value.TimeZone); + } + + writer.WriteEndObject(); + } + + private static DateTime? ParseDateTime(string dateTimeString, out bool includeTime) + { + includeTime = false; + + if (string.IsNullOrEmpty(dateTimeString)) + { + return null; + } + + includeTime = dateTimeString.Contains("T") || dateTimeString.Contains(" "); + + return DateTimeOffset.Parse(dateTimeString).UtcDateTime; + } + } +} diff --git a/Src/Notion.Client/Models/PropertyValue/DateJsonObject.cs b/Src/Notion.Client/Models/PropertyValue/DateJsonObject.cs new file mode 100644 index 00000000..b33b58c7 --- /dev/null +++ b/Src/Notion.Client/Models/PropertyValue/DateJsonObject.cs @@ -0,0 +1,16 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + internal class DateJsonObject + { + [JsonProperty("start")] + public string Start { get; set; } + + [JsonProperty("end")] + public string End { get; set; } + + [JsonProperty("time_zone")] + public string TimeZone { get; set; } + } +} diff --git a/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs index 7d785212..b79707db 100644 --- a/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs @@ -50,88 +50,4 @@ public class Date /// public bool IncludeTime { get; set; } = true; } - - public class DateJsonObject - { - [JsonProperty("start")] - public string Start { get; set; } - - [JsonProperty("end")] - public string End { get; set; } - - [JsonProperty("time_zone")] - public string TimeZone { get; set; } - } - - public class DateCustomConverter : JsonConverter - { - public override Date ReadJson(JsonReader reader, Type objectType, Date existingValue, bool hasExistingValue, - JsonSerializer serializer) - { - var jsonObject = serializer.Deserialize(reader); - - if (jsonObject == null) - { - return null; - } - - var date = new Date - { - Start = ParseDateTime(jsonObject.Start, out bool includeTime), - End = ParseDateTime(jsonObject.End, out _), - TimeZone = jsonObject.TimeZone, - IncludeTime = includeTime, - }; - - return date; - } - - public override void WriteJson(JsonWriter writer, Date value, JsonSerializer serializer) - { - if (value is null) - { - writer.WriteNull(); - - return; - } - - writer.WriteStartObject(); - - if (value.Start.HasValue) - { - string startFormat = value.IncludeTime ? "yyyy-MM-ddTHH:mm:ss" : "yyyy-MM-dd"; - writer.WritePropertyName("start"); - writer.WriteValue(value.Start.Value.ToString(startFormat)); - } - - if (value.End.HasValue) - { - string endFormat = value.IncludeTime ? "yyyy-MM-ddTHH:mm:ss" : "yyyy-MM-dd"; - writer.WritePropertyName("end"); - writer.WriteValue(value.End.Value.ToString(endFormat)); - } - - if (!string.IsNullOrEmpty(value.TimeZone)) - { - writer.WritePropertyName("time_zone"); - writer.WriteValue(value.TimeZone); - } - - writer.WriteEndObject(); - } - - private static DateTime? ParseDateTime(string dateTimeString, out bool includeTime) - { - includeTime = false; - - if (string.IsNullOrEmpty(dateTimeString)) - { - return null; - } - - includeTime = dateTimeString.Contains("T") || dateTimeString.Contains(" "); - - return DateTimeOffset.Parse(dateTimeString).UtcDateTime; - } - } } From 80d32df3b95035d044d62a73bf23184d1035633c Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sat, 12 Apr 2025 17:14:04 +0530 Subject: [PATCH 189/216] 431: Throw error if database id was not provided --- Src/Notion.Client/Api/Databases/DatabasesClient.cs | 8 +++++++- Test/Notion.UnitTests/DatabasesClientTests.cs | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Src/Notion.Client/Api/Databases/DatabasesClient.cs b/Src/Notion.Client/Api/Databases/DatabasesClient.cs index 673ee122..a3dc9a8c 100644 --- a/Src/Notion.Client/Api/Databases/DatabasesClient.cs +++ b/Src/Notion.Client/Api/Databases/DatabasesClient.cs @@ -1,4 +1,5 @@ -using System.Threading; +using System; +using System.Threading; using System.Threading.Tasks; using static Notion.Client.ApiEndpoints; @@ -15,6 +16,11 @@ public DatabasesClient(IRestClient client) public async Task RetrieveAsync(string databaseId, CancellationToken cancellationToken = default) { + if (string.IsNullOrWhiteSpace(databaseId)) + { + throw new ArgumentNullException(nameof(databaseId)); + } + return await _client.GetAsync(DatabasesApiUrls.Retrieve(databaseId), cancellationToken: cancellationToken); } diff --git a/Test/Notion.UnitTests/DatabasesClientTests.cs b/Test/Notion.UnitTests/DatabasesClientTests.cs index 3bd047a7..1edbc2ed 100644 --- a/Test/Notion.UnitTests/DatabasesClientTests.cs +++ b/Test/Notion.UnitTests/DatabasesClientTests.cs @@ -504,4 +504,18 @@ var jsonData formulaPropertyValue.Formula.Date.End.Should().BeNull(); } } + + [Theory] + [InlineData(null)] + [InlineData("")] + [InlineData(" ")] + public async Task RetrieveAsync_throws_argument_null_exception_if_database_id_is_null_or_empty(string databaseId) + { + // Arrange && Act + async Task Act() => await _client.RetrieveAsync(databaseId); + + // Assert + var exception = await Assert.ThrowsAsync(Act); + Assert.Equal("databaseId", exception.ParamName); + } } From 4836c4b863b43a767f686add471387b5b9b32c61 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sat, 12 Apr 2025 23:52:00 +0530 Subject: [PATCH 190/216] fix: enhance DateCustomSerializer and add tests * use ISO 8601 date and time format * fix breaking test --- .../PropertyValue/DateCustomConverter.cs | 9 +- Test/Notion.UnitTests/DatabasesClientTests.cs | 2 +- .../DateCustomConverterTests.cs | 219 ++++++++++++++++++ 3 files changed, 226 insertions(+), 4 deletions(-) create mode 100644 Test/Notion.UnitTests/DateCustomConverterTests.cs diff --git a/Src/Notion.Client/Models/PropertyValue/DateCustomConverter.cs b/Src/Notion.Client/Models/PropertyValue/DateCustomConverter.cs index 6823c303..d4af88f4 100644 --- a/Src/Notion.Client/Models/PropertyValue/DateCustomConverter.cs +++ b/Src/Notion.Client/Models/PropertyValue/DateCustomConverter.cs @@ -5,6 +5,9 @@ namespace Notion.Client { public class DateCustomConverter : JsonConverter { + private const string DateFormat = "yyyy-MM-dd"; + private const string DateTimeFormat = "yyyy-MM-ddTHH:mm:ssZ"; + public override Date ReadJson(JsonReader reader, Type objectType, Date existingValue, bool hasExistingValue, JsonSerializer serializer) { @@ -39,14 +42,14 @@ public override void WriteJson(JsonWriter writer, Date value, JsonSerializer ser if (value.Start.HasValue) { - string startFormat = value.IncludeTime ? "yyyy-MM-ddTHH:mm:ss" : "yyyy-MM-dd"; + string startFormat = value.IncludeTime ? DateTimeFormat : DateFormat; writer.WritePropertyName("start"); writer.WriteValue(value.Start.Value.ToString(startFormat)); } if (value.End.HasValue) { - string endFormat = value.IncludeTime ? "yyyy-MM-ddTHH:mm:ss" : "yyyy-MM-dd"; + string endFormat = value.IncludeTime ? DateTimeFormat : DateFormat; writer.WritePropertyName("end"); writer.WriteValue(value.End.Value.ToString(endFormat)); } @@ -71,7 +74,7 @@ public override void WriteJson(JsonWriter writer, Date value, JsonSerializer ser includeTime = dateTimeString.Contains("T") || dateTimeString.Contains(" "); - return DateTimeOffset.Parse(dateTimeString).UtcDateTime; + return DateTimeOffset.Parse(dateTimeString, null, System.Globalization.DateTimeStyles.AssumeUniversal).UtcDateTime; } } } diff --git a/Test/Notion.UnitTests/DatabasesClientTests.cs b/Test/Notion.UnitTests/DatabasesClientTests.cs index 1edbc2ed..30deae75 100644 --- a/Test/Notion.UnitTests/DatabasesClientTests.cs +++ b/Test/Notion.UnitTests/DatabasesClientTests.cs @@ -500,7 +500,7 @@ var jsonData }); //var formulaPropertyValue = (FormulaPropertyValue)page.Properties["FormulaProp"]; - formulaPropertyValue.Formula.Date.Start.Should().Be(DateTime.Parse("2021-06-28")); + formulaPropertyValue.Formula.Date.Start.Should().Be(DateTimeOffset.Parse("2021-06-28", null, System.Globalization.DateTimeStyles.AssumeUniversal).UtcDateTime); formulaPropertyValue.Formula.Date.End.Should().BeNull(); } } diff --git a/Test/Notion.UnitTests/DateCustomConverterTests.cs b/Test/Notion.UnitTests/DateCustomConverterTests.cs new file mode 100644 index 00000000..81c33f57 --- /dev/null +++ b/Test/Notion.UnitTests/DateCustomConverterTests.cs @@ -0,0 +1,219 @@ +using System; +using System.IO; +using Newtonsoft.Json; +using Notion.Client; +using Xunit; + +namespace NotionUnitTests.PropertyValue; + +public class DateCustomConverterTests +{ + private readonly DateCustomConverter _converter = new(); + private readonly JsonSerializer _serializer = new(); + + [Fact] + public void Serialize_null_writes_null() + { + // Arrange + Date date = null; + var stringWriter = new StringWriter(); + var jsonWriter = new JsonTextWriter(stringWriter); + + // Act + _converter.WriteJson(jsonWriter, date, _serializer); + jsonWriter.Flush(); + + // Assert + Assert.Equal("null", stringWriter.ToString()); + } + + [Fact] + public void Serialize_start_date_only_produces_correct_json() + { + // Arrange + var date = new Date + { + Start = new DateTimeOffset(2023, 5, 15, 0, 0, 0, TimeSpan.Zero), + IncludeTime = false + }; + + // Act + var json = JsonConvert.SerializeObject(date); + + // Assert + Assert.Contains("\"start\":\"2023-05-15\"", json); + Assert.DoesNotContain("\"end\":", json); + Assert.DoesNotContain("\"time_zone\":", json); + } + + [Fact] + public void Serialize_start_and_end_dates_produces_correct_json() + { + // Arrange + var date = new Date + { + Start = new DateTimeOffset(2023, 5, 15, 0, 0, 0, TimeSpan.Zero), + End = new DateTimeOffset(2023, 5, 20, 0, 0, 0, TimeSpan.Zero), + IncludeTime = false + }; + + // Act + var json = JsonConvert.SerializeObject(date); + + // Assert + Assert.Contains("\"start\":\"2023-05-15\"", json); + Assert.Contains("\"end\":\"2023-05-20\"", json); + Assert.DoesNotContain("\"time_zone\":", json); + } + + [Fact] + public void Serialize_with_time_included_formats_time_correctly() + { + // Arrange + var date = new Date + { + Start = new DateTimeOffset(2023, 5, 15, 14, 30, 45, TimeSpan.Zero), + IncludeTime = true + }; + + // Act + var json = JsonConvert.SerializeObject(date); + + // Assert + Assert.Contains("\"start\":\"2023-05-15T14:30:45Z\"", json); + } + + [Fact] + public void Serialize_with_time_zone_includes_time_zone() + { + // Arrange + var date = new Date + { + Start = new DateTimeOffset(2023, 5, 15, 14, 30, 45, TimeSpan.Zero), + TimeZone = "Europe/London", + IncludeTime = true + }; + + // Act + var json = JsonConvert.SerializeObject(date); + + // Assert + Assert.Contains("\"start\":\"2023-05-15T14:30:45Z\"", json); + Assert.Contains("\"time_zone\":\"Europe/London\"", json); + } + + [Fact] + public void Deserialize_null_returns_null() + { + // Arrange + const string Json = "null"; + + // Act + var result = JsonConvert.DeserializeObject(Json); + + // Assert + Assert.Null(result); + } + + [Fact] + public void Deserialize_start_date_only_returns_correct_date() + { + // Arrange + const string Json = "{\"start\":\"2023-05-15\"}"; + + // Act + var result = JsonConvert.DeserializeObject(Json); + + // Assert + Assert.NotNull(result); + Assert.Equal(new DateTimeOffset(2023, 5, 15, 0, 0, 0, TimeSpan.Zero), result.Start); + Assert.Null(result.End); + Assert.Null(result.TimeZone); + Assert.False(result.IncludeTime); + } + + [Fact] + public void Deserialize_with_time_sets_include_time_flag() + { + // Arrange + const string Json = "{\"start\":\"2023-05-15T14:30:45\"}"; + + // Act + var result = JsonConvert.DeserializeObject(Json); + + // Assert + Assert.NotNull(result); + Assert.Equal(new DateTimeOffset(2023, 5, 15, 14, 30, 45, TimeSpan.Zero), result.Start); + Assert.True(result.IncludeTime); + } + + [Fact] + public void Deserialize_with_start_end_and_time_zone_returns_complete_date() + { + // Arrange + const string Json = "{\"start\":\"2023-05-15T14:30:45\",\"end\":\"2023-05-20T16:45:00\",\"time_zone\":\"America/New_York\"}"; + + // Act + var result = JsonConvert.DeserializeObject(Json); + + // Assert + Assert.NotNull(result); + Assert.Equal(new DateTimeOffset(2023, 5, 15, 14, 30, 45, TimeSpan.Zero), result.Start); + Assert.Equal(new DateTimeOffset(2023, 5, 20, 16, 45, 0, TimeSpan.Zero), result.End); + Assert.Equal("America/New_York", result.TimeZone); + Assert.True(result.IncludeTime); + } + + [Fact] + public void Date_property_value_serialize_deserialize_maintains_data() + { + // Arrange + var datePropertyValue = new DatePropertyValue + { + Date = new Date + { + Start = new DateTimeOffset(2023, 5, 15, 14, 30, 45, TimeSpan.Zero), + End = new DateTimeOffset(2023, 5, 20, 16, 45, 0, TimeSpan.Zero), + TimeZone = "Europe/Berlin", + IncludeTime = true + } + }; + + // Act + var json = JsonConvert.SerializeObject(datePropertyValue); + var result = JsonConvert.DeserializeObject(json); + + // Assert + Assert.NotNull(result); + Assert.Equal(PropertyValueType.Date, result.Type); + Assert.NotNull(result.Date); + Assert.Equal(datePropertyValue.Date.Start, result.Date.Start); + Assert.Equal(datePropertyValue.Date.End, result.Date.End); + Assert.Equal(datePropertyValue.Date.TimeZone, result.Date.TimeZone); + Assert.Equal(datePropertyValue.Date.IncludeTime, result.Date.IncludeTime); + } + + [Fact] + public void Round_trip_preserves_data() + { + // Arrange + var originalDate = new Date + { + Start = new DateTimeOffset(2023, 5, 15, 14, 30, 45, TimeSpan.Zero), + End = new DateTimeOffset(2023, 5, 20, 16, 45, 0, TimeSpan.Zero), + TimeZone = "Europe/Berlin", + IncludeTime = true + }; + + // Act + var json = JsonConvert.SerializeObject(originalDate); + var deserializedDate = JsonConvert.DeserializeObject(json); + + // Assert + Assert.NotNull(deserializedDate); + Assert.Equal(originalDate.Start, deserializedDate.Start); + Assert.Equal(originalDate.End, deserializedDate.End); + Assert.Equal(originalDate.TimeZone, deserializedDate.TimeZone); + Assert.True(deserializedDate.IncludeTime); + } +} From 42d7e798f663cf8189f09c6b6444c4771d89b6c0 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sat, 12 Apr 2025 23:52:36 +0530 Subject: [PATCH 191/216] add explicit JsonIgnore attribute to IncludeTime property in Date class --- Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs b/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs index b79707db..66f9c6b6 100644 --- a/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs +++ b/Src/Notion.Client/Models/PropertyValue/DatePropertyValue.cs @@ -48,6 +48,7 @@ public class Date /// /// Whether to include time /// + [JsonIgnore] public bool IncludeTime { get; set; } = true; } } From 48ee22a8f1afecc05a8ae24f4b0d932b06b4baa9 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 13 Apr 2025 00:49:23 +0530 Subject: [PATCH 192/216] ensure culture-invariant date formatting in DateCustomConverter --- .../Models/PropertyValue/DateCustomConverter.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Src/Notion.Client/Models/PropertyValue/DateCustomConverter.cs b/Src/Notion.Client/Models/PropertyValue/DateCustomConverter.cs index d4af88f4..78f14cdb 100644 --- a/Src/Notion.Client/Models/PropertyValue/DateCustomConverter.cs +++ b/Src/Notion.Client/Models/PropertyValue/DateCustomConverter.cs @@ -1,4 +1,5 @@ using System; +using System.Globalization; using Newtonsoft.Json; namespace Notion.Client @@ -44,14 +45,14 @@ public override void WriteJson(JsonWriter writer, Date value, JsonSerializer ser { string startFormat = value.IncludeTime ? DateTimeFormat : DateFormat; writer.WritePropertyName("start"); - writer.WriteValue(value.Start.Value.ToString(startFormat)); + writer.WriteValue(value.Start.Value.ToString(startFormat, CultureInfo.InvariantCulture)); } if (value.End.HasValue) { string endFormat = value.IncludeTime ? DateTimeFormat : DateFormat; writer.WritePropertyName("end"); - writer.WriteValue(value.End.Value.ToString(endFormat)); + writer.WriteValue(value.End.Value.ToString(endFormat, CultureInfo.InvariantCulture)); } if (!string.IsNullOrEmpty(value.TimeZone)) @@ -74,7 +75,7 @@ public override void WriteJson(JsonWriter writer, Date value, JsonSerializer ser includeTime = dateTimeString.Contains("T") || dateTimeString.Contains(" "); - return DateTimeOffset.Parse(dateTimeString, null, System.Globalization.DateTimeStyles.AssumeUniversal).UtcDateTime; + return DateTimeOffset.Parse(dateTimeString, null, DateTimeStyles.AssumeUniversal).UtcDateTime; } } } From 4e9c6bebae87b314724e72942fe6243125debb9d Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 13 Apr 2025 01:09:13 +0530 Subject: [PATCH 193/216] Use CultureInfo.InvariantCulture in DateTimeOffset.Parse to ensure consistent parsing of ISO 8601 dates across different environments Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- Src/Notion.Client/Models/PropertyValue/DateCustomConverter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/Notion.Client/Models/PropertyValue/DateCustomConverter.cs b/Src/Notion.Client/Models/PropertyValue/DateCustomConverter.cs index 78f14cdb..37b84bc5 100644 --- a/Src/Notion.Client/Models/PropertyValue/DateCustomConverter.cs +++ b/Src/Notion.Client/Models/PropertyValue/DateCustomConverter.cs @@ -75,7 +75,7 @@ public override void WriteJson(JsonWriter writer, Date value, JsonSerializer ser includeTime = dateTimeString.Contains("T") || dateTimeString.Contains(" "); - return DateTimeOffset.Parse(dateTimeString, null, DateTimeStyles.AssumeUniversal).UtcDateTime; + return DateTimeOffset.Parse(dateTimeString, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).UtcDateTime; } } } From 3ea8bc4541087ecd7d738a516aa05c4f73760322 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 13 Apr 2025 00:36:28 +0530 Subject: [PATCH 194/216] fix: creation and parsing of Date Mentions --- .../DatabasesCreateParameters/MentionInput.cs | 2 +- .../Database/RichText/RichTextMention.cs | 2 +- .../DatabasesClientTests.cs | 47 ++++++++++++++++++- .../PageClientTests.cs | 20 +++----- 4 files changed, 54 insertions(+), 17 deletions(-) diff --git a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/MentionInput.cs b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/MentionInput.cs index 83d1e699..48b34948 100644 --- a/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/MentionInput.cs +++ b/Src/Notion.Client/Api/Databases/RequestParams/DatabasesCreateParameters/MentionInput.cs @@ -17,6 +17,6 @@ public class MentionInput public ObjectId Database { get; set; } [JsonProperty("date")] - public DatePropertyValue Date { get; set; } + public Date Date { get; set; } } } diff --git a/Src/Notion.Client/Models/Database/RichText/RichTextMention.cs b/Src/Notion.Client/Models/Database/RichText/RichTextMention.cs index 02f6beb0..5a5b6d0c 100644 --- a/Src/Notion.Client/Models/Database/RichText/RichTextMention.cs +++ b/Src/Notion.Client/Models/Database/RichText/RichTextMention.cs @@ -25,7 +25,7 @@ public class Mention public ObjectId Database { get; set; } [JsonProperty("date")] - public DatePropertyValue Date { get; set; } + public Date Date { get; set; } } public class ObjectId diff --git a/Test/Notion.IntegrationTests/DatabasesClientTests.cs b/Test/Notion.IntegrationTests/DatabasesClientTests.cs index d5278519..7abd7b4e 100644 --- a/Test/Notion.IntegrationTests/DatabasesClientTests.cs +++ b/Test/Notion.IntegrationTests/DatabasesClientTests.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using FluentAssertions; @@ -140,4 +141,48 @@ private async Task CreateDatabaseWithAPageAsync(string databaseName) return createdDatabase; } + + [Fact] + public async Task Verify_mention_date_property_parsed_properly() + { + // Arrange + var createDbRequest = new DatabasesCreateParameters + { + Title = new List + { + new RichTextTextInput + { + Text = new Text + { + Content = "Test DB", + Link = null + } + }, + new RichTextMentionInput + { + Mention = new MentionInput + { + Date = new Date + { + Start = DateTime.UtcNow, + End = DateTime.UtcNow.AddDays(1) + } + } + } + }, + Properties = new Dictionary + { + { "Name", new TitlePropertySchema { Title = new Dictionary() } }, + }, + Parent = new ParentPageInput { PageId = _page.Id } + }; + + // Act + var createdDatabase = await Client.Databases.CreateAsync(createDbRequest); + + // Assert + var mention = createdDatabase.Title.OfType().First().Mention; + mention.Date.Start.Should().NotBeNull(); + mention.Date.End.Should().NotBeNull(); + } } diff --git a/Test/Notion.IntegrationTests/PageClientTests.cs b/Test/Notion.IntegrationTests/PageClientTests.cs index 31678d73..4938bcfa 100644 --- a/Test/Notion.IntegrationTests/PageClientTests.cs +++ b/Test/Notion.IntegrationTests/PageClientTests.cs @@ -400,23 +400,16 @@ public async Task Verify_date_property_is_parsed_correctly_in_mention_object() { Mention = new Mention() { - Page = new ObjectId() + Date = new Date() { - Id = _page.Id, - }, - Date = new DatePropertyValue() - { - Date = new Date() - { - Start = DateTime.UtcNow - } + Start = DateTime.UtcNow } } } } }) .Build(); - + var page = await Client.Pages.CreateAsync(pageRequest); page.Should().NotBeNull(); @@ -434,9 +427,8 @@ public async Task Verify_date_property_is_parsed_correctly_in_mention_object() PropertyId = pageProperty.Id }); - titleProperty.Results.First() - .As() - .Title.As() - .Mention.Date.Date.Should().NotBeNull(); + var mention = titleProperty.Results.First().As().Title.As().Mention; + mention.Date.Start.Should().NotBeNull(); + mention.Date.End.Should().BeNull(); } } From ae94eb5209d16464d1a410cd3e486a9efa5dcc36 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 13 Apr 2025 12:27:38 +0530 Subject: [PATCH 195/216] =?UTF-8?q?add=20support=20for=20reading=20and=20w?= =?UTF-8?q?riting=20Name=20&=20Caption=20properties=20to=20file=20blocks?= =?UTF-8?q?=20=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../File/FIleInput/ExternalFileInput.cs | 7 ++- .../Models/File/FIleInput/IFileObjectInput.cs | 10 ++++- .../File/FIleInput/UploadedFileInput.cs | 5 +++ .../BlocksClientTests.cs | 45 +++++++++++++++++++ 4 files changed, 65 insertions(+), 2 deletions(-) diff --git a/Src/Notion.Client/Models/File/FIleInput/ExternalFileInput.cs b/Src/Notion.Client/Models/File/FIleInput/ExternalFileInput.cs index 9c258ceb..38ad781c 100644 --- a/Src/Notion.Client/Models/File/FIleInput/ExternalFileInput.cs +++ b/Src/Notion.Client/Models/File/FIleInput/ExternalFileInput.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json; +using System.Collections.Generic; +using Newtonsoft.Json; namespace Notion.Client { @@ -7,6 +8,10 @@ public class ExternalFileInput : IFileObjectInput [JsonProperty("external")] public Data External { get; set; } + public string Name { get; set; } + + public IEnumerable Caption { get; set; } + public class Data { [JsonProperty("url")] diff --git a/Src/Notion.Client/Models/File/FIleInput/IFileObjectInput.cs b/Src/Notion.Client/Models/File/FIleInput/IFileObjectInput.cs index 31df1573..5883b7c1 100644 --- a/Src/Notion.Client/Models/File/FIleInput/IFileObjectInput.cs +++ b/Src/Notion.Client/Models/File/FIleInput/IFileObjectInput.cs @@ -1,6 +1,14 @@ -namespace Notion.Client +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client { public interface IFileObjectInput { + [JsonProperty("name")] + public string Name { get; set; } + + [JsonProperty("caption")] + public IEnumerable Caption { get; set; } } } diff --git a/Src/Notion.Client/Models/File/FIleInput/UploadedFileInput.cs b/Src/Notion.Client/Models/File/FIleInput/UploadedFileInput.cs index 52d7934d..dabca4e1 100644 --- a/Src/Notion.Client/Models/File/FIleInput/UploadedFileInput.cs +++ b/Src/Notion.Client/Models/File/FIleInput/UploadedFileInput.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using Newtonsoft.Json; namespace Notion.Client @@ -8,6 +9,10 @@ public class UploadedFileInput : IFileObjectInput [JsonProperty("file")] public Data File { get; set; } + public string Name { get; set; } + + public IEnumerable Caption { get; set; } + public class Data { [JsonProperty("url")] diff --git a/Test/Notion.IntegrationTests/BlocksClientTests.cs b/Test/Notion.IntegrationTests/BlocksClientTests.cs index 5c8e4618..d52b8f64 100644 --- a/Test/Notion.IntegrationTests/BlocksClientTests.cs +++ b/Test/Notion.IntegrationTests/BlocksClientTests.cs @@ -399,6 +399,51 @@ private static IEnumerable BlockData() .Subject.Should().BeOfType() .Subject.Text.Content.Should().Be("Data"); }) + }, + new object[] + { + new FileBlockRequest { + File = new ExternalFile + { + Name = "Test file", + External = new ExternalFile.Info + { + Url = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg" + }, + Caption = new List + { + new RichTextTextInput { Text = new Text { Content = "Test file" } } + } + } + }, + new FileUpdateBlock + { + File = new ExternalFileInput + { + Name = "Test file name", + External = new ExternalFileInput.Data + { + Url = "https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg" + }, + Caption = new List + { + new RichTextTextInput { Text = new Text { Content = "Test file caption" } } + } + } + }, + new Action((block, client) => + { + var fileBlock = block.Should().NotBeNull().And.BeOfType().Subject; + fileBlock.HasChildren.Should().BeFalse(); + + var file = fileBlock.File.Should().NotBeNull().And.BeOfType().Subject; + file.Name.Should().Be("Test file name.jpg"); + file.External.Should().NotBeNull(); + file.External.Url.Should().Be("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg"); + file.Caption.Should().NotBeNull().And.ContainSingle() + .Subject.Should().BeOfType().Subject + .Text.Content.Should().Be("Test file caption"); + }) } }; } From 4af4559095c8ad46d55bc5c3b94f82235fad23f9 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 13 Apr 2025 14:15:44 +0530 Subject: [PATCH 196/216] adding a [JsonProperty("name")] attribute for the Name property to ensure consistent JSON serialization Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- Src/Notion.Client/Models/File/FIleInput/UploadedFileInput.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Src/Notion.Client/Models/File/FIleInput/UploadedFileInput.cs b/Src/Notion.Client/Models/File/FIleInput/UploadedFileInput.cs index dabca4e1..31715b12 100644 --- a/Src/Notion.Client/Models/File/FIleInput/UploadedFileInput.cs +++ b/Src/Notion.Client/Models/File/FIleInput/UploadedFileInput.cs @@ -9,6 +9,7 @@ public class UploadedFileInput : IFileObjectInput [JsonProperty("file")] public Data File { get; set; } + [JsonProperty("name")] public string Name { get; set; } public IEnumerable Caption { get; set; } From 93ad9654a5555402bb8809fd1f970aebd343f370 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 13 Apr 2025 14:16:33 +0530 Subject: [PATCH 197/216] add a [JsonProperty("caption")] attribute for the Caption property to ensure it serializes consistently with the interface Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- Src/Notion.Client/Models/File/FIleInput/UploadedFileInput.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Src/Notion.Client/Models/File/FIleInput/UploadedFileInput.cs b/Src/Notion.Client/Models/File/FIleInput/UploadedFileInput.cs index 31715b12..949df10c 100644 --- a/Src/Notion.Client/Models/File/FIleInput/UploadedFileInput.cs +++ b/Src/Notion.Client/Models/File/FIleInput/UploadedFileInput.cs @@ -12,6 +12,7 @@ public class UploadedFileInput : IFileObjectInput [JsonProperty("name")] public string Name { get; set; } + [JsonProperty("caption")] public IEnumerable Caption { get; set; } public class Data From dd4e517d51e6ee5f66575724fe83ba7d6a26dae0 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 13 Apr 2025 14:16:56 +0530 Subject: [PATCH 198/216] add a [JsonProperty("name")] attribute here for consistency with the JSON contract Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- Src/Notion.Client/Models/File/FIleInput/ExternalFileInput.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Src/Notion.Client/Models/File/FIleInput/ExternalFileInput.cs b/Src/Notion.Client/Models/File/FIleInput/ExternalFileInput.cs index 38ad781c..8a602d38 100644 --- a/Src/Notion.Client/Models/File/FIleInput/ExternalFileInput.cs +++ b/Src/Notion.Client/Models/File/FIleInput/ExternalFileInput.cs @@ -8,6 +8,7 @@ public class ExternalFileInput : IFileObjectInput [JsonProperty("external")] public Data External { get; set; } + [JsonProperty("name")] public string Name { get; set; } public IEnumerable Caption { get; set; } From 28d6b212dbd50513734bd0a68d87accf8a38cb2e Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 13 Apr 2025 14:17:18 +0530 Subject: [PATCH 199/216] add a [JsonProperty("caption")] attribute to ensure proper serialization Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- Src/Notion.Client/Models/File/FIleInput/ExternalFileInput.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Src/Notion.Client/Models/File/FIleInput/ExternalFileInput.cs b/Src/Notion.Client/Models/File/FIleInput/ExternalFileInput.cs index 8a602d38..6e2627cf 100644 --- a/Src/Notion.Client/Models/File/FIleInput/ExternalFileInput.cs +++ b/Src/Notion.Client/Models/File/FIleInput/ExternalFileInput.cs @@ -11,6 +11,7 @@ public class ExternalFileInput : IFileObjectInput [JsonProperty("name")] public string Name { get; set; } + [JsonProperty("caption")] public IEnumerable Caption { get; set; } public class Data From dcd3d98d06e503829a6f8e949750419d6e63fe89 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 13 Apr 2025 14:22:07 +0530 Subject: [PATCH 200/216] =?UTF-8?q?add=20a=20comment=20to=20clarify=20why?= =?UTF-8?q?=20the=20file=20name=20is=20expected=20to=20automatically=20hav?= =?UTF-8?q?e=20a=20'.jpg'=20or=20other=20file=20extension=F0=9F=92=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Notion.Client/Models/File/FileObject.cs | 3 +++ Test/Notion.IntegrationTests/BlocksClientTests.cs | 3 +++ 2 files changed, 6 insertions(+) diff --git a/Src/Notion.Client/Models/File/FileObject.cs b/Src/Notion.Client/Models/File/FileObject.cs index aa7aed1b..0ac30a6c 100644 --- a/Src/Notion.Client/Models/File/FileObject.cs +++ b/Src/Notion.Client/Models/File/FileObject.cs @@ -12,6 +12,9 @@ public abstract class FileObject : IPageIcon [JsonProperty("caption")] public IEnumerable Caption { get; set; } + /// + /// The name of the file block, as shown in the Notion UI. Note that the UI may auto-append .pdf or other extensions. + /// [JsonProperty("name")] public string Name { get; set; } diff --git a/Test/Notion.IntegrationTests/BlocksClientTests.cs b/Test/Notion.IntegrationTests/BlocksClientTests.cs index d52b8f64..5f1ca25b 100644 --- a/Test/Notion.IntegrationTests/BlocksClientTests.cs +++ b/Test/Notion.IntegrationTests/BlocksClientTests.cs @@ -437,7 +437,10 @@ private static IEnumerable BlockData() fileBlock.HasChildren.Should().BeFalse(); var file = fileBlock.File.Should().NotBeNull().And.BeOfType().Subject; + + // NOTE: The name of the file block, as shown in the Notion UI. Note that the UI may auto-append .pdf or other extensions. file.Name.Should().Be("Test file name.jpg"); + file.External.Should().NotBeNull(); file.External.Url.Should().Be("https://www.iaspaper.net/wp-content/uploads/2017/09/TNEA-Online-Application.jpg"); file.Caption.Should().NotBeNull().And.ContainSingle() From 19568ad2eb99b3f5eab0a8dbf76a1e7021f48acd Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 13 Apr 2025 15:17:23 +0530 Subject: [PATCH 201/216] Create dependabot.yml --- .github/dependabot.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..331a95d5 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,14 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file + +version: 2 +updates: + - package-ecosystem: "nuget" # See documentation for possible values + directory: "/" # Location of package manifests + schedule: + interval: "weekly" + open-pull-requests-limit: 10 + commit-message: + prefix: "deps" From 419bd1f55948a4a925da42a65174bcd80ffcb578 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 13 Apr 2025 09:59:31 +0000 Subject: [PATCH 202/216] deps: bump coverlet.collector from 1.3.0 to 6.0.4 Bumps [coverlet.collector](https://github.com/coverlet-coverage/coverlet) from 1.3.0 to 6.0.4. - [Release notes](https://github.com/coverlet-coverage/coverlet/releases) - [Commits](https://github.com/coverlet-coverage/coverlet/commits/v6.0.4) --- updated-dependencies: - dependency-name: coverlet.collector dependency-version: 6.0.4 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- Test/Notion.UnitTests/Notion.UnitTests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Test/Notion.UnitTests/Notion.UnitTests.csproj b/Test/Notion.UnitTests/Notion.UnitTests.csproj index 588ddc54..60bbd3ff 100644 --- a/Test/Notion.UnitTests/Notion.UnitTests.csproj +++ b/Test/Notion.UnitTests/Notion.UnitTests.csproj @@ -16,7 +16,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all From 85ebe93d52b59557e520362695abc0e950b4d3eb Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 13 Apr 2025 15:30:10 +0530 Subject: [PATCH 203/216] Bump version to 4.3.0 --- Src/Notion.Client/Notion.Client.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Src/Notion.Client/Notion.Client.csproj b/Src/Notion.Client/Notion.Client.csproj index c7e96e08..3e353339 100644 --- a/Src/Notion.Client/Notion.Client.csproj +++ b/Src/Notion.Client/Notion.Client.csproj @@ -1,7 +1,7 @@  - 4.2.0-preview + 4.3.0-preview netstandard2.0 9.0 From d0f1eac7bbd51e251219cbb28bb2d52af2b75b34 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 13 Apr 2025 16:04:02 +0530 Subject: [PATCH 204/216] update outdated actions in publish code workflow --- .github/workflows/publish-code.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish-code.yml b/.github/workflows/publish-code.yml index ef76a197..2073a733 100644 --- a/.github/workflows/publish-code.yml +++ b/.github/workflows/publish-code.yml @@ -36,7 +36,7 @@ jobs: dotnet pack --no-restore --no-build -o PackOutputs -c Release -p:Version=${{ github.event.release.tag_name }} -p:PackageReleaseNotes="See https://github.com/notion-dotnet/notion-sdk-net/releases/tag/${{ github.event.release.tag_name }}" -p:PackageReadmeFile=README.md - name: Upload artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: Notion.Net path: PackOutputs/* @@ -45,7 +45,7 @@ jobs: run: dotnet nuget push PackOutputs/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} - name: Upload Nuget packages as release artifacts - uses: actions/github-script@v2 + uses: actions/github-script@v7 with: github-token: ${{secrets.GITHUB_TOKEN}} script: | From d6947cca04a07e600079dc999d6aa0b67f3f293f Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 13 Apr 2025 16:11:57 +0530 Subject: [PATCH 205/216] update test publish code github workflow --- .github/workflows/test-publish-code.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-publish-code.yml b/.github/workflows/test-publish-code.yml index e90afd73..ce6974e6 100644 --- a/.github/workflows/test-publish-code.yml +++ b/.github/workflows/test-publish-code.yml @@ -45,7 +45,7 @@ jobs: ls -l PackOutputs/ - name: Upload artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: Notion.Net path: PackOutputs/* From ae01e9e253a22bf74cc470353a01136e1e7ceacf Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Tue, 15 Apr 2025 06:45:37 +0530 Subject: [PATCH 206/216] workflow to greet first-time contributors --- .github/workflows/greetings.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/greetings.yml diff --git a/.github/workflows/greetings.yml b/.github/workflows/greetings.yml new file mode 100644 index 00000000..55a63c2c --- /dev/null +++ b/.github/workflows/greetings.yml @@ -0,0 +1,23 @@ +name: Greetings + +on: [pull_request_target, issues] + +jobs: + greet-first-time-contributors: + name: Greet First-Time Contributors + runs-on: ubuntu-latest + permissions: + issues: write + pull-requests: write + + steps: + - name: Send greeting to first-time contributors + uses: actions/first-interaction@v1 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + issue-message: > + 👋 Hi there! Thanks for opening your first issue in this repository. + We appreciate your contribution. A maintainer will take a look soon. + pr-message: > + 🎉 Thanks for your first pull request! + The team will review it shortly. We’re excited to have you contribute! From 8a69e7d26725bd1f39058fbd4a8bbcc1421e0739 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 13 Apr 2025 09:57:03 +0000 Subject: [PATCH 207/216] deps: bump Microsoft.SourceLink.GitHub from 1.1.1 to 8.0.0 Bumps [Microsoft.SourceLink.GitHub](https://github.com/dotnet/sourcelink) from 1.1.1 to 8.0.0. - [Release notes](https://github.com/dotnet/sourcelink/releases) - [Commits](https://github.com/dotnet/sourcelink/compare/1.1.1...8.0.0) --- updated-dependencies: - dependency-name: Microsoft.SourceLink.GitHub dependency-version: 8.0.0 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- Src/Notion.Client/Notion.Client.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Src/Notion.Client/Notion.Client.csproj b/Src/Notion.Client/Notion.Client.csproj index 3e353339..2a6555c3 100644 --- a/Src/Notion.Client/Notion.Client.csproj +++ b/Src/Notion.Client/Notion.Client.csproj @@ -1,4 +1,4 @@ - + 4.3.0-preview @@ -16,7 +16,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive From d9c3cd2cc23fa4f2457fa249dae2ea7286c25d16 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 13 Apr 2025 09:57:44 +0000 Subject: [PATCH 208/216] deps: bump Microsoft.NET.Test.Sdk from 16.7.1 to 17.13.0 Bumps [Microsoft.NET.Test.Sdk](https://github.com/microsoft/vstest) from 16.7.1 to 17.13.0. - [Release notes](https://github.com/microsoft/vstest/releases) - [Changelog](https://github.com/microsoft/vstest/blob/main/docs/releases.md) - [Commits](https://github.com/microsoft/vstest/compare/v16.7.1...v17.13.0) --- updated-dependencies: - dependency-name: Microsoft.NET.Test.Sdk dependency-version: 17.13.0 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- Test/Notion.UnitTests/Notion.UnitTests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Test/Notion.UnitTests/Notion.UnitTests.csproj b/Test/Notion.UnitTests/Notion.UnitTests.csproj index 588ddc54..ef5c1d34 100644 --- a/Test/Notion.UnitTests/Notion.UnitTests.csproj +++ b/Test/Notion.UnitTests/Notion.UnitTests.csproj @@ -8,7 +8,7 @@ - + From 966f95893fca1c855f136d536746bb26dfa0ff95 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 13 Apr 2025 10:00:14 +0000 Subject: [PATCH 209/216] deps: bump xunit.runner.visualstudio from 2.4.3 to 3.0.2 Bumps [xunit.runner.visualstudio](https://github.com/xunit/visualstudio.xunit) from 2.4.3 to 3.0.2. - [Release notes](https://github.com/xunit/visualstudio.xunit/releases) - [Commits](https://github.com/xunit/visualstudio.xunit/compare/2.4.3...3.0.2) --- updated-dependencies: - dependency-name: xunit.runner.visualstudio dependency-version: 3.0.2 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- Test/Notion.IntegrationTests/Notion.IntegrationTests.csproj | 2 +- Test/Notion.UnitTests/Notion.UnitTests.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Test/Notion.IntegrationTests/Notion.IntegrationTests.csproj b/Test/Notion.IntegrationTests/Notion.IntegrationTests.csproj index 42a1975a..1284ee3f 100644 --- a/Test/Notion.IntegrationTests/Notion.IntegrationTests.csproj +++ b/Test/Notion.IntegrationTests/Notion.IntegrationTests.csproj @@ -15,7 +15,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/Test/Notion.UnitTests/Notion.UnitTests.csproj b/Test/Notion.UnitTests/Notion.UnitTests.csproj index 2da01ae8..f04f3c8e 100644 --- a/Test/Notion.UnitTests/Notion.UnitTests.csproj +++ b/Test/Notion.UnitTests/Notion.UnitTests.csproj @@ -12,7 +12,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all From 744229db390be105aa419074f45e23d30ed6daa7 Mon Sep 17 00:00:00 2001 From: Mr-Bally <25254611+Mr-Bally@users.noreply.github.com> Date: Tue, 15 Apr 2025 10:39:47 +0000 Subject: [PATCH 210/216] Added revoke functionality --- Src/Notion.Client/Api/ApiEndpoints.cs | 1 + .../Authentication/IAuthenticationClient.cs | 11 ++++++++++ .../RevokeToken/AuthenticationClient.cs | 21 +++++++++++++++++++ .../Request/IRevokeTokenBodyParameters.cs | 13 ++++++++++++ .../RevokeToken/Request/RevokeTokenRequest.cs | 7 +++++++ 5 files changed, 53 insertions(+) create mode 100644 Src/Notion.Client/Api/Authentication/RevokeToken/AuthenticationClient.cs create mode 100644 Src/Notion.Client/Api/Authentication/RevokeToken/Request/IRevokeTokenBodyParameters.cs create mode 100644 Src/Notion.Client/Api/Authentication/RevokeToken/Request/RevokeTokenRequest.cs diff --git a/Src/Notion.Client/Api/ApiEndpoints.cs b/Src/Notion.Client/Api/ApiEndpoints.cs index 4ed80bb1..86d703b3 100644 --- a/Src/Notion.Client/Api/ApiEndpoints.cs +++ b/Src/Notion.Client/Api/ApiEndpoints.cs @@ -135,6 +135,7 @@ public static string Create() public static class AuthenticationUrls { public static string CreateToken() => "/v1/oauth/token"; + public static string RevokeToken() => "/v1/oauth/revoke"; } } } diff --git a/Src/Notion.Client/Api/Authentication/IAuthenticationClient.cs b/Src/Notion.Client/Api/Authentication/IAuthenticationClient.cs index 0b4ebeb8..2aa3e7a8 100644 --- a/Src/Notion.Client/Api/Authentication/IAuthenticationClient.cs +++ b/Src/Notion.Client/Api/Authentication/IAuthenticationClient.cs @@ -18,5 +18,16 @@ Task CreateTokenAsync( CreateTokenRequest createTokenRequest, CancellationToken cancellationToken = default ); + + /// + /// Revokes an access token. + /// + /// + /// + /// + Task RevokeTokenAsync( + RevokeTokenRequest revokeTokenRequest, + CancellationToken cancellationToken = default + ); } } diff --git a/Src/Notion.Client/Api/Authentication/RevokeToken/AuthenticationClient.cs b/Src/Notion.Client/Api/Authentication/RevokeToken/AuthenticationClient.cs new file mode 100644 index 00000000..8cc5c85e --- /dev/null +++ b/Src/Notion.Client/Api/Authentication/RevokeToken/AuthenticationClient.cs @@ -0,0 +1,21 @@ +using System.Threading; +using System.Threading.Tasks; + +namespace Notion.Client +{ + public sealed partial class AuthenticationClient + { + public async Task RevokeTokenAsync( + RevokeTokenRequest revokeTokenRequest, + CancellationToken cancellationToken = default) + { + var body = (IRevokeTokenBodyParameters)revokeTokenRequest; + + return (await _client.PostAsync( + ApiEndpoints.AuthenticationUrls.RevokeToken(), + body, + cancellationToken: cancellationToken + )).StatusCode; + } + } +} diff --git a/Src/Notion.Client/Api/Authentication/RevokeToken/Request/IRevokeTokenBodyParameters.cs b/Src/Notion.Client/Api/Authentication/RevokeToken/Request/IRevokeTokenBodyParameters.cs new file mode 100644 index 00000000..0a194516 --- /dev/null +++ b/Src/Notion.Client/Api/Authentication/RevokeToken/Request/IRevokeTokenBodyParameters.cs @@ -0,0 +1,13 @@ +using Newtonsoft.Json; + +namespace Notion.Client +{ + public interface IRevokeTokenBodyParameters + { + /// + /// The token to be revoked. + /// + [JsonProperty("token")] + string Token { get; set; } + } +} diff --git a/Src/Notion.Client/Api/Authentication/RevokeToken/Request/RevokeTokenRequest.cs b/Src/Notion.Client/Api/Authentication/RevokeToken/Request/RevokeTokenRequest.cs new file mode 100644 index 00000000..7e92ca01 --- /dev/null +++ b/Src/Notion.Client/Api/Authentication/RevokeToken/Request/RevokeTokenRequest.cs @@ -0,0 +1,7 @@ +namespace Notion.Client +{ + public class RevokeTokenRequest : IRevokeTokenBodyParameters + { + public string Token { get; set; } + } +} From a96af1ab55464f49fd03acdbe630a02fec6766e8 Mon Sep 17 00:00:00 2001 From: Sam-Ballantyne <25254611+Sam-Ballantyne@users.noreply.github.com> Date: Wed, 16 Apr 2025 10:25:02 +0100 Subject: [PATCH 211/216] Updates from PR review --- .../Authentication/IAuthenticationClient.cs | 4 ++-- .../RevokeToken/AuthenticationClient.cs | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Src/Notion.Client/Api/Authentication/IAuthenticationClient.cs b/Src/Notion.Client/Api/Authentication/IAuthenticationClient.cs index 2aa3e7a8..1973638f 100644 --- a/Src/Notion.Client/Api/Authentication/IAuthenticationClient.cs +++ b/Src/Notion.Client/Api/Authentication/IAuthenticationClient.cs @@ -18,14 +18,14 @@ Task CreateTokenAsync( CreateTokenRequest createTokenRequest, CancellationToken cancellationToken = default ); - + /// /// Revokes an access token. /// /// /// /// - Task RevokeTokenAsync( + Task RevokeTokenAsync( RevokeTokenRequest revokeTokenRequest, CancellationToken cancellationToken = default ); diff --git a/Src/Notion.Client/Api/Authentication/RevokeToken/AuthenticationClient.cs b/Src/Notion.Client/Api/Authentication/RevokeToken/AuthenticationClient.cs index 8cc5c85e..d9087aa4 100644 --- a/Src/Notion.Client/Api/Authentication/RevokeToken/AuthenticationClient.cs +++ b/Src/Notion.Client/Api/Authentication/RevokeToken/AuthenticationClient.cs @@ -1,21 +1,30 @@ +using System.Net.Http; using System.Threading; using System.Threading.Tasks; namespace Notion.Client { public sealed partial class AuthenticationClient - { - public async Task RevokeTokenAsync( + { + public async Task RevokeTokenAsync( RevokeTokenRequest revokeTokenRequest, CancellationToken cancellationToken = default) { var body = (IRevokeTokenBodyParameters)revokeTokenRequest; - - return (await _client.PostAsync( + + var response = await _client.PostAsync( ApiEndpoints.AuthenticationUrls.RevokeToken(), body, cancellationToken: cancellationToken - )).StatusCode; + ); + + if (!response.IsSuccessStatusCode) + { + throw new NotionApiException(response.StatusCode, + null, + "None success status code returned from revoke endpoint" + ); + } } } } From 0a9ed73fe62e9ecbc653a957978dea760c4f4d6b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 17 Apr 2025 11:53:18 +0000 Subject: [PATCH 212/216] deps: bump Microsoft.VisualStudio.VsixColorCompiler Bumps Microsoft.VisualStudio.VsixColorCompiler from 16.0.0 to 17.11.35325.10. --- updated-dependencies: - dependency-name: Microsoft.VisualStudio.VsixColorCompiler dependency-version: 17.11.35325.10 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- Test/Notion.UnitTests/Notion.UnitTests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Test/Notion.UnitTests/Notion.UnitTests.csproj b/Test/Notion.UnitTests/Notion.UnitTests.csproj index f04f3c8e..6a33f5c0 100644 --- a/Test/Notion.UnitTests/Notion.UnitTests.csproj +++ b/Test/Notion.UnitTests/Notion.UnitTests.csproj @@ -9,7 +9,7 @@ - + From 0cc805772d78e0a4b7f2ad8d18992d8889bcf67b Mon Sep 17 00:00:00 2001 From: Mr-Bally <25254611+Mr-Bally@users.noreply.github.com> Date: Thu, 17 Apr 2025 16:24:51 +0100 Subject: [PATCH 213/216] Update from PR review --- .../Authentication/RevokeToken/AuthenticationClient.cs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/Src/Notion.Client/Api/Authentication/RevokeToken/AuthenticationClient.cs b/Src/Notion.Client/Api/Authentication/RevokeToken/AuthenticationClient.cs index d9087aa4..0d67057b 100644 --- a/Src/Notion.Client/Api/Authentication/RevokeToken/AuthenticationClient.cs +++ b/Src/Notion.Client/Api/Authentication/RevokeToken/AuthenticationClient.cs @@ -12,19 +12,11 @@ public async Task RevokeTokenAsync( { var body = (IRevokeTokenBodyParameters)revokeTokenRequest; - var response = await _client.PostAsync( + await _client.PostAsync( ApiEndpoints.AuthenticationUrls.RevokeToken(), body, cancellationToken: cancellationToken ); - - if (!response.IsSuccessStatusCode) - { - throw new NotionApiException(response.StatusCode, - null, - "None success status code returned from revoke endpoint" - ); - } } } } From bb62d1e3b5ec057fc951d46d8cc964e1f790700e Mon Sep 17 00:00:00 2001 From: Mr-Bally <25254611+Mr-Bally@users.noreply.github.com> Date: Thu, 17 Apr 2025 16:52:20 +0100 Subject: [PATCH 214/216] Added empty object for HttpClient --- .../Api/Authentication/RevokeToken/AuthenticationClient.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Src/Notion.Client/Api/Authentication/RevokeToken/AuthenticationClient.cs b/Src/Notion.Client/Api/Authentication/RevokeToken/AuthenticationClient.cs index 0d67057b..2c4d2c28 100644 --- a/Src/Notion.Client/Api/Authentication/RevokeToken/AuthenticationClient.cs +++ b/Src/Notion.Client/Api/Authentication/RevokeToken/AuthenticationClient.cs @@ -12,11 +12,15 @@ public async Task RevokeTokenAsync( { var body = (IRevokeTokenBodyParameters)revokeTokenRequest; - await _client.PostAsync( + await _client.PostAsync( ApiEndpoints.AuthenticationUrls.RevokeToken(), body, cancellationToken: cancellationToken ); } } + + internal class RevokeTokenResponse + { + } } From c7349ed96f35d1f38633dfa9788bac05c72b195f Mon Sep 17 00:00:00 2001 From: Sam-Ballantyne <25254611+Sam-Ballantyne@users.noreply.github.com> Date: Thu, 17 Apr 2025 18:45:15 +0100 Subject: [PATCH 215/216] moved class into separate file --- .../Api/Authentication/RevokeToken/AuthenticationClient.cs | 5 ----- .../RevokeToken/Response/RevokeTokenResponse.cs | 6 ++++++ 2 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 Src/Notion.Client/Api/Authentication/RevokeToken/Response/RevokeTokenResponse.cs diff --git a/Src/Notion.Client/Api/Authentication/RevokeToken/AuthenticationClient.cs b/Src/Notion.Client/Api/Authentication/RevokeToken/AuthenticationClient.cs index 2c4d2c28..c1f3ab9d 100644 --- a/Src/Notion.Client/Api/Authentication/RevokeToken/AuthenticationClient.cs +++ b/Src/Notion.Client/Api/Authentication/RevokeToken/AuthenticationClient.cs @@ -1,4 +1,3 @@ -using System.Net.Http; using System.Threading; using System.Threading.Tasks; @@ -19,8 +18,4 @@ await _client.PostAsync( ); } } - - internal class RevokeTokenResponse - { - } } diff --git a/Src/Notion.Client/Api/Authentication/RevokeToken/Response/RevokeTokenResponse.cs b/Src/Notion.Client/Api/Authentication/RevokeToken/Response/RevokeTokenResponse.cs new file mode 100644 index 00000000..428dd287 --- /dev/null +++ b/Src/Notion.Client/Api/Authentication/RevokeToken/Response/RevokeTokenResponse.cs @@ -0,0 +1,6 @@ +namespace Notion.Client +{ + internal class RevokeTokenResponse + { + } +} From 237bb13e5656bd010f25839f10b12515d866d828 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sat, 19 Apr 2025 06:06:11 +0530 Subject: [PATCH 216/216] remove lgtm yaml and links --- README.md | 3 --- lgtm.yml | 6 ------ 2 files changed, 9 deletions(-) delete mode 100644 lgtm.yml diff --git a/README.md b/README.md index 5ab47338..d74a4cc6 100644 --- a/README.md +++ b/README.md @@ -14,9 +14,6 @@ [![Publish Code](https://github.com/notion-dotnet/notion-sdk-net/actions/workflows/publish-code.yml/badge.svg)](https://github.com/notion-dotnet/notion-sdk-net/actions/workflows/publish-code.yml) [![CodeQL](https://github.com/notion-dotnet/notion-sdk-net/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/notion-dotnet/notion-sdk-net/actions/workflows/codeql-analysis.yml) -[![LGTM Alerts](https://img.shields.io/lgtm/alerts/github/notion-dotnet/notion-sdk-net)](https://lgtm.com/projects/g/notion-dotnet/notion-sdk-net/alerts/?mode=list) -[![LGTM Grade](https://img.shields.io/lgtm/grade/csharp/github/notion-dotnet/notion-sdk-net)](https://lgtm.com/projects/g/notion-dotnet/notion-sdk-net/alerts/?mode=list) - [![GitHub last commit](https://img.shields.io/github/last-commit/notion-dotnet/notion-sdk-net)]() [![GitHub commit activity](https://img.shields.io/github/commit-activity/w/notion-dotnet/notion-sdk-net)]() [![GitHub commit activity](https://img.shields.io/github/commit-activity/m/notion-dotnet/notion-sdk-net)]() diff --git a/lgtm.yml b/lgtm.yml deleted file mode 100644 index 5d5e1e4f..00000000 --- a/lgtm.yml +++ /dev/null @@ -1,6 +0,0 @@ -extraction: - csharp: - index: - all_solutions: true - dotnet: - version: 6.0.400