add TagInfo, TagFollow, TagUnfollow and TagsFollowed

This commit is contained in:
Rasmus Lindroth 2022-12-30 11:55:06 +01:00
parent f59d7e630f
commit 481c724c6d
3 changed files with 331 additions and 7 deletions

55
tags.go Normal file
View file

@ -0,0 +1,55 @@
package mastodon
import (
"context"
"fmt"
"net/http"
"net/url"
)
// Tag hold information for tag.
type Tag struct {
Name string `json:"name"`
URL string `json:"url"`
History []History `json:"history"`
Following interface{} `json:"following"`
}
// TagInfo gets statistics and information about a tag
func (c *Client) TagInfo(ctx context.Context, tag string) (*Tag, error) {
var hashtag Tag
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/tags/%s", url.PathEscape(string(tag))), nil, &hashtag, nil)
if err != nil {
return nil, err
}
return &hashtag, nil
}
// TagFollow lets you follow a hashtag
func (c *Client) TagFollow(ctx context.Context, tag string) (*Tag, error) {
var hashtag Tag
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/tags/%s/follow", url.PathEscape(string(tag))), nil, &hashtag, nil)
if err != nil {
return nil, err
}
return &hashtag, nil
}
// TagUnfollow lets you unfollow a hashtag
func (c *Client) TagUnfollow(ctx context.Context, tag string) (*Tag, error) {
var hashtag Tag
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/tags/%s/unfollow", url.PathEscape(string(tag))), nil, &hashtag, nil)
if err != nil {
return nil, err
}
return &hashtag, nil
}
func (c *Client) TagsFollowed(ctx context.Context, pg *Pagination) ([]*Tag, error) {
var hashtags []*Tag
err := c.doAPI(ctx, http.MethodGet, "/api/v1/followed_tags", nil, &hashtags, pg)
if err != nil {
return nil, err
}
return hashtags, nil
}