Documentation ¶
Index ¶
- type Client
- func (c *Client) AppendBlockChildren(ctx context.Context, block *notion.Block) (*notion.Block, error)
- func (c *Client) CreateDatabase(ctx context.Context, db *notion.Database) error
- func (c *Client) CreatePage(ctx context.Context, page *notion.Page) (*notion.Page, error)
- func (c *Client) DeleteBlock(ctx context.Context, id string) error
- func (c *Client) GetBlock(ctx context.Context, id string) (*notion.Block, error)
- func (c *Client) GetBlockChildren(ctx context.Context, id string, cursor *string, maxResults int) ([]*notion.Block, error)
- func (c *Client) GetDatabase(ctx context.Context, id string) (*notion.Database, error)
- func (c *Client) GetDatabaseAndChildren(ctx context.Context, id string, maxResults int) (*notion.Database, error)
- func (c *Client) GetDatabases(ctx context.Context, cursor *string, maxResults int) (*notion.Databases, error)
- func (c *Client) GetPage(ctx context.Context, id string) (*notion.Page, error)
- func (c *Client) GetPageAndChildren(ctx context.Context, id string, maxResults int) (*notion.Page, error)
- func (c *Client) GetUser(ctx context.Context, id string) (*notion.User, error)
- func (c *Client) GetUsers(ctx context.Context, cursor *string, maxResults int) ([]*notion.User, error)
- func (c *Client) QueryDatabase(ctx context.Context, id string, query *DBQuery) ([]*notion.Page, error)
- func (c *Client) Search(ctx context.Context, query *SearchQuery) (*SearchResults, error)
- func (c *Client) UpdateBlock(ctx context.Context, block *notion.Block) error
- func (c *Client) UpdateDatabase(ctx context.Context, db *notion.Database) error
- func (c *Client) UpdatePageProperties(ctx context.Context, page *notion.Page) error
- type DBQuery
- type Option
- func WithAPIVersion(v string) Option
- func WithBackoffStrategy(b pester.BackoffStrategy) Option
- func WithMaxRetries(n int) Option
- func WithPesterClient(pesterClient *pester.Client) Option
- func WithRateLimiter(r *rate.Limiter) Option
- func WithRetryOnHTTP429() Option
- func WithSettings(s *notion.Settings) Option
- func WithTimeout(t time.Duration) Option
- func WithToken(t string) Option
- func WithUserAgent(u string) Option
- func WithoutRetryOnHTTP429() Option
- type Result
- type SearchQuery
- type SearchResults
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a client used to make calls to the Notion API.
func NewClient ¶
NewClient creates a new gotion client to use with the API. By default: - the client will use the most recent accepted Notion API version. - Timeout is 30 seconds - Backoff strategy is set to pester.ExponentialJitterBackoff - Rate limiter is set to 3 requests per second - MaxRetries is set to 8 - the client will retry on 429 errors.
func (*Client) AppendBlockChildren ¶
func (c *Client) AppendBlockChildren(ctx context.Context, block *notion.Block) (*notion.Block, error)
AppendBlockChildren adds the given blocks as children of the block with the ID provided in the Notion API. All that is needed in the notion.Block are the page ID and the blocks that need to be added. Providing the current children of the block will result in duplicate blocks. On success, the notion.Block returned will be the complete block from the Notion API. On error, the notion.Block returned is the original one.
func (*Client) CreateDatabase ¶
CreateDatabase will send a request to create the given database in the Notion API. All that is needed in the notion.Database object are the Parent and Properties. Optionally, a Title can be set. No IDs need to be given. On success, the notion.Database will be the complete page from the Notion API. On error, the notion.Page will not be changed.
func (*Client) CreatePage ¶
CreatePage will send a request to create the given page in the Notion API. All that is needed in the notion.Page object are the Parent, Properties, and Children. No IDs need to be given. On success, the notion.Page returned will be the complete page from the Notion API. On error, the notion.Page returned is the original one.
func (*Client) DeleteBlock ¶
DeleteBlock deletes a block with the given id from the Notion API.
func (*Client) GetBlockChildren ¶
func (c *Client) GetBlockChildren(ctx context.Context, id string, cursor *string, maxResults int) ([]*notion.Block, error)
GetBlockChildren gets the children of the block with the given id from the Notion API. If `maxResults < 0`, then this will get all the children of the block.
func (*Client) GetDatabase ¶
GetDatabase gets a database with the given id from the Notion API.
func (*Client) GetDatabaseAndChildren ¶
func (c *Client) GetDatabaseAndChildren(ctx context.Context, id string, maxResults int) (*notion.Database, error)
GetDatabaseAndChildren gets a database with the given id from the Notion API, as well as the children of the database. If `maxResults < 0`, then this gets all children.
func (*Client) GetDatabases ¶
func (c *Client) GetDatabases(ctx context.Context, cursor *string, maxResults int) (*notion.Databases, error)
GetDatabases gets a number of databases with from the Notion API. If `maxResults < 0`, then all databases are retrieved.
func (*Client) GetPage ¶
GetPage gets a page with the given id from the Notion API. To get the contents of a page, use `GetPageWithChildren` with the page id.
func (*Client) GetPageAndChildren ¶
func (c *Client) GetPageAndChildren(ctx context.Context, id string, maxResults int) (*notion.Page, error)
GetPageAndChildren gets a page with the given id from the Notion API, as well as the children of the page. If `maxResults < 0`, then this gets all children.
func (*Client) GetUsers ¶
func (c *Client) GetUsers(ctx context.Context, cursor *string, maxResults int) ([]*notion.User, error)
GetUsers gets a user with the given id from the Notion API. If `maxResults < 0`, then this will get all users.
func (*Client) QueryDatabase ¶
func (c *Client) QueryDatabase(ctx context.Context, id string, query *DBQuery) ([]*notion.Page, error)
QueryDatabase will query the database with the given id in the Notion API.
func (*Client) Search ¶
func (c *Client) Search(ctx context.Context, query *SearchQuery) (*SearchResults, error)
Search allows searching the Notion API. Currently, this is limited by Notion. query -- search the titles of objects (pages and databases) sort -- can only sort by last_edited_time filter -- can only filter by object type: pages or databases.
func (*Client) UpdateBlock ¶
UpdateBlock updates a block in the Notion API. On success, the block will be the complete block from the Notion API. On error, the block will not be changed.
func (*Client) UpdateDatabase ¶
UpdateDatabase updates the database in the Notion API. On success, the database is the complete database from the Notion API. On error, the database is not updated.
func (*Client) UpdatePageProperties ¶
UpdatePageProperties updates the page properties in the Notion API. All that is needed in the notion.Page are the page ID and Properties. A caller doesn't need to provide all properties, but only the updates ones. However, providing all properties works fine as well. On success, the notion.Page will be the complete page from the Notion API. On error, the notion.Page will be changed.
type DBQuery ¶
type DBQuery struct { Filter *notion.Filter `json:"filter,omitempty"` Sort *notion.Sort `json:"sort,omitempty"` Cursor *string `json:"cursor,omitempty"` MaxResults *int `json:"page_size,omitempty"` }
DBQuery represents the parameters needed to query a database in the Notion API.
type Option ¶
type Option func(*Client)
An Option is a way of customizing the gotion client
func WithAPIVersion ¶
WithAPIVersion uses the given Notion API version with the gotion client. It checks that the string provided is an accepted API version. If the string does not represent an accepted API version, then this is a no-op.
func WithBackoffStrategy ¶
func WithBackoffStrategy(b pester.BackoffStrategy) Option
WithBackoffStrategy applies the given backoff strategy to the gotion client
func WithMaxRetries ¶
WithMaxRetries sets the maximum number of retries for the gotion client.
func WithPesterClient ¶
WithPesterClient uses the given pester client for the gotion client
func WithRateLimiter ¶
WithRateLimiter users the given rate limiter with the gotion client.
func WithRetryOnHTTP429 ¶
func WithRetryOnHTTP429() Option
WithRetryOnHTTP429 sets the gotion client to retry on 429 errors. The rate limiter should help with this as well.
func WithSettings ¶
WithSettings uses the given settings with the gotion client.
func WithTimeout ¶
WithTimeout sets the timeout parameter for the gotion client.
func WithUserAgent ¶
WithUserAgent uses the given user agent string with the gotion client.
func WithoutRetryOnHTTP429 ¶
func WithoutRetryOnHTTP429() Option
WithoutRetryOnHTTP429 sets the gotion client to NOT retry on 429 errors. The rate limiter should help with this as well.
type Result ¶
type Result struct { NextCursor *string `json:"next_cursor"` HasMore bool `json:"has_more"` Results interface{} `json:"results"` }
A Result is a response from the Notion API when getting more than one thing back (i.e. listing)
type SearchQuery ¶
type SearchQuery struct { Query string `json:"query"` Filter *notion.Filter `json:"filter,omitempty"` Sort *notion.Sort `json:"sort,omitempty"` Cursor *string `json:"cursor,omitempty"` MaxResults *int `json:"page_size,omitempty"` }
SearchQuery represents the body needed to search the Notion API. Currently, one can only filter based on object: page or database. Currently, one can only sort based on last_edited_time.
type SearchResults ¶
SearchResults represent the returned results from searching the Notion API.
func (*SearchResults) Len ¶
func (sr *SearchResults) Len() int
Len returns the total number of results, pages plus databases
func (*SearchResults) UnmarshalJSON ¶
func (sr *SearchResults) UnmarshalJSON(b []byte) error
UnmarshalJSON unmarshals the SearchResults into Pages and Databases.