File tree Expand file tree Collapse file tree 5 files changed +113
-0
lines changed Expand file tree Collapse file tree 5 files changed +113
-0
lines changed Original file line number Diff line number Diff line change @@ -20,5 +20,12 @@ public static class BlocksApiUrls
20
20
public static string RetrieveChildren ( string blockId ) => $ "/v1/blocks/{ blockId } /children";
21
21
public static string AppendChildren ( string blockId ) => $ "/v1/blocks/{ blockId } /children";
22
22
}
23
+
24
+ public static class PagesApiUrls
25
+ {
26
+ public static string Create ( ) => $ "/v1/pages";
27
+ public static string Retrieve ( string pageId ) => $ "/v1/pages/{ pageId } ";
28
+ public static string UpdateProperties ( string pageId ) => $ "/v1/pages/{ pageId } ";
29
+ }
23
30
}
24
31
}
Original file line number Diff line number Diff line change
1
+ using System . Collections . Generic ;
2
+ using System . Threading . Tasks ;
3
+
4
+ namespace Notion . Client
5
+ {
6
+ public interface IPagesClient
7
+ {
8
+ Task < Page > CreateAsync ( NewPage page ) ;
9
+ Task < Page > RetrieveAsync ( string pageId ) ;
10
+
11
+ Task < Page > UpdatePropertiesAsync (
12
+ string pageId ,
13
+ IDictionary < string , PropertyValue > updatedProperties
14
+ ) ;
15
+ }
16
+ }
Original file line number Diff line number Diff line change
1
+ using System . Collections . Generic ;
2
+ using System . Threading . Tasks ;
3
+ using static Notion . Client . ApiEndpoints ;
4
+
5
+ namespace Notion . Client
6
+ {
7
+ public class PagesClient : IPagesClient
8
+ {
9
+ private readonly IRestClient _client ;
10
+
11
+ public PagesClient ( IRestClient client )
12
+ {
13
+ _client = client ;
14
+ }
15
+
16
+ public async Task < Page > CreateAsync ( NewPage page )
17
+ {
18
+ return await _client . PostAsync < Page > ( PagesApiUrls . Create ( ) , page ) ;
19
+ }
20
+
21
+ public async Task < Page > RetrieveAsync ( string pageId )
22
+ {
23
+ var url = PagesApiUrls . Retrieve ( pageId ) ;
24
+ return await _client . GetAsync < Page > ( url ) ;
25
+ }
26
+
27
+ public async Task < Page > UpdatePropertiesAsync (
28
+ string pageId ,
29
+ IDictionary < string , PropertyValue > updatedProperties )
30
+ {
31
+ var url = PagesApiUrls . UpdateProperties ( pageId ) ;
32
+ var body = new UpdatePropertiesParameters { Properties = updatedProperties } ;
33
+
34
+ return await _client . PatchAsync < Page > ( url , body ) ;
35
+ }
36
+
37
+ private class UpdatePropertiesParameters
38
+ {
39
+ public IDictionary < string , PropertyValue > Properties { get ; set ; }
40
+ }
41
+ }
42
+ }
Original file line number Diff line number Diff line change
1
+ using System . Collections . Generic ;
2
+
3
+ namespace Notion . Client
4
+ {
5
+ public class NewPage
6
+ {
7
+ /// <summary>
8
+ /// Constructor without arguments: added for class initializations using class literals.
9
+ /// </summary>
10
+ public NewPage ( )
11
+ {
12
+ Properties = new Dictionary < string , PropertyValue > ( ) ;
13
+ Children = new List < Block > ( ) ;
14
+ }
15
+
16
+ /// <summary>
17
+ /// Constructor that adds required <c>Parent</c> property. Used when you don't want to
18
+ /// assign properties in separate operations.
19
+ /// </summary>
20
+ public NewPage ( Parent parent )
21
+ {
22
+ Parent = parent ;
23
+ Properties = new Dictionary < string , PropertyValue > ( ) ;
24
+ Children = new List < Block > ( ) ;
25
+ }
26
+
27
+ public Parent Parent { get ; set ; }
28
+
29
+ public Dictionary < string , PropertyValue > Properties { get ; set ; }
30
+
31
+ public List < Block > Children { get ; set ; }
32
+
33
+ public NewPage AddProperty ( string nameOrId , PropertyValue value )
34
+ {
35
+ Properties [ nameOrId ] = value ;
36
+ return this ;
37
+ }
38
+
39
+ public NewPage AddPageContent ( Block block )
40
+ {
41
+ Children . Add ( block ) ;
42
+ return this ;
43
+ }
44
+ }
45
+ }
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ public interface INotionClient
4
4
{
5
5
IUsersClient Users { get ; }
6
6
IDatabasesClient Databases { get ; }
7
+ IPagesClient Pages { get ; }
7
8
}
8
9
9
10
public class NotionClient : INotionClient
@@ -13,9 +14,11 @@ public NotionClient(ClientOptions options)
13
14
var restClient = new RestClient ( options ) ;
14
15
Users = new UsersClient ( restClient ) ;
15
16
Databases = new DatabasesClient ( restClient ) ;
17
+ Pages = new PagesClient ( restClient ) ;
16
18
}
17
19
18
20
public IUsersClient Users { get ; }
19
21
public IDatabasesClient Databases { get ; }
22
+ public IPagesClient Pages { get ; }
20
23
}
21
24
}
You can’t perform that action at this time.
0 commit comments