Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GetActivityLog() in the style of LoadPageChunk().
This lets us retrieve the list of recent changes to pages in a given notion database.
- Loading branch information
Showing
5 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package notionapi | ||
|
||
// Author represents the author of an Edit | ||
type Author struct { | ||
ID string `json:"id"` | ||
Table string `json:"table"` | ||
} | ||
|
||
// Edit represents a Notion edit (ie. a change made during an Activity) | ||
type Edit struct { | ||
SpaceID string `json:"space_id"` | ||
Authors []Author `json:"authors"` | ||
Timestamp int64 `json:"timestamp"` | ||
Type string `json:"type"` | ||
Version int `json:"version"` | ||
|
||
CommentData Comment `json:"comment_data"` | ||
CommentID string `json:"comment_id"` | ||
DiscussionID string `json:"discussion_id"` | ||
|
||
BlockID string `json:"block_id"` | ||
BlockData struct { | ||
BlockValue Block `json:"block_value"` | ||
} `json:"block_data"` | ||
NavigableBlockID string `json:"navigable_block_id"` | ||
|
||
CollectionID string `json:"collection_id"` | ||
CollectionRowID string `json:"collection_row_id"` | ||
} | ||
|
||
// Activity represents a Notion activity (ie. event) | ||
type Activity struct { | ||
Role string `json:"role"` | ||
|
||
ID string `json:"id"` | ||
SpaceID string `json:"space_id"` | ||
StartTime string `json:"start_time"` | ||
EndTime string `json:"end_time"` | ||
Type string `json:"type"` | ||
Version int `json:"version"` | ||
|
||
ParentID string `json:"parent_id"` | ||
ParentTable string `json:"parent_table"` | ||
|
||
// If the edit was to a block inside a regular page | ||
NavigableBlockID string `json:"navigable_block_id"` | ||
|
||
// If the edit was to a block inside a collection or collection row | ||
CollectionID string `json:"collection_id"` | ||
CollectionRowID string `json:"collection_row_id"` | ||
|
||
Edits []Edit `json:"edits"` | ||
|
||
Index int `json:"index"` | ||
Invalid bool `json:"invalid"` | ||
|
||
RawJSON map[string]interface{} `json:"-"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package notionapi | ||
|
||
// /api/v3/getActivityLog request | ||
type getActivityLogRequest struct { | ||
SpaceID string `json:"spaceId"` | ||
StartingAfterID string `json:"startingAfterId,omitempty"` | ||
Limit int `json:"limit"` | ||
} | ||
|
||
// LoadPageChunkResponse is a response to /api/v3/loadPageChunk 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. | ||
func (c *Client) GetActivityLog(spaceID string, startingAfterID string, limit int) (*GetActivityLogResponse, error) { | ||
apiURL := "/api/v3/getActivityLog" | ||
req := &getActivityLogRequest{ | ||
SpaceID: spaceID, | ||
StartingAfterID: startingAfterID, | ||
Limit: limit, | ||
} | ||
var rsp GetActivityLogResponse | ||
var err error | ||
if rsp.RawJSON, err = doNotionAPI(c, apiURL, req, &rsp); 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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters