notion

package module
v0.0.0-...-02c344b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 20, 2021 License: MIT Imports: 13 Imported by: 0

README

Notion GO Client

Notion is an interesting platform that just released its beta API. They currently only have an implementation of their client in node.js -- this is an attempt at one in Go.

See: https://developers.notion.com/reference/intro

Parts of the API that are working:

  • Pages
    • Retrieve
  • Database
    • Retrieve
  • Users
    • List
    • List All Users (handle pagination internally)
  • Blocks
    • Retrieve Children
    • Retrieve All Children (handle pagination internally)

Parts the API that are not working:

  • Pages
    • Create
    • Update properties
  • Database
    • Query
    • List (probably won't ever add)
  • Blocks
    • Append Children
  • Search

Documentation

Index

Constants

View Source
const (
	UserTypePerson = "person"
	UserTypeBot    = "bot"
)

Variables

View Source
var (
	DefaultUserAgent = "go-notion-client"
	DefaultVersion   = "2021-05-13"
	DefaultBaseUrl   = "https://api.notion.com/"

	DefaultDialer                      = &net.Dialer{Timeout: 1000 * time.Millisecond}
	DefaultTransport http.RoundTripper = &http.Transport{Dial: DefaultDialer.Dial, Proxy: http.ProxyFromEnvironment}
	DefaultClient                      = &http.Client{Transport: DefaultTransport}

	DefaultRequestTimeout = 5 * time.Second
	DefaultRetries        = 3
	DefaultRetryDelay     = 3 * time.Second
	DefaultRequestRate    = 3
	DefaultRequestBurst   = 5
)
View Source
var (
	ErrMissingBlockID = errors.New("missing block id")
)

Functions

func SetConnectTimeout

func SetConnectTimeout(duration time.Duration)

Types

type Annotation

type Annotation struct {
	Bold          bool   `json:"bold"`
	Italic        bool   `json:"italic"`
	Strikethrough bool   `json:"strikethrough"`
	Underline     bool   `json:"underline"`
	Code          bool   `json:"code"`
	Color         string `json:"color"`
}

type Block

type Block struct {
	ID          string    `json:"id"`
	Created     time.Time `json:"created_time"`
	Edited      time.Time `json:"last_edited_time"`
	HasChildren bool      `json:"has_children"`

	Type string `json:"type"`

	Paragraph        BlockContent `json:"paragraph"`
	HeadingOne       BlockContent `json:"heading_1"`
	HeadingTwo       BlockContent `json:"heading_2"`
	HeadingThree     BlockContent `json:"heading_3"`
	BulletedListItem BlockContent `json:"bulleted_list_item"`
	Todo             BlockContent `json:"to_do"`
	Toggle           BlockContent `json:"toggle"`
	ChildPage        BlockContent `json:"child_page"`
	// contains filtered or unexported fields
}

func (Block) Checked

func (b Block) Checked() bool

func (Block) Content

func (b Block) Content() []RichText

func (Block) Error

func (b Block) Error() error

func (Block) IsUnsupported

func (b Block) IsUnsupported() bool

func (Block) Object

func (b Block) Object() string

type BlockContent

type BlockContent struct {
	Title    string     `json:"title"`
	Text     []RichText `json:"text"`
	Children []Block    `json:"children"`
	Checked  bool       `json:"checked"`
}

type BlockList

type BlockList struct {
	NextCursor string `json:"next_cursor"`
	HasMore    bool   `json:"has_more"`

	Results []Block `json:"results"`
	// contains filtered or unexported fields
}

func (BlockList) Error

func (l BlockList) Error() error

func (BlockList) Object

func (l BlockList) Object() string

type BlockListOptions

type BlockListOptions = Options

type BlockService

type BlockService service

func (*BlockService) All

func (s *BlockService) All(ctx context.Context, id string, options *BlockListOptions) <-chan Block

All allows for ranging over all users, handling pagination internally. If there is an error the User.Error() will return the non-nill error. To prevent leaking resources, either the channel must be read until it closes or the context must be cancelled.

func (*BlockService) Retrieve

func (s *BlockService) Retrieve(ctx context.Context, id string, options *BlockListOptions) (BlockList, error)

Retrieve a user with the given id

type Bot

type Bot struct{}

type Client

type Client struct {
	BaseURL   *url.URL
	UserAgent string
	Token     string
	Version   string

	Retries        int
	RetryDelay     time.Duration
	RequestRate    int
	RequestBurst   int
	RequestTimeout time.Duration

	Users     *UserService
	Databases *DatabaseService
	Pages     *PageService
	Blocks    *BlockService
	// contains filtered or unexported fields
}

func New

func New(token string, httpClient *http.Client) *Client

func (*Client) Do

func (client *Client) Do(ctx context.Context, req *http.Request, mods ...RequestModifier) (*http.Response, error)

Do sends an HTTP request and returns an HTTP response, following the settings configured by the client.

func (*Client) Get

func (client *Client) Get(ctx context.Context, subject interface{}, path string, mods ...RequestModifier) error

func (*Client) NewRequest

func (client *Client) NewRequest(method string, urlStr string, body interface{}) (*http.Request, error)

func (*Client) Patch

func (client *Client) Patch(ctx context.Context, url string, body interface{}, mods ...RequestModifier) (*http.Response, error)

func (*Client) Post

func (client *Client) Post(ctx context.Context, url string, body interface{}, mods ...RequestModifier) (*http.Response, error)

type Database

type Database struct {
	ID         string
	Created    time.Time
	LastEdited time.Time
	Title      []RichText
	Properties map[string]Property
	// contains filtered or unexported fields
}

func (Database) Error

func (d Database) Error() error

func (Database) Object

func (d Database) Object() string

type DatabaseListOptions

type DatabaseListOptions = UserListOptions

type DatabaseQueryOptions

type DatabaseQueryOptions struct {
	StartCursor string
	PageSize    int
	Filter      interface{} // TODO
	Sorts       interface{} // TODO
}

type DatabaseQueryResults

type DatabaseQueryResults struct {
	Results    []interface{}
	NextCursor string
	HasMore    bool
}

type DatabaseService

type DatabaseService service

func (*DatabaseService) Retrieve

func (s *DatabaseService) Retrieve(ctx context.Context, id string) (Database, error)

Retrieve a user with the given id

type Error

type Error struct {
	Status  int
	Code    string
	Message string
}

func (Error) Error

func (e Error) Error() string

func (Error) Object

func (e Error) Object() string

type FormulaProperty

type FormulaProperty struct {
	Expression string `json:"expression"`
}

type List

type List struct {
	NextCursor string
	HasMore    bool
	// contains filtered or unexported fields
}

func (List) Error

func (l List) Error() error

func (List) Object

func (l List) Object() string

type MultiSelectProperty

type MultiSelectProperty struct {
	Options []SelectOption
}

type Object

type Object interface {
	Object() string
	Error() error
}

type Options

type Options struct {
	StartCursor string
	PageSize    int
}

type Page

type Page struct {
	ID         string
	Created    time.Time
	Edited     time.Time
	Archived   bool
	Properties map[string]Property
	// contains filtered or unexported fields
}

func (Page) Error

func (p Page) Error() error

func (Page) Object

func (p Page) Object() string

type PageService

type PageService service

func (*PageService) Retrieve

func (s *PageService) Retrieve(ctx context.Context, id string) (Page, error)

Retrieve a user with the given id

type Person

type Person struct {
	Email string
}

type Property

type Property struct {
	ID          string              `json:"id"`
	Type        string              `json:"type"`
	Title       interface{}         `json:"title"`
	Select      SelectProperty      `json:"select"`
	MultiSelect MultiSelectProperty `json:"multi_select"`
	Date        time.Time           `json:"date"`
	People      interface{}         `json:"people"`
	File        interface{}         `json:"file"`
	Checkbox    interface{}         `json:"checkbox"`
	URL         interface{}         `json:"url"`
	Email       interface{}         `json:"email"`
	PhoneNumber interface{}         `json:"phone_number"`
	Formula     FormulaProperty     `json:"formula"`
	Relation    RelationProperty    `json:"relation"`
	Rollup      RollupProperty      `json:"rollup"`
	CreatedTime interface{}         `json:"created_time"`
	CreatedBy   interface{}         `json:"created_by"`
	EditedTime  interface{}         `json:"edited_time"`
	EditedBy    interface{}         `json:"edited_by"`
}

type RelationProperty

type RelationProperty struct {
	ID         string `json:"database_id"`
	SyncedName string `json:"synced_property_name"`
	SyncedID   string `json:"synced_property_id"`
}

type RequestModifier

type RequestModifier func(*http.Request)

func Accepts

func Accepts(t string) RequestModifier

func ContentType

func ContentType(t string) RequestModifier

func QueryParams

func QueryParams(vals url.Values) RequestModifier

QueryParams adds the given url.Values to the request

func UserAgent

func UserAgent(t string) RequestModifier

type RichText

type RichText struct {
	Plain       string     `json:"plain_text" mapstructure:"plain_text"`
	Href        string     `json:"href"`
	Annotations Annotation `json:"annotations"`
	Type        string     `json:"type"`

	Text struct {
		Content string
		Link    string
	}
}

type RollupProperty

type RollupProperty struct {
	RelationName string `json:"relation_property_name"`
	RelationID   string `json:"relation_property_id"`
	RollupName   string `json:"rollup_property_name"`
	RollupID     string `json:"rollup_property_id"`
	Function     string `json:"function"`
}

type SelectOption

type SelectOption struct {
	Name  string `json:"name"`
	ID    string `json:"id"`
	Color string `json:"color"`
}

type SelectProperty

type SelectProperty struct {
	Options []SelectOption
}

type User

type User struct {
	ID        string
	Type      string
	Name      string
	AvatarUrl string

	Person Person
	Bot    Bot
	// contains filtered or unexported fields
}

func (User) Error

func (u User) Error() error

func (User) Object

func (u User) Object() string

type UserList

type UserList struct {
	NextCursor string
	HasMore    bool

	Results []User
	// contains filtered or unexported fields
}

func (UserList) Error

func (l UserList) Error() error

func (UserList) Object

func (l UserList) Object() string

type UserListOptions

type UserListOptions = Options

type UserService

type UserService service

func (*UserService) All

func (s *UserService) All(ctx context.Context, options *UserListOptions) <-chan User

All allows for ranging over all users, handling pagination internally. If there is an error the User.Error() will return the non-nill error. To prevent leaking resources, either the channel must be read until it closes or the context must be cancelled.

func (*UserService) List

func (s *UserService) List(ctx context.Context, options *UserListOptions) (UserList, error)

List the users. This is a paginated resource, see: https://developers.notion.com/reference/get-users

func (*UserService) Retrieve

func (s *UserService) Retrieve(ctx context.Context, id string) (User, error)

Retrieve a user with the given id

Directories

Path Synopsis
cmd
x

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL