diff --git a/Src/Notion.Client/Api/Blocks/BlocksClient.cs b/Src/Notion.Client/Api/Blocks/BlocksClient.cs index 4c038cc5..cc06642e 100644 --- a/Src/Notion.Client/Api/Blocks/BlocksClient.cs +++ b/Src/Notion.Client/Api/Blocks/BlocksClient.cs @@ -14,7 +14,7 @@ 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)) { @@ -31,10 +31,10 @@ public async Task> RetrieveChildrenAsync(string blockId, Bl { "page_size", queryParameters?.PageSize?.ToString() } }; - return await _client.GetAsync>(url, queryParams); + 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)) { @@ -45,10 +45,10 @@ public async Task> AppendChildrenAsync(string blockId, Bloc var body = (IBlocksAppendChildrenBodyParameters)parameters; - return await _client.PatchAsync>(url, body); + return await _client.PatchAsync>(url, body); } - public async Task RetrieveAsync(string blockId) + public async Task RetrieveAsync(string blockId) { if (string.IsNullOrWhiteSpace(blockId)) { @@ -57,10 +57,10 @@ public async Task RetrieveAsync(string blockId) var url = BlocksApiUrls.Retrieve(blockId); - return await _client.GetAsync(url); + return await _client.GetAsync(url); } - public async Task UpdateAsync(string blockId, IUpdateBlock updateBlock) + public async Task UpdateAsync(string blockId, IUpdateBlock updateBlock) { if (string.IsNullOrWhiteSpace(blockId)) { @@ -69,7 +69,7 @@ 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); } public async Task DeleteAsync(string blockId) diff --git a/Src/Notion.Client/Api/Blocks/IBlocksClient.cs b/Src/Notion.Client/Api/Blocks/IBlocksClient.cs index 4c088803..90ebf073 100644 --- a/Src/Notion.Client/Api/Blocks/IBlocksClient.cs +++ b/Src/Notion.Client/Api/Blocks/IBlocksClient.cs @@ -9,7 +9,7 @@ public interface IBlocksClient /// /// /// Block - Task RetrieveAsync(string blockId); + Task RetrieveAsync(string blockId); /// /// Updates the content for the specified block_id based on the block type. @@ -17,9 +17,9 @@ public interface IBlocksClient /// /// /// Block - Task UpdateAsync(string blockId, IUpdateBlock updateBlock); + 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. @@ -27,7 +27,7 @@ public interface IBlocksClient /// 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. diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksAppendChildrenParameters.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksAppendChildrenParameters.cs index a2ad3440..e78899bb 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksAppendChildrenParameters.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksAppendChildrenParameters.cs @@ -4,6 +4,6 @@ namespace Notion.Client { public class BlocksAppendChildrenParameters : IBlocksAppendChildrenBodyParameters { - public IEnumerable Children { get; set; } + public IEnumerable Children { get; set; } } } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/IBlocksAppendChildrenBodyParameters.cs b/Src/Notion.Client/Api/Blocks/RequestParams/IBlocksAppendChildrenBodyParameters.cs index 33b0ca0f..bdd4d324 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/IBlocksAppendChildrenBodyParameters.cs +++ b/Src/Notion.Client/Api/Blocks/RequestParams/IBlocksAppendChildrenBodyParameters.cs @@ -7,6 +7,6 @@ namespace Notion.Client public interface IBlocksAppendChildrenBodyParameters { [JsonProperty("children")] - IEnumerable Children { get; set; } + IEnumerable Children { get; set; } } } diff --git a/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/IPagesCreateBodyParameters.cs b/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/IPagesCreateBodyParameters.cs index 7e275bfc..9b9f0631 100644 --- a/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/IPagesCreateBodyParameters.cs +++ b/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/IPagesCreateBodyParameters.cs @@ -12,7 +12,7 @@ public interface IPagesCreateBodyParameters IDictionary Properties { get; set; } [JsonProperty("children")] - IList Children { get; set; } + IList Children { get; set; } [JsonProperty("icon")] IPageIcon Icon { get; set; } diff --git a/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParameters.cs b/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParameters.cs index 49b8f44d..52cb0a89 100644 --- a/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParameters.cs +++ b/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParameters.cs @@ -6,7 +6,7 @@ public class PagesCreateParameters : IPagesCreateBodyParameters, IPagesCreateQue { public IPageParentInput Parent { get; set; } public IDictionary Properties { get; set; } - public IList Children { 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 02e5b57b..b86a207a 100644 --- a/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParametersBuilder.cs +++ b/Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParametersBuilder.cs @@ -6,7 +6,7 @@ public class PagesCreateParametersBuilder { private IPageParentInput parent; private readonly Dictionary properties = new Dictionary(); - private readonly IList children = new List(); + private readonly IList children = new List(); private IPageIcon icon; private FileObject cover; @@ -28,7 +28,7 @@ public PagesCreateParametersBuilder AddProperty(string nameOrId, PropertyValue v return this; } - public PagesCreateParametersBuilder AddPageContent(Block block) + public PagesCreateParametersBuilder AddPageContent(IBlock block) { children.Add(block); return this; diff --git a/Src/Notion.Client/Models/Blocks/AudioBlock.cs b/Src/Notion.Client/Models/Blocks/AudioBlock.cs index b43bbc9c..040f346b 100644 --- a/Src/Notion.Client/Models/Blocks/AudioBlock.cs +++ b/Src/Notion.Client/Models/Blocks/AudioBlock.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - public class AudioBlock : Block + public class AudioBlock : Block, IColumnChildrenBlock, INonColumnBlock { 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 c0687860..9ba90612 100644 --- a/Src/Notion.Client/Models/Blocks/Block.cs +++ b/Src/Notion.Client/Models/Blocks/Block.cs @@ -1,50 +1,17 @@ -using JsonSubTypes; -using Newtonsoft.Json; -using Newtonsoft.Json.Converters; - -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(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(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 class Block : IObject + public abstract class Block : IBlock { public ObjectType Object => ObjectType.Block; + public string Id { get; set; } - [JsonProperty("type")] - [JsonConverter(typeof(StringEnumConverter))] public virtual BlockType Type { get; set; } - [JsonProperty("created_time")] public string CreatedTime { get; set; } - [JsonProperty("last_edited_time")] public string LastEditedTime { get; set; } - [JsonProperty("has_children")] public virtual bool HasChildren { get; set; } } } diff --git a/Src/Notion.Client/Models/Blocks/BlockType.cs b/Src/Notion.Client/Models/Blocks/BlockType.cs index 1c353686..b46e6c9a 100644 --- a/Src/Notion.Client/Models/Blocks/BlockType.cs +++ b/Src/Notion.Client/Models/Blocks/BlockType.cs @@ -76,6 +76,12 @@ public enum BlockType [EnumMember(Value = "quote")] Quote, + [EnumMember(Value = "column")] + Column, + + [EnumMember(Value = "column_list")] + ColumnList, + [EnumMember(Value = "unsupported")] Unsupported } diff --git a/Src/Notion.Client/Models/Blocks/BookmarkBlock.cs b/Src/Notion.Client/Models/Blocks/BookmarkBlock.cs index c0380b73..735b1725 100644 --- a/Src/Notion.Client/Models/Blocks/BookmarkBlock.cs +++ b/Src/Notion.Client/Models/Blocks/BookmarkBlock.cs @@ -3,7 +3,7 @@ namespace Notion.Client { - public class BookmarkBlock : Block + public class BookmarkBlock : Block, IColumnChildrenBlock, INonColumnBlock { public override BlockType Type => BlockType.Bookmark; diff --git a/Src/Notion.Client/Models/Blocks/BreadcrumbBlock.cs b/Src/Notion.Client/Models/Blocks/BreadcrumbBlock.cs index 197122bc..73ae614d 100644 --- a/Src/Notion.Client/Models/Blocks/BreadcrumbBlock.cs +++ b/Src/Notion.Client/Models/Blocks/BreadcrumbBlock.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - public class BreadcrumbBlock : Block + public class BreadcrumbBlock : Block, IColumnChildrenBlock, INonColumnBlock { public override BlockType Type => BlockType.Breadcrumb; diff --git a/Src/Notion.Client/Models/Blocks/BulletedListItemBlock.cs b/Src/Notion.Client/Models/Blocks/BulletedListItemBlock.cs index c787da86..15d168af 100644 --- a/Src/Notion.Client/Models/Blocks/BulletedListItemBlock.cs +++ b/Src/Notion.Client/Models/Blocks/BulletedListItemBlock.cs @@ -3,7 +3,7 @@ namespace Notion.Client { - public class BulletedListItemBlock : Block + public class BulletedListItemBlock : Block, IColumnChildrenBlock, INonColumnBlock { public override BlockType Type => BlockType.BulletedListItem; @@ -16,7 +16,7 @@ public class Info public IEnumerable Text { get; set; } [JsonProperty("children")] - public IEnumerable Children { get; set; } + public IEnumerable Children { get; set; } } } } diff --git a/Src/Notion.Client/Models/Blocks/CalloutBlock.cs b/Src/Notion.Client/Models/Blocks/CalloutBlock.cs index 7c355a21..9fed148a 100644 --- a/Src/Notion.Client/Models/Blocks/CalloutBlock.cs +++ b/Src/Notion.Client/Models/Blocks/CalloutBlock.cs @@ -3,7 +3,7 @@ namespace Notion.Client { - public class CalloutBlock : Block + public class CalloutBlock : Block, IColumnChildrenBlock, INonColumnBlock { public override BlockType Type => BlockType.Callout; @@ -19,7 +19,7 @@ public class Info public IPageIcon Icon { get; set; } [JsonProperty("children")] - public IEnumerable Children { get; set; } + public IEnumerable Children { get; set; } } } } diff --git a/Src/Notion.Client/Models/Blocks/ChildDatabaseBlock.cs b/Src/Notion.Client/Models/Blocks/ChildDatabaseBlock.cs index eb4577b7..273836a9 100644 --- a/Src/Notion.Client/Models/Blocks/ChildDatabaseBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ChildDatabaseBlock.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - public class ChildDatabaseBlock : Block + public class ChildDatabaseBlock : Block, IColumnChildrenBlock, INonColumnBlock { public override BlockType Type => BlockType.ChildDatabase; diff --git a/Src/Notion.Client/Models/Blocks/ChildPageBlock.cs b/Src/Notion.Client/Models/Blocks/ChildPageBlock.cs index 9fdc4b7b..91c8f343 100644 --- a/Src/Notion.Client/Models/Blocks/ChildPageBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ChildPageBlock.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - public class ChildPageBlock : Block + public class ChildPageBlock : Block, IColumnChildrenBlock, INonColumnBlock { public override BlockType Type => BlockType.ChildPage; diff --git a/Src/Notion.Client/Models/Blocks/CodeBlock.cs b/Src/Notion.Client/Models/Blocks/CodeBlock.cs index 58ac5d6a..7eb4205d 100644 --- a/Src/Notion.Client/Models/Blocks/CodeBlock.cs +++ b/Src/Notion.Client/Models/Blocks/CodeBlock.cs @@ -3,7 +3,7 @@ namespace Notion.Client { - public class CodeBlock : Block + public class CodeBlock : Block, IColumnChildrenBlock, INonColumnBlock { public override BlockType Type => BlockType.Code; diff --git a/Src/Notion.Client/Models/Blocks/ColumnBlock.cs b/Src/Notion.Client/Models/Blocks/ColumnBlock.cs new file mode 100644 index 00000000..72cf2f3c --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/ColumnBlock.cs @@ -0,0 +1,19 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class ColumnBlock : Block + { + 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/ColumnListBlock.cs b/Src/Notion.Client/Models/Blocks/ColumnListBlock.cs new file mode 100644 index 00000000..f86ecba0 --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/ColumnListBlock.cs @@ -0,0 +1,19 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class ColumnListBlock : Block, INonColumnBlock + { + public override BlockType Type => BlockType.ColumnList; + + [JsonProperty("column_list")] + public Info ColumnList { get; set; } + + public class Info + { + [JsonProperty("children")] + public IEnumerable Children { get; set; } + } + } +} diff --git a/Src/Notion.Client/Models/Blocks/DividerBlock.cs b/Src/Notion.Client/Models/Blocks/DividerBlock.cs index 1b7bb447..61e0301b 100644 --- a/Src/Notion.Client/Models/Blocks/DividerBlock.cs +++ b/Src/Notion.Client/Models/Blocks/DividerBlock.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - public class DividerBlock : Block + public class DividerBlock : Block, IColumnChildrenBlock, INonColumnBlock { public override BlockType Type => BlockType.Divider; diff --git a/Src/Notion.Client/Models/Blocks/EmbedBlock.cs b/Src/Notion.Client/Models/Blocks/EmbedBlock.cs index 5b3f715f..8332b683 100644 --- a/Src/Notion.Client/Models/Blocks/EmbedBlock.cs +++ b/Src/Notion.Client/Models/Blocks/EmbedBlock.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - public class EmbedBlock : Block + public class EmbedBlock : Block, IColumnChildrenBlock, INonColumnBlock { public override BlockType Type => BlockType.Embed; diff --git a/Src/Notion.Client/Models/Blocks/EquationBlock.cs b/Src/Notion.Client/Models/Blocks/EquationBlock.cs index 79585539..310a76df 100644 --- a/Src/Notion.Client/Models/Blocks/EquationBlock.cs +++ b/Src/Notion.Client/Models/Blocks/EquationBlock.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - public class EquationBlock : Block + public class EquationBlock : Block, IColumnChildrenBlock, INonColumnBlock { public override BlockType Type => BlockType.Equation; diff --git a/Src/Notion.Client/Models/Blocks/FileBlock.cs b/Src/Notion.Client/Models/Blocks/FileBlock.cs index c06533ed..5495e4bc 100644 --- a/Src/Notion.Client/Models/Blocks/FileBlock.cs +++ b/Src/Notion.Client/Models/Blocks/FileBlock.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - public class FileBlock : Block + public class FileBlock : Block, IColumnChildrenBlock, INonColumnBlock { 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 2105cefe..d9c107c3 100644 --- a/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs +++ b/Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs @@ -3,7 +3,7 @@ namespace Notion.Client { - public class HeadingOneBlock : Block + public class HeadingOneBlock : Block, IColumnChildrenBlock, INonColumnBlock { 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 4f1ca0a0..0728f200 100644 --- a/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs +++ b/Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs @@ -3,7 +3,7 @@ namespace Notion.Client { - public class HeadingThreeeBlock : Block + public class HeadingThreeeBlock : Block, IColumnChildrenBlock, INonColumnBlock { 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 5b07e758..c9caec09 100644 --- a/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs +++ b/Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs @@ -3,7 +3,7 @@ namespace Notion.Client { - public class HeadingTwoBlock : Block + public class HeadingTwoBlock : Block, IColumnChildrenBlock, INonColumnBlock { public override BlockType Type => BlockType.Heading_2; diff --git a/Src/Notion.Client/Models/Blocks/IBlock.cs b/Src/Notion.Client/Models/Blocks/IBlock.cs new file mode 100644 index 00000000..e36f371a --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/IBlock.cs @@ -0,0 +1,50 @@ +using JsonSubTypes; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; + +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(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 IBlock : IObject + { + [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/Blocks/IColumnChildrenBlock.cs b/Src/Notion.Client/Models/Blocks/IColumnChildrenBlock.cs new file mode 100644 index 00000000..9eaa5622 --- /dev/null +++ b/Src/Notion.Client/Models/Blocks/IColumnChildrenBlock.cs @@ -0,0 +1,66 @@ +using JsonSubTypes; +using Newtonsoft.Json; + +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 + { + } + + //[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/ImageBlock.cs b/Src/Notion.Client/Models/Blocks/ImageBlock.cs index cead4547..17aa6bae 100644 --- a/Src/Notion.Client/Models/Blocks/ImageBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ImageBlock.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - public class ImageBlock : Block + public class ImageBlock : Block, IColumnChildrenBlock, INonColumnBlock { public override BlockType Type => BlockType.Image; diff --git a/Src/Notion.Client/Models/Blocks/NumberedListItemBlock.cs b/Src/Notion.Client/Models/Blocks/NumberedListItemBlock.cs index 3d233af3..90823f57 100644 --- a/Src/Notion.Client/Models/Blocks/NumberedListItemBlock.cs +++ b/Src/Notion.Client/Models/Blocks/NumberedListItemBlock.cs @@ -3,7 +3,7 @@ namespace Notion.Client { - public class NumberedListItemBlock : Block + public class NumberedListItemBlock : Block, IColumnChildrenBlock, INonColumnBlock { public override BlockType Type => BlockType.NumberedListItem; @@ -16,7 +16,7 @@ public class Info public IEnumerable Text { get; set; } [JsonProperty("children")] - public IEnumerable Children { get; set; } + public IEnumerable Children { get; set; } } } } diff --git a/Src/Notion.Client/Models/Blocks/PDFBlock.cs b/Src/Notion.Client/Models/Blocks/PDFBlock.cs index 84a3a29f..85458796 100644 --- a/Src/Notion.Client/Models/Blocks/PDFBlock.cs +++ b/Src/Notion.Client/Models/Blocks/PDFBlock.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - public class PDFBlock : Block + public class PDFBlock : Block, IColumnChildrenBlock, INonColumnBlock { 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 ebce97a7..4a0b5d07 100644 --- a/Src/Notion.Client/Models/Blocks/ParagraphBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ParagraphBlock.cs @@ -3,7 +3,7 @@ namespace Notion.Client { - public class ParagraphBlock : Block + public class ParagraphBlock : Block, IColumnChildrenBlock, INonColumnBlock { public override BlockType Type => BlockType.Paragraph; @@ -16,7 +16,7 @@ public class Info public IEnumerable Text { get; set; } [JsonProperty("children")] - public IEnumerable Children { get; set; } + public IEnumerable Children { get; set; } } } } diff --git a/Src/Notion.Client/Models/Blocks/QuoteBlock.cs b/Src/Notion.Client/Models/Blocks/QuoteBlock.cs index e7f6d829..3a4c6d9f 100644 --- a/Src/Notion.Client/Models/Blocks/QuoteBlock.cs +++ b/Src/Notion.Client/Models/Blocks/QuoteBlock.cs @@ -3,7 +3,7 @@ namespace Notion.Client { - public class QuoteBlock : Block + public class QuoteBlock : Block, IColumnChildrenBlock, INonColumnBlock { public override BlockType Type => BlockType.Quote; @@ -16,7 +16,7 @@ public class Info public IEnumerable Text { get; set; } [JsonProperty("children")] - public IEnumerable Children { get; set; } + public IEnumerable Children { get; set; } } } } diff --git a/Src/Notion.Client/Models/Blocks/TableOfContentsBlock.cs b/Src/Notion.Client/Models/Blocks/TableOfContentsBlock.cs index fe1e7b2e..49e11bf4 100644 --- a/Src/Notion.Client/Models/Blocks/TableOfContentsBlock.cs +++ b/Src/Notion.Client/Models/Blocks/TableOfContentsBlock.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - public class TableOfContentsBlock : Block + public class TableOfContentsBlock : Block, IColumnChildrenBlock, INonColumnBlock { public override BlockType Type => BlockType.TableOfContents; diff --git a/Src/Notion.Client/Models/Blocks/ToDoBlock.cs b/Src/Notion.Client/Models/Blocks/ToDoBlock.cs index da6518a2..2d033c95 100644 --- a/Src/Notion.Client/Models/Blocks/ToDoBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ToDoBlock.cs @@ -3,7 +3,7 @@ namespace Notion.Client { - public class ToDoBlock : Block + public class ToDoBlock : Block, IColumnChildrenBlock, INonColumnBlock { public override BlockType Type => BlockType.ToDo; @@ -19,7 +19,7 @@ public class Info public bool IsChecked { get; set; } [JsonProperty("children")] - public IEnumerable Children { get; set; } + public IEnumerable Children { get; set; } } } } diff --git a/Src/Notion.Client/Models/Blocks/ToggleBlock.cs b/Src/Notion.Client/Models/Blocks/ToggleBlock.cs index 3da4d6d7..95eef646 100644 --- a/Src/Notion.Client/Models/Blocks/ToggleBlock.cs +++ b/Src/Notion.Client/Models/Blocks/ToggleBlock.cs @@ -3,7 +3,7 @@ namespace Notion.Client { - public class ToggleBlock : Block + public class ToggleBlock : Block, IColumnChildrenBlock, INonColumnBlock { public override BlockType Type => BlockType.Toggle; @@ -16,7 +16,7 @@ public class Info public IEnumerable Text { get; set; } [JsonProperty("children")] - public IEnumerable Children { get; set; } + public IEnumerable Children { get; set; } } } } diff --git a/Src/Notion.Client/Models/Blocks/UnsupportedBlock.cs b/Src/Notion.Client/Models/Blocks/UnsupportedBlock.cs index b275813a..4164d550 100644 --- a/Src/Notion.Client/Models/Blocks/UnsupportedBlock.cs +++ b/Src/Notion.Client/Models/Blocks/UnsupportedBlock.cs @@ -1,6 +1,6 @@ namespace Notion.Client { - public class UnsupportedBlock : Block + public class UnsupportedBlock : Block, IColumnChildrenBlock, INonColumnBlock { public override BlockType Type => BlockType.Unsupported; } diff --git a/Src/Notion.Client/Models/Blocks/VideoBlock.cs b/Src/Notion.Client/Models/Blocks/VideoBlock.cs index 49a1a697..015bed96 100644 --- a/Src/Notion.Client/Models/Blocks/VideoBlock.cs +++ b/Src/Notion.Client/Models/Blocks/VideoBlock.cs @@ -2,7 +2,7 @@ namespace Notion.Client { - public class VideoBlock : Block + public class VideoBlock : Block, IColumnChildrenBlock, INonColumnBlock { public override BlockType Type => BlockType.Video; diff --git a/Src/Notion.Client/Models/IObject.cs b/Src/Notion.Client/Models/IObject.cs index 98f50f3f..2f72f929 100644 --- a/Src/Notion.Client/Models/IObject.cs +++ b/Src/Notion.Client/Models/IObject.cs @@ -7,7 +7,7 @@ namespace Notion.Client [JsonConverter(typeof(JsonSubtypes), "object")] [JsonSubtypes.KnownSubType(typeof(Page), ObjectType.Page)] [JsonSubtypes.KnownSubType(typeof(Database), ObjectType.Database)] - [JsonSubtypes.KnownSubType(typeof(Block), ObjectType.Block)] + [JsonSubtypes.KnownSubType(typeof(IBlock), ObjectType.Block)] [JsonSubtypes.KnownSubType(typeof(User), ObjectType.User)] public interface IObject { diff --git a/Test/Notion.IntegrationTests/IBlocksClientTests.cs b/Test/Notion.IntegrationTests/IBlocksClientTests.cs index 64d9b332..0db08a7c 100644 --- a/Test/Notion.IntegrationTests/IBlocksClientTests.cs +++ b/Test/Notion.IntegrationTests/IBlocksClientTests.cs @@ -40,7 +40,7 @@ public async Task AppendChildrenAsync_AppendsBlocksGivenBlocks() page.Id, new BlocksAppendChildrenParameters { - Children = new List() + Children = new List() { new BreadcrumbBlock { @@ -100,7 +100,7 @@ public async Task UpdateBlockAsync_UpdatesGivenBlock() page.Id, new BlocksAppendChildrenParameters { - Children = new List() + Children = new List() { new BreadcrumbBlock { @@ -141,7 +141,7 @@ public async Task DeleteAsync_DeleteBlockWithGivenId() page.Id, new BlocksAppendChildrenParameters { - Children = new List() + Children = new List() { new DividerBlock { @@ -166,7 +166,7 @@ public async Task DeleteAsync_DeleteBlockWithGivenId() [Theory] [MemberData(nameof(BlockData))] - public async Task UpdateAsync_UpdatesGivenBlock(Block block, IUpdateBlock updateBlock, Action assert) + public async Task UpdateAsync_UpdatesGivenBlock(IBlock block, IUpdateBlock updateBlock, Action assert) { var pageParentId = "3c357473a28149a488c010d2b245a589"; @@ -183,7 +183,7 @@ public async Task UpdateAsync_UpdatesGivenBlock(Block block, IUpdateBlock update page.Id, new BlocksAppendChildrenParameters { - Children = new List() + Children = new List() { block } @@ -245,7 +245,7 @@ private static IEnumerable BlockData() } } }, - new Action((block) => { + 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); @@ -265,7 +265,7 @@ private static IEnumerable BlockData() Expression = "e=mc^2" } }, - new Action((block) => { + new Action((block) => { var updatedBlock = (EquationBlock)block; Assert.Equal("e=mc^2", updatedBlock.Equation.Expression); }) @@ -275,7 +275,7 @@ private static IEnumerable BlockData() Divider = new DividerBlock.Data() }, new DividerUpdateBlock(), - new Action((block) => { + new Action((block) => { Assert.NotNull(block); Assert.IsType(block); }) @@ -295,7 +295,7 @@ private static IEnumerable BlockData() } } }, - new Action((block) => { + new Action((block) => { block.Should().NotBeNull(); block.Should().BeOfType().Subject @@ -309,7 +309,7 @@ private static IEnumerable BlockData() TableOfContents = new TableOfContentsBlock.Data() }, new TableOfContentsUpdateBlock(), - new Action((block) => + new Action((block) => { Assert.NotNull(block); Assert.IsType(block); @@ -349,7 +349,7 @@ private static IEnumerable BlockData() } } }, - new Action((block) => + new Action((block) => { Assert.NotNull(block); var calloutBlock = Assert.IsType(block); @@ -391,7 +391,7 @@ private static IEnumerable BlockData() } } }, - new Action((block) => + new Action((block) => { Assert.NotNull(block); var quoteBlock = Assert.IsType(block); diff --git a/Test/Notion.UnitTests/BlocksClientTests.cs b/Test/Notion.UnitTests/BlocksClientTests.cs index cb1b0f99..3e1a1b53 100644 --- a/Test/Notion.UnitTests/BlocksClientTests.cs +++ b/Test/Notion.UnitTests/BlocksClientTests.cs @@ -59,7 +59,7 @@ public async Task AppendBlockChildren() var parameters = new BlocksAppendChildrenParameters() { - Children = new List + Children = new List { new HeadingTwoBlock() {