From 70efe09ff42f4f69cc72c017e24a94ae6ee37dcb Mon Sep 17 00:00:00 2001 From: 178inaba <178inaba@users.noreply.github.com> Date: Sat, 15 Apr 2017 02:23:17 +0900 Subject: [PATCH 1/8] Add GetBlocks --- accounts.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/accounts.go b/accounts.go index 751e3d3..4504758 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"` From dde3686355d4e2f1f6e189fc8bba3e7019b9b669 Mon Sep 17 00:00:00 2001 From: 178inaba <178inaba@users.noreply.github.com> Date: Sat, 15 Apr 2017 02:30:47 +0900 Subject: [PATCH 2/8] Add TestGetBlocks --- accounts_test.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/accounts_test.go b/accounts_test.go index 4ee715b..7c2dbe2 100644 --- a/accounts_test.go +++ b/accounts_test.go @@ -7,6 +7,38 @@ import ( "testing" ) +func TestGetBlocks(t *testing.T) { + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.URL.Path != "/api/v1/blocks" { + http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) + return + } + 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" { From 2338b8e97e6b25507173cdcb826dad76513c9102 Mon Sep 17 00:00:00 2001 From: 178inaba <178inaba@users.noreply.github.com> Date: Sat, 15 Apr 2017 02:31:22 +0900 Subject: [PATCH 3/8] Minor fix --- accounts_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/accounts_test.go b/accounts_test.go index 7c2dbe2..3dec6b0 100644 --- a/accounts_test.go +++ b/accounts_test.go @@ -58,7 +58,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 { From 4eb784dd8159fe5ca1133ceed1ed3490ce8f090c Mon Sep 17 00:00:00 2001 From: 178inaba <178inaba@users.noreply.github.com> Date: Sat, 15 Apr 2017 03:28:50 +0900 Subject: [PATCH 4/8] Add GetFavourites --- status.go | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 From af2ce2c3b177e9f7e502cea07ce45f2206f463d4 Mon Sep 17 00:00:00 2001 From: 178inaba <178inaba@users.noreply.github.com> Date: Sat, 15 Apr 2017 03:40:06 +0900 Subject: [PATCH 5/8] Add TestGetFavourites --- status_test.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 status_test.go 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) + } +} From 280982f0342a735f91ebe30c38d5223389a865b6 Mon Sep 17 00:00:00 2001 From: 178inaba <178inaba@users.noreply.github.com> Date: Sat, 15 Apr 2017 04:04:34 +0900 Subject: [PATCH 6/8] Remove uri to GetFollowRequests --- accounts.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/accounts.go b/accounts.go index 4504758..3de8000 100644 --- a/accounts.go +++ b/accounts.go @@ -187,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 } From 920eb1ad5ad7c2de24b203ccb1d223c5c90cf860 Mon Sep 17 00:00:00 2001 From: 178inaba <178inaba@users.noreply.github.com> Date: Sat, 15 Apr 2017 04:08:43 +0900 Subject: [PATCH 7/8] Add TestGetFollowRequests --- accounts_test.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/accounts_test.go b/accounts_test.go index 3dec6b0..f68b31a 100644 --- a/accounts_test.go +++ b/accounts_test.go @@ -104,3 +104,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) + } +} From d61ce1c2415dd23bb77814b4e50273d823179d53 Mon Sep 17 00:00:00 2001 From: 178inaba <178inaba@users.noreply.github.com> Date: Sat, 15 Apr 2017 04:09:33 +0900 Subject: [PATCH 8/8] Fix test server to TestGetBlocks --- accounts_test.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/accounts_test.go b/accounts_test.go index f68b31a..0dc8a82 100644 --- a/accounts_test.go +++ b/accounts_test.go @@ -9,10 +9,6 @@ import ( func TestGetBlocks(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.URL.Path != "/api/v1/blocks" { - http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound) - return - } fmt.Fprintln(w, `[{"Username": "foo"}, {"Username": "bar"}]`) return }))