Skip to content

Add type specific pagination information #395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
25 changes: 25 additions & 0 deletions Src/Notion.Client/Api/Blocks/AppendChildren/BlocksClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Threading;
using System.Threading.Tasks;

namespace Notion.Client
{
public sealed partial class BlocksClient
{
public async Task<AppendChildrenResponse> AppendChildrenAsync(
BlockAppendChildrenRequest request,
CancellationToken cancellationToken = default)
{
if (string.IsNullOrWhiteSpace(request.BlockId))
{
throw new ArgumentNullException(nameof(request.BlockId));
}

var url = ApiEndpoints.BlocksApiUrls.AppendChildren(request.BlockId);

var body = (IBlockAppendChildrenBodyParameters)request;

return await _client.PatchAsync<AppendChildrenResponse>(url, body, cancellationToken: cancellationToken);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace Notion.Client
{
public class BlocksAppendChildrenParameters : IBlocksAppendChildrenBodyParameters
public class BlockAppendChildrenRequest : IBlockAppendChildrenBodyParameters, IBlockAppendChildrenPathParameters
{
public IEnumerable<IBlock> Children { get; set; }

public string After { get; set; }

public string BlockId { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace Notion.Client
{
// TODO: need an input version of Block
public interface IBlocksAppendChildrenBodyParameters
public interface IBlockAppendChildrenBodyParameters
{
[JsonProperty("children")]
IEnumerable<IBlock> Children { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Notion.Client
{
public interface IBlockAppendChildrenPathParameters
{
public string BlockId { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Notion.Client
{
public class AppendChildrenResponse : PaginatedList<IBlock>
{
[JsonProperty("block")]
public Dictionary<string, object> Block { get; set; }
}
}
40 changes: 1 addition & 39 deletions Src/Notion.Client/Api/Blocks/BlocksClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Notion.Client
{
public class BlocksClient : IBlocksClient
public sealed partial class BlocksClient : IBlocksClient
{
private readonly IRestClient _client;

Expand All @@ -15,44 +15,6 @@ public BlocksClient(IRestClient client)
_client = client;
}

public async Task<PaginatedList<IBlock>> RetrieveChildrenAsync(
string blockId,
BlocksRetrieveChildrenParameters parameters = null, CancellationToken cancellationToken = default)
{
if (string.IsNullOrWhiteSpace(blockId))
{
throw new ArgumentNullException(nameof(blockId));
}

var url = BlocksApiUrls.RetrieveChildren(blockId);

var queryParameters = (IBlocksRetrieveChildrenQueryParameters)parameters;

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

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

public async Task<PaginatedList<IBlock>> AppendChildrenAsync(
string blockId,
BlocksAppendChildrenParameters parameters = null, CancellationToken cancellationToken = default)
{
if (string.IsNullOrWhiteSpace(blockId))
{
throw new ArgumentNullException(nameof(blockId));
}

var url = BlocksApiUrls.AppendChildren(blockId);

var body = (IBlocksAppendChildrenBodyParameters)parameters;

return await _client.PatchAsync<PaginatedList<IBlock>>(url, body, cancellationToken: cancellationToken);
}

public async Task<IBlock> RetrieveAsync(string blockId, CancellationToken cancellationToken = default)
{
if (string.IsNullOrWhiteSpace(blockId))
Expand Down
30 changes: 21 additions & 9 deletions Src/Notion.Client/Api/Blocks/IBlocksClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,33 @@ public interface IBlocksClient
/// <param name="blockId"></param>
/// <param name="updateBlock"></param>
/// <returns>Block</returns>
Task<IBlock> UpdateAsync(string blockId, IUpdateBlock updateBlock, CancellationToken cancellationToken = default);
Task<IBlock> UpdateAsync(string blockId, IUpdateBlock updateBlock,
CancellationToken cancellationToken = default);

Task<PaginatedList<IBlock>> RetrieveChildrenAsync(
string blockId,
BlocksRetrieveChildrenParameters parameters = null, CancellationToken cancellationToken = default);
/// <summary>
/// Returns a paginated array of child block objects contained in the block using the ID specified.
/// <br/>
/// In order to receive a complete representation of a block, you may need to recursively retrieve the
/// block children of child blocks.
/// </summary>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<RetrieveChildrenResponse> RetrieveChildrenAsync(
BlockRetrieveChildrenRequest request,
CancellationToken cancellationToken = default
);

/// <summary>
/// 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>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns>A paginated list of newly created first level children block objects.</returns>
Task<PaginatedList<IBlock>> AppendChildrenAsync(
string blockId,
BlocksAppendChildrenParameters parameters = null, CancellationToken cancellationToken = default);
Task<AppendChildrenResponse> AppendChildrenAsync(
BlockAppendChildrenRequest request,
CancellationToken cancellationToken = default
);

/// <summary>
/// Sets a Block object, including page blocks, to archived: true using the ID specified.
Expand Down

This file was deleted.

This file was deleted.

36 changes: 36 additions & 0 deletions Src/Notion.Client/Api/Blocks/RetrieveChildren/BlocksClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

namespace Notion.Client
{
public sealed partial class BlocksClient
{
public async Task<RetrieveChildrenResponse> RetrieveChildrenAsync(
BlockRetrieveChildrenRequest request,
CancellationToken cancellationToken = default)
{
if (string.IsNullOrWhiteSpace(request.BlockId))
{
throw new ArgumentNullException(nameof(request.BlockId));
}

var url = ApiEndpoints.BlocksApiUrls.RetrieveChildren(request.BlockId);

var queryParameters = (IBlockRetrieveChildrenQueryParameters)request;

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

return await _client.GetAsync<RetrieveChildrenResponse>(
url,
queryParams,
cancellationToken: cancellationToken
);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Notion.Client
{
public class BlockRetrieveChildrenRequest :
IBlockRetrieveChildrenQueryParameters,
IBlockRetrieveChildrenPathParameters
{
public string StartCursor { get; set; }

public int? PageSize { get; set; }

public string BlockId { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Notion.Client
{
public interface IBlockRetrieveChildrenPathParameters
{
public string BlockId { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Notion.Client
{
public interface IBlockRetrieveChildrenQueryParameters : IPaginationParameters
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Notion.Client
{
public class RetrieveChildrenResponse : PaginatedList<IBlock>
{
[JsonProperty("block")]
public Dictionary<string, object> Block { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
namespace Notion.Client
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Notion.Client
{
// ReSharper disable once ClassNeverInstantiated.Global
public class DatabaseQueryResponse : PaginatedList<IWikiDatabase>
{
[JsonProperty("database")]
public Dictionary<string, object> Database { get; set; }
}
}
8 changes: 6 additions & 2 deletions Src/Notion.Client/Api/Search/ISearchClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ public interface ISearchClient
/// Searches all original pages, databases, and child pages/databases that are shared with the integration.
/// It will not return linked databases, since these duplicate their source databases.
/// </summary>
/// <param name="parameters">Search filters and body parameters</param>
/// <param name="request">Search filters and body parameters</param>
/// <param name="cancellationToken"></param>
/// <returns>
/// <see cref="PaginatedList{IObject}" />
/// </returns>
Task<PaginatedList<IObject>> SearchAsync(SearchParameters parameters, CancellationToken cancellationToken = default);
Task<SearchResponse> SearchAsync(
SearchRequest request,
CancellationToken cancellationToken = default
);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Notion.Client
{
public class SearchParameters : ISearchBodyParameters
public class SearchRequest : ISearchBodyParameters
{
public string Query { get; set; }

Expand Down
11 changes: 11 additions & 0 deletions Src/Notion.Client/Api/Search/Response/SearchResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Notion.Client
{
public class SearchResponse : PaginatedList<IObject>
{
[JsonProperty("page_or_database")]
public Dictionary<string, object> PageOrDatabase { get; set; }
}
}
10 changes: 6 additions & 4 deletions Src/Notion.Client/Api/Search/SearchClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Notion.Client
{
public class SearchClient : ISearchClient
public sealed class SearchClient : ISearchClient
{
private readonly IRestClient _client;

Expand All @@ -13,13 +13,15 @@ public SearchClient(IRestClient client)
_client = client;
}

public async Task<PaginatedList<IObject>> SearchAsync(SearchParameters parameters, CancellationToken cancellationToken = default)
public async Task<SearchResponse> SearchAsync(
SearchRequest request,
CancellationToken cancellationToken = default)
{
var url = SearchApiUrls.Search();

var body = (ISearchBodyParameters)parameters;
var body = (ISearchBodyParameters)request;

return await _client.PostAsync<PaginatedList<IObject>>(url, body, cancellationToken: cancellationToken);
return await _client.PostAsync<SearchResponse>(url, body, cancellationToken: cancellationToken);
}
}
}
18 changes: 14 additions & 4 deletions Src/Notion.Client/Api/Users/IUsersClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,23 @@ public interface IUsersClient
/// Returns a paginated list of Users for the workspace.
/// The response may contain fewer than page_size of results.
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns>
/// <see cref="PaginatedList{User}" />
/// <see cref="ListUsersResponse" />
/// </returns>
Task<PaginatedList<User>> ListAsync(CancellationToken cancellationToken = default);
Task<ListUsersResponse> ListAsync(CancellationToken cancellationToken = default);

Task<PaginatedList<User>> ListAsync(
ListUsersParameters listUsersParameters,
/// <summary>
/// Returns a paginated list of Users for the workspace.
/// The response may contain fewer than page_size of results.
/// </summary>
/// <param name="listUsersRequest"></param>
/// <param name="cancellationToken"></param>
/// <returns>
/// <see cref="ListUsersResponse" />
/// </returns>
Task<ListUsersResponse> ListAsync(
ListUsersRequest listUsersRequest,
CancellationToken cancellationToken = default
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public interface IListUsersQueryParameters : IPaginationParameters
{
}

public class ListUsersParameters : IListUsersQueryParameters
public class ListUsersRequest : IListUsersQueryParameters
{
public string StartCursor { get; set; }

Expand Down
11 changes: 11 additions & 0 deletions Src/Notion.Client/Api/Users/List/Response/ListUsersResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Collections.Generic;
using Newtonsoft.Json;

namespace Notion.Client
{
public class ListUsersResponse : PaginatedList<User>
{
[JsonProperty("user")]
public Dictionary<string, object> User { get; set; }
}
}
Loading