-
Notifications
You must be signed in to change notification settings - Fork 87
/
api_loadUserContent.go
58 lines (48 loc) · 1.16 KB
/
api_loadUserContent.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
package notionapi
import "encoding/json"
type LoadUserResponse struct {
ID string `json:"id"`
Table string `json:"table"`
Role string `json:"role"`
Value json.RawMessage `json:"value"`
Block *Block `json:"-"`
Space *Space `json:"-"`
User *NotionUser `json:"-"`
RawJSON map[string]interface{} `json:"-"`
}
func (c *Client) LoadUserContent() (*LoadUserResponse, error) {
req := struct{}{}
var rsp struct {
RecordMap map[string]map[string]*LoadUserResponse `json:"recordMap"`
}
apiURL := "/api/v3/loadUserContent"
result := LoadUserResponse{}
err := c.doNotionAPI(apiURL, req, &rsp, &result.RawJSON)
if err != nil {
return nil, err
}
for table, values := range rsp.RecordMap {
for _, value := range values {
var obj interface{}
if table == TableNotionUser {
result.User = &NotionUser{}
obj = result.User
}
if table == TableBlock {
result.Block = &Block{}
obj = result.Block
}
if table == TableSpace {
result.Space = &Space{}
obj = result.Space
}
if obj == nil {
continue
}
if err := jsonit.Unmarshal(value.Value, &obj); err != nil {
return nil, err
}
}
}
return &result, nil
}