checkpoint: display followed accounts
This commit is contained in:
parent
c080568c2d
commit
031dd9a0b0
4 changed files with 53 additions and 2 deletions
|
@ -31,6 +31,7 @@ const (
|
||||||
statusResource = "status"
|
statusResource = "status"
|
||||||
timelineResource = "timeline"
|
timelineResource = "timeline"
|
||||||
followersResource = "followers"
|
followersResource = "followers"
|
||||||
|
followingResource = "following"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Executor interface {
|
type Executor interface {
|
||||||
|
|
|
@ -57,6 +57,7 @@ func (c *showCommand) Execute() error {
|
||||||
timelineResource: c.showTimeline,
|
timelineResource: c.showTimeline,
|
||||||
listResource: c.showList,
|
listResource: c.showList,
|
||||||
followersResource: c.showFollowers,
|
followersResource: c.showFollowers,
|
||||||
|
followingResource: c.showFollowing,
|
||||||
}
|
}
|
||||||
|
|
||||||
doFunc, ok := funcMap[c.resourceType]
|
doFunc, ok := funcMap[c.resourceType]
|
||||||
|
@ -197,6 +198,7 @@ func (c *showCommand) showList(gts *client.Client) error {
|
||||||
for i := range accounts {
|
for i := range accounts {
|
||||||
accountMap[accounts[i].ID] = accounts[i].Username
|
accountMap[accounts[i].ID] = accounts[i].Username
|
||||||
}
|
}
|
||||||
|
|
||||||
list.Accounts = accountMap
|
list.Accounts = accountMap
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,3 +243,22 @@ func (c *showCommand) showFollowers(gts *client.Client) error {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *showCommand) showFollowing(gts *client.Client) error {
|
||||||
|
if c.accountID == "" {
|
||||||
|
return flagNotSetError{flagText: accountIDFlag}
|
||||||
|
}
|
||||||
|
|
||||||
|
following, err := gts.GetFollowing(c.accountID, c.limit)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to retrieve the list of followed accounts; %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(following) > 0 {
|
||||||
|
fmt.Println(following)
|
||||||
|
} else {
|
||||||
|
fmt.Println("This account is not following anyone or the list is hidden.")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -51,8 +51,20 @@ func (g *Client) GetFollowers(accountID string, limit int) (model.Followers, err
|
||||||
var followers model.Followers
|
var followers model.Followers
|
||||||
|
|
||||||
if err := g.sendRequest(http.MethodGet, url, nil, &followers); err != nil {
|
if err := g.sendRequest(http.MethodGet, url, nil, &followers); err != nil {
|
||||||
return nil, fmt.Errorf("received an error after sending the request to get followers; %w", err)
|
return nil, fmt.Errorf("received an error after sending the request to get the list of followers; %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return followers, nil
|
return followers, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (g *Client) GetFollowing(accountID string, limit int) (model.Following, error) {
|
||||||
|
url := g.Authentication.Instance + fmt.Sprintf("/api/v1/accounts/%s/following?limit=%d", accountID, limit)
|
||||||
|
|
||||||
|
var following model.Following
|
||||||
|
|
||||||
|
if err := g.sendRequest(http.MethodGet, url, nil, &following); err != nil {
|
||||||
|
return nil, fmt.Errorf("received an error after sending the request to get the list of followed accounts; %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return following, nil
|
||||||
|
}
|
||||||
|
|
|
@ -10,7 +10,24 @@ type Followers []Account
|
||||||
|
|
||||||
func (f Followers) String() string {
|
func (f Followers) String() string {
|
||||||
output := "\n"
|
output := "\n"
|
||||||
output += utilities.HeaderFormat("FOLLOWERS:")
|
output += utilities.HeaderFormat("FOLLOWED BY:")
|
||||||
|
|
||||||
|
for i := range f {
|
||||||
|
output += fmt.Sprintf(
|
||||||
|
"\n • %s (%s)",
|
||||||
|
utilities.DisplayNameFormat(f[i].DisplayName),
|
||||||
|
f[i].Acct,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return output
|
||||||
|
}
|
||||||
|
|
||||||
|
type Following []Account
|
||||||
|
|
||||||
|
func (f Following) String() string {
|
||||||
|
output := "\n"
|
||||||
|
output += utilities.HeaderFormat("FOLLOWING:")
|
||||||
|
|
||||||
for i := range f {
|
for i := range f {
|
||||||
output += fmt.Sprintf(
|
output += fmt.Sprintf(
|
||||||
|
|
Loading…
Reference in a new issue