Skip to content

Commit bf6e33c

Browse files
add search api client ✨
1 parent 90c99f8 commit bf6e33c

File tree

11 files changed

+112
-0
lines changed

11 files changed

+112
-0
lines changed

Src/Notion.Client/Api/ApiEndpoints.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,10 @@ public static class BlocksApiUrls
2020
public static string RetrieveChildren(string blockId) => $"/v1/blocks/{blockId}/children";
2121
public static string AppendChildren(string blockId) => $"/v1/blocks/{blockId}/children";
2222
}
23+
24+
public static class SearchApiUrls
25+
{
26+
public static string Search() => "/v1/search";
27+
}
2328
}
2429
}
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/PaginatedList.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ namespace Notion.Client
55
{
66
public interface IPaginationParameters
77
{
8+
[JsonProperty("start_cursor")]
89
string StartCursor { get; set; }
10+
11+
[JsonProperty("page_size")]
912
string PageSize { get; set; }
1013
}
1114

0 commit comments

Comments
 (0)