Skip to content

Commit b476e81

Browse files
Merge pull request #28 from notion-dotnet/feature/add-support-for-search-apis
Add support for Search APIs ✨
2 parents 69cf5bc + ccf3408 commit b476e81

17 files changed

+155
-8
lines changed

Src/Notion.Client/Api/ApiEndpoints.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,10 @@ public static class PagesApiUrls
2727
public static string Retrieve(string pageId) => $"/v1/pages/{pageId}";
2828
public static string UpdateProperties(string pageId) => $"/v1/pages/{pageId}";
2929
}
30+
31+
public static class SearchApiUrls
32+
{
33+
public static string Search() => "/v1/search";
34+
}
3035
}
3136
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System.Threading.Tasks;
2+
3+
namespace Notion.Client
4+
{
5+
public interface ISearchClient
6+
{
7+
Task<PaginatedList<IObject>> SearchAsync(SearchParameters parameters);
8+
}
9+
}
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 interface ISearchBodyParameters : IPaginationParameters
4+
{
5+
string Query { get; set; }
6+
SearchSort Sort { get; set; }
7+
SearchFilter Filter { get; set; }
8+
}
9+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Runtime.Serialization;
2+
3+
namespace Notion.Client
4+
{
5+
public enum SearchDirection
6+
{
7+
[EnumMember(Value = "ascending")]
8+
Ascending,
9+
10+
[EnumMember(Value = "descending")]
11+
Descending
12+
}
13+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Notion.Client
2+
{
3+
public class SearchFilter
4+
{
5+
public SearchObjectType Value { get; set; }
6+
public string Property => "object";
7+
}
8+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Runtime.Serialization;
2+
3+
namespace Notion.Client
4+
{
5+
public enum SearchObjectType
6+
{
7+
[EnumMember(Value = "page")]
8+
Page,
9+
10+
[EnumMember(Value = "database")]
11+
Database
12+
}
13+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace Notion.Client
2+
{
3+
public class SearchParameters : ISearchBodyParameters
4+
{
5+
public string Query { get; set; }
6+
public SearchSort Sort { get; set; }
7+
public SearchFilter Filter { get; set; }
8+
public string StartCursor { get; set; }
9+
public string PageSize { get; set; }
10+
}
11+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using Newtonsoft.Json;
3+
using Newtonsoft.Json.Converters;
4+
5+
namespace Notion.Client
6+
{
7+
public class SearchSort
8+
{
9+
public SearchDirection Direction { get; set; }
10+
11+
[JsonConverter(typeof(IsoDateTimeConverter))]
12+
public DateTime Timestamp { get; set; }
13+
}
14+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.Threading.Tasks;
2+
using static Notion.Client.ApiEndpoints;
3+
4+
namespace Notion.Client
5+
{
6+
public class SearchClient : ISearchClient
7+
{
8+
private readonly IRestClient client;
9+
10+
public SearchClient(IRestClient client)
11+
{
12+
this.client = client;
13+
}
14+
15+
public async Task<PaginatedList<IObject>> SearchAsync(SearchParameters parameters)
16+
{
17+
var url = SearchApiUrls.Search();
18+
19+
var body = (ISearchBodyParameters)parameters;
20+
21+
return await client.PostAsync<PaginatedList<IObject>>(url, body);
22+
}
23+
}
24+
}

Src/Notion.Client/Models/Blocks/Block.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ namespace Notion.Client
1515
[JsonSubtypes.KnownSubType(typeof(ToDoBlock), BlockType.ToDo)]
1616
[JsonSubtypes.KnownSubType(typeof(ToggleBlock), BlockType.Toggle)]
1717
[JsonSubtypes.KnownSubType(typeof(UnsupportedBlock), BlockType.Unsupported)]
18-
public class Block
18+
public class Block : IObject
1919
{
20-
public string Object => "block";
20+
public ObjectType Object => ObjectType.Block;
2121
public string Id { get; set; }
2222

2323
[JsonConverter(typeof(StringEnumConverter))]

0 commit comments

Comments
 (0)