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
12 changes: 12 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"jetbrains.resharper.globaltools": {
"version": "2022.2.3",
"commands": [
"jb"
]
}
}
}
255 changes: 237 additions & 18 deletions .editorconfig

Large diffs are not rendered by default.

124 changes: 96 additions & 28 deletions Src/Notion.Client/Api/ApiEndpoints.cs
Original file line number Diff line number Diff line change
@@ -1,72 +1,140 @@
using System;

namespace Notion.Client
namespace Notion.Client
{
public static class ApiEndpoints
{
public static class DatabasesApiUrls
{
public static string Retrieve(string databaseId) => $"/v1/databases/{databaseId}";
public static string List() => "/v1/databases";
public static string Query(string databaseId) => $"/v1/databases/{databaseId}/query";
public static string Create => "/v1/databases";
public static string Update(string databaseId) => $"/v1/databases/{databaseId}";

public static string Retrieve(string databaseId)
{
return $"/v1/databases/{databaseId}";
}

public static string List()
{
return "/v1/databases";
}

public static string Query(string databaseId)
{
return $"/v1/databases/{databaseId}/query";
}

public static string Update(string databaseId)
{
return $"/v1/databases/{databaseId}";
}
}

public static class UsersApiUrls
{
public static string Retrieve(string userId) => $"/v1/users/{userId}";
public static string List() => "/v1/users";
public static string Retrieve(string userId)
{
return $"/v1/users/{userId}";
}

public static string List()
{
return "/v1/users";
}

/// <summary>
/// Get the <see cref="uri string"/> for retrieve your token's bot user.
/// Get the <see cref="uri string" /> for retrieve your token's bot user.
/// </summary>
/// <returns>Returns a <see cref="uri string"/> retrieve your token's bot user.</returns>
public static string Me() => "/v1/users/me";
/// <returns>Returns a <see cref="uri string" /> retrieve your token's bot user.</returns>
public static string Me()
{
return "/v1/users/me";
}
}

public static class BlocksApiUrls
{
public static string Retrieve(string blockId) => $"/v1/blocks/{blockId}";
public static string Update(string blockId) => $"/v1/blocks/{blockId}";
public static string Retrieve(string blockId)
{
return $"/v1/blocks/{blockId}";
}

public static string Update(string blockId)
{
return $"/v1/blocks/{blockId}";
}

/// <summary>
/// Get the <see cref="uri string"/> for deleting a block.
/// Get the <see cref="uri string" /> for deleting a block.
/// </summary>
/// <param name="blockId">Identifier for a Notion block</param>
/// <returns>Returns a <see cref="uri string"/> for deleting a block.</returns>
public static string Delete(string blockId) => $"/v1/blocks/{blockId}";
/// <returns>Returns a <see cref="uri string" /> for deleting a block.</returns>
public static string Delete(string blockId)
{
return $"/v1/blocks/{blockId}";
}

public static string RetrieveChildren(string blockId)
{
return $"/v1/blocks/{blockId}/children";
}

public static string RetrieveChildren(string blockId) => $"/v1/blocks/{blockId}/children";
public static string AppendChildren(string blockId) => $"/v1/blocks/{blockId}/children";
public static string AppendChildren(string blockId)
{
return $"/v1/blocks/{blockId}/children";
}
}

public static class PagesApiUrls
{
public static string Create() => $"/v1/pages";
public static string Retrieve(string pageId) => $"/v1/pages/{pageId}";
public static string Update(string pageId) => $"/v1/pages/{pageId}";
public static string UpdateProperties(string pageId) => $"/v1/pages/{pageId}";
public static string Create()
{
return "/v1/pages";
}

public static string Retrieve(string pageId)
{
return $"/v1/pages/{pageId}";
}

public static string Update(string pageId)
{
return $"/v1/pages/{pageId}";
}

public static string UpdateProperties(string pageId)
{
return $"/v1/pages/{pageId}";
}

/// <summary>
/// Get the <see cref="uri string"/> for retrieve page property item
/// Get the <see cref="uri string" /> for retrieve page property item
/// </summary>
/// <param name="pageId">Identifier for a Notion Page</param>
/// <param name="propertyId">Identifier for a Notion Property</param>
/// <returns></returns>
public static string RetrievePropertyItem(string pageId, string propertyId) => $"/v1/pages/{pageId}/properties/{propertyId}";
public static string RetrievePropertyItem(string pageId, string propertyId)
{
return $"/v1/pages/{pageId}/properties/{propertyId}";
}
}

public static class SearchApiUrls
{
public static string Search() => "/v1/search";
public static string Search()
{
return "/v1/search";
}
}

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

public static string Create() => "/v1/comments";
public static string Create()
{
return "/v1/comments";
}
}
}
}
12 changes: 8 additions & 4 deletions Src/Notion.Client/Api/Blocks/BlocksClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ public BlocksClient(IRestClient client)
_client = client;
}

public async Task<PaginatedList<IBlock>> RetrieveChildrenAsync(string blockId, BlocksRetrieveChildrenParameters parameters = null)
public async Task<PaginatedList<IBlock>> RetrieveChildrenAsync(
string blockId,
BlocksRetrieveChildrenParameters parameters = null)
{
if (string.IsNullOrWhiteSpace(blockId))
{
Expand All @@ -25,16 +27,18 @@ public async Task<PaginatedList<IBlock>> RetrieveChildrenAsync(string blockId, B

var queryParameters = (IBlocksRetrieveChildrenQueryParameters)parameters;

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

return await _client.GetAsync<PaginatedList<IBlock>>(url, queryParams);
}

public async Task<PaginatedList<IBlock>> AppendChildrenAsync(string blockId, BlocksAppendChildrenParameters parameters = null)
public async Task<PaginatedList<IBlock>> AppendChildrenAsync(
string blockId,
BlocksAppendChildrenParameters parameters = null)
{
if (string.IsNullOrWhiteSpace(blockId))
{
Expand Down
16 changes: 10 additions & 6 deletions Src/Notion.Client/Api/Blocks/IBlocksClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,36 @@ namespace Notion.Client
public interface IBlocksClient
{
/// <summary>
/// Retrieves a Block object using the ID specified.
/// Retrieves a Block object using the ID specified.
/// </summary>
/// <param name="blockId"></param>
/// <returns>Block</returns>
Task<IBlock> RetrieveAsync(string blockId);

/// <summary>
/// Updates the content for the specified block_id based on the block type.
/// Updates the content for the specified block_id based on the block type.
/// </summary>
/// <param name="blockId"></param>
/// <param name="updateBlock"></param>
/// <returns>Block</returns>
Task<IBlock> UpdateAsync(string blockId, IUpdateBlock updateBlock);

Task<PaginatedList<IBlock>> RetrieveChildrenAsync(string blockId, BlocksRetrieveChildrenParameters parameters = null);
Task<PaginatedList<IBlock>> RetrieveChildrenAsync(
string blockId,
BlocksRetrieveChildrenParameters parameters = null);

/// <summary>
/// Creates and appends new children blocks to the parent block_id specified.
/// Creates and appends new children blocks to the parent block_id specified.
/// </summary>
/// <param name="blockId">Identifier for a block</param>
/// <param name="parameters"></param>
/// <returns>A paginated list of newly created first level children block objects.</returns>
Task<PaginatedList<IBlock>> AppendChildrenAsync(string blockId, BlocksAppendChildrenParameters parameters = null);
Task<PaginatedList<IBlock>> AppendChildrenAsync(
string blockId,
BlocksAppendChildrenParameters parameters = null);

/// <summary>
/// Sets a Block object, including page blocks, to archived: true using the ID specified.
/// Sets a Block object, including page blocks, to archived: true using the ID specified.
/// </summary>
/// <param name="blockId">Identifier for a Notion block</param>
Task DeleteAsync(string blockId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public class BlocksRetrieveChildrenParameters : IBlocksRetrieveChildrenQueryParameters
{
public string StartCursor { get; set; }

public int? PageSize { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json;

namespace Notion.Client
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ namespace Notion.Client
{
public class BookmarkUpdateBlock : IUpdateBlock
{
public bool Archived { get; set; }

[JsonProperty("bookmark")]
public Info Bookmark { get; set; }

public bool Archived { get; set; }

public class Info
{
[JsonProperty("url")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ namespace Notion.Client
{
public class BreadcrumbUpdateBlock : IUpdateBlock
{
public bool Archived { get; set; }
public BreadcrumbUpdateBlock()
{
Breadcrumb = new Info();
}

[JsonProperty("breadcrumb")]
public Info Breadcrumb { get; set; }

public class Info
{
}
public bool Archived { get; set; }

public BreadcrumbUpdateBlock()
public class Info
{
Breadcrumb = new Info();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ namespace Notion.Client
{
public class DividerUpdateBlock : IUpdateBlock
{
public bool Archived { get; set; }
public DividerUpdateBlock()
{
Divider = new Info();
}

[JsonProperty("divider")]
public Info Divider { get; set; }

public class Info
{
}
public bool Archived { get; set; }

public DividerUpdateBlock()
public class Info
{
Divider = new Info();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ namespace Notion.Client
{
public class TableOfContentsUpdateBlock : IUpdateBlock
{
public bool Archived { get; set; }
public TableOfContentsUpdateBlock()
{
TableOfContents = new Info();
}

[JsonProperty("table_of_contents")]
public Info TableOfContents { get; set; }

public class Info
{
}
public bool Archived { get; set; }

public TableOfContentsUpdateBlock()
public class Info
{
TableOfContents = new Info();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@ public interface ICreatePageCommentBodyParameters : ICreateCommentsBodyParameter
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)
public static CreateCommentParameters CreatePageComment(
ParentPageInput parent,
IEnumerable<RichTextBaseInput> richText)
{
return new CreateCommentParameters
{
Expand All @@ -36,7 +40,9 @@ public static CreateCommentParameters CreatePageComment(ParentPageInput parent,
};
}

public static CreateCommentParameters CreateDiscussionComment(string discussionId, IEnumerable<RichTextBaseInput> richText)
public static CreateCommentParameters CreateDiscussionComment(
string discussionId,
IEnumerable<RichTextBaseInput> richText)
{
return new CreateCommentParameters
{
Expand Down
Loading