Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Src/Notion.Client/Api/ApiEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,12 @@ public static class SearchApiUrls
{
public static string Search() => "/v1/search";
}

public static class CommentsApiUrls
{
public static string Retrieve() => "/v1/comments";

public static string Create() => "/v1/comments";
}
}
}
12 changes: 12 additions & 0 deletions Src/Notion.Client/Api/Comments/CommentsClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Notion.Client
{
public partial class CommentsClient : ICommentsClient
{
private readonly IRestClient _client;

public CommentsClient(IRestClient restClient)
{
_client = restClient;
}
}
}
17 changes: 17 additions & 0 deletions Src/Notion.Client/Api/Comments/Create/CommentsClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Threading.Tasks;

namespace Notion.Client
{
public partial class CommentsClient
{
public async Task<CreateCommentResponse> Create(CreateCommentParameters parameters)
{
var body = (ICreateCommentsBodyParameters)parameters;

return await _client.PostAsync<CreateCommentResponse>(
ApiEndpoints.CommentsApiUrls.Create(),
body
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Notion.Client
{
public interface ICreateCommentsBodyParameters
{
[JsonProperty("rich_text")]
public IEnumerable<RichTextBaseInput> RichText { get; set; }
}

public interface ICreateDiscussionCommentBodyParameters : ICreateCommentsBodyParameters
{
[JsonProperty("discussion_id")]
public string DiscussionId { get; set; }
}

public interface ICreatePageCommentBodyParameters : ICreateCommentsBodyParameters
{
[JsonProperty("parent")]
public ParentPageInput Parent { get; set; }
}

public class CreateCommentParameters : ICreateDiscussionCommentBodyParameters, ICreatePageCommentBodyParameters
{
public string DiscussionId { get; set; }
public IEnumerable<RichTextBaseInput> RichText { get; set; }
public ParentPageInput Parent { get; set; }

public static CreateCommentParameters CreatePageComment(ParentPageInput parent, IEnumerable<RichTextBaseInput> richText)
{
return new CreateCommentParameters
{
Parent = parent,
RichText = richText
};
}

public static CreateCommentParameters CreateDiscussionComment(string discussionId, IEnumerable<RichTextBaseInput> richText)
{
return new CreateCommentParameters
{
DiscussionId = discussionId,
RichText = richText
};
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Notion.Client
{
public class CreateCommentResponse : Comment
{
}
}
16 changes: 16 additions & 0 deletions Src/Notion.Client/Api/Comments/ICommentsClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Threading.Tasks;

namespace Notion.Client
{
public interface ICommentsClient
{
/// <summary>
/// Retrieves a list of un-resolved Comment objects from a page or block.
/// </summary>
/// <param name="retrieveCommentsParameters">Retrieve comments parameters</param>
/// <returns><see cref="RetrieveCommentsResponse"/></returns>
Task<RetrieveCommentsResponse> Retrieve(RetrieveCommentsParameters retrieveCommentsParameters);

Task<CreateCommentResponse> Create(CreateCommentParameters createCommentParameters);
}
}
25 changes: 25 additions & 0 deletions Src/Notion.Client/Api/Comments/Retrieve/CommentsClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Notion.Client
{
public partial class CommentsClient
{
public async Task<RetrieveCommentsResponse> Retrieve(RetrieveCommentsParameters parameters)
{
var qp = (IRetrieveCommentsQueryParameters)parameters;

var queryParams = new Dictionary<string, string>()
{
{ "block_id", qp.BlockId },
{ "start_cursor", qp.StartCursor },
{ "page_size", qp.PageSize.ToString() },
};

return await _client.GetAsync<RetrieveCommentsResponse>(
ApiEndpoints.CommentsApiUrls.Retrieve(),
queryParams
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Newtonsoft.Json;

namespace Notion.Client
{
public interface IRetrieveCommentsQueryParameters : IPaginationParameters
{
[JsonProperty("block_id")]
string BlockId { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Notion.Client
{
public class RetrieveCommentsParameters : IRetrieveCommentsQueryParameters
{
public string BlockId { get; set; }
public string StartCursor { get; set; }
public int? PageSize { get; set; }
}
}
31 changes: 31 additions & 0 deletions Src/Notion.Client/Api/Comments/Retrieve/Response/Comment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Notion.Client
{
public class Comment : IObject
{
public string Id { get; set; }

public ObjectType Object => ObjectType.Comment;

[JsonProperty("parent")]
public ICommentParent Parent { get; set; }

[JsonProperty("discussion_id")]
public string DiscussionId { get; set; }

[JsonProperty("rich_text")]
public IEnumerable<RichTextBase> RichText { get; set; }

[JsonProperty("created_by")]
public PartialUser CreatedBy { get; set; }

[JsonProperty("created_time")]
public DateTime CreatedTime { get; set; }

[JsonProperty("last_edited_time")]
public DateTime LastEditedTime { get; set; }
}
}
14 changes: 14 additions & 0 deletions Src/Notion.Client/Api/Comments/Retrieve/Response/Comments.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Notion.Client
{
public class RetrieveCommentsResponse : PaginatedList<Comment>
{
[JsonProperty("type")]
public string Type { get; set; }

[JsonProperty("comment")]
public Dictionary<string, object> Comment { get; set; }
}
}
12 changes: 12 additions & 0 deletions Src/Notion.Client/Api/Comments/Retrieve/Response/ICommentParent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using JsonSubTypes;
using Newtonsoft.Json;

namespace Notion.Client
{
[JsonConverter(typeof(JsonSubtypes), "type")]
[JsonSubtypes.KnownSubType(typeof(PageParent), ParentType.PageId)]
[JsonSubtypes.KnownSubType(typeof(BlockParent), ParentType.BlockId)]
public interface ICommentParent
{
}
}
3 changes: 3 additions & 0 deletions Src/Notion.Client/Models/ObjectType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,8 @@ public enum ObjectType

[EnumMember(Value = "user")]
User,

[EnumMember(Value = "comment")]
Comment,
}
}
2 changes: 1 addition & 1 deletion Src/Notion.Client/Models/Parents/BlockParent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Notion.Client
{
public class BlockParent : IPageParent, IDatabaseParent, IBlockParent
public class BlockParent : IPageParent, IDatabaseParent, IBlockParent, ICommentParent
{
/// <summary>
/// Always has a value "block_id"
Expand Down
2 changes: 1 addition & 1 deletion Src/Notion.Client/Models/Parents/PageParent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Notion.Client
{
public class PageParent : IPageParent, IDatabaseParent, IBlockParent
public class PageParent : IPageParent, IDatabaseParent, IBlockParent, ICommentParent
{
/// <summary>
/// Always "page_id".
Expand Down
4 changes: 4 additions & 0 deletions Src/Notion.Client/NotionClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public interface INotionClient
IPagesClient Pages { get; }
ISearchClient Search { get; }
IBlocksClient Blocks { get; }
ICommentsClient Comments { get; }
IRestClient RestClient { get; }
}

Expand All @@ -18,13 +19,15 @@ public NotionClient(
DatabasesClient databases,
PagesClient pages,
SearchClient search,
CommentsClient comments,
BlocksClient blocks)
{
RestClient = restClient;
Users = users;
Databases = databases;
Pages = pages;
Search = search;
Comments = comments;
Blocks = blocks;
}

Expand All @@ -33,6 +36,7 @@ public NotionClient(
public IPagesClient Pages { get; }
public ISearchClient Search { get; }
public IBlocksClient Blocks { get; }
public ICommentsClient Comments { get; }
public IRestClient RestClient { get; }
}
}
1 change: 1 addition & 0 deletions Src/Notion.Client/NotionClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public static NotionClient Create(ClientOptions options)
, pages: new PagesClient(restClient)
, search: new SearchClient(restClient)
, blocks: new BlocksClient(restClient)
, comments: new CommentsClient(restClient)
);
}
}
Expand Down
Loading