Skip to content

Commit 69b5e4c

Browse files
Add support to add/update callout block ✨
1 parent 16a44c6 commit 69b5e4c

File tree

5 files changed

+116
-22
lines changed

5 files changed

+116
-22
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System.Collections.Generic;
2+
using Newtonsoft.Json;
3+
4+
namespace Notion.Client
5+
{
6+
public class CalloutUpdateBlock : UpdateBlock, IUpdateBlock
7+
{
8+
[JsonProperty("callout")]
9+
public Info Callout { get; set; }
10+
11+
public class Info
12+
{
13+
[JsonProperty("text")]
14+
public IEnumerable<RichTextBaseInput> Text { get; set; }
15+
16+
[JsonProperty("icon")]
17+
public IPageIcon Icon { get; set; }
18+
}
19+
}
20+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace Notion.Client
88
[JsonSubtypes.KnownSubType(typeof(AudioBlock), BlockType.Audio)]
99
[JsonSubtypes.KnownSubType(typeof(BookmarkBlock), BlockType.Bookmark)]
1010
[JsonSubtypes.KnownSubType(typeof(BulletedListItemBlock), BlockType.BulletedListItem)]
11+
[JsonSubtypes.KnownSubType(typeof(CalloutBlock), BlockType.Callout)]
1112
[JsonSubtypes.KnownSubType(typeof(ChildPageBlock), BlockType.ChildPage)]
1213
[JsonSubtypes.KnownSubType(typeof(ChildDatabaseBlock), BlockType.ChildDatabase)]
1314
[JsonSubtypes.KnownSubType(typeof(CodeBlock), BlockType.Code)]

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ public enum BlockType
7070
[EnumMember(Value = "table_of_contents")]
7171
TableOfContents,
7272

73+
[EnumMember(Value = "callout")]
74+
Callout,
75+
7376
[EnumMember(Value = "unsupported")]
7477
Unsupported
7578
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System.Collections.Generic;
2+
using Newtonsoft.Json;
3+
4+
namespace Notion.Client
5+
{
6+
public class CalloutBlock : Block
7+
{
8+
public override BlockType Type => BlockType.Callout;
9+
10+
[JsonProperty("callout")]
11+
public Info Callout { get; set; }
12+
13+
public class Info
14+
{
15+
[JsonProperty("text")]
16+
public IEnumerable<RichTextBase> Text { get; set; }
17+
18+
[JsonProperty("icon")]
19+
public IPageIcon Icon { get; set; }
20+
21+
[JsonProperty("children")]
22+
public IEnumerable<Block> Children { get; set; }
23+
}
24+
}
25+
}

Test/Notion.IntegrationTests/IBlocksClientTests.cs

Lines changed: 67 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,21 @@ namespace Notion.IntegrationTests
1010
{
1111
public class IBlocksClientTests
1212
{
13-
[Fact]
14-
public async Task AppendChildrenAsync_AppendsBlocksGivenBlocks()
13+
private readonly INotionClient _client;
14+
15+
public IBlocksClientTests()
1516
{
1617
var options = new ClientOptions
1718
{
1819
AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN")
1920
};
20-
INotionClient _client = NotionClientFactory.Create(options);
2121

22+
_client = NotionClientFactory.Create(options);
23+
}
24+
25+
[Fact]
26+
public async Task AppendChildrenAsync_AppendsBlocksGivenBlocks()
27+
{
2228
var pageId = "3c357473a28149a488c010d2b245a589";
2329

2430
var page = await _client.Pages.CreateAsync(
@@ -47,12 +53,27 @@ public async Task AppendChildrenAsync_AppendsBlocksGivenBlocks()
4753
new TableOfContentsBlock
4854
{
4955
TableOfContents = new TableOfContentsBlock.Data()
56+
},
57+
new CalloutBlock
58+
{
59+
Callout = new CalloutBlock.Info
60+
{
61+
Text = new List<RichTextBaseInput> {
62+
new RichTextTextInput
63+
{
64+
Text = new Text
65+
{
66+
Content = "Test"
67+
}
68+
}
69+
}
70+
}
5071
}
5172
}
5273
}
5374
);
5475

55-
blocks.Results.Should().HaveCount(3);
76+
blocks.Results.Should().HaveCount(4);
5677

5778
// cleanup
5879
await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters
@@ -64,12 +85,6 @@ public async Task AppendChildrenAsync_AppendsBlocksGivenBlocks()
6485
[Fact]
6586
public async Task UpdateBlockAsync_UpdatesGivenBlock()
6687
{
67-
var options = new ClientOptions
68-
{
69-
AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN")
70-
};
71-
INotionClient _client = NotionClientFactory.Create(options);
72-
7388
var pageId = "3c357473a28149a488c010d2b245a589";
7489

7590
var page = await _client.Pages.CreateAsync(
@@ -111,12 +126,6 @@ public async Task UpdateBlockAsync_UpdatesGivenBlock()
111126
[Fact]
112127
public async Task DeleteAsync_DeleteBlockWithGivenId()
113128
{
114-
var options = new ClientOptions
115-
{
116-
AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN")
117-
};
118-
INotionClient _client = NotionClientFactory.Create(options);
119-
120129
var pageId = "3c357473a28149a488c010d2b245a589";
121130

122131
var page = await _client.Pages.CreateAsync(
@@ -159,12 +168,6 @@ public async Task DeleteAsync_DeleteBlockWithGivenId()
159168
[MemberData(nameof(BlockData))]
160169
public async Task UpdateAsync_UpdatesGivenBlock(Block block, IUpdateBlock updateBlock, Action<Block> assert)
161170
{
162-
var options = new ClientOptions
163-
{
164-
AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN")
165-
};
166-
INotionClient _client = NotionClientFactory.Create(options);
167-
168171
var pageParentId = "3c357473a28149a488c010d2b245a589";
169172

170173
var page = await _client.Pages.CreateAsync(
@@ -311,6 +314,48 @@ private static IEnumerable<object[]> BlockData()
311314
Assert.NotNull(block);
312315
Assert.IsType<TableOfContentsBlock>(block);
313316
})
317+
},
318+
new object[]
319+
{
320+
new CalloutBlock
321+
{
322+
Callout = new CalloutBlock.Info
323+
{
324+
Text = new List<RichTextBaseInput>
325+
{
326+
new RichTextTextInput
327+
{
328+
Text = new Text
329+
{
330+
Content = "Test"
331+
}
332+
}
333+
}
334+
}
335+
},
336+
new CalloutUpdateBlock()
337+
{
338+
Callout = new CalloutUpdateBlock.Info
339+
{
340+
Text = new List<RichTextBaseInput>
341+
{
342+
new RichTextTextInput
343+
{
344+
Text = new Text
345+
{
346+
Content = "Test 2"
347+
}
348+
}
349+
}
350+
}
351+
},
352+
new Action<Block>((block) =>
353+
{
354+
Assert.NotNull(block);
355+
var calloutBlock = Assert.IsType<CalloutBlock>(block);
356+
357+
Assert.Equal("Test 2", calloutBlock.Callout.Text.OfType<RichTextText>().First().Text.Content);
358+
})
314359
}
315360
};
316361
}

0 commit comments

Comments
 (0)