1
0
mirror of https://github.com/dstotijn/go-notion.git synced 2025-06-08 23:46:12 +02:00

Add "retrieve a user" endpoint support

This commit is contained in:
David Stotijn 2021-05-15 20:29:37 +02:00
parent 019301c714
commit 9b807dd473
2 changed files with 27 additions and 1 deletions

View File

@ -26,7 +26,7 @@ Go client for the [Notion API](https://developers.notion.com/reference).
### Users
- [ ] Retrieve a user
- [x] [Retrieve a user](client.go)
- [ ] List all users
### Search

View File

@ -297,3 +297,29 @@ func (c *Client) AppendBlockChildren(ctx context.Context, blockID string, childr
return block, nil
}
// FindUserByID fetches a user by ID.
// See: https://developers.notion.com/reference/get-user
func (c *Client) FindUserByID(ctx context.Context, id string) (user User, err error) {
req, err := c.newRequest(ctx, http.MethodGet, "/users/"+id, nil)
if err != nil {
return User{}, fmt.Errorf("notion: invalid request: %w", err)
}
res, err := c.httpClient.Do(req)
if err != nil {
return User{}, fmt.Errorf("notion: failed to make HTTP request: %w", err)
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
return User{}, fmt.Errorf("notion: failed to find user: %w", parseErrorResponse(res))
}
err = json.NewDecoder(res.Body).Decode(&user)
if err != nil {
return User{}, fmt.Errorf("notion: failed to parse HTTP response: %w", err)
}
return user, nil
}