Skip to content

Commit 809ea31

Browse files
Merge pull request #186 from notion-dotnet/feature/181-add-support-for-breadcrumb-block
Add support for breadcrumb block ✨
2 parents 957bd85 + 6b96d39 commit 809ea31

File tree

4 files changed

+119
-0
lines changed

4 files changed

+119
-0
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 BreadcrumbUpdateBlock : IUpdateBlock
6+
{
7+
public bool Archived { get; set; }
8+
9+
[JsonProperty("breadcrumb")]
10+
public Data Breadcrumb { get; set; }
11+
12+
public class Data
13+
{
14+
}
15+
16+
public BreadcrumbUpdateBlock()
17+
{
18+
Breadcrumb = new Data();
19+
}
20+
}
21+
}

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

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ public enum BlockType
5858
[EnumMember(Value = "equation")]
5959
Equation,
6060

61+
[EnumMember(Value = "breadcrumb")]
62+
Breadcrumb,
63+
6164
[EnumMember(Value = "unsupported")]
6265
Unsupported
6366
}
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 BreadcrumbBlock : Block
6+
{
7+
public override BlockType Type => BlockType.Breadcrumb;
8+
9+
[JsonProperty("breadcrumb")]
10+
public Data Breadcrumb { get; set; }
11+
12+
public class Data
13+
{
14+
}
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using FluentAssertions;
6+
using Notion.Client;
7+
using Xunit;
8+
9+
namespace Notion.IntegrationTests
10+
{
11+
public class IBlocksClientTests
12+
{
13+
[Fact]
14+
public async Task AppendChildrenAsync_AppendsBlocksGivenBlocks()
15+
{
16+
var options = new ClientOptions
17+
{
18+
AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN")
19+
};
20+
INotionClient _client = NotionClientFactory.Create(options);
21+
22+
var pageId = "3c357473a28149a488c010d2b245a589";
23+
var blocks = await _client.Blocks.AppendChildrenAsync(
24+
pageId,
25+
new BlocksAppendChildrenParameters
26+
{
27+
Children = new List<Block>()
28+
{
29+
new BreadcrumbBlock
30+
{
31+
Breadcrumb = new BreadcrumbBlock.Data()
32+
}
33+
}
34+
}
35+
);
36+
37+
blocks.Results.Should().HaveCount(1);
38+
39+
// cleanup
40+
var tasks = blocks.Results.Select(x => _client.Blocks.DeleteAsync(x.Id));
41+
await Task.WhenAll(tasks);
42+
}
43+
44+
[Fact]
45+
public async Task UpdateBlobkAsync_UpdatesGivenBlock()
46+
{
47+
var options = new ClientOptions
48+
{
49+
AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN")
50+
};
51+
INotionClient _client = NotionClientFactory.Create(options);
52+
53+
var pageId = "3c357473a28149a488c010d2b245a589";
54+
var blocks = await _client.Blocks.AppendChildrenAsync(
55+
pageId,
56+
new BlocksAppendChildrenParameters
57+
{
58+
Children = new List<Block>()
59+
{
60+
new BreadcrumbBlock
61+
{
62+
Breadcrumb = new BreadcrumbBlock.Data()
63+
}
64+
}
65+
}
66+
);
67+
68+
var blockId = blocks.Results.First().Id;
69+
await _client.Blocks.UpdateAsync(blockId, new BreadcrumbUpdateBlock());
70+
71+
blocks = await _client.Blocks.RetrieveChildrenAsync(pageId);
72+
blocks.Results.Should().HaveCount(1);
73+
74+
// cleanup
75+
var tasks = blocks.Results.Select(x => _client.Blocks.DeleteAsync(x.Id));
76+
await Task.WhenAll(tasks);
77+
}
78+
}
79+
}

0 commit comments

Comments
 (0)