Skip to content

Commit ce393c0

Browse files
Merge branch 'main' into bug/TimestampLastEditedTimeFilter
2 parents 366c5a4 + dd5a5ad commit ce393c0

26 files changed

+176
-76
lines changed

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Threading;
34
using System.Threading.Tasks;
45
using static Notion.Client.ApiEndpoints;
56

@@ -16,7 +17,7 @@ public BlocksClient(IRestClient client)
1617

1718
public async Task<PaginatedList<IBlock>> RetrieveChildrenAsync(
1819
string blockId,
19-
BlocksRetrieveChildrenParameters parameters = null)
20+
BlocksRetrieveChildrenParameters parameters = null, CancellationToken cancellationToken = default)
2021
{
2122
if (string.IsNullOrWhiteSpace(blockId))
2223
{
@@ -33,12 +34,12 @@ public async Task<PaginatedList<IBlock>> RetrieveChildrenAsync(
3334
{ "page_size", queryParameters?.PageSize?.ToString() }
3435
};
3536

36-
return await _client.GetAsync<PaginatedList<IBlock>>(url, queryParams);
37+
return await _client.GetAsync<PaginatedList<IBlock>>(url, queryParams, cancellationToken: cancellationToken);
3738
}
3839

3940
public async Task<PaginatedList<IBlock>> AppendChildrenAsync(
4041
string blockId,
41-
BlocksAppendChildrenParameters parameters = null)
42+
BlocksAppendChildrenParameters parameters = null, CancellationToken cancellationToken = default)
4243
{
4344
if (string.IsNullOrWhiteSpace(blockId))
4445
{
@@ -49,10 +50,10 @@ public async Task<PaginatedList<IBlock>> AppendChildrenAsync(
4950

5051
var body = (IBlocksAppendChildrenBodyParameters)parameters;
5152

52-
return await _client.PatchAsync<PaginatedList<IBlock>>(url, body);
53+
return await _client.PatchAsync<PaginatedList<IBlock>>(url, body, cancellationToken: cancellationToken);
5354
}
5455

55-
public async Task<IBlock> RetrieveAsync(string blockId)
56+
public async Task<IBlock> RetrieveAsync(string blockId, CancellationToken cancellationToken = default)
5657
{
5758
if (string.IsNullOrWhiteSpace(blockId))
5859
{
@@ -61,10 +62,10 @@ public async Task<IBlock> RetrieveAsync(string blockId)
6162

6263
var url = BlocksApiUrls.Retrieve(blockId);
6364

64-
return await _client.GetAsync<IBlock>(url);
65+
return await _client.GetAsync<IBlock>(url, cancellationToken: cancellationToken);
6566
}
6667

67-
public async Task<IBlock> UpdateAsync(string blockId, IUpdateBlock updateBlock)
68+
public async Task<IBlock> UpdateAsync(string blockId, IUpdateBlock updateBlock, CancellationToken cancellationToken = default)
6869
{
6970
if (string.IsNullOrWhiteSpace(blockId))
7071
{
@@ -73,10 +74,10 @@ public async Task<IBlock> UpdateAsync(string blockId, IUpdateBlock updateBlock)
7374

7475
var url = BlocksApiUrls.Update(blockId);
7576

76-
return await _client.PatchAsync<IBlock>(url, updateBlock);
77+
return await _client.PatchAsync<IBlock>(url, updateBlock, cancellationToken: cancellationToken);
7778
}
7879

79-
public async Task DeleteAsync(string blockId)
80+
public async Task DeleteAsync(string blockId, CancellationToken cancellationToken = default)
8081
{
8182
if (string.IsNullOrWhiteSpace(blockId))
8283
{
@@ -85,7 +86,7 @@ public async Task DeleteAsync(string blockId)
8586

8687
var url = BlocksApiUrls.Delete(blockId);
8788

88-
await _client.DeleteAsync(url);
89+
await _client.DeleteAsync(url, cancellationToken: cancellationToken);
8990
}
9091
}
9192
}
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Threading.Tasks;
1+
using System.Threading;
2+
using System.Threading.Tasks;
23

34
namespace Notion.Client
45
{
@@ -9,19 +10,19 @@ public interface IBlocksClient
910
/// </summary>
1011
/// <param name="blockId"></param>
1112
/// <returns>Block</returns>
12-
Task<IBlock> RetrieveAsync(string blockId);
13+
Task<IBlock> RetrieveAsync(string blockId, CancellationToken cancellationToken = default);
1314

1415
/// <summary>
1516
/// Updates the content for the specified block_id based on the block type.
1617
/// </summary>
1718
/// <param name="blockId"></param>
1819
/// <param name="updateBlock"></param>
1920
/// <returns>Block</returns>
20-
Task<IBlock> UpdateAsync(string blockId, IUpdateBlock updateBlock);
21+
Task<IBlock> UpdateAsync(string blockId, IUpdateBlock updateBlock, CancellationToken cancellationToken = default);
2122

2223
Task<PaginatedList<IBlock>> RetrieveChildrenAsync(
2324
string blockId,
24-
BlocksRetrieveChildrenParameters parameters = null);
25+
BlocksRetrieveChildrenParameters parameters = null, CancellationToken cancellationToken = default);
2526

2627
/// <summary>
2728
/// Creates and appends new children blocks to the parent block_id specified.
@@ -31,12 +32,12 @@ Task<PaginatedList<IBlock>> RetrieveChildrenAsync(
3132
/// <returns>A paginated list of newly created first level children block objects.</returns>
3233
Task<PaginatedList<IBlock>> AppendChildrenAsync(
3334
string blockId,
34-
BlocksAppendChildrenParameters parameters = null);
35+
BlocksAppendChildrenParameters parameters = null, CancellationToken cancellationToken = default);
3536

3637
/// <summary>
3738
/// Sets a Block object, including page blocks, to archived: true using the ID specified.
3839
/// </summary>
3940
/// <param name="blockId">Identifier for a Notion block</param>
40-
Task DeleteAsync(string blockId);
41+
Task DeleteAsync(string blockId, CancellationToken cancellationToken = default);
4142
}
4243
}

Src/Notion.Client/Api/Comments/Create/CommentsClient.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
using System.Threading.Tasks;
1+
using System.Threading;
2+
using System.Threading.Tasks;
23

34
namespace Notion.Client
45
{
56
public partial class CommentsClient
67
{
7-
public async Task<CreateCommentResponse> CreateAsync(CreateCommentParameters parameters)
8+
public async Task<CreateCommentResponse> CreateAsync(CreateCommentParameters parameters, CancellationToken cancellationToken = default)
89
{
910
var body = (ICreateCommentsBodyParameters)parameters;
1011

1112
return await _client.PostAsync<CreateCommentResponse>(
1213
ApiEndpoints.CommentsApiUrls.Create(),
13-
body
14+
body,
15+
cancellationToken: cancellationToken
1416
);
1517
}
1618
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
using System.Threading;
12
using System.Threading.Tasks;
23

34
namespace Notion.Client
45
{
56
public interface ICommentsClient
67
{
7-
Task<CreateCommentResponse> CreateAsync(CreateCommentParameters createCommentParameters);
8+
Task<CreateCommentResponse> CreateAsync(CreateCommentParameters createCommentParameters, CancellationToken cancellationToken = default);
89

9-
Task<RetrieveCommentsResponse> RetrieveAsync(RetrieveCommentsParameters parameters);
10+
Task<RetrieveCommentsResponse> RetrieveAsync(RetrieveCommentsParameters parameters, CancellationToken cancellationToken = default);
1011
}
1112
}

Src/Notion.Client/Api/Comments/Retrieve/CommentsClient.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
using System.Collections.Generic;
22
using System.Diagnostics.CodeAnalysis;
3+
using System.Threading;
34
using System.Threading.Tasks;
45

56
namespace Notion.Client
67
{
78
public partial class CommentsClient
89
{
910
[SuppressMessage("ReSharper", "UnusedMember.Global")]
10-
public async Task<RetrieveCommentsResponse> RetrieveAsync(RetrieveCommentsParameters parameters)
11+
public async Task<RetrieveCommentsResponse> RetrieveAsync(RetrieveCommentsParameters parameters, CancellationToken cancellationToken = default)
1112
{
1213
var qp = (IRetrieveCommentsQueryParameters)parameters;
1314

@@ -20,7 +21,8 @@ public async Task<RetrieveCommentsResponse> RetrieveAsync(RetrieveCommentsParame
2021

2122
return await _client.GetAsync<RetrieveCommentsResponse>(
2223
ApiEndpoints.CommentsApiUrls.Retrieve(),
23-
queryParams
24+
queryParams,
25+
cancellationToken: cancellationToken
2426
);
2527
}
2628
}
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Threading.Tasks;
1+
using System.Threading;
2+
using System.Threading.Tasks;
23
using static Notion.Client.ApiEndpoints;
34

45
namespace Notion.Client
@@ -12,32 +13,32 @@ public DatabasesClient(IRestClient client)
1213
_client = client;
1314
}
1415

15-
public async Task<Database> RetrieveAsync(string databaseId)
16+
public async Task<Database> RetrieveAsync(string databaseId, CancellationToken cancellationToken = default)
1617
{
17-
return await _client.GetAsync<Database>(DatabasesApiUrls.Retrieve(databaseId));
18+
return await _client.GetAsync<Database>(DatabasesApiUrls.Retrieve(databaseId), cancellationToken: cancellationToken);
1819
}
1920

2021
public async Task<PaginatedList<Page>> QueryAsync(
2122
string databaseId,
22-
DatabasesQueryParameters databasesQueryParameters)
23+
DatabasesQueryParameters databasesQueryParameters, CancellationToken cancellationToken = default)
2324
{
2425
var body = (IDatabaseQueryBodyParameters)databasesQueryParameters;
2526

26-
return await _client.PostAsync<PaginatedList<Page>>(DatabasesApiUrls.Query(databaseId), body);
27+
return await _client.PostAsync<PaginatedList<Page>>(DatabasesApiUrls.Query(databaseId), body, cancellationToken: cancellationToken);
2728
}
2829

29-
public async Task<Database> CreateAsync(DatabasesCreateParameters databasesCreateParameters)
30+
public async Task<Database> CreateAsync(DatabasesCreateParameters databasesCreateParameters, CancellationToken cancellationToken = default)
3031
{
3132
var body = (IDatabasesCreateBodyParameters)databasesCreateParameters;
3233

33-
return await _client.PostAsync<Database>(DatabasesApiUrls.Create, body);
34+
return await _client.PostAsync<Database>(DatabasesApiUrls.Create, body, cancellationToken: cancellationToken);
3435
}
3536

36-
public async Task<Database> UpdateAsync(string databaseId, DatabasesUpdateParameters databasesUpdateParameters)
37+
public async Task<Database> UpdateAsync(string databaseId, DatabasesUpdateParameters databasesUpdateParameters, CancellationToken cancellationToken = default)
3738
{
3839
var body = (IDatabasesUpdateBodyParameters)databasesUpdateParameters;
3940

40-
return await _client.PatchAsync<Database>(DatabasesApiUrls.Update(databaseId), body);
41+
return await _client.PatchAsync<Database>(DatabasesApiUrls.Update(databaseId), body, cancellationToken: cancellationToken);
4142
}
4243
}
4344
}

Src/Notion.Client/Api/Databases/IDatabasesClient.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Threading.Tasks;
1+
using System.Threading;
2+
using System.Threading.Tasks;
23

34
namespace Notion.Client
45
{
@@ -11,7 +12,7 @@ public interface IDatabasesClient
1112
/// <returns>
1213
/// <see cref="Database" />
1314
/// </returns>
14-
Task<Database> RetrieveAsync(string databaseId);
15+
Task<Database> RetrieveAsync(string databaseId, CancellationToken cancellationToken = default);
1516

1617
/// <summary>
1718
/// Gets a list of Pages contained in the database, filtered and ordered according to the
@@ -23,7 +24,7 @@ public interface IDatabasesClient
2324
/// <returns>
2425
/// <see cref="PaginatedList{T}" />
2526
/// </returns>
26-
Task<PaginatedList<Page>> QueryAsync(string databaseId, DatabasesQueryParameters databasesQueryParameters);
27+
Task<PaginatedList<Page>> QueryAsync(string databaseId, DatabasesQueryParameters databasesQueryParameters, CancellationToken cancellationToken = default);
2728

2829
/// <summary>
2930
/// Creates a database as a subpage in the specified parent page, with the specified properties schema.
@@ -32,7 +33,7 @@ public interface IDatabasesClient
3233
/// <returns>
3334
/// <see cref="Database" />
3435
/// </returns>
35-
Task<Database> CreateAsync(DatabasesCreateParameters databasesCreateParameters);
36+
Task<Database> CreateAsync(DatabasesCreateParameters databasesCreateParameters, CancellationToken cancellationToken = default);
3637

3738
/// <summary>
3839
/// Updates an existing database as specified by the parameters.
@@ -42,6 +43,6 @@ public interface IDatabasesClient
4243
/// <returns>
4344
/// <see cref="Database" />
4445
/// </returns>
45-
Task<Database> UpdateAsync(string databaseId, DatabasesUpdateParameters databasesUpdateParameters);
46+
Task<Database> UpdateAsync(string databaseId, DatabasesUpdateParameters databasesUpdateParameters, CancellationToken cancellationToken = default);
4647
}
4748
}

Src/Notion.Client/Api/Pages/IPagesClient.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using System.Threading;
23
using System.Threading.Tasks;
34

45
namespace Notion.Client
@@ -15,7 +16,7 @@ public interface IPagesClient
1516
/// </summary>
1617
/// <param name="pagesCreateParameters">Create page parameters</param>
1718
/// <returns>Created <see cref="Page" /> object.</returns>
18-
Task<Page> CreateAsync(PagesCreateParameters pagesCreateParameters);
19+
Task<Page> CreateAsync(PagesCreateParameters pagesCreateParameters, CancellationToken cancellationToken = default);
1920

2021
/// <summary>
2122
/// Retrieves a Page object using the ID specified.
@@ -24,7 +25,7 @@ public interface IPagesClient
2425
/// <returns>
2526
/// <see cref="Page" />
2627
/// </returns>
27-
Task<Page> RetrieveAsync(string pageId);
28+
Task<Page> RetrieveAsync(string pageId, CancellationToken cancellationToken = default);
2829

2930
/// <summary>
3031
/// Updates page property values for the specified page.
@@ -38,7 +39,7 @@ public interface IPagesClient
3839
/// <returns>Updated <see cref="Page" /> object</returns>
3940
Task<Page> UpdatePropertiesAsync(
4041
string pageId,
41-
IDictionary<string, PropertyValue> updatedProperties);
42+
IDictionary<string, PropertyValue> updatedProperties, CancellationToken cancellationToken = default);
4243

4344
/// <summary>
4445
/// Updates page property values for the specified page.
@@ -47,7 +48,7 @@ Task<Page> UpdatePropertiesAsync(
4748
/// <param name="pageId">Identifier for a Notion page</param>
4849
/// <param name="pagesUpdateParameters">Update property parameters</param>
4950
/// <returns>Updated <see cref="Page" /> object</returns>
50-
Task<Page> UpdateAsync(string pageId, PagesUpdateParameters pagesUpdateParameters);
51+
Task<Page> UpdateAsync(string pageId, PagesUpdateParameters pagesUpdateParameters, CancellationToken cancellationToken = default);
5152

5253
/// <summary>
5354
/// Retrieves a property_item object for a given pageId and propertyId. Depending on the property type, the object
@@ -58,6 +59,6 @@ Task<Page> UpdatePropertiesAsync(
5859
/// <see cref="IPropertyItemObject" />
5960
/// </returns>
6061
Task<IPropertyItemObject> RetrievePagePropertyItemAsync(
61-
RetrievePropertyItemParameters retrievePropertyItemParameters);
62+
RetrievePropertyItemParameters retrievePropertyItemParameters, CancellationToken cancellationToken = default);
6263
}
6364
}

Src/Notion.Client/Api/Pages/PagesClient.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics.CodeAnalysis;
4+
using System.Threading;
45
using System.Threading.Tasks;
56
using static Notion.Client.ApiEndpoints;
67

@@ -25,7 +26,7 @@ public PagesClient(IRestClient client)
2526
/// </summary>
2627
/// <param name="pagesCreateParameters">Create page parameters</param>
2728
/// <returns>Created page.</returns>
28-
public async Task<Page> CreateAsync(PagesCreateParameters pagesCreateParameters)
29+
public async Task<Page> CreateAsync(PagesCreateParameters pagesCreateParameters, CancellationToken cancellationToken = default)
2930
{
3031
if (pagesCreateParameters is null)
3132
{
@@ -44,18 +45,18 @@ public async Task<Page> CreateAsync(PagesCreateParameters pagesCreateParameters)
4445
throw new ArgumentNullException(nameof(bodyParameters.Properties), "Properties are required!");
4546
}
4647

47-
return await _client.PostAsync<Page>(PagesApiUrls.Create(), bodyParameters);
48+
return await _client.PostAsync<Page>(PagesApiUrls.Create(), bodyParameters, cancellationToken: cancellationToken);
4849
}
4950

50-
public async Task<Page> RetrieveAsync(string pageId)
51+
public async Task<Page> RetrieveAsync(string pageId, CancellationToken cancellationToken = default)
5152
{
5253
var url = PagesApiUrls.Retrieve(pageId);
5354

54-
return await _client.GetAsync<Page>(url);
55+
return await _client.GetAsync<Page>(url, cancellationToken: cancellationToken);
5556
}
5657

5758
public async Task<IPropertyItemObject> RetrievePagePropertyItemAsync(
58-
RetrievePropertyItemParameters retrievePropertyItemParameters)
59+
RetrievePropertyItemParameters retrievePropertyItemParameters, CancellationToken cancellationToken = default)
5960
{
6061
var pathParameters = (IRetrievePropertyItemPathParameters)retrievePropertyItemParameters;
6162
var queryParameters = (IRetrievePropertyQueryParameters)retrievePropertyItemParameters;
@@ -68,27 +69,27 @@ public async Task<IPropertyItemObject> RetrievePagePropertyItemAsync(
6869
{ "page_size", queryParameters?.PageSize?.ToString() }
6970
};
7071

71-
return await _client.GetAsync<IPropertyItemObject>(url, queryParams);
72+
return await _client.GetAsync<IPropertyItemObject>(url, queryParams, cancellationToken: cancellationToken);
7273
}
7374

74-
public async Task<Page> UpdateAsync(string pageId, PagesUpdateParameters pagesUpdateParameters)
75+
public async Task<Page> UpdateAsync(string pageId, PagesUpdateParameters pagesUpdateParameters, CancellationToken cancellationToken = default)
7576
{
7677
var url = PagesApiUrls.Update(pageId);
7778
var body = (IPagesUpdateBodyParameters)pagesUpdateParameters;
7879

79-
return await _client.PatchAsync<Page>(url, body);
80+
return await _client.PatchAsync<Page>(url, body, cancellationToken: cancellationToken);
8081
}
8182

8283
[Obsolete("This method is obsolete. Use UpdateAsync instead. This API will be removed in future release")]
8384
public async Task<Page> UpdatePropertiesAsync(
8485
string pageId,
85-
IDictionary<string, PropertyValue> updatedProperties)
86+
IDictionary<string, PropertyValue> updatedProperties, CancellationToken cancellationToken = default)
8687
{
8788
var url = PagesApiUrls.UpdateProperties(pageId);
8889

8990
var body = new UpdatePropertiesParameters { Properties = updatedProperties };
9091

91-
return await _client.PatchAsync<Page>(url, body);
92+
return await _client.PatchAsync<Page>(url, body, cancellationToken: cancellationToken);
9293
}
9394

9495
[SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Local")]

0 commit comments

Comments
 (0)