Documentation
¶
Overview ¶
Package notion exposes a client for use with the notion.so API.
Please see usage examples below.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PrintAsVim ¶
func PrintAsVim(block *notiontypes.Block, indent string) ([]byte, error)
PrintAsVim renders a notion block as a vim block.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the primary type that implements an interface to the notion.so API.
func NewClient ¶
func NewClient(opts ...ClientOption) (*Client, error)
NewClient initializes a new Client.
Example ¶
package main import ( "fmt" "github.com/tmc/notion" ) var testPageSimple = "aa8fc126-6770-4e83-ad6c-3968dcfc9b82" func main() { c, err := notion.NewClient() //c, err := notion.NewClient(notion.WithDebugLogging()) if err != nil { fmt.Println(err) } page, err := c.GetPage(testPageSimple) if err != nil { fmt.Println(err) return } fmt.Println(page.Type) fmt.Println(page.Title) }
Output: page le-title
Example (Authenticated) ¶
package main import ( "os" "github.com/tmc/notion" ) func main() { token := os.Getenv("NOTION_TOKEN") client, err := notion.NewClient(notion.WithToken(token), notion.WithDebugLogging()) _, _ = client, err }
func (*Client) GetBlock ¶
func (c *Client) GetBlock(blockID string) (*notiontypes.Block, error)
GetBlock returns a Block given an id.
func (*Client) GetRecordValues ¶
func (c *Client) GetRecordValues(records ...Record) ([]*notiontypes.BlockWithRole, error)
GetRecordValues returns details about the given record types.
type ClientOption ¶
type ClientOption func(*Client)
ClientOption allows customization of Clients.
func WithBaseURL ¶
func WithBaseURL(baseURL string) ClientOption
WithBaseURL allows configuration on of a custom base URL.
func WithDebugLogging ¶
func WithDebugLogging() ClientOption
WithDebugLogging attaches a debug-level logger to the client.
Example ¶
package main import ( "github.com/tmc/notion" ) func main() { client, err := notion.NewClient(notion.WithDebugLogging()) _, _ = client, err }
func WithHTTPClient ¶
func WithHTTPClient(client *http.Client) ClientOption
WithHTTPClient allows customization of the http.Client that is used for API communication.
func WithLogger ¶
func WithLogger(logger Logger) ClientOption
WithLogger allows configuration of the Logger.
See the WrapLogrus utility type to supply a logrus Logger.
func WithToken ¶
func WithToken(token string) ClientOption
WithToken allows configuration on of an authentication token.
type Cursor ¶
type Cursor struct {
Stack [][]StackPosition `json:"stack"`
}
Cursor is used for pagination of entities.
type Logger ¶
type Logger interface { WithField(key string, value interface{}) Logger WithError(err error) Logger Debugln(args ...interface{}) Infoln(args ...interface{}) Println(args ...interface{}) Warnln(args ...interface{}) Errorln(args ...interface{}) Fatalln(args ...interface{}) }
Logger defines the logger type this package uses.
type Record ¶
Record describes a type of notion.no entity.
Example: block1 := Record{Table:"block","ID":"aa8fc12667704e83ad6c3968dcfc9b82"}
type StackPosition ¶
type StackPosition struct { ID string `json:"id,omitempty"` Index float64 `json:"index,omitempty"` Table string `json:"table,omitempty"` }
StackPosition refers to a position within a list of entities (usually blocks).
type WrapLogrus ¶
type WrapLogrus struct {
logrus.FieldLogger
}
WrapLogrus wraps a logrus Logger to conform to the Logger interface defined in this package.
func (WrapLogrus) WithError ¶
func (wl WrapLogrus) WithError(err error) Logger
WithError attaches a key-value pair to a log line.
func (WrapLogrus) WithField ¶
func (wl WrapLogrus) WithField(key string, value interface{}) Logger
WithField attaches a key-value pair to a log line.