Skip to content

Commit 40a4251

Browse files
Add support to update block ✨
1 parent a1d801f commit 40a4251

File tree

13 files changed

+113
-0
lines changed

13 files changed

+113
-0
lines changed

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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ public interface IBlocksClient
1111
/// <returns>Block</returns>
1212
Task<Block> Retrieve(string blockId);
1313

14+
Task<Block> UpdateAsync(string blockId, IUpdateBlock updateBlock);
15+
1416
Task<PaginatedList<Block>> RetrieveChildrenAsync(string blockId, BlocksRetrieveChildrenParameters parameters = null);
1517
Task<Block> AppendChildrenAsync(string blockId, BlocksAppendChildrenParameters parameters = null);
1618
}
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+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Notion.Client
2+
{
3+
public class ParagraphUpdateBlock : IUpdateBlock
4+
{
5+
public TextContentUpdate Paragraph { get; set; }
6+
}
7+
}

0 commit comments

Comments
 (0)