Skip to content

Commit 3af7b98

Browse files
committed
Add support for the table of contents block type
1 parent 1cb7607 commit 3af7b98

File tree

5 files changed

+64
-3
lines changed

5 files changed

+64
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Notion.Client
4+
{
5+
public class TableOfContentsUpdateBlock : IUpdateBlock
6+
{
7+
public bool Archived { get; set; }
8+
9+
[JsonProperty("table_of_contents")]
10+
public Data TableOfContents { get; set; }
11+
12+
public class Data
13+
{
14+
}
15+
16+
public TableOfContentsUpdateBlock()
17+
{
18+
TableOfContents = new Data();
19+
}
20+
}
21+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace Notion.Client
2222
[JsonSubtypes.KnownSubType(typeof(NumberedListItemBlock), BlockType.NumberedListItem)]
2323
[JsonSubtypes.KnownSubType(typeof(ParagraphBlock), BlockType.Paragraph)]
2424
[JsonSubtypes.KnownSubType(typeof(PDFBlock), BlockType.PDF)]
25+
[JsonSubtypes.KnownSubType(typeof(TableOfContentsBlock), BlockType.TableOfContents)]
2526
[JsonSubtypes.KnownSubType(typeof(ToDoBlock), BlockType.ToDo)]
2627
[JsonSubtypes.KnownSubType(typeof(ToggleBlock), BlockType.Toggle)]
2728
[JsonSubtypes.KnownSubType(typeof(VideoBlock), BlockType.Video)]

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ public enum BlockType
6767
[EnumMember(Value = "audio")]
6868
Audio,
6969

70+
[EnumMember(Value = "table_of_contents")]
71+
TableOfContents,
72+
7073
[EnumMember(Value = "unsupported")]
7174
Unsupported
7275
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Notion.Client
4+
{
5+
public class TableOfContentsBlock : Block
6+
{
7+
public override BlockType Type => BlockType.TableOfContents;
8+
9+
[JsonProperty("table_of_contents")]
10+
public Data TableOfContents { get; set; }
11+
12+
public class Data
13+
{
14+
}
15+
}
16+
}

Test/Notion.IntegrationTests/IBlocksClientTests.cs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,16 @@ public async Task AppendChildrenAsync_AppendsBlocksGivenBlocks()
4343
new DividerBlock
4444
{
4545
Divider = new DividerBlock.Data()
46+
},
47+
new TableOfContentsBlock
48+
{
49+
TableOfContents = new TableOfContentsBlock.Data()
4650
}
4751
}
4852
}
4953
);
5054

51-
blocks.Results.Should().HaveCount(2);
55+
blocks.Results.Should().HaveCount(3);
5256

5357
// cleanup
5458
await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters
@@ -133,12 +137,16 @@ public async Task DeleteAsync_DeleteBlockWithGivenId()
133137
new DividerBlock
134138
{
135139
Divider = new DividerBlock.Data()
136-
}
140+
},
141+
new TableOfContentsBlock
142+
{
143+
TableOfContents = new TableOfContentsBlock.Data()
144+
},
137145
}
138146
}
139147
);
140148

141-
blocks.Results.Should().HaveCount(1);
149+
blocks.Results.Should().HaveCount(2);
142150

143151
// cleanup
144152
await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters
@@ -291,6 +299,18 @@ private static IEnumerable<object[]> BlockData()
291299
.Audio.Should().BeOfType<ExternalFile>().Subject
292300
.External.Url.Should().Be("https://www.soundhelix.com/examples/mp3/SoundHelix-Song-3.mp3");
293301
})
302+
},
303+
new object[]
304+
{
305+
new TableOfContentsBlock {
306+
TableOfContents = new TableOfContentsBlock.Data()
307+
},
308+
new TableOfContentsUpdateBlock(),
309+
new Action<Block>((block) =>
310+
{
311+
Assert.NotNull(block);
312+
Assert.IsType<TableOfContentsBlock>(block);
313+
})
294314
}
295315
};
296316
}

0 commit comments

Comments
 (0)