From 79a70ac3cbfa5d8394027a6ac75bc9e6bf1347c7 Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Fri, 1 Oct 2021 22:33:42 +0530 Subject: [PATCH 1/2] =?UTF-8?q?Update=20rest=20client=20to=20send=20delete?= =?UTF-8?q?=20request=20=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Notion.Client/RestClient/IRestClient.cs | 7 +++++++ Src/Notion.Client/RestClient/RestClient.cs | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/Src/Notion.Client/RestClient/IRestClient.cs b/Src/Notion.Client/RestClient/IRestClient.cs index 9aa41173..792840b6 100644 --- a/Src/Notion.Client/RestClient/IRestClient.cs +++ b/Src/Notion.Client/RestClient/IRestClient.cs @@ -29,5 +29,12 @@ Task PatchAsync( IDictionary headers = null, JsonSerializerSettings serializerSettings = null, CancellationToken cancellationToken = default); + + Task DeleteAsync( + string uri, + IDictionary queryParams = null, + IDictionary headers = null, + JsonSerializerSettings serializerSettings = null, + CancellationToken cancellationToken = default); } } diff --git a/Src/Notion.Client/RestClient/RestClient.cs b/Src/Notion.Client/RestClient/RestClient.cs index 91428218..abc4491c 100644 --- a/Src/Notion.Client/RestClient/RestClient.cs +++ b/Src/Notion.Client/RestClient/RestClient.cs @@ -144,6 +144,11 @@ void AttachContent(HttpRequestMessage httpRequest) return await response.ParseStreamAsync(serializerSettings); } + public async Task DeleteAsync(string uri, IDictionary queryParams = null, IDictionary headers = null, JsonSerializerSettings serializerSettings = null, CancellationToken cancellationToken = default) + { + await SendAsync(uri, HttpMethod.Delete, queryParams, headers, null, cancellationToken); + } + private HttpClient EnsureHttpClient() { if (_httpClient == null) From 55d842a9dd089a838407aa41a3f0b288c12f7a9e Mon Sep 17 00:00:00 2001 From: Vedant Koditkar Date: Fri, 1 Oct 2021 22:34:26 +0530 Subject: [PATCH 2/2] =?UTF-8?q?Add=20support=20to=20delete=20block=20api?= =?UTF-8?q?=20=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Src/Notion.Client/Api/ApiEndpoints.cs | 8 ++++++++ Src/Notion.Client/Api/Blocks/BlocksClient.cs | 12 ++++++++++++ Src/Notion.Client/Api/Blocks/IBlocksClient.cs | 6 ++++++ 3 files changed, 26 insertions(+) diff --git a/Src/Notion.Client/Api/ApiEndpoints.cs b/Src/Notion.Client/Api/ApiEndpoints.cs index e2fa13cf..8e68e22b 100644 --- a/Src/Notion.Client/Api/ApiEndpoints.cs +++ b/Src/Notion.Client/Api/ApiEndpoints.cs @@ -21,6 +21,14 @@ public static class BlocksApiUrls { public static string Retrieve(string blockId) => $"/v1/blocks/{blockId}"; public static string Update(string blockId) => $"/v1/blocks/{blockId}"; + + /// + /// Get the for deleting a block. + /// + /// Identifier for a Notion block + /// Returns a for deleting a block. + public static string Delete(string blockId) => $"/v1/blocks/{blockId}"; + public static string RetrieveChildren(string blockId) => $"/v1/blocks/{blockId}/children"; public static string AppendChildren(string blockId) => $"/v1/blocks/{blockId}/children"; } diff --git a/Src/Notion.Client/Api/Blocks/BlocksClient.cs b/Src/Notion.Client/Api/Blocks/BlocksClient.cs index 19d07474..4c038cc5 100644 --- a/Src/Notion.Client/Api/Blocks/BlocksClient.cs +++ b/Src/Notion.Client/Api/Blocks/BlocksClient.cs @@ -71,5 +71,17 @@ public async Task UpdateAsync(string blockId, IUpdateBlock updateBlock) return await _client.PatchAsync(url, updateBlock); } + + public async Task DeleteAsync(string blockId) + { + if (string.IsNullOrWhiteSpace(blockId)) + { + throw new ArgumentNullException(nameof(blockId)); + } + + var url = BlocksApiUrls.Delete(blockId); + + await _client.DeleteAsync(url); + } } } diff --git a/Src/Notion.Client/Api/Blocks/IBlocksClient.cs b/Src/Notion.Client/Api/Blocks/IBlocksClient.cs index 917f8f95..4c088803 100644 --- a/Src/Notion.Client/Api/Blocks/IBlocksClient.cs +++ b/Src/Notion.Client/Api/Blocks/IBlocksClient.cs @@ -28,5 +28,11 @@ public interface IBlocksClient /// /// A paginated list of newly created first level children block objects. Task> AppendChildrenAsync(string blockId, BlocksAppendChildrenParameters parameters = null); + + /// + /// Sets a Block object, including page blocks, to archived: true using the ID specified. + /// + /// Identifier for a Notion block + Task DeleteAsync(string blockId); } }