Skip to content

Commit 12bc6ab

Browse files
Merge pull request #169 from notion-dotnet/feature/168-add-support-to-retrieve-bot-user-assigned-to-a-token
Add support to retrieve bot user assigned to a token ✨
2 parents ce76079 + 51f4876 commit 12bc6ab

File tree

15 files changed

+192
-12
lines changed

15 files changed

+192
-12
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ var complexFiler = new CompoundFilter(
117117
- [x] Users
118118
- [x] Retrieve a User
119119
- [x] List all users
120+
- [x] Retrieve your token's bot user
120121
- [x] Search
121122

122123
## Contribution Guideline

Src/Notion.Client/Api/ApiEndpoints.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace Notion.Client
1+
using System;
2+
3+
namespace Notion.Client
24
{
35
public static class ApiEndpoints
46
{
@@ -15,6 +17,12 @@ public static class UsersApiUrls
1517
{
1618
public static string Retrieve(string userId) => $"/v1/users/{userId}";
1719
public static string List() => "/v1/users";
20+
21+
/// <summary>
22+
/// Get the <see cref="uri string"/> for retrieve your token's bot user.
23+
/// </summary>
24+
/// <returns>Returns a <see cref="uri string"/> retrieve your token's bot user.</returns>
25+
public static string Me() => "/v1/users/me";
1826
}
1927

2028
public static class BlocksApiUrls

Src/Notion.Client/Api/Users/IUsersClient.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,11 @@ public interface IUsersClient
66
{
77
Task<User> RetrieveAsync(string userId);
88
Task<PaginatedList<User>> ListAsync();
9+
10+
/// <summary>
11+
/// Retrieves the bot User associated with the API token provided in the authorization header.
12+
/// </summary>
13+
/// <returns>User object of type bot having an owner field with information about the person who authorized the integration.</returns>
14+
Task<User> MeAsync();
915
}
1016
}

Src/Notion.Client/Api/Users/UsersClient.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,14 @@ public async Task<PaginatedList<User>> ListAsync()
2121
{
2222
return await _client.GetAsync<PaginatedList<User>>(UsersApiUrls.List());
2323
}
24+
25+
/// <summary>
26+
/// Retrieves the bot User associated with the API token provided in the authorization header.
27+
/// </summary>
28+
/// <returns>User object of type bot having an owner field with information about the person who authorized the integration.</returns>
29+
public async Task<User> MeAsync()
30+
{
31+
return await _client.GetAsync<User>(UsersApiUrls.Me());
32+
}
2433
}
2534
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Notion.Client
4+
{
5+
public class Bot
6+
{
7+
[JsonProperty("owner")]
8+
public IBotOwner Owner { get; set; }
9+
}
10+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using JsonSubTypes;
2+
using Newtonsoft.Json;
3+
4+
namespace Notion.Client
5+
{
6+
[JsonConverter(typeof(JsonSubtypes), "type")]
7+
[JsonSubtypes.KnownSubType(typeof(UserOwner), "user")]
8+
[JsonSubtypes.KnownSubType(typeof(WorkspaceIntegrationOwner), "workspace")]
9+
public interface IBotOwner
10+
{
11+
[JsonProperty("type")]
12+
string Type { get; set; }
13+
}
14+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Notion.Client
4+
{
5+
public class UserOwner : IBotOwner
6+
{
7+
public string Type { get; set; }
8+
9+
[JsonProperty("user")]
10+
public User User { get; set; }
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Notion.Client
4+
{
5+
public class WorkspaceIntegrationOwner : IBotOwner
6+
{
7+
public string Type { get; set; }
8+
9+
[JsonProperty("workspace")]
10+
public bool Workspace { get; set; }
11+
}
12+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using Newtonsoft.Json;
2+
3+
namespace Notion.Client
4+
{
5+
public class Person
6+
{
7+
[JsonProperty("email")]
8+
public string Email { get; set; }
9+
}
10+
}

Src/Notion.Client/Models/User.cs renamed to Src/Notion.Client/Models/User/User.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,4 @@ public class User : IObject
2222
[JsonProperty("bot")]
2323
public Bot Bot { get; set; }
2424
}
25-
26-
public class Person
27-
{
28-
[JsonProperty("email")]
29-
public string Email { get; set; }
30-
}
31-
32-
public class Bot
33-
{
34-
35-
}
3625
}

0 commit comments

Comments
 (0)