show blocked accounts
This commit is contained in:
parent
a6129d14f5
commit
ae3163e212
4 changed files with 53 additions and 0 deletions
|
@ -40,6 +40,7 @@ const (
|
||||||
timelineResource = "timeline"
|
timelineResource = "timeline"
|
||||||
followersResource = "followers"
|
followersResource = "followers"
|
||||||
followingResource = "following"
|
followingResource = "following"
|
||||||
|
blockedResource = "blocked"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Executor interface {
|
type Executor interface {
|
||||||
|
|
|
@ -59,6 +59,7 @@ func (c *showCommand) Execute() error {
|
||||||
listResource: c.showList,
|
listResource: c.showList,
|
||||||
followersResource: c.showFollowers,
|
followersResource: c.showFollowers,
|
||||||
followingResource: c.showFollowing,
|
followingResource: c.showFollowing,
|
||||||
|
blockedResource: c.showBlocked,
|
||||||
}
|
}
|
||||||
|
|
||||||
doFunc, ok := funcMap[c.resourceType]
|
doFunc, ok := funcMap[c.resourceType]
|
||||||
|
@ -299,3 +300,18 @@ func (c *showCommand) showFollowing(gts *client.Client) error {
|
||||||
|
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -131,3 +131,15 @@ func (g *Client) UnblockAccount(accountID string) error {
|
||||||
|
|
||||||
return nil
|
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
24
internal/model/blocked.go
Normal 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
|
||||||
|
}
|
Loading…
Reference in a new issue