Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 69cf5bc

Browse files
Merge pull request #27 from asevos/feature/pages_endpoints
Add Pages API's support ✨
2 parents 871fab4 + f3656a6 commit 69cf5bc

File tree

5 files changed

+113
-0
lines changed

5 files changed

+113
-0
lines changed

‎Src/Notion.Client/Api/ApiEndpoints.cs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,12 @@ 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+
public static string Retrieve(string pageId) => $"/v1/pages/{pageId}";
28+
public static string UpdateProperties(string pageId) => $"/v1/pages/{pageId}";
29+
}
2330
}
2431
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
}

‎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)

AltStyle によって変換されたページ (->オリジナル) /