Skip to content

Commit 4b62a88

Browse files
Add support to Retrieve a block ✨
1 parent 71c926c commit 4b62a88

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

Src/Notion.Client/Api/ApiEndpoints.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public static class UsersApiUrls
1919

2020
public static class BlocksApiUrls
2121
{
22+
public static string Retrieve(string blockId) => $"/v1/blocks/{blockId}";
2223
public static string RetrieveChildren(string blockId) => $"/v1/blocks/{blockId}/children";
2324
public static string AppendChildren(string blockId) => $"/v1/blocks/{blockId}/children";
2425
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,17 @@ public async Task<Block> AppendChildrenAsync(string blockId, BlocksAppendChildre
4747

4848
return await _client.PatchAsync<Block>(url, body);
4949
}
50+
51+
public async Task<Block> Retrieve(string blockId)
52+
{
53+
if (string.IsNullOrWhiteSpace(blockId))
54+
{
55+
throw new ArgumentNullException(nameof(blockId));
56+
}
57+
58+
var url = BlocksApiUrls.Retrieve(blockId);
59+
60+
return await _client.GetAsync<Block>(url);
61+
}
5062
}
5163
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ namespace Notion.Client
44
{
55
public interface IBlocksClient
66
{
7+
/// <summary>
8+
/// Retrieves a Block object using the ID specified.
9+
/// </summary>
10+
/// <param name="blockId"></param>
11+
/// <returns>Block</returns>
12+
Task<Block> Retrieve(string blockId);
13+
714
Task<PaginatedList<Block>> RetrieveChildrenAsync(string blockId, BlocksRetrieveChildrenParameters parameters = null);
815
Task<Block> AppendChildrenAsync(string blockId, BlocksAppendChildrenParameters parameters = null);
916
}

0 commit comments

Comments
 (0)