Dan Anglin
1a95384ba0
This commit adds the ability to follow and unfollow (remote) accounts and to display a list of followers and followees for a specified account. Changes: - Added a command to follow an account. - Added a command to unfollow an account. - When displaying an account you can optionally view the relationship between that account and yourself. - Added a command to view accounts that are following a specified account. - Added a command to view accounts that are followed by a specified account.
51 lines
1.6 KiB
Go
51 lines
1.6 KiB
Go
package client
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/model"
|
|
)
|
|
|
|
func (g *Client) VerifyCredentials() (model.Account, error) {
|
|
path := "/api/v1/accounts/verify_credentials"
|
|
url := g.Authentication.Instance + path
|
|
|
|
var account model.Account
|
|
|
|
if err := g.sendRequest(http.MethodGet, url, nil, &account); err != nil {
|
|
return model.Account{}, fmt.Errorf("received an error after sending the request to verify the credentials; %w", err)
|
|
}
|
|
|
|
return account, nil
|
|
}
|
|
|
|
func (g *Client) GetAccount(accountURI string) (model.Account, error) {
|
|
path := "/api/v1/accounts/lookup?acct=" + accountURI
|
|
url := g.Authentication.Instance + path
|
|
|
|
var account model.Account
|
|
|
|
if err := g.sendRequest(http.MethodGet, url, nil, &account); err != nil {
|
|
return model.Account{}, fmt.Errorf("received an error after sending the request to get the account information; %w", err)
|
|
}
|
|
|
|
return account, nil
|
|
}
|
|
|
|
func (g *Client) GetAccountRelationship(accountID string) (model.AccountRelationship, error) {
|
|
path := "/api/v1/accounts/relationships?id=" + accountID
|
|
url := g.Authentication.Instance + path
|
|
|
|
var relationships []model.AccountRelationship
|
|
|
|
if err := g.sendRequest(http.MethodGet, url, nil, &relationships); err != nil {
|
|
return model.AccountRelationship{}, fmt.Errorf("received an error after sending the request to get the account relationship; %w", err)
|
|
}
|
|
|
|
if len(relationships) != 1 {
|
|
return model.AccountRelationship{}, fmt.Errorf("unexpected number of account relationships returned; want 1, got %d", len(relationships))
|
|
}
|
|
|
|
return relationships[0], nil
|
|
}
|