diff --git a/internal/client/accounts.go b/internal/client/accounts.go index 0513eb2..e32e103 100644 --- a/internal/client/accounts.go +++ b/internal/client/accounts.go @@ -52,24 +52,20 @@ func (g *Client) GetAccountRelationship(accountID string) (model.AccountRelation return relationships[0], nil } -func (g *Client) FollowAccount(accountID string, reblogs, notify bool) error { - form := struct { - ID string `json:"id"` - Reblogs bool `json:"reblogs"` - Notify bool `json:"notify"` - }{ - ID: accountID, - Reblogs: reblogs, - Notify: notify, - } +type FollowAccountForm struct { + AccountID string `json:"id"` + ShowReposts bool `json:"reblogs"` + Notify bool `json:"notify"` +} +func (g *Client) FollowAccount(form FollowAccountForm) error { data, err := json.Marshal(form) if err != nil { return fmt.Errorf("unable to marshal the form; %w", err) } requestBody := bytes.NewBuffer(data) - url := g.Authentication.Instance + fmt.Sprintf("/api/v1/accounts/%s/follow", accountID) + url := g.Authentication.Instance + fmt.Sprintf("/api/v1/accounts/%s/follow", form.AccountID) if err := g.sendRequest(http.MethodPost, url, requestBody, nil); err != nil { return fmt.Errorf("received an error after sending the follow request; %w", err) diff --git a/internal/client/lists.go b/internal/client/lists.go index b1d022d..17fe5b8 100644 --- a/internal/client/lists.go +++ b/internal/client/lists.go @@ -43,15 +43,12 @@ func (g *Client) GetList(listID string) (model.List, error) { return list, nil } -func (g *Client) CreateList(title string, repliesPolicy model.ListRepliesPolicy) (model.List, error) { - form := struct { - Title string `json:"title"` - RepliesPolicy model.ListRepliesPolicy `json:"replies_policy"` - }{ - Title: title, - RepliesPolicy: repliesPolicy, - } +type CreateListForm struct { + Title string `json:"title"` + RepliesPolicy model.ListRepliesPolicy `json:"replies_policy"` +} +func (g *Client) CreateList(form CreateListForm) (model.List, error) { data, err := json.Marshal(form) if err != nil { return model.List{}, fmt.Errorf("unable to marshal the form; %w", err) diff --git a/internal/executor/create.go b/internal/executor/create.go index 23ca645..274fec6 100644 --- a/internal/executor/create.go +++ b/internal/executor/create.go @@ -86,7 +86,12 @@ func (c *CreateExecutor) createList(gtsClient *client.Client) error { return InvalidListRepliesPolicyError{Policy: c.listRepliesPolicy} } - list, err := gtsClient.CreateList(c.listTitle, parsedListRepliesPolicy) + form := client.CreateListForm{ + Title: c.listTitle, + RepliesPolicy: parsedListRepliesPolicy, + } + + list, err := gtsClient.CreateList(form) if err != nil { return fmt.Errorf("unable to create the list; %w", err) } diff --git a/internal/executor/follow.go b/internal/executor/follow.go index ee8291c..b837657 100644 --- a/internal/executor/follow.go +++ b/internal/executor/follow.go @@ -63,7 +63,13 @@ func (c *FollowExecutor) followAccount(gtsClient *client.Client) error { return c.unfollowAccount(gtsClient, accountID) } - if err := gtsClient.FollowAccount(accountID, c.showReposts, c.notify); err != nil { + form := client.FollowAccountForm{ + AccountID: accountID, + ShowReposts: c.showReposts, + Notify: c.notify, + } + + if err := gtsClient.FollowAccount(form); err != nil { return fmt.Errorf("unable to follow the account; %w", err) }