Add GetFavouritedBy
parent
3cb20b5925
commit
74901c994c
12
status.go
12
status.go
|
@ -85,7 +85,7 @@ func (c *Client) GetStatusCard(id string) (*Card, error) {
|
||||||
return &card, nil
|
return &card, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRebloggedBy returns the account of the user who re-blogged.
|
// GetRebloggedBy returns the account list of the user who reblogged the toot of id.
|
||||||
func (c *Client) GetRebloggedBy(id int64) ([]*Account, error) {
|
func (c *Client) GetRebloggedBy(id int64) ([]*Account, error) {
|
||||||
var accounts []*Account
|
var accounts []*Account
|
||||||
err := c.doAPI(http.MethodGet, fmt.Sprintf("/api/v1/statuses/%d/reblogged_by", id), nil, &accounts)
|
err := c.doAPI(http.MethodGet, fmt.Sprintf("/api/v1/statuses/%d/reblogged_by", id), nil, &accounts)
|
||||||
|
@ -95,6 +95,16 @@ func (c *Client) GetRebloggedBy(id int64) ([]*Account, error) {
|
||||||
return accounts, nil
|
return accounts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetFavouritedBy returns the account list of the user who liked the toot of id.
|
||||||
|
func (c *Client) GetFavouritedBy(id int64) ([]*Account, error) {
|
||||||
|
var accounts []*Account
|
||||||
|
err := c.doAPI(http.MethodGet, fmt.Sprintf("/api/v1/statuses/%d/favourited_by", id), nil, &accounts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return accounts, nil
|
||||||
|
}
|
||||||
|
|
||||||
// GetTimelineHome return statuses from home timeline.
|
// GetTimelineHome return statuses from home timeline.
|
||||||
func (c *Client) GetTimelineHome() ([]*Status, error) {
|
func (c *Client) GetTimelineHome() ([]*Status, error) {
|
||||||
var statuses []*Status
|
var statuses []*Status
|
||||||
|
|
|
@ -70,3 +70,39 @@ func TestGetRebloggedBy(t *testing.T) {
|
||||||
t.Fatalf("want %q but %q", "bar", rbs[0].Username)
|
t.Fatalf("want %q but %q", "bar", rbs[0].Username)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetFavouritedBy(t *testing.T) {
|
||||||
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if r.URL.Path != "/api/v1/statuses/1234567/favourited_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.GetFavouritedBy(123)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("should be fail: %v", err)
|
||||||
|
}
|
||||||
|
fbs, err := client.GetFavouritedBy(1234567)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("should not be fail: %v", err)
|
||||||
|
}
|
||||||
|
if len(fbs) != 2 {
|
||||||
|
t.Fatalf("result should be two: %d", len(fbs))
|
||||||
|
}
|
||||||
|
if fbs[0].Username != "foo" {
|
||||||
|
t.Fatalf("want %q but %q", "foo", fbs[0].Username)
|
||||||
|
}
|
||||||
|
if fbs[1].Username != "bar" {
|
||||||
|
t.Fatalf("want %q but %q", "bar", fbs[0].Username)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue