34 lines
756 B
Go
34 lines
756 B
Go
package client
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
)
|
|
|
|
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,
|
|
}
|
|
|
|
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)
|
|
|
|
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 nil
|
|
}
|