generated from padok-team/yatas-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNotionClient.go
94 lines (82 loc) · 2.37 KB
/
NotionClient.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
"errors"
"github.com/jomei/notionapi"
)
type NotionClient struct {
*NotionClientV1
*NotionClientV3
}
func NewNotionClient(account *NotionAccount) NotionClient {
// Create a good type token
// Create the default notionapi/v1 Client
token := notionapi.Token(account.Token)
client := notionapi.NewClient(token)
// Create custom Clients
clientV1 := NewClientV1(client, token)
var notionClient NotionClient
if account.AuthToken != "" {
clientV3 := NewClientV3(account.AuthToken, account.PageID)
notionClient = NotionClient{
NotionClientV1: clientV1,
NotionClientV3: clientV3,
}
} else {
notionClient = NotionClient{
NotionClientV1: clientV1,
}
}
return notionClient
}
func (client *NotionClient) GetTableViewType(databaseID string) (string, string, bool) {
clientV3 := client.NotionClientV3
if clientV3 == nil {
return "", "", false
}
return clientV3.GetTableViewType(databaseID)
}
func (client *NotionClient) GetTableViewProperties(databaseID string) []string {
clientV3 := client.NotionClientV3
var properties []string
if clientV3 == nil {
return properties
}
return clientV3.GetTableViewProperties(databaseID)
}
func (client *NotionClient) UpdateTableViewList(viewID, desiredType string) error {
clientV3 := client.NotionClientV3
if clientV3 == nil {
err := errors.New("NotionClientV3 does not exist, please provide authToken.")
return err
}
err := clientV3.UpdateTableViewList(viewID, desiredType)
return err
}
func (client *NotionClient) LockPage(pageID string) error {
clientV3 := client.NotionClientV3
if clientV3 == nil {
err := errors.New("NotionClientV3 does not exist, please provide authToken.")
return err
}
err := clientV3.LockPage(pageID)
return err
}
func (client *NotionClient) ShowProperties(viewID string, properties []string) error {
clientV3 := client.NotionClientV3
if clientV3 == nil {
err := errors.New("NotionClientV3 does not exist, please provide authToken.")
return err
}
err := clientV3.ShowProperties(viewID, properties)
return err
}
func (client *NotionClient) ShowAllProperties(viewID, databaseID string) error {
clientV3 := client.NotionClientV3
if clientV3 == nil {
err := errors.New("NotionClientV3 does not exist, please provide authToken.")
return err
}
properties := clientV3.GetTableViewProperties(databaseID)
err := clientV3.ShowProperties(viewID, properties)
return err
}