refactor: add more form types for the client
This commit is contained in:
parent
35575f32de
commit
b6b6f75715
4 changed files with 25 additions and 21 deletions
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue