diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BookmarkUpdateBlock.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BookmarkUpdateBlock.cs new file mode 100644 index 00000000..71b0cec6 --- /dev/null +++ b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksUpdateParameters/UpdateBlocks/BookmarkUpdateBlock.cs @@ -0,0 +1,22 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class BookmarkUpdateBlock : IUpdateBlock + { + public bool Archived { get; set; } + + [JsonProperty("bookmark")] + public Data Bookmark { get; set; } + + public class Data + { + [JsonProperty("url")] + public string Url { get; set; } + + [JsonProperty("caption")] + public IEnumerable Caption { get; set; } + } + } +} diff --git a/Src/Notion.Client/Models/Blocks/BookmarkBlock.cs b/Src/Notion.Client/Models/Blocks/BookmarkBlock.cs index f4df3a90..c0380b73 100644 --- a/Src/Notion.Client/Models/Blocks/BookmarkBlock.cs +++ b/Src/Notion.Client/Models/Blocks/BookmarkBlock.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json; +using System.Collections.Generic; +using Newtonsoft.Json; namespace Notion.Client { @@ -13,6 +14,9 @@ public class Info { [JsonProperty("url")] public string Url { get; set; } + + [JsonProperty("caption")] + public IEnumerable Caption { get; set; } } } } diff --git a/Test/Notion.IntegrationTests/IBlocksClientTests.cs b/Test/Notion.IntegrationTests/IBlocksClientTests.cs index 88294504..58909160 100644 --- a/Test/Notion.IntegrationTests/IBlocksClientTests.cs +++ b/Test/Notion.IntegrationTests/IBlocksClientTests.cs @@ -146,5 +146,101 @@ public async Task DeleteAsync_DeleteBlockWithGivenId() Archived = true }); } + + [Theory] + [MemberData(nameof(BlockData))] + public async Task UpdateAsync_UpdatesGivenBlock(Block block, IUpdateBlock updateBlock, Action assert) + { + var options = new ClientOptions + { + AuthToken = Environment.GetEnvironmentVariable("NOTION_AUTH_TOKEN") + }; + INotionClient _client = NotionClientFactory.Create(options); + + var pageParentId = "3c357473a28149a488c010d2b245a589"; + + var page = await _client.Pages.CreateAsync( + PagesCreateParametersBuilder.Create( + new ParentPageInput + { + PageId = pageParentId + } + ).Build() + ); + + var blocks = await _client.Blocks.AppendChildrenAsync( + page.Id, + new BlocksAppendChildrenParameters + { + Children = new List() + { + block + } + } + ); + + var blockId = blocks.Results.First().Id; + await _client.Blocks.UpdateAsync(blockId, updateBlock); + + blocks = await _client.Blocks.RetrieveChildrenAsync(page.Id); + blocks.Results.Should().HaveCount(1); + + var updatedBlock = blocks.Results.First(); + + assert.Invoke(updatedBlock); + + // cleanup + await _client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters + { + Archived = true + }); + } + + private static IEnumerable BlockData() + { + return new List + { + new object[] { + new BookmarkBlock + { + Bookmark = new BookmarkBlock.Info + { + Url = "https://developers.notion.com/reference/rich-text", + Caption = new List + { + new RichTextTextInput + { + Text = new Text + { + Content = "Notion API" + } + } + } + } + }, + new BookmarkUpdateBlock { + Bookmark = new BookmarkUpdateBlock.Data + { + Url = "https://github.com/notion-dotnet/notion-sdk-net", + Caption = new List + { + new RichTextTextInput + { + Text = new Text + { + Content = "Github" + } + } + } + } + }, + new Action((block) => { + var updatedBlock = (BookmarkBlock)block; + Assert.Equal("https://github.com/notion-dotnet/notion-sdk-net", updatedBlock.Bookmark.Url); + Assert.Equal("Github", updatedBlock.Bookmark.Caption.OfType().First().Text.Content); + }) + } + }; + } } }