notion

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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 BlockManager

type BlockManager struct {
	// contains filtered or unexported fields
}

BlockManager ...

func NewBlockManager

func NewBlockManager(version, token string) *BlockManager

NewBlockManager return a new database manager

func (BlockManager) Headers

func (i BlockManager) Headers() []fetch.RequestOption

func (*BlockManager) ID

func (bm *BlockManager) ID() string

ID get block id

func (BlockManager) Set

func (i BlockManager) Set(version, token string)

func (BlockManager) WithContext

func (bm BlockManager) WithContext(ctx context.Context) *BlockManager

WithContext set Context

func (BlockManager) WithID

func (bm BlockManager) WithID(id string) *BlockManager

WithID set block id

func (BlockManager) WithLimiter

func (bm BlockManager) WithLimiter(limiter *rate.Limiter) *BlockManager

WithLimiter with limiiter

type CheckBoxFilter

type CheckBoxFilter struct {
	Equals       bool `json:"equals"`
	DoesNotEqual bool `json:"does_not_equal"`
}

CheckBoxFilter ...

type Condition

type Condition struct {
	PageSize    int                 `json:"page_size,omitempty"`
	StartCursor string              `json:"start_cursor,omitempty"`
	Filter      *FilterCondition    `json:"filter,omitempty"`
	Sorts       []PropSortCondition `json:"sorts,omitempty"`
}

Condition query filter

func (*Condition) Payload

func (f *Condition) Payload() (data []byte)

Payload return payload

type DatabaseManager

type DatabaseManager struct {
	// contains filtered or unexported fields
}

DatabaseManager ...

func NewDatabaseManager

func NewDatabaseManager(version, token string) *DatabaseManager

NewDatabaseManager return a new database manager

func (*DatabaseManager) AsynQuery

func (dm *DatabaseManager) AsynQuery(cond *Condition) <-chan Object

AsynQuery ...

func (*DatabaseManager) Create

func (dm *DatabaseManager) Create(parent PageItem, title []TextObject, properties map[string]*Property) error

Create create database docs: https://developers.notion.com/reference/create-a-database POST https://api.notion.com/v1/databases

func (DatabaseManager) Headers

func (i DatabaseManager) Headers() []fetch.RequestOption

func (*DatabaseManager) ID

func (dm *DatabaseManager) ID() string

ID get database id

func (*DatabaseManager) Query

func (dm *DatabaseManager) Query(cond *Condition) (objects []Object, err error)

Query query databases docs: https://developers.notion.com/reference/post-database-query POST https://api.notion.com/v1/databases/{database_id}/query

func (DatabaseManager) Set

func (i DatabaseManager) Set(version, token string)

func (*DatabaseManager) Update

func (dm *DatabaseManager) Update(payload io.Reader) error

Update update database docs: https://developers.notion.com/reference/update-a-database PATCH https://api.notion.com/v1/databases/{database_id}

func (DatabaseManager) WithContext

func (dm DatabaseManager) WithContext(ctx context.Context) *DatabaseManager

WithContext set Context

func (DatabaseManager) WithID

func (dm DatabaseManager) WithID(id string) *DatabaseManager

WithID set database id

func (DatabaseManager) WithLimiter

func (dm DatabaseManager) WithLimiter(limiter *rate.Limiter) *DatabaseManager

WithLimiter with limiiter

type FileItem

type FileItem struct {
	Name     string `json:"name"`
	Type     string `json:"type"`
	External struct {
		URL string `json:"url"`
	} `json:"external"`
}

type FilesFilter

type FilesFilter struct {
	IsEmpty    bool `json:"is_empty,omitempty"`
	IsNotEmpty bool `json:"is_not_empty,omitempty"`
}

FilesFilter ... doc: https://developers.notion.com/reference/post-database-query-filter#files

type FilterCondition

type FilterCondition struct {
	FilterSingleCondition

	CompoundConditions map[string][]FilterCondition
}

FilterCondition ...

{
  "and": [
    {
      "property": "Done",
      "checkbox": {
        "equals": true
      }
    },
    {
      "or": [
        {
          "property": "Tags",
          "contains": "A"
        },
        {
          "property": "Tags",
          "contains": "B"
        }
      ]
    }
  ]
}

func (*FilterCondition) MarshalJSON

func (cond *FilterCondition) MarshalJSON() ([]byte, error)

type FilterSingleCondition

type FilterSingleCondition struct {
	Property string          `json:"property"`
	CheckBox *CheckBoxFilter `json:"checkbox,omitempty"`
	RichText *RichTextFilter `json:"rich_text,omitempty"`
	Number   *NumberFilter   `json:"number,omitempty"`
	Files    *FilesFilter    `json:"files,omitempty"`

	Contains string `json:"contains,omitempty"`
}

FilterSingleCondition filter single condition https://developers.notion.com/reference/post-database-query-filter#the-filter-object

type IconItem

type IconItem struct {
	Type  string `json:"type"`
	Emoji string `json:"emoji"`
}

type Manager

type Manager struct {
	*DatabaseManager
	*PageManager
	*BlockManager
	*SearchManager
	// contains filtered or unexported fields
}

Manager is a manager for notion

func NewManager

func NewManager(version, token string) *Manager

NewManager return a new notion manager

func (Manager) Headers

func (i Manager) Headers() []fetch.RequestOption

func (*Manager) Set

func (mgr *Manager) Set(version, token string)

Set set notion version and token

func (Manager) WithContext

func (mgr Manager) WithContext(ctx context.Context) *Manager

WithContext set context for notion manager

func (Manager) WithLimiter

func (mgr Manager) WithLimiter(limiter *rate.Limiter) *Manager

WithLimiter set limiter for notion manager

type NumberFilter

type NumberFilter struct {
	Equals               float64 `json:"equals,omitempty"`
	DoesNotEqual         float64 `json:"does_not_equal,omitempty"`
	GreaterThan          float64 `json:"greater_than,omitempty"`
	GreaterThanOrEqualTo float64 `json:"greater_than_or_equal_to,omitempty"`
	LessThan             float64 `json:"less_than,omitempty"`
	LessThanOrEqualTo    float64 `json:"less_than_or_equal_to,omitempty"`
	IsEmpty              bool    `json:"is_empty,omitempty"`
	IsNotEmpty           bool    `json:"is_not_empty,omitempty"`
}

NumberFilter ... doc: https://developers.notion.com/reference/post-database-query-filter#number

type NumberProperty

type NumberProperty struct {
	Format string `json:"format"`
}

type Object

type Object struct {
	PureObject
	CreatedTime    string              `json:"created_time"`
	CreatedBy      PureObject          `json:"created_by"`
	LastEditedTime string              `json:"last_edited_time"`
	LastEditedBy   PureObject          `json:"last_edited_by"`
	Cover          FileItem            `json:"cover,omitempty"`
	Icon           IconItem            `json:"icon,omitempty"`
	Title          []TextItem          `json:"title,omitempty"`
	Description    []TextItem          `json:"description,omitempty"`
	IsInline       bool                `json:"is_inline,omitempty"`
	Properties     map[string]Property `json:"properties,omitempty"`
	Parent         PageItem            `json:"parent,omitempty"`
	URL            string              `json:"url,omitempty"`
	Archived       bool                `json:"archived,omitempty"`
	Results        []Object            `json:"results,omitempty"`
	NextCursor     string              `json:"next_cursor"`
	HasMore        bool                `json:"has_more"`
	Type           string              `json:"type"`

	Status  int    `json:"status,omitempty"`
	Code    string `json:"code,omitempty"`
	Message string `json:"message,omitempty"`
}

Object notion object

type PageItem

type PageItem struct {
	Type       string `json:"type,omitempty"`
	PageID     string `json:"page_id,omitempty"`
	DatabaseID string `json:"database_id,omitempty"`
}

type PageManager

type PageManager struct {
	// contains filtered or unexported fields
}

PageManager ...

func NewPageManager

func NewPageManager(version, token string) *PageManager

NewPageManager return a new page manager

func (*PageManager) Create

func (pm *PageManager) Create(parent PageItem, properties ...*Property) error

Create create page docs: https://developers.notion.com/reference/post-page POST https://api.notion.com/v1/pages

func (PageManager) Headers

func (i PageManager) Headers() []fetch.RequestOption

func (*PageManager) ID

func (pm *PageManager) ID() string

ID get page id

func (PageManager) Set

func (i PageManager) Set(version, token string)

func (*PageManager) Update

func (pm *PageManager) Update(properties ...*Property) error

Update update page docs: https://developers.notion.com/reference/patch-page PATCH https://api.notion.com/v1/pages/{page_id}

func (PageManager) WithContext

func (pm PageManager) WithContext(ctx context.Context) *PageManager

WithContext set Context

func (PageManager) WithID

func (pm PageManager) WithID(id string) *PageManager

WithID set page id

func (PageManager) WithLimiter

func (pm PageManager) WithLimiter(limiter *rate.Limiter) *PageManager

WithLimiter with limiiter

type PropSortCondition

type PropSortCondition struct {
	Property  string `json:"property"`
	Direction string `json:"direction"` // "ascending" or "descending"
}

type Property

type Property struct {
	ID   string       `json:"id"`
	Name string       `json:"name"`
	Type PropertyType `json:"type"`

	Title       interface{} `json:"title,omitempty"`
	Number      interface{} `json:"number,omitempty"`
	RichText    interface{} `json:"rich_text,omitempty"`
	Select      interface{} `json:"select,omitempty"`
	MultiSelect interface{} `json:"multi_select,omitempty"`
	Files       interface{} `json:"files,omitempty"`
}

Property

func (*Property) ForUpdate

func (p *Property) ForUpdate() map[PropertyType]interface{}

ForUpdate return update format data

func (*Property) PlainText

func (p *Property) PlainText() (text string)

PlainText parse rich text to plain text

type PropertyArray

type PropertyArray []*Property

func (PropertyArray) ForUpdate

func (pa PropertyArray) ForUpdate() map[string]interface{}

type PropertyType

type PropertyType string

PropertyType property type

const (
	TitleProp       PropertyType = "title"
	NumberProp      PropertyType = "number"
	RichTextProp    PropertyType = "rich_text"
	SelectProp      PropertyType = "select"
	MultiSelectProp PropertyType = "multi_select"
	FilesProp       PropertyType = "files"
)

type PureObject

type PureObject struct {
	Object string `json:"object"`
	ID     string `json:"id"`
}

PureObject pure notion object

type RichTextFilter

type RichTextFilter struct {
	Contains       string `json:"contains,omitempty"`
	DoesNotContain string `json:"does_not_contain,omitempty"`
	Equals         string `json:"equals,omitempty"`
	DoesNotEqual   string `json:"does_not_equal,omitempty"`
	StartsWith     string `json:"starts_with,omitempty"`
	EndsWith       string `json:"ends_with,omitempty"`
	IsEmpty        bool   `json:"is_empty,omitempty"`
	IsNotEmpty     bool   `json:"is_not_empty,omitempty"`
}

RichTextFilter ...

type SearchManager

type SearchManager struct {
	// contains filtered or unexported fields
}

SearchManager ...

func NewSearchManager

func NewSearchManager(version, token string) *SearchManager

NewSearchManager return a new search manager

func (SearchManager) Headers

func (i SearchManager) Headers() []fetch.RequestOption

func (SearchManager) Set

func (i SearchManager) Set(version, token string)

func (SearchManager) WithContext

func (sm SearchManager) WithContext(ctx context.Context) *SearchManager

WithContext set Context

func (SearchManager) WithLimiter

func (sm SearchManager) WithLimiter(limiter *rate.Limiter) *SearchManager

WithLimiter with limiiter

type SelectOption

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

type SelectProperty

type SelectProperty struct {
	Options []SelectOption `json:"options"`
}

type TextItem

type TextItem struct {
	Content string  `json:"content"`
	Link    *string `json:"link,omitempty"`
}

type TextObject

type TextObject struct {
	Type        string      `json:"type,omitempty"`
	Text        TextItem    `json:"text"`
	Annotations *Annotation `json:"annotations,omitempty"`
	PlainText   string      `json:"plain_text,omitempty"`
	Href        *string     `json:"href,omitempty"`
}

Jump to

Keyboard shortcuts

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