diff --git a/cmd/enbas/main.go b/cmd/enbas/main.go index 5f6f0c4..792e024 100644 --- a/cmd/enbas/main.go +++ b/cmd/enbas/main.go @@ -40,6 +40,7 @@ const ( timelineResource = "timeline" followersResource = "followers" followingResource = "following" + blockedResource = "blocked" ) type Executor interface { diff --git a/cmd/enbas/show.go b/cmd/enbas/show.go index cd4d148..01dc729 100644 --- a/cmd/enbas/show.go +++ b/cmd/enbas/show.go @@ -59,6 +59,7 @@ func (c *showCommand) Execute() error { listResource: c.showList, followersResource: c.showFollowers, followingResource: c.showFollowing, + blockedResource: c.showBlocked, } doFunc, ok := funcMap[c.resourceType] @@ -299,3 +300,18 @@ func (c *showCommand) showFollowing(gts *client.Client) error { return nil } + +func (c *showCommand) showBlocked(gts *client.Client) error { + blocked, err := gts.GetBlockedAccounts(c.limit) + if err != nil { + return fmt.Errorf("unable to retrieve the list of blocked accounts; %w", err) + } + + if len(blocked) > 0 { + fmt.Println(blocked) + } else { + fmt.Println("You have no blocked accounts.") + } + + return nil +} diff --git a/internal/client/accounts.go b/internal/client/accounts.go index dc0f0cb..43411bc 100644 --- a/internal/client/accounts.go +++ b/internal/client/accounts.go @@ -131,3 +131,15 @@ func (g *Client) UnblockAccount(accountID string) error { return nil } + +func (g *Client) GetBlockedAccounts(limit int) (model.BlockedAccounts, error) { + url := g.Authentication.Instance + fmt.Sprintf("/api/v1/blocks?limit=%d", limit) + + var blocked model.BlockedAccounts + + if err := g.sendRequest(http.MethodGet, url, nil, &blocked); err != nil { + return nil, fmt.Errorf("received an error after sending the request to get the list of blocked accounts; %w", err) + } + + return blocked, nil +} diff --git a/internal/model/blocked.go b/internal/model/blocked.go new file mode 100644 index 0000000..7bebb70 --- /dev/null +++ b/internal/model/blocked.go @@ -0,0 +1,24 @@ +package model + +import ( + "fmt" + + "codeflow.dananglin.me.uk/apollo/enbas/internal/utilities" +) + +type BlockedAccounts []Account + +func (b BlockedAccounts) String() string { + output := "\n" + output += utilities.HeaderFormat("BLOCKED ACCOUNTS:") + + for i := range b { + output += fmt.Sprintf( + "\n • %s (%s)", + b[i].Acct, + b[i].ID, + ) + } + + return output +}