Add GetMutes
parent
f181df17a0
commit
b0b43a8d7d
10
accounts.go
10
accounts.go
|
@ -252,3 +252,13 @@ func (c *Client) FollowRequestAuthorize(ctx context.Context, id int64) error {
|
||||||
func (c *Client) FollowRequestReject(ctx context.Context, id int64) error {
|
func (c *Client) FollowRequestReject(ctx context.Context, id int64) error {
|
||||||
return c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/follow_requests/%d/reject", id), nil, nil)
|
return c.doAPI(ctx, http.MethodPost, fmt.Sprintf("/api/v1/follow_requests/%d/reject", id), nil, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetMutes returns the list of users muted by the current user.
|
||||||
|
func (c *Client) GetMutes(ctx context.Context) ([]*Account, error) {
|
||||||
|
var accounts []*Account
|
||||||
|
err := c.doAPI(ctx, http.MethodGet, "/api/v1/mutes", nil, &accounts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return accounts, nil
|
||||||
|
}
|
||||||
|
|
|
@ -214,3 +214,41 @@ func TestFollowRequestReject(t *testing.T) {
|
||||||
t.Fatalf("should not be fail: %v", err)
|
t.Fatalf("should not be fail: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetMutes(t *testing.T) {
|
||||||
|
canErr := true
|
||||||
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if canErr {
|
||||||
|
canErr = false
|
||||||
|
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Fprintln(w, `[{"Username": "foo"}, {"Username": "bar"}]`)
|
||||||
|
return
|
||||||
|
}))
|
||||||
|
defer ts.Close()
|
||||||
|
|
||||||
|
client := NewClient(&Config{
|
||||||
|
Server: ts.URL,
|
||||||
|
ClientID: "foo",
|
||||||
|
ClientSecret: "bar",
|
||||||
|
AccessToken: "zoo",
|
||||||
|
})
|
||||||
|
_, err := client.GetMutes(context.Background())
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("should be fail: %v", err)
|
||||||
|
}
|
||||||
|
mutes, err := client.GetMutes(context.Background())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("should not be fail: %v", err)
|
||||||
|
}
|
||||||
|
if len(mutes) != 2 {
|
||||||
|
t.Fatalf("result should be two: %d", len(mutes))
|
||||||
|
}
|
||||||
|
if mutes[0].Username != "foo" {
|
||||||
|
t.Fatalf("want %q but %q", "foo", mutes[0].Username)
|
||||||
|
}
|
||||||
|
if mutes[1].Username != "bar" {
|
||||||
|
t.Fatalf("want %q but %q", "bar", mutes[1].Username)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue