Skip to content

Commit 49ffe1e

Browse files
committed
Added support for link preview block and link preview mention
1 parent e3234b2 commit 49ffe1e

File tree

6 files changed

+31
-11
lines changed

6 files changed

+31
-11
lines changed

src/Notion.Sharp/Converters/BlockConverter.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ public override Block Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSe
124124
"unsupported" => Parser.EmptyObject.Updater((Void _, Block block) => block.Copy<Block.Unsupported>()),
125125
"column_list" => Parser.EmptyObject.Updater((Void _, Block block) => block.Copy<Block.ColumnList>()),
126126
"column" => Parser.EmptyObject.Updater((Void _, Block block) => block.Copy<Block.ColumnList>()),
127+
"link_preview" => Parser.ParseObject(propertyName => propertyName switch
128+
{
129+
"url" => Parser.Uri.Updater((Uri uri, Block.LinkPreview linkPreview) => linkPreview with { Url = uri }),
130+
var key => Parser.FailUpdate<Block.LinkPreview>($"Unknown key link_preview.{key}")
131+
}, (Block block) => block.Copy<Block.LinkPreview>()),
127132
var key => Parser.FailUpdate<Block>($"Unknown key {key}")
128133
}).Parse(ref reader, options);
129134
}

src/Notion.Sharp/Converters/RichTextConverter.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ public override RichText Read(ref Utf8JsonReader reader, Type typeToConvert, Jso
5050
"id" => Parser.Guid.Updater((Guid id, RichText.DatabaseMention databaseMention) => databaseMention with { Id = id }),
5151
var key => Parser.FailUpdate<RichText.DatabaseMention>($"Unknown key '{key}'")
5252
}, (RichText.Mention mention) => mention.Copy<RichText.DatabaseMention>()),
53+
"link_preview" => Parser.ParseObject(propertyName => propertyName switch
54+
{
55+
"url" => Parser.Uri.Updater((Uri url, RichText.LinkPreviewMention linkPreview) => linkPreview with { Url = url }),
56+
var key => Parser.FailUpdate<RichText.LinkPreviewMention>($"Unknown key '{key}'")
57+
}, (RichText.Mention mention) => mention.Copy<RichText.LinkPreviewMention>()),
5358
var key => Parser.FailUpdate<RichText.Mention>($"Unknown key '{key}'")
5459
}, (RichText richText) => richText.Copy<RichText.Mention>()),
5560
var key => Parser.FailUpdate<RichText>()

src/Notion.Sharp/dto/Blocks/Block.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,5 +232,10 @@ public record ColumnList : Block { }
232232

233233
public record Column : Block { }
234234

235+
public record LinkPreview : Block
236+
{
237+
public Uri Url { get; init; }
238+
}
239+
235240
#endregion
236241
}

src/Notion.Sharp/dto/Common/RichText.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ public record PageMention : Mention
4040
public Guid Id { get; init; }
4141
}
4242

43+
public record LinkPreviewMention: Mention
44+
{
45+
public Uri Url { get; init; }
46+
}
47+
4348
public record DateMention : Mention
4449
{
4550
public DateTimeOffset? Start { get; init; }

tests/Notion.Sharp.Tests/ModelTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,15 +260,15 @@ public async Task GetBlock_Fails_OnInvalidId()
260260
await SUT.Awaiting(sut => sut.GetBlockAsync(Guid.NewGuid())).Should().ThrowAsync<NotionException>();
261261
}
262262

263-
[Fact]
264-
public async Task GetBlock_Succeds_OnValidId()
263+
[Theory]
264+
[InlineData("eb3f156343164743971a4c44f713a127")]
265+
[InlineData("68d00e3a200b497e80d82285708d58d2")]
266+
public async Task GetBlock_Succeds_OnValidId(string id)
265267
{
266-
var block = await SUT.GetBlockAsync(ValidBlockId);
268+
var block = await SUT.GetBlockAsync(Guid.Parse(id));
267269
block.Should().NotBeNull();
268270
}
269271

270-
271-
272272
[Fact]
273273
public async Task AppendChildren_Fails_OnInvalidId() => await RetryAsync(async () =>
274274
{

tests/Notion.Sharp.Tests/Notion.Sharp.Tests.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,24 @@
66
<ImplicitUsings>enable</ImplicitUsings>
77
</PropertyGroup>
88

9-
<ItemGroup >
9+
<ItemGroup>
1010
<Using Include="System.Text.Json" />
1111
<Using Include="Xunit" />
1212
<Using Include="FluentAssertions" />
13-
<Using Include="Notion.Model"/>
13+
<Using Include="Notion.Model" />
1414
</ItemGroup>
1515

1616
<ItemGroup>
1717
<DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="1.0.1" />
18-
<PackageReference Include="FluentAssertions" Version="6.1.0" />
19-
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="5.0.0" />
20-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
18+
<PackageReference Include="FluentAssertions" Version="6.2.0" />
19+
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.0" />
20+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
2121
<PackageReference Include="xunit" Version="2.4.1" />
2222
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
2323
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2424
<PrivateAssets>all</PrivateAssets>
2525
</PackageReference>
26-
<PackageReference Include="coverlet.collector" Version="3.0.2">
26+
<PackageReference Include="coverlet.collector" Version="3.1.0">
2727
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2828
<PrivateAssets>all</PrivateAssets>
2929
</PackageReference>

0 commit comments

Comments
 (0)