Skip to content

Add support for column and column list block types #205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Src/Notion.Client/Api/Blocks/BlocksClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public BlocksClient(IRestClient client)
_client = client;
}

public async Task<PaginatedList<Block>> RetrieveChildrenAsync(string blockId, BlocksRetrieveChildrenParameters parameters = null)
public async Task<PaginatedList<IBlock>> RetrieveChildrenAsync(string blockId, BlocksRetrieveChildrenParameters parameters = null)
{
if (string.IsNullOrWhiteSpace(blockId))
{
Expand All @@ -31,10 +31,10 @@ public async Task<PaginatedList<Block>> RetrieveChildrenAsync(string blockId, Bl
{ "page_size", queryParameters?.PageSize?.ToString() }
};

return await _client.GetAsync<PaginatedList<Block>>(url, queryParams);
return await _client.GetAsync<PaginatedList<IBlock>>(url, queryParams);
}

public async Task<PaginatedList<Block>> AppendChildrenAsync(string blockId, BlocksAppendChildrenParameters parameters = null)
public async Task<PaginatedList<IBlock>> AppendChildrenAsync(string blockId, BlocksAppendChildrenParameters parameters = null)
{
if (string.IsNullOrWhiteSpace(blockId))
{
Expand All @@ -45,10 +45,10 @@ public async Task<PaginatedList<Block>> AppendChildrenAsync(string blockId, Bloc

var body = (IBlocksAppendChildrenBodyParameters)parameters;

return await _client.PatchAsync<PaginatedList<Block>>(url, body);
return await _client.PatchAsync<PaginatedList<IBlock>>(url, body);
}

public async Task<Block> RetrieveAsync(string blockId)
public async Task<IBlock> RetrieveAsync(string blockId)
{
if (string.IsNullOrWhiteSpace(blockId))
{
Expand All @@ -57,10 +57,10 @@ public async Task<Block> RetrieveAsync(string blockId)

var url = BlocksApiUrls.Retrieve(blockId);

return await _client.GetAsync<Block>(url);
return await _client.GetAsync<IBlock>(url);
}

public async Task<Block> UpdateAsync(string blockId, IUpdateBlock updateBlock)
public async Task<IBlock> UpdateAsync(string blockId, IUpdateBlock updateBlock)
{
if (string.IsNullOrWhiteSpace(blockId))
{
Expand All @@ -69,7 +69,7 @@ public async Task<Block> UpdateAsync(string blockId, IUpdateBlock updateBlock)

var url = BlocksApiUrls.Update(blockId);

return await _client.PatchAsync<Block>(url, updateBlock);
return await _client.PatchAsync<IBlock>(url, updateBlock);
}

public async Task DeleteAsync(string blockId)
Expand Down
8 changes: 4 additions & 4 deletions Src/Notion.Client/Api/Blocks/IBlocksClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@ public interface IBlocksClient
/// </summary>
/// <param name="blockId"></param>
/// <returns>Block</returns>
Task<Block> RetrieveAsync(string blockId);
Task<IBlock> RetrieveAsync(string blockId);

/// <summary>
/// Updates the content for the specified block_id based on the block type.
/// </summary>
/// <param name="blockId"></param>
/// <param name="updateBlock"></param>
/// <returns>Block</returns>
Task<Block> UpdateAsync(string blockId, IUpdateBlock updateBlock);
Task<IBlock> UpdateAsync(string blockId, IUpdateBlock updateBlock);

Task<PaginatedList<Block>> RetrieveChildrenAsync(string blockId, BlocksRetrieveChildrenParameters parameters = null);
Task<PaginatedList<IBlock>> RetrieveChildrenAsync(string blockId, BlocksRetrieveChildrenParameters parameters = null);

/// <summary>
/// Creates and appends new children blocks to the parent block_id specified.
/// </summary>
/// <param name="blockId">Identifier for a block</param>
/// <param name="parameters"></param>
/// <returns>A paginated list of newly created first level children block objects.</returns>
Task<PaginatedList<Block>> AppendChildrenAsync(string blockId, BlocksAppendChildrenParameters parameters = null);
Task<PaginatedList<IBlock>> AppendChildrenAsync(string blockId, BlocksAppendChildrenParameters parameters = null);

/// <summary>
/// Sets a Block object, including page blocks, to archived: true using the ID specified.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ namespace Notion.Client
{
public class BlocksAppendChildrenParameters : IBlocksAppendChildrenBodyParameters
{
public IEnumerable<Block> Children { get; set; }
public IEnumerable<IBlock> Children { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ namespace Notion.Client
public interface IBlocksAppendChildrenBodyParameters
{
[JsonProperty("children")]
IEnumerable<Block> Children { get; set; }
IEnumerable<IBlock> Children { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public interface IPagesCreateBodyParameters
IDictionary<string, PropertyValue> Properties { get; set; }

[JsonProperty("children")]
IList<Block> Children { get; set; }
IList<IBlock> Children { get; set; }

[JsonProperty("icon")]
IPageIcon Icon { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class PagesCreateParameters : IPagesCreateBodyParameters, IPagesCreateQue
{
public IPageParentInput Parent { get; set; }
public IDictionary<string, PropertyValue> Properties { get; set; }
public IList<Block> Children { get; set; }
public IList<IBlock> Children { get; set; }
public IPageIcon Icon { get; set; }
public FileObject Cover { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class PagesCreateParametersBuilder
{
private IPageParentInput parent;
private readonly Dictionary<string, PropertyValue> properties = new Dictionary<string, PropertyValue>();
private readonly IList<Block> children = new List<Block>();
private readonly IList<IBlock> children = new List<IBlock>();
private IPageIcon icon;
private FileObject cover;

Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Src/Notion.Client/Models/Blocks/AudioBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Notion.Client
{
public class AudioBlock : Block
public class AudioBlock : Block, IColumnChildrenBlock, INonColumnBlock
{
public override BlockType Type => BlockType.Audio;

Expand Down
39 changes: 3 additions & 36 deletions Src/Notion.Client/Models/Blocks/Block.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
6 changes: 6 additions & 0 deletions Src/Notion.Client/Models/Blocks/BlockType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ public enum BlockType
[EnumMember(Value = "quote")]
Quote,

[EnumMember(Value = "column")]
Column,

[EnumMember(Value = "column_list")]
ColumnList,

[EnumMember(Value = "unsupported")]
Unsupported
}
Expand Down
2 changes: 1 addition & 1 deletion Src/Notion.Client/Models/Blocks/BookmarkBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Notion.Client
{
public class BookmarkBlock : Block
public class BookmarkBlock : Block, IColumnChildrenBlock, INonColumnBlock
{
public override BlockType Type => BlockType.Bookmark;

Expand Down
2 changes: 1 addition & 1 deletion Src/Notion.Client/Models/Blocks/BreadcrumbBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Notion.Client
{
public class BreadcrumbBlock : Block
public class BreadcrumbBlock : Block, IColumnChildrenBlock, INonColumnBlock
{
public override BlockType Type => BlockType.Breadcrumb;

Expand Down
4 changes: 2 additions & 2 deletions Src/Notion.Client/Models/Blocks/BulletedListItemBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Notion.Client
{
public class BulletedListItemBlock : Block
public class BulletedListItemBlock : Block, IColumnChildrenBlock, INonColumnBlock
{
public override BlockType Type => BlockType.BulletedListItem;

Expand All @@ -16,7 +16,7 @@ public class Info
public IEnumerable<RichTextBase> Text { get; set; }

[JsonProperty("children")]
public IEnumerable<Block> Children { get; set; }
public IEnumerable<INonColumnBlock> Children { get; set; }
}
}
}
4 changes: 2 additions & 2 deletions Src/Notion.Client/Models/Blocks/CalloutBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Notion.Client
{
public class CalloutBlock : Block
public class CalloutBlock : Block, IColumnChildrenBlock, INonColumnBlock
{
public override BlockType Type => BlockType.Callout;

Expand All @@ -19,7 +19,7 @@ public class Info
public IPageIcon Icon { get; set; }

[JsonProperty("children")]
public IEnumerable<Block> Children { get; set; }
public IEnumerable<INonColumnBlock> Children { get; set; }
}
}
}
2 changes: 1 addition & 1 deletion Src/Notion.Client/Models/Blocks/ChildDatabaseBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Notion.Client
{
public class ChildDatabaseBlock : Block
public class ChildDatabaseBlock : Block, IColumnChildrenBlock, INonColumnBlock
{
public override BlockType Type => BlockType.ChildDatabase;

Expand Down
2 changes: 1 addition & 1 deletion Src/Notion.Client/Models/Blocks/ChildPageBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Notion.Client
{
public class ChildPageBlock : Block
public class ChildPageBlock : Block, IColumnChildrenBlock, INonColumnBlock
{
public override BlockType Type => BlockType.ChildPage;

Expand Down
2 changes: 1 addition & 1 deletion Src/Notion.Client/Models/Blocks/CodeBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Notion.Client
{
public class CodeBlock : Block
public class CodeBlock : Block, IColumnChildrenBlock, INonColumnBlock
{
public override BlockType Type => BlockType.Code;

Expand Down
19 changes: 19 additions & 0 deletions Src/Notion.Client/Models/Blocks/ColumnBlock.cs
Original file line number Diff line number Diff line change
@@ -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<IColumnChildrenBlock> Children { get; set; }
}
}
}
19 changes: 19 additions & 0 deletions Src/Notion.Client/Models/Blocks/ColumnListBlock.cs
Original file line number Diff line number Diff line change
@@ -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<ColumnBlock> Children { get; set; }
}
}
}
2 changes: 1 addition & 1 deletion Src/Notion.Client/Models/Blocks/DividerBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Notion.Client
{
public class DividerBlock : Block
public class DividerBlock : Block, IColumnChildrenBlock, INonColumnBlock
{
public override BlockType Type => BlockType.Divider;

Expand Down
2 changes: 1 addition & 1 deletion Src/Notion.Client/Models/Blocks/EmbedBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Notion.Client
{
public class EmbedBlock : Block
public class EmbedBlock : Block, IColumnChildrenBlock, INonColumnBlock
{
public override BlockType Type => BlockType.Embed;

Expand Down
2 changes: 1 addition & 1 deletion Src/Notion.Client/Models/Blocks/EquationBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Notion.Client
{
public class EquationBlock : Block
public class EquationBlock : Block, IColumnChildrenBlock, INonColumnBlock
{
public override BlockType Type => BlockType.Equation;

Expand Down
2 changes: 1 addition & 1 deletion Src/Notion.Client/Models/Blocks/FileBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Notion.Client
{
public class FileBlock : Block
public class FileBlock : Block, IColumnChildrenBlock, INonColumnBlock
{
public override BlockType Type => BlockType.File;

Expand Down
2 changes: 1 addition & 1 deletion Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Notion.Client
{
public class HeadingOneBlock : Block
public class HeadingOneBlock : Block, IColumnChildrenBlock, INonColumnBlock
{
public override BlockType Type => BlockType.Heading_1;

Expand Down
2 changes: 1 addition & 1 deletion Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Notion.Client
{
public class HeadingThreeeBlock : Block
public class HeadingThreeeBlock : Block, IColumnChildrenBlock, INonColumnBlock
{
public override BlockType Type => BlockType.Heading_3;

Expand Down
2 changes: 1 addition & 1 deletion Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Notion.Client
{
public class HeadingTwoBlock : Block
public class HeadingTwoBlock : Block, IColumnChildrenBlock, INonColumnBlock
{
public override BlockType Type => BlockType.Heading_2;

Expand Down
Loading