Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<RichTextBaseInput> Caption { get; set; }
}
}
}
6 changes: 5 additions & 1 deletion Src/Notion.Client/Models/Blocks/BookmarkBlock.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Notion.Client
{
Expand All @@ -13,6 +14,9 @@ public class Info
{
[JsonProperty("url")]
public string Url { get; set; }

[JsonProperty("caption")]
public IEnumerable<RichTextBase> Caption { get; set; }
}
}
}
96 changes: 96 additions & 0 deletions Test/Notion.IntegrationTests/IBlocksClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Block> 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>()
{
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<object[]> BlockData()
{
return new List<object[]>
{
new object[] {
new BookmarkBlock
{
Bookmark = new BookmarkBlock.Info
{
Url = "https://developers.notion.com/reference/rich-text",
Caption = new List<RichTextBase>
{
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<RichTextBaseInput>
{
new RichTextTextInput
{
Text = new Text
{
Content = "Github"
}
}
}
}
},
new Action<Block>((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<RichTextText>().First().Text.Content);
})
}
};
}
}
}