checkpoint: get bookmarks

This commit is contained in:
Dan Anglin 2024-06-03 04:34:12 +01:00
parent 674f277eba
commit 4d30e643af
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638
3 changed files with 34 additions and 0 deletions

View file

@ -62,3 +62,20 @@ func (g *Client) CreateStatus(form CreateStatusForm) (model.Status, error) {
return status, nil
}
func (g *Client) GetBookmarks(limit int) (model.StatusList, error) {
path := fmt.Sprintf("/api/v1/bookmarks?limit=%d", limit)
url := g.Authentication.Instance + path
bookmarks := model.StatusList{
Type: model.StatusListBookMarks,
Name: "BOOKMARKS",
Statuses: nil,
}
if err := g.sendRequest(http.MethodGet, url, nil, &bookmarks.Statuses); err != nil {
return bookmarks, fmt.Errorf("received an error after sending the request to get the bookmarks: %w", err)
}
return bookmarks, nil
}

View file

@ -44,4 +44,5 @@ const (
resourceNote = "note"
resourceStatus = "status"
resourceTimeline = "timeline"
resourceBookmarks = "bookmarks"
)

View file

@ -66,6 +66,7 @@ func (c *ShowExecutor) Execute() error {
resourceFollowers: c.showFollowers,
resourceFollowing: c.showFollowing,
resourceBlocked: c.showBlocked,
resourceBookmarks: c.showBookmarks,
}
doFunc, ok := funcMap[c.resourceType]
@ -313,3 +314,18 @@ func (c *ShowExecutor) showBlocked(gtsClient *client.Client) error {
return nil
}
func (c *ShowExecutor) showBookmarks(gtsClient *client.Client) error {
bookmarks, err := gtsClient.GetBookmarks(c.limit)
if err != nil {
return fmt.Errorf("unable to retrieve the list of bookmarks: %w", err)
}
if len(bookmarks.Statuses) > 0 {
utilities.Display(bookmarks, *c.topLevelFlags.NoColor)
} else {
fmt.Println("You have no bookmarks.")
}
return nil
}