Compare commits

..

No commits in common. "3e47dea9ba9f07f6f30ac6354b9c12d5727b9c82" and "6e260266b139cb488936e37a3cf58a92e2207dff" have entirely different histories.

5 changed files with 23 additions and 111 deletions

View file

@ -13,13 +13,9 @@ import (
"codeflow.dananglin.me.uk/apollo/enbas/internal/model" "codeflow.dananglin.me.uk/apollo/enbas/internal/model"
) )
const (
baseAccountsPath = "/api/v1/accounts"
baseFollowRequestsPath = "/api/v1/follow_requests"
)
func (g *Client) VerifyCredentials() (model.Account, error) { func (g *Client) VerifyCredentials() (model.Account, error) {
url := g.Authentication.Instance + baseAccountsPath + "/verify_credentials" path := "/api/v1/accounts/verify_credentials"
url := g.Authentication.Instance + path
var account model.Account var account model.Account
@ -31,7 +27,8 @@ func (g *Client) VerifyCredentials() (model.Account, error) {
} }
func (g *Client) GetAccount(accountURI string) (model.Account, error) { func (g *Client) GetAccount(accountURI string) (model.Account, error) {
url := g.Authentication.Instance + baseAccountsPath + "/lookup?acct=" + accountURI path := "/api/v1/accounts/lookup?acct=" + accountURI
url := g.Authentication.Instance + path
var account model.Account var account model.Account
@ -43,7 +40,8 @@ func (g *Client) GetAccount(accountURI string) (model.Account, error) {
} }
func (g *Client) GetAccountRelationship(accountID string) (*model.AccountRelationship, error) { func (g *Client) GetAccountRelationship(accountID string) (*model.AccountRelationship, error) {
url := g.Authentication.Instance + baseAccountsPath + "/relationships?id=" + accountID path := "/api/v1/accounts/relationships?id=" + accountID
url := g.Authentication.Instance + path
var relationships []model.AccountRelationship var relationships []model.AccountRelationship
@ -77,7 +75,7 @@ func (g *Client) FollowAccount(form FollowAccountForm) error {
} }
requestBody := bytes.NewBuffer(data) requestBody := bytes.NewBuffer(data)
url := g.Authentication.Instance + baseAccountsPath + "/" + form.AccountID + "/follow" url := g.Authentication.Instance + fmt.Sprintf("/api/v1/accounts/%s/follow", form.AccountID)
if err := g.sendRequest(http.MethodPost, url, requestBody, nil); err != nil { if err := g.sendRequest(http.MethodPost, url, requestBody, nil); err != nil {
return fmt.Errorf("received an error after sending the follow request: %w", err) return fmt.Errorf("received an error after sending the follow request: %w", err)
@ -87,7 +85,7 @@ func (g *Client) FollowAccount(form FollowAccountForm) error {
} }
func (g *Client) UnfollowAccount(accountID string) error { func (g *Client) UnfollowAccount(accountID string) error {
url := g.Authentication.Instance + baseAccountsPath + "/" + accountID + "/unfollow" url := g.Authentication.Instance + fmt.Sprintf("/api/v1/accounts/%s/unfollow", accountID)
if err := g.sendRequest(http.MethodPost, url, nil, nil); err != nil { if err := g.sendRequest(http.MethodPost, url, nil, nil); err != nil {
return fmt.Errorf("received an error after sending the request to unfollow the account: %w", err) return fmt.Errorf("received an error after sending the request to unfollow the account: %w", err)
@ -97,7 +95,7 @@ func (g *Client) UnfollowAccount(accountID string) error {
} }
func (g *Client) GetFollowers(accountID string, limit int) (model.AccountList, error) { func (g *Client) GetFollowers(accountID string, limit int) (model.AccountList, error) {
url := g.Authentication.Instance + fmt.Sprintf("%s/%s/followers?limit=%d", baseAccountsPath, accountID, limit) url := g.Authentication.Instance + fmt.Sprintf("/api/v1/accounts/%s/followers?limit=%d", accountID, limit)
accounts := make([]model.Account, limit) accounts := make([]model.Account, limit)
@ -114,7 +112,7 @@ func (g *Client) GetFollowers(accountID string, limit int) (model.AccountList, e
} }
func (g *Client) GetFollowing(accountID string, limit int) (model.AccountList, error) { func (g *Client) GetFollowing(accountID string, limit int) (model.AccountList, error) {
url := g.Authentication.Instance + fmt.Sprintf("%s/%s/following?limit=%d", baseAccountsPath, accountID, limit) url := g.Authentication.Instance + fmt.Sprintf("/api/v1/accounts/%s/following?limit=%d", accountID, limit)
accounts := make([]model.Account, limit) accounts := make([]model.Account, limit)
@ -131,7 +129,7 @@ func (g *Client) GetFollowing(accountID string, limit int) (model.AccountList, e
} }
func (g *Client) BlockAccount(accountID string) error { func (g *Client) BlockAccount(accountID string) error {
url := g.Authentication.Instance + baseAccountsPath + "/" + accountID + "/block" url := g.Authentication.Instance + fmt.Sprintf("/api/v1/accounts/%s/block", accountID)
if err := g.sendRequest(http.MethodPost, url, nil, nil); err != nil { if err := g.sendRequest(http.MethodPost, url, nil, nil); err != nil {
return fmt.Errorf("received an error after sending the request to block the account: %w", err) return fmt.Errorf("received an error after sending the request to block the account: %w", err)
@ -141,7 +139,7 @@ func (g *Client) BlockAccount(accountID string) error {
} }
func (g *Client) UnblockAccount(accountID string) error { func (g *Client) UnblockAccount(accountID string) error {
url := g.Authentication.Instance + baseAccountsPath + "/" + accountID + "/unblock" url := g.Authentication.Instance + fmt.Sprintf("/api/v1/accounts/%s/unblock", accountID)
if err := g.sendRequest(http.MethodPost, url, nil, nil); err != nil { if err := g.sendRequest(http.MethodPost, url, nil, nil); err != nil {
return fmt.Errorf("received an error after sending the request to unblock the account: %w", err) return fmt.Errorf("received an error after sending the request to unblock the account: %w", err)
@ -180,7 +178,7 @@ func (g *Client) SetPrivateNote(accountID, note string) error {
} }
requestBody := bytes.NewBuffer(data) requestBody := bytes.NewBuffer(data)
url := g.Authentication.Instance + baseAccountsPath + "/" + accountID + "/note" url := g.Authentication.Instance + fmt.Sprintf("/api/v1/accounts/%s/note", accountID)
if err := g.sendRequest(http.MethodPost, url, requestBody, nil); err != nil { if err := g.sendRequest(http.MethodPost, url, requestBody, nil); err != nil {
return fmt.Errorf("received an error after sending the request to set the private note: %w", err) return fmt.Errorf("received an error after sending the request to set the private note: %w", err)
@ -190,7 +188,7 @@ func (g *Client) SetPrivateNote(accountID, note string) error {
} }
func (g *Client) GetFollowRequests(limit int) (model.AccountList, error) { func (g *Client) GetFollowRequests(limit int) (model.AccountList, error) {
url := g.Authentication.Instance + fmt.Sprintf("%s?limit=%d", baseFollowRequestsPath, limit) url := g.Authentication.Instance + fmt.Sprintf("/api/v1/follow_requests?limit=%d", limit)
var accounts []model.Account var accounts []model.Account
@ -207,7 +205,7 @@ func (g *Client) GetFollowRequests(limit int) (model.AccountList, error) {
} }
func (g *Client) AcceptFollowRequest(accountID string) error { func (g *Client) AcceptFollowRequest(accountID string) error {
url := g.Authentication.Instance + baseFollowRequestsPath + "/" + accountID + "/authorize" url := g.Authentication.Instance + "/api/v1/follow_requests/" + accountID + "/authorize"
if err := g.sendRequest(http.MethodPost, url, nil, nil); err != nil { if err := g.sendRequest(http.MethodPost, url, nil, nil); err != nil {
return fmt.Errorf("received an error after sending the request to accept the follow request: %w", err) return fmt.Errorf("received an error after sending the request to accept the follow request: %w", err)
@ -217,7 +215,7 @@ func (g *Client) AcceptFollowRequest(accountID string) error {
} }
func (g *Client) RejectFollowRequest(accountID string) error { func (g *Client) RejectFollowRequest(accountID string) error {
url := g.Authentication.Instance + baseFollowRequestsPath + "/" + accountID + "/reject" url := g.Authentication.Instance + "/api/v1/follow_requests/" + accountID + "/reject"
if err := g.sendRequest(http.MethodPost, url, nil, nil); err != nil { if err := g.sendRequest(http.MethodPost, url, nil, nil); err != nil {
return fmt.Errorf("received an error after sending the request to reject the follow request: %w", err) return fmt.Errorf("received an error after sending the request to reject the follow request: %w", err)
@ -255,7 +253,7 @@ func (g *Client) MuteAccount(accountID string, form MuteAccountForm) error {
} }
requestBody := bytes.NewBuffer(data) requestBody := bytes.NewBuffer(data)
url := g.Authentication.Instance + baseAccountsPath + "/" + accountID + "/mute" url := g.Authentication.Instance + "/api/v1/accounts/" + accountID + "/mute"
if err := g.sendRequest(http.MethodPost, url, requestBody, nil); err != nil { if err := g.sendRequest(http.MethodPost, url, requestBody, nil); err != nil {
return fmt.Errorf("received an error after sending the request to mute the account: %w", err) return fmt.Errorf("received an error after sending the request to mute the account: %w", err)
@ -265,7 +263,7 @@ func (g *Client) MuteAccount(accountID string, form MuteAccountForm) error {
} }
func (g *Client) UnmuteAccount(accountID string) error { func (g *Client) UnmuteAccount(accountID string) error {
url := g.Authentication.Instance + baseAccountsPath + "/" + accountID + "/unmute" url := g.Authentication.Instance + "/api/v1/accounts/" + accountID + "/unmute"
if err := g.sendRequest(http.MethodPost, url, nil, nil); err != nil { if err := g.sendRequest(http.MethodPost, url, nil, nil); err != nil {
return fmt.Errorf("received an error after sending the request to unmute the account: %w", err) return fmt.Errorf("received an error after sending the request to unmute the account: %w", err)
@ -273,40 +271,3 @@ func (g *Client) UnmuteAccount(accountID string) error {
return nil return nil
} }
type GetAccountStatusesForm struct {
AccountID string
Limit int
ExcludeReplies bool
ExcludeReblogs bool
Pinned bool
OnlyMedia bool
OnlyPublic bool
}
func (g *Client) GetAccountStatuses(form GetAccountStatusesForm) (*model.StatusList, error) {
path := baseAccountsPath + "/" + form.AccountID + "/statuses"
query := fmt.Sprintf(
"?limit=%d&exclude_replies=%t&exclude_reblogs=%t&pinned=%t&only_media=%t&only_public=%t",
form.Limit,
form.ExcludeReplies,
form.ExcludeReblogs,
form.Pinned,
form.OnlyMedia,
form.OnlyPublic,
)
url := g.Authentication.Instance + path + query
var statuses []model.Status
if err := g.sendRequest(http.MethodGet, url, nil, &statuses); err != nil {
return nil, fmt.Errorf("received an error after sending the request to get the account's statuses: %w", err)
}
statusList := model.StatusList{
Name: "STATUSES:",
Statuses: statuses,
}
return &statusList, nil
}

View file

@ -22,8 +22,6 @@ const (
flagEnableLikes = "enable-likes" flagEnableLikes = "enable-likes"
flagEnableReplies = "enable-replies" flagEnableReplies = "enable-replies"
flagEnableReposts = "enable-reposts" flagEnableReposts = "enable-reposts"
flagExcludeBoosts = "exclude-boosts"
flagExcludeReplies = "exclude-replies"
flagFrom = "from" flagFrom = "from"
flagFromFile = "from-file" flagFromFile = "from-file"
flagFull = "full" flagFull = "full"
@ -38,9 +36,6 @@ const (
flagMuteDuration = "mute-duration" flagMuteDuration = "mute-duration"
flagMuteNotifications = "mute-notifications" flagMuteNotifications = "mute-notifications"
flagNotify = "notify" flagNotify = "notify"
flagOnlyMedia = "only-media"
flagOnlyPinned = "only-pinned"
flagOnlyPublic = "only-public"
flagPollAllowsMultipleChoices = "poll-allows-multiple-choices" flagPollAllowsMultipleChoices = "poll-allows-multiple-choices"
flagPollExpiresIn = "poll-expires-in" flagPollExpiresIn = "poll-expires-in"
flagPollHidesVoteCounts = "poll-hides-vote-counts" flagPollHidesVoteCounts = "poll-hides-vote-counts"
@ -50,7 +45,6 @@ const (
flagSkipRelationship = "skip-relationship" flagSkipRelationship = "skip-relationship"
flagShowPreferences = "show-preferences" flagShowPreferences = "show-preferences"
flagShowReposts = "show-reposts" flagShowReposts = "show-reposts"
flagShowStatuses = "show-statuses"
flagSpoilerText = "spoiler-text" flagSpoilerText = "spoiler-text"
flagStatusID = "status-id" flagStatusID = "status-id"
flagTag = "tag" flagTag = "tag"

View file

@ -23,15 +23,9 @@ type ShowExecutor struct {
printer *printer.Printer printer *printer.Printer
config *config.Config config *config.Config
myAccount bool myAccount bool
excludeBoosts bool
excludeReplies bool
onlyMedia bool
onlyPinned bool
onlyPublic bool
showInBrowser bool
showUserPreferences bool
showStatuses bool
skipAccountRelationship bool skipAccountRelationship bool
showUserPreferences bool
showInBrowser bool
resourceType string resourceType string
accountName string accountName string
statusID string statusID string
@ -56,12 +50,6 @@ func NewShowExecutor(printer *printer.Printer, config *config.Config, name, summ
showExe.BoolVar(&showExe.skipAccountRelationship, flagSkipRelationship, false, "Set to true to skip showing your relationship to the specified account") showExe.BoolVar(&showExe.skipAccountRelationship, flagSkipRelationship, false, "Set to true to skip showing your relationship to the specified account")
showExe.BoolVar(&showExe.showUserPreferences, flagShowPreferences, false, "Show your preferences") showExe.BoolVar(&showExe.showUserPreferences, flagShowPreferences, false, "Show your preferences")
showExe.BoolVar(&showExe.showInBrowser, flagBrowser, false, "Set to true to view in the browser") showExe.BoolVar(&showExe.showInBrowser, flagBrowser, false, "Set to true to view in the browser")
showExe.BoolVar(&showExe.showStatuses, flagShowStatuses, false, "Set to true to view the statuses created from the specified account")
showExe.BoolVar(&showExe.excludeReplies, flagExcludeReplies, false, "Set to true to exclude statuses that are a reply to another status")
showExe.BoolVar(&showExe.excludeBoosts, flagExcludeBoosts, false, "Set to true to exclude statuses that are boosts of another status")
showExe.BoolVar(&showExe.onlyPinned, flagOnlyPinned, false, "Set to true to show only the account's pinned statuses")
showExe.BoolVar(&showExe.onlyMedia, flagOnlyMedia, false, "Set to true to show only the statuses with media attachments")
showExe.BoolVar(&showExe.onlyPublic, flagOnlyPublic, false, "Set to true to show only the account's public posts")
showExe.StringVar(&showExe.resourceType, flagType, "", "Specify the type of resource to display") showExe.StringVar(&showExe.resourceType, flagType, "", "Specify the type of resource to display")
showExe.StringVar(&showExe.accountName, flagAccountName, "", "Specify the account name in full (username@domain)") showExe.StringVar(&showExe.accountName, flagAccountName, "", "Specify the account name in full (username@domain)")
showExe.StringVar(&showExe.statusID, flagStatusID, "", "Specify the ID of the status to display") showExe.StringVar(&showExe.statusID, flagStatusID, "", "Specify the ID of the status to display")
@ -159,7 +147,6 @@ func (s *ShowExecutor) showAccount(gtsClient *client.Client) error {
var ( var (
relationship *model.AccountRelationship relationship *model.AccountRelationship
preferences *model.Preferences preferences *model.Preferences
statuses *model.StatusList
) )
if !s.myAccount && !s.skipAccountRelationship { if !s.myAccount && !s.skipAccountRelationship {
@ -176,24 +163,7 @@ func (s *ShowExecutor) showAccount(gtsClient *client.Client) error {
} }
} }
if s.showStatuses { s.printer.PrintAccount(account, relationship, preferences)
form := client.GetAccountStatusesForm{
AccountID: account.ID,
Limit: s.limit,
ExcludeReplies: s.excludeReplies,
ExcludeReblogs: s.excludeBoosts,
Pinned: s.onlyPinned,
OnlyMedia: s.onlyMedia,
OnlyPublic: s.onlyPublic,
}
statuses, err = gtsClient.GetAccountStatuses(form)
if err != nil {
return fmt.Errorf("unable to retrieve the account's statuses: %w", err)
}
}
s.printer.PrintAccount(account, relationship, preferences, statuses)
return nil return nil
} }

View file

@ -11,12 +11,7 @@ import (
"codeflow.dananglin.me.uk/apollo/enbas/internal/model" "codeflow.dananglin.me.uk/apollo/enbas/internal/model"
) )
func (p Printer) PrintAccount( func (p Printer) PrintAccount(account model.Account, relationship *model.AccountRelationship, preferences *model.Preferences) {
account model.Account,
relationship *model.AccountRelationship,
preferences *model.Preferences,
statuses *model.StatusList,
) {
var builder strings.Builder var builder strings.Builder
builder.WriteString("\n" + p.fullDisplayNameFormat(account.DisplayName, account.Acct)) builder.WriteString("\n" + p.fullDisplayNameFormat(account.DisplayName, account.Acct))
@ -50,10 +45,6 @@ func (p Printer) PrintAccount(
builder.WriteString(p.userPreferences(preferences)) builder.WriteString(p.userPreferences(preferences))
} }
if statuses != nil {
builder.WriteString("\n\n" + p.statusList(*statuses))
}
builder.WriteString("\n\n") builder.WriteString("\n\n")
p.print(builder.String()) p.print(builder.String())

View file

@ -77,10 +77,6 @@ func (p Printer) PrintStatus(status model.Status) {
} }
func (p Printer) PrintStatusList(list model.StatusList) { func (p Printer) PrintStatusList(list model.StatusList) {
p.print(p.statusList(list))
}
func (p Printer) statusList(list model.StatusList) string {
var builder strings.Builder var builder strings.Builder
builder.WriteString(p.headerFormat(list.Name) + "\n") builder.WriteString(p.headerFormat(list.Name) + "\n")
@ -174,5 +170,5 @@ func (p Printer) statusList(list model.StatusList) string {
builder.WriteString("\n" + p.statusSeparator + "\n") builder.WriteString("\n" + p.statusSeparator + "\n")
} }
return builder.String() p.print(builder.String())
} }