Skip to content

Commit bfc9874

Browse files
Add support for Quote block ✨
1 parent 4846731 commit bfc9874

File tree

5 files changed

+92
-7
lines changed

5 files changed

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

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ namespace Notion.Client
2323
[JsonSubtypes.KnownSubType(typeof(NumberedListItemBlock), BlockType.NumberedListItem)]
2424
[JsonSubtypes.KnownSubType(typeof(ParagraphBlock), BlockType.Paragraph)]
2525
[JsonSubtypes.KnownSubType(typeof(PDFBlock), BlockType.PDF)]
26+
[JsonSubtypes.KnownSubType(typeof(QuoteBlock), BlockType.Quote)]
2627
[JsonSubtypes.KnownSubType(typeof(TableOfContentsBlock), BlockType.TableOfContents)]
2728
[JsonSubtypes.KnownSubType(typeof(ToDoBlock), BlockType.ToDo)]
2829
[JsonSubtypes.KnownSubType(typeof(ToggleBlock), BlockType.Toggle)]

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ public enum BlockType
7373
[EnumMember(Value = "callout")]
7474
Callout,
7575

76+
[EnumMember(Value = "quote")]
77+
Quote,
78+
7679
[EnumMember(Value = "unsupported")]
7780
Unsupported
7881
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System.Collections.Generic;
2+
using Newtonsoft.Json;
3+
4+
namespace Notion.Client
5+
{
6+
public class QuoteBlock : Block
7+
{
8+
public override BlockType Type => BlockType.Quote;
9+
10+
[JsonProperty("quote")]
11+
public Info Quote { get; set; }
12+
13+
public class Info
14+
{
15+
[JsonProperty("text")]
16+
public IEnumerable<RichTextBaseInput> Text { get; set; }
17+
18+
[JsonProperty("children")]
19+
public IEnumerable<Block> Children { get; set; }
20+
}
21+
}
22+
}

Test/Notion.IntegrationTests/IBlocksClientTests.cs

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ public IBlocksClientTests()
2525
[Fact]
2626
public async Task AppendChildrenAsync_AppendsBlocksGivenBlocks()
2727
{
28-
var pageId = "3c357473a28149a488c010d2b245a589";
28+
var pageParentId = "3c357473a28149a488c010d2b245a589";
2929

3030
var page = await _client.Pages.CreateAsync(
3131
PagesCreateParametersBuilder.Create(
3232
new ParentPageInput()
3333
{
34-
PageId = pageId
34+
PageId = pageParentId
3535
}
3636
).Build()
3737
);
@@ -85,13 +85,13 @@ public async Task AppendChildrenAsync_AppendsBlocksGivenBlocks()
8585
[Fact]
8686
public async Task UpdateBlockAsync_UpdatesGivenBlock()
8787
{
88-
var pageId = "3c357473a28149a488c010d2b245a589";
88+
var pageParentId = "3c357473a28149a488c010d2b245a589";
8989

9090
var page = await _client.Pages.CreateAsync(
9191
PagesCreateParametersBuilder.Create(
9292
new ParentPageInput()
9393
{
94-
PageId = pageId
94+
PageId = pageParentId
9595
}
9696
).Build()
9797
);
@@ -113,7 +113,7 @@ public async Task UpdateBlockAsync_UpdatesGivenBlock()
113113
var blockId = blocks.Results.First().Id;
114114
await _client.Blocks.UpdateAsync(blockId, new BreadcrumbUpdateBlock());
115115

116-
blocks = await _client.Blocks.RetrieveChildrenAsync(pageId);
116+
blocks = await _client.Blocks.RetrieveChildrenAsync(page.Id);
117117
blocks.Results.Should().HaveCount(1);
118118

119119
// cleanup
@@ -126,13 +126,13 @@ public async Task UpdateBlockAsync_UpdatesGivenBlock()
126126
[Fact]
127127
public async Task DeleteAsync_DeleteBlockWithGivenId()
128128
{
129-
var pageId = "3c357473a28149a488c010d2b245a589";
129+
var pageParentId = "3c357473a28149a488c010d2b245a589";
130130

131131
var page = await _client.Pages.CreateAsync(
132132
PagesCreateParametersBuilder.Create(
133133
new ParentPageInput()
134134
{
135-
PageId = pageId
135+
PageId = pageParentId
136136
}
137137
).Build()
138138
);
@@ -356,6 +356,48 @@ private static IEnumerable<object[]> BlockData()
356356

357357
Assert.Equal("Test 2", calloutBlock.Callout.Text.OfType<RichTextText>().First().Text.Content);
358358
})
359+
},
360+
new object[]
361+
{
362+
new QuoteBlock
363+
{
364+
Quote = new QuoteBlock.Info
365+
{
366+
Text = new List<RichTextBaseInput>
367+
{
368+
new RichTextTextInput
369+
{
370+
Text = new Text
371+
{
372+
Content = "Test"
373+
}
374+
}
375+
}
376+
}
377+
},
378+
new QuoteUpdateBlock()
379+
{
380+
Quote = new QuoteUpdateBlock.Info
381+
{
382+
Text = new List<RichTextBaseInput>
383+
{
384+
new RichTextTextInput
385+
{
386+
Text = new Text
387+
{
388+
Content = "Test 2"
389+
}
390+
}
391+
}
392+
}
393+
},
394+
new Action<Block>((block) =>
395+
{
396+
Assert.NotNull(block);
397+
var quoteBlock = Assert.IsType<QuoteBlock>(block);
398+
399+
Assert.Equal("Test 2", quoteBlock.Quote.Text.OfType<RichTextText>().First().Text.Content);
400+
})
359401
}
360402
};
361403
}

0 commit comments

Comments
 (0)