8000 Add support to delete block API 💖 by KoditkarVedant · Pull Request #144 · notion-dotnet/notion-sdk-net · GitHub
[go: up one dir, main page]

Skip to content

Add support to delete block API 💖 #144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
8000 Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Src/Notion.Client/Api/ApiEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}";

/// <summary>
/// Get the <see cref="uri string"/> for deleting a block.
/// </summary>
/// <param name="blockId">Identifier for a Notion block</param>
/// <returns>Returns a <see cref="uri string"/> for deleting a block.</returns>
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";
}
Expand Down
12 changes: 12 additions & 0 deletions Src/Notion.Client/Api/Blocks/BlocksClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,17 @@ public async Task<Block> UpdateAsync(string blockId, IUpdateBlock updateBlock)

return await _client.PatchAsync<Block>(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);
}
}
}
6 changes: 6 additions & 0 deletions Src/Notion.Client/Api/Blocks/IBlocksClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,11 @@ public interface IBlocksClient
/// <param name="parameters"></param>
/// <returns>A paginated list of newly created first level children block objects.</returns>
Task<PaginatedList<Block>> AppendChildrenAsync(string blockId, BlocksAppendChildrenParameters parameters = null);

/// <summary>
/// Sets a Block object, including page blocks, to archived: true using the ID specified.
/// </summary>
/// <param name="blockId">Identifier for a Notion block</param>
Task DeleteAsync(string blockId);
}
}
7 changes: 7 additions & 0 deletions Src/Notion.Client/RestClient/IRestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,12 @@ Task<T> PatchAsync<T>(
IDictionary<string, string> headers = null,
JsonSerializerSettings serializerSettings = null,
CancellationToken cancellationToken = default);

Task DeleteAsync(
string uri,
IDictionary<string, string> queryParams = null,
IDictionary<string, string> headers = null,
JsonSerializerSettings serializerSettings = null,
CancellationToken cancellationToken = default);
}
}
5 changes: 5 additions & 0 deletions Src/Notion.Client/RestClient/RestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ void AttachContent(HttpRequestMessage httpRequest)
return await response.ParseStreamAsync<T>(serializerSettings);
}

public async Task DeleteAsync(string uri, IDictionary<string, string> queryParams = null, IDictionary<string, string> headers = null, JsonSerializerSettings serializerSettings = null, CancellationToken cancellationToken = default)
{
await SendAsync(uri, HttpMethod.Delete, queryParams, headers, null, cancellationToken);
}

private HttpClient EnsureHttpClient()
{
if (_httpClient == null)
Expand Down
0