forked from kjk/notionapi
/
load_user_content.go
62 lines (52 loc) · 1.15 KB
/
load_user_content.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
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 *User `json:"-"`
RawJSON map[string]interface{} `json:"-"`
}
func (c *Client) LoadUserContent() (*LoadUserResponse, error) {
req := struct{}{}
apiURL := "/api/v3/loadUserContent"
var rsp struct {
RecordMap map[string]map[string]*LoadUserResponse `json:"recordMap"`
}
rawJSON, err := doNotionAPI(c, apiURL, req, &rsp)
if err != nil {
return nil, err
}
result := &LoadUserResponse{
RawJSON: rawJSON,
}
for table, values := range rsp.RecordMap {
for _, value := range values {
var obj interface{}
if table == TableUser {
result.User = &User{}
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 := json.Unmarshal(value.Value, &obj); err != nil {
return nil, err
}
}
}
return result, nil
}