show blocked accounts

This commit is contained in:
Dan Anglin 2024-05-21 13:07:21 +01:00
parent a6129d14f5
commit ae3163e212
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638
4 changed files with 53 additions and 0 deletions

View file

@ -40,6 +40,7 @@ const (
timelineResource = "timeline"
followersResource = "followers"
followingResource = "following"
blockedResource = "blocked"
)
type Executor interface {

View file

@ -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
}

View file

@ -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
}

24
internal/model/blocked.go Normal file
View file

@ -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
}