Skip to content

Commit 8f8f4b9

Browse files
Merge pull request #101 from notion-dotnet/feature/79-add-support-to-update-a-block
Add support to update a block 💖
2 parents a1d801f + 52fa7a2 commit 8f8f4b9

18 files changed

+203
-7
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ var complexFiler = new CompoundFilter(
103103
- [x] Retrieve a page
104104
- [x] Create a page
105105
- [x] Update page
106-
- [ ] Blocks
106+
- [x] Blocks
107107
- [x] Retrieve a block
108-
- [ ] Update a block
108+
- [x] Update a block
109109
- [x] Retrieve block children
110110
- [x] Append block children
111111
- [x] Users

Src/Notion.Client/Api/ApiEndpoints.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public static class UsersApiUrls
2020
public static class BlocksApiUrls
2121
{
2222
public static string Retrieve(string blockId) => $"/v1/blocks/{blockId}";
23+
public static string Update(string blockId) => $"/v1/blocks/{blockId}";
2324
public static string RetrieveChildren(string blockId) => $"/v1/blocks/{blockId}/children";
2425
public static string AppendChildren(string blockId) => $"/v1/blocks/{blockId}/children";
2526
}

Src/Notion.Client/Api/Blocks/BlocksClient.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public async Task<Block> AppendChildrenAsync(string blockId, BlocksAppendChildre
4848
return await _client.PatchAsync<Block>(url, body);
4949
}
5050

51-
public async Task<Block> Retrieve(string blockId)
51+
public async Task<Block> RetrieveAsync(string blockId)
5252
{
5353
if (string.IsNullOrWhiteSpace(blockId))
5454
{
@@ -59,5 +59,17 @@ public async Task<Block> Retrieve(string blockId)
5959

6060
return await _client.GetAsync<Block>(url);
6161
}
62+
63+
public async Task<Block> UpdateAsync(string blockId, IUpdateBlock updateBlock)
64+
{
65+
if (string.IsNullOrWhiteSpace(blockId))
66+
{
67+
throw new ArgumentNullException(nameof(blockId));
68+
}
69+
70+
var url = BlocksApiUrls.Update(blockId);
71+
72+
return await _client.PatchAsync<Block>(url, updateBlock);
73+
}
6274
}
6375
}

Src/Notion.Client/Api/Blocks/IBlocksClient.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@ public interface IBlocksClient
99
/// </summary>
1010
/// <param name="blockId"></param>
1111
/// <returns>Block</returns>
12-
Task<Block> Retrieve(string blockId);
12+
Task<Block> RetrieveAsync(string blockId);
13+
14+
/// <summary>
15+
/// Updates the content for the specified block_id based on the block type.
16+
/// </summary>
17+
/// <param name="blockId"></param>
18+
/// <param name="updateBlock"></param>
19+
/// <returns>Block</returns>
20+
Task<Block> UpdateAsync(string blockId, IUpdateBlock updateBlock);
1321

1422
Task<PaginatedList<Block>> RetrieveChildrenAsync(string blockId, BlocksRetrieveChildrenParameters parameters = null);
1523
Task<Block> AppendChildrenAsync(string blockId, BlocksAppendChildrenParameters parameters = null);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Notion.Client
4+
{
5+
public class BulletedListItemUpdateBlock : IUpdateBlock
6+
{
7+
[JsonProperty("bulleted_list_item")]
8+
public TextContentUpdate BulletedListItem { get; set; }
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Notion.Client
4+
{
5+
public class HeadingOneUpdateBlock : IUpdateBlock
6+
{
7+
[JsonProperty("heading_1")]
8+
public TextContentUpdate Heading_1 { get; set; }
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Notion.Client
4+
{
5+
public class HeadingThreeeUpdateBlock : IUpdateBlock
6+
{
7+
[JsonProperty("heading_3")]
8+
public TextContentUpdate Heading_3 { get; set; }
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Notion.Client
4+
{
5+
public class HeadingTwoUpdateBlock : IUpdateBlock
6+
{
7+
[JsonProperty("heading_2")]
8+
public TextContentUpdate Heading_2 { get; set; }
9+
}
10+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace Notion.Client
2+
{
3+
public interface IUpdateBlock
4+
{
5+
}
6+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Notion.Client
4+
{
5+
public class NumberedListItemUpdateBlock : IUpdateBlock
6+
{
7+
[JsonProperty("numbered_list_item")]
8+
public TextContentUpdate NumberedListItem { get; set; }
9+
}
10+
}

0 commit comments

Comments
 (0)