From 4d30e643af6d16e837db9f15b9aee9cc454b48e8 Mon Sep 17 00:00:00 2001 From: Dan Anglin Date: Mon, 3 Jun 2024 04:34:12 +0100 Subject: [PATCH] checkpoint: get bookmarks --- internal/client/statuses.go | 17 +++++++++++++++++ internal/executor/const.go | 1 + internal/executor/show.go | 16 ++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/internal/client/statuses.go b/internal/client/statuses.go index 30a1086..7515399 100644 --- a/internal/client/statuses.go +++ b/internal/client/statuses.go @@ -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 +} diff --git a/internal/executor/const.go b/internal/executor/const.go index f126f1d..58263f7 100644 --- a/internal/executor/const.go +++ b/internal/executor/const.go @@ -44,4 +44,5 @@ const ( resourceNote = "note" resourceStatus = "status" resourceTimeline = "timeline" + resourceBookmarks = "bookmarks" ) diff --git a/internal/executor/show.go b/internal/executor/show.go index b53d11b..f72f129 100644 --- a/internal/executor/show.go +++ b/internal/executor/show.go @@ -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 +}