From 3cb20b5925e2f690190085f479d28d3ab2d169ff Mon Sep 17 00:00:00 2001 From: 178inaba <178inaba@users.noreply.github.com> Date: Sun, 16 Apr 2017 13:11:56 +0900 Subject: [PATCH] Add GetRebloggedBy --- status.go | 10 ++++++++++ status_test.go | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/status.go b/status.go index e9d817d..155a764 100644 --- a/status.go +++ b/status.go @@ -85,6 +85,16 @@ func (c *Client) GetStatusCard(id string) (*Card, error) { return &card, nil } +// GetRebloggedBy returns the account of the user who re-blogged. +func (c *Client) GetRebloggedBy(id int64) ([]*Account, error) { + var accounts []*Account + err := c.doAPI(http.MethodGet, fmt.Sprintf("/api/v1/statuses/%d/reblogged_by", id), nil, &accounts) + if err != nil { + return nil, err + } + return accounts, nil +} + // GetTimelineHome return statuses from home timeline. func (c *Client) GetTimelineHome() ([]*Status, error) { var statuses []*Status diff --git a/status_test.go b/status_test.go index 4add3cd..9c42e35 100644 --- a/status_test.go +++ b/status_test.go @@ -34,3 +34,39 @@ func TestGetFavourites(t *testing.T) { t.Fatalf("want %q but %q", "bar", favs[1].Content) } } + +func TestGetRebloggedBy(t *testing.T) { + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.URL.Path != "/api/v1/statuses/1234567/reblogged_by" { + 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", + }) + _, err := client.GetRebloggedBy(123) + if err == nil { + t.Fatalf("should be fail: %v", err) + } + rbs, err := client.GetRebloggedBy(1234567) + if err != nil { + t.Fatalf("should not be fail: %v", err) + } + if len(rbs) != 2 { + t.Fatalf("result should be two: %d", len(rbs)) + } + if rbs[0].Username != "foo" { + t.Fatalf("want %q but %q", "foo", rbs[0].Username) + } + if rbs[1].Username != "bar" { + t.Fatalf("want %q but %q", "bar", rbs[0].Username) + } +}