notion

package module
v0.0.0-...-192eddd Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2018 License: BSD-2-Clause Imports: 10 Imported by: 0

README

notion

A notion.so client for Go.

Notion is a team collaboration tool.

Details at https://www.notion.so/about and https://www.notion.so/product

https://godoc.org/github.com/tmc/notion

Please reference the godoc link above for api documentation.

Commands

  • cmd/notion-to-plaintext - renders vim-foldmarker style output from a notion page.
  • cmd/update-notion-block-text - updates the text content of a text block using content from stdin.

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) GetPage

func (c *Client) GetPage(pageId string) (*Page, error)

GetPage returns a Page given an id.

func (*Client) GetRecordValues

func (c *Client) GetRecordValues(records ...Record) ([]*notiontypes.BlockWithRole, error)

GetRecordValues returns details about the given record types.

func (*Client) UpdateBlock

func (c *Client) UpdateBlock(blockID string, path string, value string) error

UpdateBlock returns a Block given an id.

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 Error

type Error struct {
	URL        string
	StatusCode int
	Body       string
}

Error represents an error returned from the notion.so API.

func (*Error) Error

func (e *Error) Error() string

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 Page

type Page struct {
	*notiontypes.Block
}

Page is a notion.so page.

type Record

type Record struct {
	ID    string `json:"id"`
	Table string `json:"table"`
}

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.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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