diff --git a/accounts.go b/accounts.go index 751e3d3..3de8000 100644 --- a/accounts.go +++ b/accounts.go @@ -66,6 +66,16 @@ func (c *Client) GetAccountFollowing(id int64) ([]*Account, error) { return accounts, nil } +// GetBlocks return block list. +func (c *Client) GetBlocks() ([]*Account, error) { + var accounts []*Account + err := c.doAPI(http.MethodGet, "/api/v1/blocks", nil, &accounts) + if err != nil { + return nil, err + } + return accounts, nil +} + // Relationship hold information for relation-ship to the account. type Relationship struct { ID int64 `json:"id"` @@ -177,12 +187,9 @@ func (c *Client) FollowRemoteUser(uri string) (*Account, error) { } // GetFollowRequests return follow-requests. -func (c *Client) GetFollowRequests(uri string) ([]*Account, error) { - params := url.Values{} - params.Set("uri", uri) - +func (c *Client) GetFollowRequests() ([]*Account, error) { var accounts []*Account - err := c.doAPI(http.MethodGet, "/api/v1/follow_requests", params, &accounts) + err := c.doAPI(http.MethodGet, "/api/v1/follow_requests", nil, &accounts) if err != nil { return nil, err } diff --git a/accounts_test.go b/accounts_test.go index 4ee715b..0dc8a82 100644 --- a/accounts_test.go +++ b/accounts_test.go @@ -7,6 +7,34 @@ import ( "testing" ) +func TestGetBlocks(t *testing.T) { + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + fmt.Fprintln(w, `[{"Username": "foo"}, {"Username": "bar"}]`) + return + })) + defer ts.Close() + + client := NewClient(&Config{ + Server: ts.URL, + ClientID: "foo", + ClientSecret: "bar", + AccessToken: "zoo", + }) + bl, err := client.GetBlocks() + if err != nil { + t.Fatalf("should not be fail: %v", err) + } + if len(bl) != 2 { + t.Fatalf("result should be two: %d", len(bl)) + } + if bl[0].Username != "foo" { + t.Fatalf("want %q but %q", "foo", bl[0].Username) + } + if bl[1].Username != "bar" { + t.Fatalf("want %q but %q", "bar", bl[0].Username) + } +} + func TestAccountFollow(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.URL.Path != "/api/v1/accounts/1234567/follow" { @@ -26,7 +54,7 @@ func TestAccountFollow(t *testing.T) { }) rel, err := client.AccountFollow(123) if err == nil { - t.Fatalf("should be fail: %v", err) + t.Fatalf("should be fail: %v", err) } rel, err = client.AccountFollow(1234567) if err != nil { @@ -72,3 +100,31 @@ func TestAccountUnfollow(t *testing.T) { t.Fatalf("want %t but %t", false, rel.Following) } } + +func TestGetFollowRequests(t *testing.T) { + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + fmt.Fprintln(w, `[{"Username": "foo"}, {"Username": "bar"}]`) + return + })) + defer ts.Close() + + client := NewClient(&Config{ + Server: ts.URL, + ClientID: "foo", + ClientSecret: "bar", + AccessToken: "zoo", + }) + fReqs, err := client.GetFollowRequests() + if err != nil { + t.Fatalf("should not be fail: %v", err) + } + if len(fReqs) != 2 { + t.Fatalf("result should be two: %d", len(fReqs)) + } + if fReqs[0].Username != "foo" { + t.Fatalf("want %q but %q", "foo", fReqs[0].Username) + } + if fReqs[1].Username != "bar" { + t.Fatalf("want %q but %q", "bar", fReqs[0].Username) + } +} diff --git a/status.go b/status.go index b597fe5..56f5fe1 100644 --- a/status.go +++ b/status.go @@ -45,6 +45,16 @@ type Card struct { Image string `json:"image"` } +// GetFavourites return the favorite list of the current user. +func (c *Client) GetFavourites() ([]*Status, error) { + var statuses []*Status + err := c.doAPI(http.MethodGet, "/api/v1/favourites", nil, &statuses) + if err != nil { + return nil, err + } + return statuses, nil +} + // GetStatus return status specified by id. func (c *Client) GetStatus(id string) (*Status, error) { var status Status diff --git a/status_test.go b/status_test.go new file mode 100644 index 0000000..4add3cd --- /dev/null +++ b/status_test.go @@ -0,0 +1,36 @@ +package mastodon + +import ( + "fmt" + "net/http" + "net/http/httptest" + "testing" +) + +func TestGetFavourites(t *testing.T) { + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + fmt.Fprintln(w, `[{"Content": "foo"}, {"Content": "bar"}]`) + return + })) + defer ts.Close() + + client := NewClient(&Config{ + Server: ts.URL, + ClientID: "foo", + ClientSecret: "bar", + AccessToken: "zoo", + }) + favs, err := client.GetFavourites() + if err != nil { + t.Fatalf("should not be fail: %v", err) + } + if len(favs) != 2 { + t.Fatalf("result should be two: %d", len(favs)) + } + if favs[0].Content != "foo" { + t.Fatalf("want %q but %q", "foo", favs[0].Content) + } + if favs[1].Content != "bar" { + t.Fatalf("want %q but %q", "bar", favs[1].Content) + } +}