Some working
This commit is contained in:
@@ -2,15 +2,14 @@ package notion
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/jomei/notionapi"
|
||||
)
|
||||
|
||||
var client *notionapi.Client
|
||||
var authToken string
|
||||
|
||||
func Init(token string) {
|
||||
authToken = token
|
||||
client = notionapi.NewClient(notionapi.Token(token))
|
||||
}
|
||||
|
||||
@@ -18,45 +17,49 @@ func GetClient() *notionapi.Client {
|
||||
return client
|
||||
}
|
||||
|
||||
func AGetBlock(blockId string) chan struct {
|
||||
Block notionapi.Block
|
||||
Error error
|
||||
} {
|
||||
retval := make(chan struct {
|
||||
Block notionapi.Block
|
||||
Error error
|
||||
func GetTableRows(tableId string, numberOfRows int, startFromId string) ([]notionapi.Block, error) {
|
||||
if client == nil {
|
||||
return nil, errors.New("notion client not initialized")
|
||||
}
|
||||
block, err := client.Block.GetChildren(context.Background(), notionapi.BlockID(tableId), ¬ionapi.Pagination{
|
||||
StartCursor: notionapi.Cursor(startFromId),
|
||||
PageSize: numberOfRows,
|
||||
})
|
||||
go func() {
|
||||
block, err := client.Block.Get(context.Background(), notionapi.BlockID(blockId))
|
||||
retval <- struct {
|
||||
Block notionapi.Block
|
||||
Error error
|
||||
}{block, err}
|
||||
}()
|
||||
return retval
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return block.Results, nil
|
||||
}
|
||||
|
||||
func AGetBlockChildren(blockId string, startCursor string, pageSize int) chan struct {
|
||||
Children []notionapi.Block
|
||||
NextCursor string
|
||||
HasMore bool
|
||||
Error error
|
||||
} {
|
||||
retval := make(chan struct {
|
||||
Children []notionapi.Block
|
||||
NextCursor string
|
||||
HasMore bool
|
||||
Error error
|
||||
func WriteTableRow(content []string, tableId string, after string) error {
|
||||
if client == nil {
|
||||
return errors.New("notion client not initialized")
|
||||
}
|
||||
rich := [][]notionapi.RichText{}
|
||||
for _, c := range content {
|
||||
rich = append(rich, []notionapi.RichText{
|
||||
{
|
||||
Type: "text",
|
||||
Text: ¬ionapi.Text{
|
||||
Content: c,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
tableRow := notionapi.TableRowBlock{
|
||||
BasicBlock: notionapi.BasicBlock{
|
||||
Object: "block",
|
||||
Type: "table_row",
|
||||
},
|
||||
TableRow: notionapi.TableRow{
|
||||
Cells: rich,
|
||||
},
|
||||
}
|
||||
|
||||
_, err := client.Block.AppendChildren(context.Background(), notionapi.BlockID(tableId), ¬ionapi.AppendBlockChildrenRequest{
|
||||
After: notionapi.BlockID(after),
|
||||
Children: []notionapi.Block{tableRow},
|
||||
})
|
||||
pagination := notionapi.Pagination{StartCursor: notionapi.Cursor(startCursor), PageSize: pageSize}
|
||||
go func() {
|
||||
children, err := client.Block.GetChildren(context.Background(), notionapi.BlockID(blockId), &pagination)
|
||||
retval <- struct {
|
||||
Children []notionapi.Block
|
||||
NextCursor string
|
||||
HasMore bool
|
||||
Error error
|
||||
}{children.Results, children.NextCursor, children.HasMore, err}
|
||||
}()
|
||||
return retval
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user