Skip to content

Commit 5a85366

Browse files
Merge pull request #311 from notion-dotnet/310-add-support-for-comments-api
Add support for Comments API
2 parents 074473f + b931a36 commit 5a85366

File tree

18 files changed

+351
-2
lines changed

18 files changed

+351
-2
lines changed

Src/Notion.Client/Api/ApiEndpoints.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,12 @@ public static class SearchApiUrls
6161
{
6262
public static string Search() => "/v1/search";
6363
}
64+
65+
public static class CommentsApiUrls
66+
{
67+
public static string Retrieve() => "/v1/comments";
68+
69+
public static string Create() => "/v1/comments";
70+
}
6471
}
6572
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace Notion.Client
2+
{
3+
public partial class CommentsClient : ICommentsClient
4+
{
5+
private readonly IRestClient _client;
6+
7+
public CommentsClient(IRestClient restClient)
8+
{
9+
_client = restClient;
10+
}
11+
}
12+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.Threading.Tasks;
2+
3+
namespace Notion.Client
4+
{
5+
public partial class CommentsClient
6+
{
7+
public async Task<CreateCommentResponse> Create(CreateCommentParameters parameters)
8+
{
9+
var body = (ICreateCommentsBodyParameters)parameters;
10+
11+
return await _client.PostAsync<CreateCommentResponse>(
12+
ApiEndpoints.CommentsApiUrls.Create(),
13+
body
14+
);
15+
}
16+
}
17+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System.Collections.Generic;
2+
using Newtonsoft.Json;
3+
4+
namespace Notion.Client
5+
{
6+
public interface ICreateCommentsBodyParameters
7+
{
8+
[JsonProperty("rich_text")]
9+
public IEnumerable<RichTextBaseInput> RichText { get; set; }
10+
}
11+
12+
public interface ICreateDiscussionCommentBodyParameters : ICreateCommentsBodyParameters
13+
{
14+
[JsonProperty("discussion_id")]
15+
public string DiscussionId { get; set; }
16+
}
17+
18+
public interface ICreatePageCommentBodyParameters : ICreateCommentsBodyParameters
19+
{
20+
[JsonProperty("parent")]
21+
public ParentPageInput Parent { get; set; }
22+
}
23+
24+
public class CreateCommentParameters : ICreateDiscussionCommentBodyParameters, ICreatePageCommentBodyParameters
25+
{
26+
public string DiscussionId { get; set; }
27+
public IEnumerable<RichTextBaseInput> RichText { get; set; }
28+
public ParentPageInput Parent { get; set; }
29+
30+
public static CreateCommentParameters CreatePageComment(ParentPageInput parent, IEnumerable<RichTextBaseInput> richText)
31+
{
32+
return new CreateCommentParameters
33+
{
34+
Parent = parent,
35+
RichText = richText
36+
};
37+
}
38+
39+
public static CreateCommentParameters CreateDiscussionComment(string discussionId, IEnumerable<RichTextBaseInput> richText)
40+
{
41+
return new CreateCommentParameters
42+
{
43+
DiscussionId = discussionId,
44+
RichText = richText
45+
};
46+
}
47+
}
48+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
namespace Notion.Client
2+
{
3+
public class CreateCommentResponse : Comment
4+
{
5+
}
6+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System.Threading.Tasks;
2+
3+
namespace Notion.Client
4+
{
5+
public interface ICommentsClient
6+
{
7+
/// <summary>
8+
/// Retrieves a list of un-resolved Comment objects from a page or block.
9+
/// </summary>
10+
/// <param name="retrieveCommentsParameters">Retrieve comments parameters</param>
11+
/// <returns><see cref="RetrieveCommentsResponse"/></returns>
12+
Task<RetrieveCommentsResponse> Retrieve(RetrieveCommentsParameters retrieveCommentsParameters);
13+
14+
Task<CreateCommentResponse> Create(CreateCommentParameters createCommentParameters);
15+
}
16+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System.Collections.Generic;
2+
using System.Threading.Tasks;
3+
4+
namespace Notion.Client
5+
{
6+
public partial class CommentsClient
7+
{
8+
public async Task<RetrieveCommentsResponse> Retrieve(RetrieveCommentsParameters parameters)
9+
{
10+
var qp = (IRetrieveCommentsQueryParameters)parameters;
11+
12+
var queryParams = new Dictionary<string, string>()
13+
{
14+
{ "block_id", qp.BlockId },
15+
{ "start_cursor", qp.StartCursor },
16+
{ "page_size", qp.PageSize.ToString() },
17+
};
18+
19+
return await _client.GetAsync<RetrieveCommentsResponse>(
20+
ApiEndpoints.CommentsApiUrls.Retrieve(),
21+
queryParams
22+
);
23+
}
24+
}
25+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Notion.Client
4+
{
5+
public interface IRetrieveCommentsQueryParameters : IPaginationParameters
6+
{
7+
[JsonProperty("block_id")]
8+
string BlockId { get; set; }
9+
}
10+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Notion.Client
2+
{
3+
public class RetrieveCommentsParameters : IRetrieveCommentsQueryParameters
4+
{
5+
public string BlockId { get; set; }
6+
public string StartCursor { get; set; }
7+
public int? PageSize { get; set; }
8+
}
9+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Newtonsoft.Json;
4+
5+
namespace Notion.Client
6+
{
7+
public class Comment : IObject
8+
{
9+
public string Id { get; set; }
10+
11+
public ObjectType Object => ObjectType.Comment;
12+
13+
[JsonProperty("parent")]
14+
public ICommentParent Parent { get; set; }
15+
16+
[JsonProperty("discussion_id")]
17+
public string DiscussionId { get; set; }
18+
19+
[JsonProperty("rich_text")]
20+
public IEnumerable<RichTextBase> RichText { get; set; }
21+
22+
[JsonProperty("created_by")]
23+
public PartialUser CreatedBy { get; set; }
24+
25+
[JsonProperty("created_time")]
26+
public DateTime CreatedTime { get; set; }
27+
28+
[JsonProperty("last_edited_time")]
29+
public DateTime LastEditedTime { get; set; }
30+
}
31+
}

0 commit comments

Comments
 (0)