return err
}
-// Get returns the details of account specified by ID.
-func (a *Account) Get(
+// GetAccount returns the details of account specified by ID.
+func GetAccount(
ID string, host string, token Token) (account Account, err error) {
id := url.PathEscape(ID)
return account, err
}
+// Get returns the currently logged in account.
+func (a *Account) Get(host string, token Token) (account Account, err error) {
+ return GetAccount(a.ID, host, token)
+}
+
// GetFollowers returns a list of all accounts following the logged in user
func (a *Account) GetFollowers(
host string, token Token) (followers []Account, err error) {
func (a *Account) GetFollowing(
host string, token Token) (following []Account, err error) {
- client := &http.Client{}
-
id := url.PathEscape(a.ID)
path, err := url.JoinPath("api/v1/accounts", id, "following")
if err != nil {
}
u.Scheme = "https"
- req, err := http.NewRequest("GET", u.String(), nil)
- if err != nil {
- return following, err
- }
- req.Header.Add("Authorization", "Bearer "+token.AccessToken)
-
- resp, err := client.Do(req)
- if err != nil {
- return following, err
- }
- if resp.StatusCode != 200 {
- err = errors.New(resp.Status)
- return following, err
- }
- defer resp.Body.Close()
-
- body, err := io.ReadAll(resp.Body)
+ body, err := Get(u, host, token)
if err != nil {
return following, err
}
--- /dev/null
+package mastodon
+
+import (
+ "encoding/json"
+ "net/url"
+)
+
+// List represents a list of some users that the authenticated user follows.
+type List struct {
+ ID string `json:"id"`
+ Title string `json:"title"`
+ RepliesPolicy string `json:"replies_policy"`
+}
+
+// GetList returns a list specified by id.
+func GetList(ID string, host string, token Token) (list List, err error) {
+ id := url.PathEscape(ID)
+ path, err := url.JoinPath("api/v1/lists", id)
+ if err != nil {
+ return
+ }
+
+ u := url.URL{
+ Host: host,
+ Path: path,
+ }
+ u.Scheme = "https"
+
+ body, err := Get(u, host, token)
+ if err != nil {
+ return
+ }
+
+ err = json.Unmarshal(body, &list)
+ if err != nil {
+ return
+ }
+
+ return list, err
+}
+
+// GetAccounts returns the accounts associated with a list.
+func (l *List) GetAccounts(host string, token Token) (accounts []Account, err error) {
+ id := url.PathEscape(l.ID)
+ path, err := url.JoinPath("api/v1/lists", id, "accounts")
+ if err != nil {
+ return
+ }
+
+ u := url.URL{
+ Host: host,
+ Path: path,
+ }
+ u.Scheme = "https"
+
+ body, err := Get(u, host, token)
+ if err != nil {
+ return
+ }
+
+ err = json.Unmarshal(body, &accounts)
+ if err != nil {
+ return
+ }
+
+ return accounts, err
+}