mirror of
https://github.com/dstotijn/go-notion.git
synced 2025-12-23 23:51:17 +02:00
Support retrieve a block (#19)
* support retrieve block by id * Update client.go Co-authored-by: David Stotijn <dstotijn@gmail.com> * Update client_test.go Co-authored-by: David Stotijn <dstotijn@gmail.com> * Update client.go Co-authored-by: David Stotijn <dstotijn@gmail.com> * fix find block's client test Co-authored-by: David Stotijn <dstotijn@gmail.com>
This commit is contained in:
26
client.go
26
client.go
@@ -337,6 +337,32 @@ func (c *Client) AppendBlockChildren(ctx context.Context, blockID string, childr
|
||||
return block, nil
|
||||
}
|
||||
|
||||
// FindBlockByID returns a single of block for a given block ID.
|
||||
// See: https://developers.notion.com/reference/retrieve-a-block
|
||||
func (c *Client) FindBlockByID(ctx context.Context, blockID string) (block Block, err error) {
|
||||
req, err := c.newRequest(ctx, http.MethodGet, fmt.Sprintf("/blocks/%v", blockID), nil)
|
||||
if err != nil {
|
||||
return Block{}, fmt.Errorf("notion: invalid request: %w", err)
|
||||
}
|
||||
|
||||
res, err := c.httpClient.Do(req)
|
||||
if err != nil {
|
||||
return Block{}, fmt.Errorf("notion: failed to make HTTP request: %w", err)
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
if res.StatusCode != http.StatusOK {
|
||||
return Block{}, fmt.Errorf("notion: failed to find block: %w", parseErrorResponse(res))
|
||||
}
|
||||
|
||||
err = json.NewDecoder(res.Body).Decode(&block)
|
||||
if err != nil {
|
||||
return Block{}, fmt.Errorf("notion: failed to parse HTTP response: %w", err)
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user