8000 Merge pull request #205 from notion-dotnet/190-add-support-for-column… · notion-dotnet/notion-sdk-net@b5f9e9b · GitHub
[go: up one dir, main page]

Skip to content

Commit b5f9e9b

Browse files
Merge pull request #205 from notion-dotnet/190-add-support-for-column-and-column-list-block-types
Add support for column and column list block types ✨
2 parents c446094 + 879e6e9 commit b5f9e9b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+227
-100
lines changed

Src/Notion.Client/Api/Blocks/BlocksClient.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public BlocksClient(IRestClient client)
1414
_client = client;
1515
}
1616

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

34-
return await _client.GetAsync<PaginatedList<Block>>(url, queryParams);
34+
return await _client.GetAsync<PaginatedList<IBlock>>(url, queryParams);
3535
}
3636

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

4646
var body = (IBlocksAppendChildrenBodyParameters)parameters;
4747

48-
return await _client.PatchAsync<PaginatedList<Block>>(url, body);
48+
return await _client.PatchAsync<PaginatedList<IBlock>>(url, body);
4949
}
5050

51-
public async Task<Block> RetrieveAsync(string blockId)
51+
public async Task<IBlock> RetrieveAsync(string blockId)
5252
{
5353
if (string.IsNullOrWhiteSpace(blockId))
5454
{
@@ -57,10 +57,10 @@ public async Task<Block> RetrieveAsync(string blockId)
5757

5858
var url = BlocksApiUrls.Retrieve(blockId);
5959

60-
return await _client.GetAsync<Block>(url);
60+
return await _client.GetAsync<IBlock>(url);
6161
}
6262

63-
public async Task<Block> UpdateAsync(string blockId, IUpdateBlock updateBlock)
63+
public async Task<IBlock> UpdateAsync(string blockId, IUpdateBlock updateBlock)
6464
{
6565
if (string.IsNullOrWhiteSpace(blockId))
6666
{
@@ -69,7 +69,7 @@ public async Task<Block> UpdateAsync(string blockId, IUpdateBlock updateBlock)
6969

7070
var url = BlocksApiUrls.Update(blockId);
7171

72-
return await _client.PatchAsync<Block>(url, updateBlock);
72+
return await _client.PatchAsync<IBlock>(url, updateBlock);
7373
}
7474

7575
public async Task DeleteAsync(string blockId)

Src/Notion.Client/Api/Blocks/IBlocksClient.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,25 @@ public interface IBlocksClient
99
/// </summary>
1010
/// <param name="blockId"></param>
1111
/// <returns>Block</returns>
12-
Task<Block> RetrieveAsync(string blockId);
12+
Task<IBlock> RetrieveAsync(string blockId);
1313

1414
/// <summary>
1515
/// Updates the content for the specified block_id based on the block type.
1616
/// </summary>
1717
/// <param name="blockId"></param>
1818
/// <param name="updateBlock"></param>
1919
/// <returns>Block</returns>
20-
Task<Block> UpdateAsync(string blockId, IUpdateBlock updateBlock);
20+
Task<IBlock> UpdateAsync(string blockId, IUpdateBlock updateBlock);
2121

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

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

3232
/// <summary>
3333
/// Sets a Block object, including page blocks, to archived: true using the ID specified.

Src/Notion.Client/Api/Blocks/RequestParams/BlocksAppendChildrenParameters.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ namespace Notion.Client
44
{
55
public class BlocksAppendChildrenParameters : IBlocksAppendChildrenBodyParameters
66
{
7-
public IEnumerable<Block> Children { get; set; }
7+
public IEnumerable<IBlock> Children { get; set; }
88
}
99
}

Src/Notion.Client/Api/Blocks/RequestParams/IBlocksAppendChildrenBodyParameters.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ namespace Notion.Client
77
public interface IBlocksAppendChildrenBodyParameters
88
{
99
[JsonProperty("children")]
10-
IEnumerable<Block> Children { get; set; }
10+
IEnumerable<IBlock> Children { get; set; }
1111
}
1212
}

Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/IPagesCreateBodyParameters.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public interface IPagesCreateBodyParameters
1212
IDictionary<string, PropertyValue> Properties { get; set; }
1313

1414
[JsonProperty("children")]
15-
IList<Block> Children { get; set; }
15+
IList<IBlock> Children { get; set; }
1616

1717
[JsonProperty("icon")]
1818
IPageIcon Icon { get; set; }

Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParameters.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public class PagesCreateParameters : IPagesCreateBodyParameters, IPagesCreateQue
66
{
77
public IPageParentInput Parent { get; set; }
88
public IDictionary<string, PropertyValue> Properties { get; set; }
9-
public IList<Block> Children { get; set; }
9+
public IList<IBlock> Children { get; set; }
1010
public IPageIcon Icon { get; set; }
1111
public FileObject Cover { get; set; }
1212
}

Src/Notion.Client/Api/Pages/RequestParams/PagesCreateParameters/PagesCreateParametersBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public class PagesCreateParametersBuilder
66
{
77
private IPageParentInput parent;
88
private readonly Dictionary<string, PropertyValue> properties = new Dictionary<string, PropertyValue>();
9-
private readonly IList<Block> children = new List<Block>();
9+
private readonly IList<IBlock> children = new List<IBlock>();
1010
private IPageIcon icon;
1111
private FileObject cover;
1212

@@ -28,7 +28,7 @@ public PagesCreateParametersBuilder AddProperty(string nameOrId, PropertyValue v
2828
return this;
2929
}
3030

31-
public PagesCreateParametersBuilder AddPageContent(Block block)
31+
public PagesCreateParametersBuilder AddPageContent(IBlock block)
3232
{
3333
children.Add(block);
3434
return this;

Src/Notion.Client/Models/Blocks/AudioBlock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Notion.Client
44
{
5-
public class AudioBlock : Block
5+
public class AudioBlock : Block, IColumnChildrenBlock, INonColumnBlock
66
{
77
public override BlockType Type => BlockType.Audio;
88

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,17 @@
1-
using JsonSubTypes;
2-
using Newtonsoft.Json;
3-
using Newtonsoft.Json.Converters;
4-
5-
namespace Notion.Client
1+
namespace Notion.Client
62
{
7-
[JsonConverter(typeof(JsonSubtypes), "type")]
8-
[JsonSubtypes.KnownSubType(typeof(AudioBlock), BlockType.Audio)]
9-
[JsonSubtypes.KnownSubType(typeof(BookmarkBlock), BlockType.Bookmark)]
10-
[JsonSubtypes.KnownSubType(typeof(BulletedListItemBlock), BlockType.BulletedListItem)]
11-
[JsonSubtypes.KnownSubType(typeof(CalloutBlock), BlockType.Callout)]
12-
[JsonSubtypes.KnownSubType(typeof(ChildPageBlock), BlockType.ChildPage)]
13-
[JsonSubtypes.KnownSubType(typeof(ChildDatabaseBlock), BlockType.ChildDatabase)]
14-
[JsonSubtypes.KnownSubType(typeof(CodeBlock), BlockType.Code)]
15-
[JsonSubtypes.KnownSubType(typeof(DividerBlock), BlockType.Divider)]
16-
[JsonSubtypes.KnownSubType(typeof(EmbedBlock), BlockType.Embed)]
17-
[JsonSubtypes.KnownSubType(typeof(EquationBlock), BlockType.Equation)]
18-
[JsonSubtypes.KnownSubType(typeof(FileBlock), BlockType.File)]
19-
[JsonSubtypes.KnownSubType(typeof(HeadingOneBlock), BlockType.Heading_1)]
20-
[JsonSubtypes.KnownSubType(typeof(HeadingTwoBlock), BlockType.Heading_2)]
21-
[JsonSubtypes.KnownSubType(typeof(HeadingThreeeBlock), BlockType.Heading_3)]
22-
[JsonSubtypes.KnownSubType(typeof(ImageBlock), BlockType.Image)]
23-
[JsonSubtypes.KnownSubType(typeof(NumberedListItemBlock), BlockType.NumberedListItem)]
24-
[JsonSubtypes.KnownSubType(typeof(ParagraphBlock), BlockType.Paragraph)]
25-
[JsonSubtypes.KnownSubType(typeof(PDFBlock), BlockType.PDF)]
26-
[JsonSubtypes.KnownSubType(typeof(QuoteBlock), BlockType.Quote)]
27-
[JsonSubtypes.KnownSubType(typeof(TableOfContentsBlock), BlockType.TableOfContents)]
28-
[JsonSubtypes.KnownSubType(typeof(ToDoBlock), BlockType.ToDo)]
29-
[JsonSubtypes.KnownSubType(typeof(ToggleBlock), BlockType.Toggle)]
30-
[JsonSubtypes.KnownSubType(typeof(VideoBlock), BlockType.Video)]
31-
[JsonSubtypes.KnownSubType(typeof(UnsupportedBlock), BlockType.Unsupported)]
32-
public class Block : IObject
3+
public abstract class Block : IBlock
334
{
345
public ObjectType Object => ObjectType.Block;
6+
357
public string Id { get; set; }
368

37-
[JsonProperty("type")]
38-
[JsonConverter(typeof(StringEnumConverter))]
399
public virtual BlockType Type { get; set; }
4010

41-
[JsonProperty("created_time")]
4211
public string CreatedTime { get; set; }
4312

44-
[JsonProperty("last_edited_time")]
4513
public string LastEditedTime { get; set; }
4614

47-
[JsonProperty("has_children")]
4815
public virtual bool HasChildren { get; set; }
4916
}
5017
}

Src/Notion.Client/Models/Blocks/BlockType.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ public enum BlockType
7676
[EnumMember(Value = "quote")]
7777
Quote,
7878

79+
[EnumMember(Value = "column")]
80+
Column,
81+
82+
[EnumMember(Value = "column_list")]
83+
ColumnList,
84+
7985
[EnumMember(Value = "unsupported")]
8086
Unsupported
8187
}

Src/Notion.Client/Models/Blocks/BookmarkBlock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace Notion.Client
55
{
6-
public class BookmarkBlock : Block
6+
public class BookmarkBlock : Block, IColumnChildrenBlock, INonColumnBlock
77
{
88
public override BlockType Type => BlockType.Bookmark;
99

Src/Notion.Client/Models/Blocks/BreadcrumbBlock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Notion.Client
44
{
5-
public class BreadcrumbBlock : Block
5+
public class BreadcrumbBlock : Block, IColumnChildrenBlock, INonColumnBlock
66
{
77
public override BlockType Type => BlockType.Breadcrumb;
88

Src/Notion.Client/Models/Blocks/BulletedListItemBlock.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace Notion.Client
55
{
6-
public class BulletedListItemBlock : Block
6+
public class BulletedListItemBlock : Block, IColumnChildrenBlock, INonColumnBlock
77
{
88
public override BlockType Type => BlockType.BulletedListItem;
99

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

1818
[JsonProperty("children")]
19-
public IEnumerable<Block> Children { get; set; }
19+
public IEnumerable<INonColumnBlock> Children { get; set; }
2020
}
2121
}
2222
}

Src/Notion.Client/Models/Blocks/CalloutBlock.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace Notion.Client
55
{
6-
public class CalloutBlock : Block
6+
public class CalloutBlock : Block, IColumnChildrenBlock, INonColumnBlock
77
{
88
public override BlockType Type => BlockType.Callout;
99

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

2121
[JsonProperty("children")]
22-
public IEnumerable<Block> Children { get; set; }
22+
public IEnumerable<INonColumnBlock> Children { get; set; }
2323
}
2424
}
2525
}

Src/Notion.Client/Models/Blocks/ChildDatabaseBlock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Notion.Client
44
{
5-
public class ChildDatabaseBlock : Block
5+
public class ChildDatabaseBlock : Block, IColumnChildrenBlock, INonColumnBlock
66
{
77
public override BlockType Type => BlockType.ChildDatabase;
88

Src/Notion.Client/Models/Blocks/ChildPageBlock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Notion.Client
44
{
5-
public class ChildPageBlock : Block
5+
public class ChildPageBlock : Block, IColumnChildrenBlock, INonColumnBlock
66
{
77
public override BlockType Type => BlockType.ChildPage;
88

Src/Notion.Client/Models/Blocks/CodeBlock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace Notion.Client
55
{
6-
public class CodeBlock : Block
6+
public class CodeBlock : Block, IColumnChildrenBlock, INonColumnBlock
77
{
88
public override BlockType Type => BlockType.Code;
99

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.Collections.Generic;
2+
using Newtonsoft.Json;
3+
4+
namespace Notion.Client
5+
{
6+
public class ColumnBlock : Block
7+
{
8+
public override BlockType Type => BlockType.Column;
9+
10+
[JsonProperty("column")]
11+
public Info Column { get; set; }
12+
13+
public class Info
14+
{
15+
[JsonProperty("children")]
16+
public IEnumerable<IColumnChildrenBlock> Children { get; set; }
17+
}
18+
}
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.Collections.Generic;
2+
using Newtonsoft.Json;
3+
4+
namespace Notion.Client
5+
{
6+
public class ColumnListBlock : Block, INonColumnBlock
7+
{
8+
public override BlockType Type => BlockType.ColumnList;
9+
10+
[JsonProperty("column_list")]
11+
public Info ColumnList { get; set; }
12+
13+
public class Info
14+
{
15+
[JsonProperty("children")]
16+
public IEnumerable<ColumnBlock> Children { get; set; }
17+
}
18+
}
19+
}

Src/Notion.Client/Models/Blocks/DividerBlock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Notion.Client
44
{
5-
public class DividerBlock : Block
5+
public class DividerBlock : Block, IColumnChildrenBlock, INonColumnBlock
66
{
77
public override BlockType Type => BlockType.Divider;
88

Src/Notion.Client/Models/Blocks/EmbedBlock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Notion.Client
44
{
5-
public class EmbedBlock : Block
5+
public class EmbedBlock : Block, IColumnChildrenBlock, INonColumnBlock
66
{
77
public override BlockType Type => BlockType.Embed;
88

Src/Notion.Client/Models/Blocks/EquationBlock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Notion.Client
44
{
5-
public class EquationBlock : Block
5+
public class EquationBlock : Block, IColumnChildrenBlock, INonColumnBlock
66
{
77
public override BlockType Type => BlockType.Equation;
88

Src/Notion.Client/Models/Blocks/FileBlock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Notion.Client
44
{
5-
public class FileBlock : Block
5+
public class FileBlock : Block, IColumnChildrenBlock, INonColumnBlock
66
{
77
public override BlockType Type => BlockType.File;
88

Src/Notion.Client/Models/Blocks/HeadingOneBlock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace Notion.Client
55
{
6-
public class HeadingOneBlock : Block
6+
public class HeadingOneBlock : Block, IColumnChildrenBlock, INonColumnBlock
77
{
88
public override BlockType Type => BlockType.Heading_1;
99

Src/Notion.Client/Models/Blocks/HeadingThreeeBlock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace Notion.Client
55
{
6-
public class HeadingThreeeBlock : Block
6+
public class HeadingThreeeBlock : Block, IColumnChildrenBlock, INonColumnBlock
77
{
88
public override BlockType Type => BlockType.Heading_3;
99

Src/Notion.Client/Models/Blocks/HeadingTwoBlock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace Notion.Client
55
{
6-
public class HeadingTwoBlock : Block
6+
public class HeadingTwoBlock : Block, IColumnChildrenBlock, INonColumnBlock
77
{
88
public override BlockType Type => BlockType.Heading_2;
99

0 commit comments

Comments
 (0)
0