Skip to content

Commit 605fc23

Browse files
committed
✨ Adds page creation via API
- Adds new class for created page - Adds new PagesClient to NotionClient - Adds new API endpoint - Renames Page to RetrievedPage
1 parent 871fab4 commit 605fc23

File tree

8 files changed

+79
-4
lines changed

8 files changed

+79
-4
lines changed

Src/Notion.Client/Api/ApiEndpoints.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,10 @@ public static class BlocksApiUrls
2020
public static string RetrieveChildren(string blockId) => $"/v1/blocks/{blockId}/children";
2121
public static string AppendChildren(string blockId) => $"/v1/blocks/{blockId}/children";
2222
}
23+
24+
public static class PagesApiUrls
25+
{
26+
public static string Create() => $"/v1/pages";
27+
}
2328
}
2429
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ public async Task<PaginatedList<Database>> ListAsync(DatabasesListParameters dat
3131
return await _client.GetAsync<PaginatedList<Database>>(DatabasesApiUrls.List(), queryParams);
3232
}
3333

34-
public async Task<PaginatedList<Page>> QueryAsync(string databaseId, DatabasesQueryParameters databasesQueryParameters)
34+
public async Task<PaginatedList<RetrievedPage>> QueryAsync(string databaseId, DatabasesQueryParameters databasesQueryParameters)
3535
{
3636
var body = (IDatabaseQueryBodyParameters)databasesQueryParameters;
3737

38-
return await _client.PostAsync<PaginatedList<Page>>(DatabasesApiUrls.Query(databaseId), body);
38+
return await _client.PostAsync<PaginatedList<RetrievedPage>>(DatabasesApiUrls.Query(databaseId), body);
3939
}
4040
}
4141
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Notion.Client
55
public interface IDatabasesClient
66
{
77
Task<Database> RetrieveAsync(string databaseId);
8-
Task<PaginatedList<Page>> QueryAsync(string databaseId, DatabasesQueryParameters databasesQueryParameters);
8+
Task<PaginatedList<RetrievedPage>> QueryAsync(string databaseId, DatabasesQueryParameters databasesQueryParameters);
99
Task<PaginatedList<Database>> ListAsync(DatabasesListParameters databasesListParameters = null);
1010
}
1111
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System.Threading.Tasks;
2+
3+
namespace Notion.Client
4+
{
5+
public interface IPagesClient
6+
{
7+
Task<RetrievedPage> CreateAsync(CreatedPage page);
8+
}
9+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Threading.Tasks;
2+
using static Notion.Client.ApiEndpoints;
3+
4+
namespace Notion.Client
5+
{
6+
public class PagesClient : IPagesClient
7+
{
8+
private readonly IRestClient _client;
9+
10+
public PagesClient(IRestClient client)
11+
{
12+
_client = client;
13+
}
14+
15+
public async Task<RetrievedPage> CreateAsync(CreatedPage page)
16+
{
17+
return await _client.PostAsync<RetrievedPage>(PagesApiUrls.Create(), page);
18+
}
19+
}
20+
21+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System.Collections.Generic;
2+
using System.Runtime.Serialization;
3+
4+
namespace Notion.Client
5+
{
6+
[DataContract]
7+
public class CreatedPage
8+
{
9+
public CreatedPage(Parent parent)
10+
{
11+
Parent = parent;
12+
Properties = new Dictionary<string, PropertyValue>();
13+
Children = new List<Block>();
14+
}
15+
16+
[DataMember]
17+
private Parent Parent;
18+
19+
[DataMember]
20+
private Dictionary<string, PropertyValue> Properties;
21+
22+
[DataMember]
23+
private List<Block> Children;
24+
25+
public CreatedPage AddProperty(string nameOrId, PropertyValue value)
26+
{
27+
Properties[nameOrId] = value;
28+
return this;
29+
}
30+
31+
public CreatedPage AddPageContent(Block block)
32+
{
33+
Children.Add(block);
34+
return this;
35+
}
36+
}
37+
}

Src/Notion.Client/Models/Page/Page.cs renamed to Src/Notion.Client/Models/Page/RetrievedPage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Notion.Client
66
{
7-
public class Page
7+
public class RetrievedPage
88
{
99
public string Object => "page";
1010
public string Id { get; set; }

Src/Notion.Client/NotionClient.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ public interface INotionClient
44
{
55
IUsersClient Users { get; }
66
IDatabasesClient Databases { get; }
7+
IPagesClient Pages { get; }
78
}
89

910
public class NotionClient : INotionClient
@@ -13,9 +14,11 @@ public NotionClient(ClientOptions options)
1314
var restClient = new RestClient(options);
1415
Users = new UsersClient(restClient);
1516
Databases = new DatabasesClient(restClient);
17+
Pages = new PagesClient(restClient);
1618
}
1719

1820
public IUsersClient Users { get; }
1921
public IDatabasesClient Databases { get; }
22+
public IPagesClient Pages { get; }
2023
}
2124
}

0 commit comments

Comments
 (0)