Adds TagUnfollow

pull/182/head^2
Paul Waldo 2023-05-28 15:16:54 -04:00
parent 5aff7298c3
commit 4836b8899c
No known key found for this signature in database
GPG Key ID: 7CD5C6BB0D0BB7F4
5 changed files with 97 additions and 4 deletions

View File

@ -363,7 +363,7 @@ func (c *Client) GetMutes(ctx context.Context, pg *Pagination) ([]*Account, erro
return accounts, nil return accounts, nil
} }
// GetMutes returns the list of users muted by the current user. // GetFollowedTags returns the list of Hashtags followed by the user.
func (c *Client) GetFollowedTags(ctx context.Context, pg *Pagination) ([]*FollowedTag, error) { func (c *Client) GetFollowedTags(ctx context.Context, pg *Pagination) ([]*FollowedTag, error) {
var followedTags []*FollowedTag var followedTags []*FollowedTag
err := c.doAPI(ctx, http.MethodGet, "/api/v1/followed_tags", nil, &followedTags, pg) err := c.doAPI(ctx, http.MethodGet, "/api/v1/followed_tags", nil, &followedTags, pg)

View File

@ -698,6 +698,7 @@ func TestGetMutes(t *testing.T) {
} }
} }
func TestGetFollowedTags(t *testing.T) { func TestGetFollowedTags(t *testing.T) {
t.Parallel()
canErr := true canErr := true
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if canErr { if canErr {

View File

@ -729,7 +729,7 @@ func TestSearch(t *testing.T) {
t.Fatalf("Hashtags have %q entries, but %q", "3", len(ret.Hashtags)) t.Fatalf("Hashtags have %q entries, but %q", "3", len(ret.Hashtags))
} }
if ret.Hashtags[2].Name != "tag3" { if ret.Hashtags[2].Name != "tag3" {
t.Fatalf("Hashtags[2] should %q , but %q", "tag3", ret.Hashtags[2]) t.Fatalf("Hashtags[2] should %v , but %v", "tag3", ret.Hashtags[2])
} }
} }

17
tags.go 100644
View File

@ -0,0 +1,17 @@
package mastodon
import (
"context"
"fmt"
"net/http"
)
// TagUnfollow unfollows a hashtag.
func (c *Client) TagUnfollow(ctx context.Context, ID string) (*FollowedTag, error) {
var tag FollowedTag
err := c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/tags/%s/unfollow", ID), nil, &tag, nil)
if err != nil {
return nil, err
}
return &tag, nil
}

75
tags_test.go 100644
View File

@ -0,0 +1,75 @@
package mastodon
import (
"context"
"fmt"
"net/http"
"net/http/httptest"
"testing"
)
func TestTagUnfollow(t *testing.T) {
t.Parallel()
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, `{
"name": "Test",
"url": "http://mastodon.example/tags/test",
"history": [
{
"day": "1668556800",
"accounts": "0",
"uses": "0"
},
{
"day": "1668470400",
"accounts": "0",
"uses": "0"
},
{
"day": "1668384000",
"accounts": "0",
"uses": "0"
},
{
"day": "1668297600",
"accounts": "1",
"uses": "1"
},
{
"day": "1668211200",
"accounts": "0",
"uses": "0"
},
{
"day": "1668124800",
"accounts": "0",
"uses": "0"
},
{
"day": "1668038400",
"accounts": "0",
"uses": "0"
}
],
"following": false
}`)
}))
defer ts.Close()
client := NewClient(&Config{
Server: ts.URL,
ClientID: "foo",
ClientSecret: "bar",
AccessToken: "zoo",
})
tag, err := client.TagUnfollow(context.Background(), "Test")
if err != nil {
t.Fatalf("should not be fail: %v", err)
}
if tag.Name != "Test" {
t.Fatalf("want %q but %q", "Test", tag.Name)
}
if tag.Following {
t.Fatalf("want %t but %t", false, tag.Following)
}
}