From e66a83fa422a4298344788bba9b805ccc276aa93 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sat, 14 Oct 2023 23:03:37 +0530 Subject: [PATCH 1/5] Add block property in paginated block children response --- Src/Notion.Client/Api/Blocks/BlocksClient.cs | 24 +------------ Src/Notion.Client/Api/Blocks/IBlocksClient.cs | 19 +++++++--- .../BlocksRetrieveChildrenParameters.cs | 9 ----- .../IBlocksRetrieveChildrenQueryParameters.cs | 6 ---- .../Blocks/RetrieveChildren/BlocksClient.cs | 36 +++++++++++++++++++ .../Request/BlockRetrieveChildrenRequest.cs | 13 +++++++ .../IBlockRetrieveChildrenPathParameters.cs | 7 ++++ .../IBlockRetrieveChildrenQueryParameters.cs | 6 ++++ .../Response/RetrieveChildrenResponse.cs | 11 ++++++ .../IBlocksClientTests.cs | 14 ++++++-- Test/Notion.UnitTests/BlocksClientTests.cs | 5 ++- 11 files changed, 104 insertions(+), 46 deletions(-) delete mode 100644 Src/Notion.Client/Api/Blocks/RequestParams/BlocksRetrieveChildrenParameters.cs delete mode 100644 Src/Notion.Client/Api/Blocks/RequestParams/IBlocksRetrieveChildrenQueryParameters.cs create mode 100644 Src/Notion.Client/Api/Blocks/RetrieveChildren/BlocksClient.cs create mode 100644 Src/Notion.Client/Api/Blocks/RetrieveChildren/Request/BlockRetrieveChildrenRequest.cs create mode 100644 Src/Notion.Client/Api/Blocks/RetrieveChildren/Request/IBlockRetrieveChildrenPathParameters.cs create mode 100644 Src/Notion.Client/Api/Blocks/RetrieveChildren/Request/IBlockRetrieveChildrenQueryParameters.cs create mode 100644 Src/Notion.Client/Api/Blocks/RetrieveChildren/Response/RetrieveChildrenResponse.cs diff --git a/Src/Notion.Client/Api/Blocks/BlocksClient.cs b/Src/Notion.Client/Api/Blocks/BlocksClient.cs index 068ce969..2c82457f 100644 --- a/Src/Notion.Client/Api/Blocks/BlocksClient.cs +++ b/Src/Notion.Client/Api/Blocks/BlocksClient.cs @@ -6,7 +6,7 @@ namespace Notion.Client { - public class BlocksClient : IBlocksClient + public sealed partial class BlocksClient : IBlocksClient { private readonly IRestClient _client; @@ -15,28 +15,6 @@ public BlocksClient(IRestClient client) _client = client; } - public async Task> RetrieveChildrenAsync( - string blockId, - BlocksRetrieveChildrenParameters parameters = null, CancellationToken cancellationToken = default) - { - if (string.IsNullOrWhiteSpace(blockId)) - { - throw new ArgumentNullException(nameof(blockId)); - } - - var url = BlocksApiUrls.RetrieveChildren(blockId); - - var queryParameters = (IBlocksRetrieveChildrenQueryParameters)parameters; - - var queryParams = new Dictionary - { - { "start_cursor", queryParameters?.StartCursor }, - { "page_size", queryParameters?.PageSize?.ToString() } - }; - - return await _client.GetAsync>(url, queryParams, cancellationToken: cancellationToken); - } - public async Task> AppendChildrenAsync( string blockId, BlocksAppendChildrenParameters parameters = null, CancellationToken cancellationToken = default) diff --git a/Src/Notion.Client/Api/Blocks/IBlocksClient.cs b/Src/Notion.Client/Api/Blocks/IBlocksClient.cs index 252a218d..59dac072 100644 --- a/Src/Notion.Client/Api/Blocks/IBlocksClient.cs +++ b/Src/Notion.Client/Api/Blocks/IBlocksClient.cs @@ -18,11 +18,22 @@ public interface IBlocksClient /// /// /// Block - Task UpdateAsync(string blockId, IUpdateBlock updateBlock, CancellationToken cancellationToken = default); + Task UpdateAsync(string blockId, IUpdateBlock updateBlock, + CancellationToken cancellationToken = default); - Task> RetrieveChildrenAsync( - string blockId, - BlocksRetrieveChildrenParameters parameters = null, CancellationToken cancellationToken = default); + /// + /// Returns a paginated array of child block objects contained in the block using the ID specified. + ///
+ /// In order to receive a complete representation of a block, you may need to recursively retrieve the + /// block children of child blocks. + ///
+ /// + /// + /// + Task RetrieveChildrenAsync( + BlockRetrieveChildrenRequest request, + CancellationToken cancellationToken = default + ); /// /// Creates and appends new children blocks to the parent block_id specified. diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksRetrieveChildrenParameters.cs b/Src/Notion.Client/Api/Blocks/RequestParams/BlocksRetrieveChildrenParameters.cs deleted file mode 100644 index 30f9c17d..00000000 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksRetrieveChildrenParameters.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Notion.Client -{ - public class BlocksRetrieveChildrenParameters : IBlocksRetrieveChildrenQueryParameters - { - public string StartCursor { get; set; } - - public int? PageSize { get; set; } - } -} diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/IBlocksRetrieveChildrenQueryParameters.cs b/Src/Notion.Client/Api/Blocks/RequestParams/IBlocksRetrieveChildrenQueryParameters.cs deleted file mode 100644 index 5c85e06a..00000000 --- a/Src/Notion.Client/Api/Blocks/RequestParams/IBlocksRetrieveChildrenQueryParameters.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Notion.Client -{ - public interface IBlocksRetrieveChildrenQueryParameters : IPaginationParameters - { - } -} diff --git a/Src/Notion.Client/Api/Blocks/RetrieveChildren/BlocksClient.cs b/Src/Notion.Client/Api/Blocks/RetrieveChildren/BlocksClient.cs new file mode 100644 index 00000000..c91f5c6d --- /dev/null +++ b/Src/Notion.Client/Api/Blocks/RetrieveChildren/BlocksClient.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +namespace Notion.Client +{ + public sealed partial class BlocksClient + { + public async Task RetrieveChildrenAsync( + BlockRetrieveChildrenRequest request, + CancellationToken cancellationToken = default) + { + if (string.IsNullOrWhiteSpace(request.BlockId)) + { + throw new ArgumentNullException(nameof(request.BlockId)); + } + + var url = ApiEndpoints.BlocksApiUrls.RetrieveChildren(request.BlockId); + + var queryParameters = (IBlockRetrieveChildrenQueryParameters)request; + + var queryParams = new Dictionary + { + { "start_cursor", queryParameters?.StartCursor }, + { "page_size", queryParameters?.PageSize?.ToString() } + }; + + return await _client.GetAsync( + url, + queryParams, + cancellationToken: cancellationToken + ); + } + } +} diff --git a/Src/Notion.Client/Api/Blocks/RetrieveChildren/Request/BlockRetrieveChildrenRequest.cs b/Src/Notion.Client/Api/Blocks/RetrieveChildren/Request/BlockRetrieveChildrenRequest.cs new file mode 100644 index 00000000..c0e87f3e --- /dev/null +++ b/Src/Notion.Client/Api/Blocks/RetrieveChildren/Request/BlockRetrieveChildrenRequest.cs @@ -0,0 +1,13 @@ +namespace Notion.Client +{ + public class BlockRetrieveChildrenRequest : + IBlockRetrieveChildrenQueryParameters, + IBlockRetrieveChildrenPathParameters + { + public string StartCursor { get; set; } + + public int? PageSize { get; set; } + + public string BlockId { get; set; } + } +} diff --git a/Src/Notion.Client/Api/Blocks/RetrieveChildren/Request/IBlockRetrieveChildrenPathParameters.cs b/Src/Notion.Client/Api/Blocks/RetrieveChildren/Request/IBlockRetrieveChildrenPathParameters.cs new file mode 100644 index 00000000..c23c2e90 --- /dev/null +++ b/Src/Notion.Client/Api/Blocks/RetrieveChildren/Request/IBlockRetrieveChildrenPathParameters.cs @@ -0,0 +1,7 @@ +namespace Notion.Client +{ + public interface IBlockRetrieveChildrenPathParameters + { + public string BlockId { get; set; } + } +} diff --git a/Src/Notion.Client/Api/Blocks/RetrieveChildren/Request/IBlockRetrieveChildrenQueryParameters.cs b/Src/Notion.Client/Api/Blocks/RetrieveChildren/Request/IBlockRetrieveChildrenQueryParameters.cs new file mode 100644 index 00000000..68c7de32 --- /dev/null +++ b/Src/Notion.Client/Api/Blocks/RetrieveChildren/Request/IBlockRetrieveChildrenQueryParameters.cs @@ -0,0 +1,6 @@ +namespace Notion.Client +{ + public interface IBlockRetrieveChildrenQueryParameters : IPaginationParameters + { + } +} diff --git a/Src/Notion.Client/Api/Blocks/RetrieveChildren/Response/RetrieveChildrenResponse.cs b/Src/Notion.Client/Api/Blocks/RetrieveChildren/Response/RetrieveChildrenResponse.cs new file mode 100644 index 00000000..0b34619f --- /dev/null +++ b/Src/Notion.Client/Api/Blocks/RetrieveChildren/Response/RetrieveChildrenResponse.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class RetrieveChildrenResponse : PaginatedList + { + [JsonProperty("block")] + public Dictionary Block { get; set; } + } +} diff --git a/Test/Notion.IntegrationTests/IBlocksClientTests.cs b/Test/Notion.IntegrationTests/IBlocksClientTests.cs index 3f616cfa..9435060c 100644 --- a/Test/Notion.IntegrationTests/IBlocksClientTests.cs +++ b/Test/Notion.IntegrationTests/IBlocksClientTests.cs @@ -68,7 +68,10 @@ public async Task UpdateBlockAsync_UpdatesGivenBlock() var blockId = blocks.Results.First().Id; await Client.Blocks.UpdateAsync(blockId, new BreadcrumbUpdateBlock()); - blocks = await Client.Blocks.RetrieveChildrenAsync(page.Id); + blocks = await Client.Blocks.RetrieveChildrenAsync(new BlockRetrieveChildrenRequest + { + BlockId = page.Id + }); blocks.Results.Should().HaveCount(1); // cleanup @@ -121,7 +124,10 @@ public async Task UpdateAsync_UpdatesGivenBlock( var blockId = blocks.Results.First().Id; await Client.Blocks.UpdateAsync(blockId, updateBlock); - blocks = await Client.Blocks.RetrieveChildrenAsync(page.Id); + blocks = await Client.Blocks.RetrieveChildrenAsync(new BlockRetrieveChildrenRequest + { + BlockId = page.Id + }); blocks.Results.Should().HaveCount(1); var updatedBlock = blocks.Results.First(); @@ -443,7 +449,9 @@ private static IEnumerable BlockData() var tableBlock = block.Should().NotBeNull().And.BeOfType().Subject; tableBlock.HasChildren.Should().BeTrue(); - var children = client.Blocks.RetrieveChildrenAsync(tableBlock.Id).GetAwaiter().GetResult(); + var children = client.Blocks.RetrieveChildrenAsync(new BlockRetrieveChildrenRequest{ + BlockId = tableBlock.Id + }).GetAwaiter().GetResult(); children.Results.Should().ContainSingle() .Subject.Should().BeOfType() diff --git a/Test/Notion.UnitTests/BlocksClientTests.cs b/Test/Notion.UnitTests/BlocksClientTests.cs index 0d6b2c01..a1432050 100644 --- a/Test/Notion.UnitTests/BlocksClientTests.cs +++ b/Test/Notion.UnitTests/BlocksClientTests.cs @@ -34,7 +34,10 @@ public async Task RetrieveBlockChildren() ); // Act - var childrenResult = await _client.RetrieveChildrenAsync(blockId, new BlocksRetrieveChildrenParameters()); + var childrenResult = await _client.RetrieveChildrenAsync(new BlockRetrieveChildrenRequest + { + BlockId = blockId + }); // Assert var children = childrenResult.Results; From 0d3f322fcf802f7b21ebc53e207693db1ac1288a Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sat, 14 Oct 2023 23:37:33 +0530 Subject: [PATCH 2/5] Add block property in Append children api response --- .../Api/Blocks/AppendChildren/BlocksClient.cs | 25 ++++++++++++++++ .../Request/BlockAppendChildrenRequest.cs} | 4 ++- .../IBlockAppendChildrenBodyParameters.cs} | 2 +- .../IBlockAppendChildrenPathParameters.cs | 7 +++++ .../Response/AppendChildrenResponse.cs | 11 +++++++ Src/Notion.Client/Api/Blocks/BlocksClient.cs | 16 ---------- Src/Notion.Client/Api/Blocks/IBlocksClient.cs | 11 +++---- .../IBlocksClientTests.cs | 29 ++++++++++--------- Test/Notion.UnitTests/BlocksClientTests.cs | 5 ++-- 9 files changed, 72 insertions(+), 38 deletions(-) create mode 100644 Src/Notion.Client/Api/Blocks/AppendChildren/BlocksClient.cs rename Src/Notion.Client/Api/Blocks/{RequestParams/BlocksAppendChildrenParameters.cs => AppendChildren/Request/BlockAppendChildrenRequest.cs} (52%) rename Src/Notion.Client/Api/Blocks/{RequestParams/IBlocksAppendChildrenBodyParameters.cs => AppendChildren/Request/IBlockAppendChildrenBodyParameters.cs} (88%) create mode 100644 Src/Notion.Client/Api/Blocks/AppendChildren/Request/IBlockAppendChildrenPathParameters.cs create mode 100644 Src/Notion.Client/Api/Blocks/AppendChildren/Response/AppendChildrenResponse.cs diff --git a/Src/Notion.Client/Api/Blocks/AppendChildren/BlocksClient.cs b/Src/Notion.Client/Api/Blocks/AppendChildren/BlocksClient.cs new file mode 100644 index 00000000..66d9e1ea --- /dev/null +++ b/Src/Notion.Client/Api/Blocks/AppendChildren/BlocksClient.cs @@ -0,0 +1,25 @@ +using System; +using System.Threading; +using System.Threading.Tasks; + +namespace Notion.Client +{ + public sealed partial class BlocksClient + { + public async Task AppendChildrenAsync( + BlockAppendChildrenRequest request, + CancellationToken cancellationToken = default) + { + if (string.IsNullOrWhiteSpace(request.BlockId)) + { + throw new ArgumentNullException(nameof(request.BlockId)); + } + + var url = ApiEndpoints.BlocksApiUrls.AppendChildren(request.BlockId); + + var body = (IBlockAppendChildrenBodyParameters)request; + + return await _client.PatchAsync(url, body, cancellationToken: cancellationToken); + } + } +} diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksAppendChildrenParameters.cs b/Src/Notion.Client/Api/Blocks/AppendChildren/Request/BlockAppendChildrenRequest.cs similarity index 52% rename from Src/Notion.Client/Api/Blocks/RequestParams/BlocksAppendChildrenParameters.cs rename to Src/Notion.Client/Api/Blocks/AppendChildren/Request/BlockAppendChildrenRequest.cs index 0d5574dd..580d164a 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/BlocksAppendChildrenParameters.cs +++ b/Src/Notion.Client/Api/Blocks/AppendChildren/Request/BlockAppendChildrenRequest.cs @@ -2,10 +2,12 @@ namespace Notion.Client { - public class BlocksAppendChildrenParameters : IBlocksAppendChildrenBodyParameters + public class BlockAppendChildrenRequest : IBlockAppendChildrenBodyParameters, IBlockAppendChildrenPathParameters { public IEnumerable Children { get; set; } public string After { get; set; } + + public string BlockId { get; set; } } } diff --git a/Src/Notion.Client/Api/Blocks/RequestParams/IBlocksAppendChildrenBodyParameters.cs b/Src/Notion.Client/Api/Blocks/AppendChildren/Request/IBlockAppendChildrenBodyParameters.cs similarity index 88% rename from Src/Notion.Client/Api/Blocks/RequestParams/IBlocksAppendChildrenBodyParameters.cs rename to Src/Notion.Client/Api/Blocks/AppendChildren/Request/IBlockAppendChildrenBodyParameters.cs index ef1321aa..3d8650aa 100644 --- a/Src/Notion.Client/Api/Blocks/RequestParams/IBlocksAppendChildrenBodyParameters.cs +++ b/Src/Notion.Client/Api/Blocks/AppendChildren/Request/IBlockAppendChildrenBodyParameters.cs @@ -4,7 +4,7 @@ namespace Notion.Client { // TODO: need an input version of Block - public interface IBlocksAppendChildrenBodyParameters + public interface IBlockAppendChildrenBodyParameters { [JsonProperty("children")] IEnumerable Children { get; set; } diff --git a/Src/Notion.Client/Api/Blocks/AppendChildren/Request/IBlockAppendChildrenPathParameters.cs b/Src/Notion.Client/Api/Blocks/AppendChildren/Request/IBlockAppendChildrenPathParameters.cs new file mode 100644 index 00000000..350382f6 --- /dev/null +++ b/Src/Notion.Client/Api/Blocks/AppendChildren/Request/IBlockAppendChildrenPathParameters.cs @@ -0,0 +1,7 @@ +namespace Notion.Client +{ + public interface IBlockAppendChildrenPathParameters + { + public string BlockId { get; set; } + } +} diff --git a/Src/Notion.Client/Api/Blocks/AppendChildren/Response/AppendChildrenResponse.cs b/Src/Notion.Client/Api/Blocks/AppendChildren/Response/AppendChildrenResponse.cs new file mode 100644 index 00000000..88e04ad5 --- /dev/null +++ b/Src/Notion.Client/Api/Blocks/AppendChildren/Response/AppendChildrenResponse.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class AppendChildrenResponse : PaginatedList + { + [JsonProperty("block")] + public Dictionary Block { get; set; } + } +} diff --git a/Src/Notion.Client/Api/Blocks/BlocksClient.cs b/Src/Notion.Client/Api/Blocks/BlocksClient.cs index 2c82457f..92713a78 100644 --- a/Src/Notion.Client/Api/Blocks/BlocksClient.cs +++ b/Src/Notion.Client/Api/Blocks/BlocksClient.cs @@ -15,22 +15,6 @@ public BlocksClient(IRestClient client) _client = client; } - public async Task> AppendChildrenAsync( - string blockId, - BlocksAppendChildrenParameters parameters = null, CancellationToken cancellationToken = default) - { - if (string.IsNullOrWhiteSpace(blockId)) - { - throw new ArgumentNullException(nameof(blockId)); - } - - var url = BlocksApiUrls.AppendChildren(blockId); - - var body = (IBlocksAppendChildrenBodyParameters)parameters; - - return await _client.PatchAsync>(url, body, cancellationToken: cancellationToken); - } - public async Task RetrieveAsync(string blockId, CancellationToken cancellationToken = default) { if (string.IsNullOrWhiteSpace(blockId)) diff --git a/Src/Notion.Client/Api/Blocks/IBlocksClient.cs b/Src/Notion.Client/Api/Blocks/IBlocksClient.cs index 59dac072..fec1b9f5 100644 --- a/Src/Notion.Client/Api/Blocks/IBlocksClient.cs +++ b/Src/Notion.Client/Api/Blocks/IBlocksClient.cs @@ -38,12 +38,13 @@ Task RetrieveChildrenAsync( /// /// Creates and appends new children blocks to the parent block_id specified. /// - /// Identifier for a block - /// + /// + /// /// A paginated list of newly created first level children block objects. - Task> AppendChildrenAsync( - string blockId, - BlocksAppendChildrenParameters parameters = null, CancellationToken cancellationToken = default); + Task AppendChildrenAsync( + BlockAppendChildrenRequest request, + CancellationToken cancellationToken = default + ); /// /// Sets a Block object, including page blocks, to archived: true using the ID specified. diff --git a/Test/Notion.IntegrationTests/IBlocksClientTests.cs b/Test/Notion.IntegrationTests/IBlocksClientTests.cs index 9435060c..24e28da7 100644 --- a/Test/Notion.IntegrationTests/IBlocksClientTests.cs +++ b/Test/Notion.IntegrationTests/IBlocksClientTests.cs @@ -20,9 +20,9 @@ public async Task AppendChildrenAsync_AppendsBlocksGivenBlocks() ); var blocks = await Client.Blocks.AppendChildrenAsync( - page.Id, - new BlocksAppendChildrenParameters + new BlockAppendChildrenRequest { + BlockId = page.Id, Children = new List { new BreadcrumbBlock { Breadcrumb = new BreadcrumbBlock.Data() }, @@ -58,9 +58,9 @@ public async Task UpdateBlockAsync_UpdatesGivenBlock() ); var blocks = await Client.Blocks.AppendChildrenAsync( - page.Id, - new BlocksAppendChildrenParameters + new BlockAppendChildrenRequest { + BlockId = page.Id, Children = new List { new BreadcrumbBlock { Breadcrumb = new BreadcrumbBlock.Data() } } } ); @@ -68,11 +68,11 @@ public async Task UpdateBlockAsync_UpdatesGivenBlock() var blockId = blocks.Results.First().Id; await Client.Blocks.UpdateAsync(blockId, new BreadcrumbUpdateBlock()); - blocks = await Client.Blocks.RetrieveChildrenAsync(new BlockRetrieveChildrenRequest + var updatedBlocks = await Client.Blocks.RetrieveChildrenAsync(new BlockRetrieveChildrenRequest { BlockId = page.Id }); - blocks.Results.Should().HaveCount(1); + updatedBlocks.Results.Should().HaveCount(1); // cleanup await Client.Pages.UpdateAsync(page.Id, new PagesUpdateParameters { Archived = true }); @@ -88,9 +88,9 @@ public async Task DeleteAsync_DeleteBlockWithGivenId() ); var blocks = await Client.Blocks.AppendChildrenAsync( - page.Id, - new BlocksAppendChildrenParameters + new BlockAppendChildrenRequest { + BlockId = page.Id, Children = new List { new DividerBlock { Divider = new DividerBlock.Data() }, @@ -117,20 +117,23 @@ public async Task UpdateAsync_UpdatesGivenBlock( ); var blocks = await Client.Blocks.AppendChildrenAsync( - page.Id, - new BlocksAppendChildrenParameters { Children = new List { block } } + new BlockAppendChildrenRequest + { + BlockId = page.Id, + Children = new List { block } + } ); var blockId = blocks.Results.First().Id; await Client.Blocks.UpdateAsync(blockId, updateBlock); - blocks = await Client.Blocks.RetrieveChildrenAsync(new BlockRetrieveChildrenRequest + var updatedBlocks = await Client.Blocks.RetrieveChildrenAsync(new BlockRetrieveChildrenRequest { BlockId = page.Id }); - blocks.Results.Should().HaveCount(1); + updatedBlocks.Results.Should().HaveCount(1); - var updatedBlock = blocks.Results.First(); + var updatedBlock = updatedBlocks.Results.First(); assert.Invoke(updatedBlock, Client); diff --git a/Test/Notion.UnitTests/BlocksClientTests.cs b/Test/Notion.UnitTests/BlocksClientTests.cs index a1432050..600e0bf4 100644 --- a/Test/Notion.UnitTests/BlocksClientTests.cs +++ b/Test/Notion.UnitTests/BlocksClientTests.cs @@ -60,8 +60,9 @@ public async Task AppendBlockChildren() .WithBody(jsonData) ); - var parameters = new BlocksAppendChildrenParameters + var request = new BlockAppendChildrenRequest { + BlockId = blockId, Children = new List { new HeadingTwoBlock @@ -100,7 +101,7 @@ public async Task AppendBlockChildren() }; // Act - var blocksResult = await _client.AppendChildrenAsync(blockId, parameters); + var blocksResult = await _client.AppendChildrenAsync(request); // Assert var blocks = blocksResult.Results; From 37a7125afac4c5b16a64d8126a3980b2e142e4fe Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sat, 14 Oct 2023 23:40:07 +0530 Subject: [PATCH 3/5] Add database property in DatabaseQuery response --- .../Api/Databases/Query/Response/DatabaseQueryResponse.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Src/Notion.Client/Api/Databases/Query/Response/DatabaseQueryResponse.cs b/Src/Notion.Client/Api/Databases/Query/Response/DatabaseQueryResponse.cs index 73968c38..5b7c9ec6 100644 --- a/Src/Notion.Client/Api/Databases/Query/Response/DatabaseQueryResponse.cs +++ b/Src/Notion.Client/Api/Databases/Query/Response/DatabaseQueryResponse.cs @@ -1,7 +1,12 @@ -namespace Notion.Client +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client { // ReSharper disable once ClassNeverInstantiated.Global public class DatabaseQueryResponse : PaginatedList { + [JsonProperty("database")] + public Dictionary Database { get; set; } } } From 063723dd96d5120ec7b53a5a99644407494b35a9 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sat, 14 Oct 2023 23:51:17 +0530 Subject: [PATCH 4/5] Add PageOrDatabase property in search response --- Src/Notion.Client/Api/Search/ISearchClient.cs | 8 ++++++-- .../{Parameters => Request}/ISearchBodyParameters.cs | 0 .../Search/{Parameters => Request}/SearchDirection.cs | 0 .../Search/{Parameters => Request}/SearchFilter.cs | 0 .../{Parameters => Request}/SearchObjectType.cs | 0 .../SearchParameters.cs => Request/SearchRequest.cs} | 2 +- .../Api/Search/{Parameters => Request}/SearchSort.cs | 0 .../Api/Search/Response/SearchResponse.cs | 11 +++++++++++ Src/Notion.Client/Api/Search/SearchClient.cs | 10 ++++++---- Test/Notion.UnitTests/SearchClientTest.cs | 2 +- 10 files changed, 25 insertions(+), 8 deletions(-) rename Src/Notion.Client/Api/Search/{Parameters => Request}/ISearchBodyParameters.cs (100%) rename Src/Notion.Client/Api/Search/{Parameters => Request}/SearchDirection.cs (100%) rename Src/Notion.Client/Api/Search/{Parameters => Request}/SearchFilter.cs (100%) rename Src/Notion.Client/Api/Search/{Parameters => Request}/SearchObjectType.cs (100%) rename Src/Notion.Client/Api/Search/{Parameters/SearchParameters.cs => Request/SearchRequest.cs} (82%) rename Src/Notion.Client/Api/Search/{Parameters => Request}/SearchSort.cs (100%) create mode 100644 Src/Notion.Client/Api/Search/Response/SearchResponse.cs diff --git a/Src/Notion.Client/Api/Search/ISearchClient.cs b/Src/Notion.Client/Api/Search/ISearchClient.cs index a1e05990..accee1e1 100644 --- a/Src/Notion.Client/Api/Search/ISearchClient.cs +++ b/Src/Notion.Client/Api/Search/ISearchClient.cs @@ -11,10 +11,14 @@ public interface ISearchClient /// Searches all original pages, databases, and child pages/databases that are shared with the integration. /// It will not return linked databases, since these duplicate their source databases. /// - /// Search filters and body parameters + /// Search filters and body parameters + /// /// /// /// - Task> SearchAsync(SearchParameters parameters, CancellationToken cancellationToken = default); + Task SearchAsync( + SearchRequest request, + CancellationToken cancellationToken = default + ); } } diff --git a/Src/Notion.Client/Api/Search/Parameters/ISearchBodyParameters.cs b/Src/Notion.Client/Api/Search/Request/ISearchBodyParameters.cs similarity index 100% rename from Src/Notion.Client/Api/Search/Parameters/ISearchBodyParameters.cs rename to Src/Notion.Client/Api/Search/Request/ISearchBodyParameters.cs diff --git a/Src/Notion.Client/Api/Search/Parameters/SearchDirection.cs b/Src/Notion.Client/Api/Search/Request/SearchDirection.cs similarity index 100% rename from Src/Notion.Client/Api/Search/Parameters/SearchDirection.cs rename to Src/Notion.Client/Api/Search/Request/SearchDirection.cs diff --git a/Src/Notion.Client/Api/Search/Parameters/SearchFilter.cs b/Src/Notion.Client/Api/Search/Request/SearchFilter.cs similarity index 100% rename from Src/Notion.Client/Api/Search/Parameters/SearchFilter.cs rename to Src/Notion.Client/Api/Search/Request/SearchFilter.cs diff --git a/Src/Notion.Client/Api/Search/Parameters/SearchObjectType.cs b/Src/Notion.Client/Api/Search/Request/SearchObjectType.cs similarity index 100% rename from Src/Notion.Client/Api/Search/Parameters/SearchObjectType.cs rename to Src/Notion.Client/Api/Search/Request/SearchObjectType.cs diff --git a/Src/Notion.Client/Api/Search/Parameters/SearchParameters.cs b/Src/Notion.Client/Api/Search/Request/SearchRequest.cs similarity index 82% rename from Src/Notion.Client/Api/Search/Parameters/SearchParameters.cs rename to Src/Notion.Client/Api/Search/Request/SearchRequest.cs index e1c8ced8..a9ac887f 100644 --- a/Src/Notion.Client/Api/Search/Parameters/SearchParameters.cs +++ b/Src/Notion.Client/Api/Search/Request/SearchRequest.cs @@ -1,6 +1,6 @@ namespace Notion.Client { - public class SearchParameters : ISearchBodyParameters + public class SearchRequest : ISearchBodyParameters { public string Query { get; set; } diff --git a/Src/Notion.Client/Api/Search/Parameters/SearchSort.cs b/Src/Notion.Client/Api/Search/Request/SearchSort.cs similarity index 100% rename from Src/Notion.Client/Api/Search/Parameters/SearchSort.cs rename to Src/Notion.Client/Api/Search/Request/SearchSort.cs diff --git a/Src/Notion.Client/Api/Search/Response/SearchResponse.cs b/Src/Notion.Client/Api/Search/Response/SearchResponse.cs new file mode 100644 index 00000000..2be0e2f1 --- /dev/null +++ b/Src/Notion.Client/Api/Search/Response/SearchResponse.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class SearchResponse : PaginatedList + { + [JsonProperty("page_or_database")] + public Dictionary PageOrDatabase { get; set; } + } +} diff --git a/Src/Notion.Client/Api/Search/SearchClient.cs b/Src/Notion.Client/Api/Search/SearchClient.cs index cebe6aa3..492e0940 100644 --- a/Src/Notion.Client/Api/Search/SearchClient.cs +++ b/Src/Notion.Client/Api/Search/SearchClient.cs @@ -4,7 +4,7 @@ namespace Notion.Client { - public class SearchClient : ISearchClient + public sealed class SearchClient : ISearchClient { private readonly IRestClient _client; @@ -13,13 +13,15 @@ public SearchClient(IRestClient client) _client = client; } - public async Task> SearchAsync(SearchParameters parameters, CancellationToken cancellationToken = default) + public async Task SearchAsync( + SearchRequest request, + CancellationToken cancellationToken = default) { var url = SearchApiUrls.Search(); - var body = (ISearchBodyParameters)parameters; + var body = (ISearchBodyParameters)request; - return await _client.PostAsync>(url, body, cancellationToken: cancellationToken); + return await _client.PostAsync(url, body, cancellationToken: cancellationToken); } } } diff --git a/Test/Notion.UnitTests/SearchClientTest.cs b/Test/Notion.UnitTests/SearchClientTest.cs index 63fb4a94..35765cef 100644 --- a/Test/Notion.UnitTests/SearchClientTest.cs +++ b/Test/Notion.UnitTests/SearchClientTest.cs @@ -30,7 +30,7 @@ public async Task Search() .WithBody(jsonData) ); - var searchParameters = new SearchParameters + var searchParameters = new SearchRequest { Query = "External tasks", Sort = new SearchSort From 535b161fc2d39cae5758a9de0955aa0532722565 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar <18693839+KoditkarVedant@users.noreply.github.com> Date: Sun, 15 Oct 2023 00:03:34 +0530 Subject: [PATCH 5/5] Add User property to ListUsers response --- Src/Notion.Client/Api/Users/IUsersClient.cs | 18 ++++++++++++++---- ...tUsersParameters.cs => ListUsersRequest.cs} | 2 +- .../Users/List/Response/ListUsersResponse.cs | 11 +++++++++++ .../Api/Users/List/UsersClient.cs | 16 ++++++++++++---- Src/Notion.Client/Api/Users/UsersClient.cs | 5 ----- 5 files changed, 38 insertions(+), 14 deletions(-) rename Src/Notion.Client/Api/Users/List/Request/{ListUsersParameters.cs => ListUsersRequest.cs} (78%) create mode 100644 Src/Notion.Client/Api/Users/List/Response/ListUsersResponse.cs diff --git a/Src/Notion.Client/Api/Users/IUsersClient.cs b/Src/Notion.Client/Api/Users/IUsersClient.cs index 0f9f18ac..bc0c3d8a 100644 --- a/Src/Notion.Client/Api/Users/IUsersClient.cs +++ b/Src/Notion.Client/Api/Users/IUsersClient.cs @@ -19,13 +19,23 @@ public interface IUsersClient /// Returns a paginated list of Users for the workspace. /// The response may contain fewer than page_size of results. /// + /// /// - /// + /// /// - Task> ListAsync(CancellationToken cancellationToken = default); + Task ListAsync(CancellationToken cancellationToken = default); - Task> ListAsync( - ListUsersParameters listUsersParameters, + /// + /// Returns a paginated list of Users for the workspace. + /// The response may contain fewer than page_size of results. + /// + /// + /// + /// + /// + /// + Task ListAsync( + ListUsersRequest listUsersRequest, CancellationToken cancellationToken = default ); diff --git a/Src/Notion.Client/Api/Users/List/Request/ListUsersParameters.cs b/Src/Notion.Client/Api/Users/List/Request/ListUsersRequest.cs similarity index 78% rename from Src/Notion.Client/Api/Users/List/Request/ListUsersParameters.cs rename to Src/Notion.Client/Api/Users/List/Request/ListUsersRequest.cs index 046a0c5b..f3684d09 100644 --- a/Src/Notion.Client/Api/Users/List/Request/ListUsersParameters.cs +++ b/Src/Notion.Client/Api/Users/List/Request/ListUsersRequest.cs @@ -4,7 +4,7 @@ public interface IListUsersQueryParameters : IPaginationParameters { } - public class ListUsersParameters : IListUsersQueryParameters + public class ListUsersRequest : IListUsersQueryParameters { public string StartCursor { get; set; } diff --git a/Src/Notion.Client/Api/Users/List/Response/ListUsersResponse.cs b/Src/Notion.Client/Api/Users/List/Response/ListUsersResponse.cs new file mode 100644 index 00000000..2d30237f --- /dev/null +++ b/Src/Notion.Client/Api/Users/List/Response/ListUsersResponse.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; +using Newtonsoft.Json; + +namespace Notion.Client +{ + public class ListUsersResponse : PaginatedList + { + [JsonProperty("user")] + public Dictionary User { get; set; } + } +} diff --git a/Src/Notion.Client/Api/Users/List/UsersClient.cs b/Src/Notion.Client/Api/Users/List/UsersClient.cs index 57c40ea3..ce13633a 100644 --- a/Src/Notion.Client/Api/Users/List/UsersClient.cs +++ b/Src/Notion.Client/Api/Users/List/UsersClient.cs @@ -7,12 +7,20 @@ namespace Notion.Client { public partial class UsersClient { - public async Task> ListAsync( - ListUsersParameters listUsersParameters, + public async Task ListAsync(CancellationToken cancellationToken = default) + { + return await _client.GetAsync( + ApiEndpoints.UsersApiUrls.List(), + cancellationToken: cancellationToken + ); + } + + public async Task ListAsync( + ListUsersRequest listUsersRequest, CancellationToken cancellationToken = default ) { - var queryParameters = (IListUsersQueryParameters)listUsersParameters; + var queryParameters = (IListUsersQueryParameters)listUsersRequest; var queryParams = new Dictionary { @@ -20,7 +28,7 @@ public async Task> ListAsync( { "page_size", queryParameters?.PageSize?.ToString() } }; - return await _client.GetAsync>( + return await _client.GetAsync( ApiEndpoints.UsersApiUrls.List(), queryParams, cancellationToken: cancellationToken diff --git a/Src/Notion.Client/Api/Users/UsersClient.cs b/Src/Notion.Client/Api/Users/UsersClient.cs index f40299ee..24681b53 100644 --- a/Src/Notion.Client/Api/Users/UsersClient.cs +++ b/Src/Notion.Client/Api/Users/UsersClient.cs @@ -18,11 +18,6 @@ public async Task RetrieveAsync(string userId, CancellationToken cancellat return await _client.GetAsync(UsersApiUrls.Retrieve(userId), cancellationToken: cancellationToken); } - public async Task> ListAsync(CancellationToken cancellationToken = default) - { - return await _client.GetAsync>(UsersApiUrls.List(), cancellationToken: cancellationToken); - } - /// /// Retrieves the bot User associated with the API token provided in the authorization header. ///