Skip to content

Commit c43475a

Browse files
Add support to fetch comments
1 parent 074473f commit c43475a

File tree

12 files changed

+137
-2
lines changed

12 files changed

+137
-2
lines changed

Src/Notion.Client/Api/ApiEndpoints.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,10 @@ 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+
}
6469
}
6570
}
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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
}
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+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.Collections.Generic;
2+
using Newtonsoft.Json;
3+
4+
namespace Notion.Client
5+
{
6+
public class RetrieveCommentsResponse : PaginatedList<Comment>
7+
{
8+
[JsonProperty("type")]
9+
public string Type { get; set; }
10+
11+
[JsonProperty("comment")]
12+
public Dictionary<string, object> Comment { get; set; }
13+
}
14+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using JsonSubTypes;
2+
using Newtonsoft.Json;
3+
4+
namespace Notion.Client
5+
{
6+
[JsonConverter(typeof(JsonSubtypes), "type")]
7+
[JsonSubtypes.KnownSubType(typeof(PageParent), ParentType.PageId)]
8+
[JsonSubtypes.KnownSubType(typeof(BlockParent), ParentType.BlockId)]
9+
public interface ICommentParent
10+
{
11+
}
12+
}

Src/Notion.Client/Models/ObjectType.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,8 @@ public enum ObjectType
1515

1616
[EnumMember(Value = "user")]
1717
User,
18+
19+
[EnumMember(Value = "comment")]
20+
Comment,
1821
}
1922
}

0 commit comments

Comments
 (0)