-
Notifications
You must be signed in to change notification settings - Fork 86
/
api_getActivityLog.go
49 lines (44 loc) · 1.53 KB
/
api_getActivityLog.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
package notionapi
type navigableBlockID struct {
ID string `json:"id"`
}
// /api/v3/getActivityLog request
type getActivityLogRequest struct {
SpaceID string `json:"spaceId"`
StartingAfterID string `json:"startingAfterId,omitempty"`
NavigableBlock navigableBlockID `json:"navigableBlock,omitempty"`
Limit int `json:"limit"`
}
// GetActivityLogResponse is a response to /api/v3/getActivityLog api
type GetActivityLogResponse struct {
ActivityIDs []string `json:"activityIds"`
RecordMap *RecordMap `json:"recordMap"`
NextID string `json:"-"`
RawJSON map[string]interface{} `json:"-"`
}
// GetActivityLog executes a raw API call /api/v3/getActivityLog.
// If startingAfterId is "", starts at the most recent log entry.
// navBlockID is the ID of a navigable block (like a page in a database)
func (c *Client) GetActivityLog(spaceID string, startingAfterID string, navBlockID string, limit int) (*GetActivityLogResponse, error) {
req := &getActivityLogRequest{
SpaceID: spaceID,
StartingAfterID: startingAfterID,
Limit: limit,
NavigableBlock: navigableBlockID{ID: navBlockID},
}
var rsp GetActivityLogResponse
var err error
apiURL := "/api/v3/getActivityLog"
if err = c.doNotionAPI(apiURL, req, &rsp, &rsp.RawJSON); err != nil {
return nil, err
}
if err = ParseRecordMap(rsp.RecordMap); err != nil {
return nil, err
}
if len(rsp.ActivityIDs) > 0 {
rsp.NextID = rsp.ActivityIDs[len(rsp.ActivityIDs)-1]
} else {
rsp.NextID = ""
}
return &rsp, nil
}