add support for pinned posts

pull/149/head
Rasmus Lindroth 2022-06-04 15:44:49 +02:00 committed by mattn
parent c6a292132e
commit b2204e0d6a
2 changed files with 50 additions and 0 deletions

View File

@ -139,6 +139,18 @@ func (c *Client) GetAccountStatuses(ctx context.Context, id ID, pg *Pagination)
return statuses, nil
}
// GetAccountPinnedStatuses return statuses pinned by specified accuont.
func (c *Client) GetAccountPinnedStatuses(ctx context.Context, id ID) ([]*Status, error) {
var statuses []*Status
params := url.Values{}
params.Set("pinned", "true")
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/accounts/%s/statuses", url.PathEscape(string(id))), params, &statuses, nil)
if err != nil {
return nil, err
}
return statuses, nil
}
// GetAccountFollowers return followers list.
func (c *Client) GetAccountFollowers(ctx context.Context, id ID, pg *Pagination) ([]*Account, error) {
var accounts []*Account

View File

@ -144,6 +144,44 @@ func TestGetAccountStatuses(t *testing.T) {
}
}
func TestGetAccountPinnedStatuses(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/api/v1/accounts/1234567/statuses" {
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
return
}
pinned := r.URL.Query().Get("pinned")
if pinned != "true" {
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
return
}
fmt.Fprintln(w, `[{"content": "foo"}, {"content": "bar"}]`)
return
}))
defer ts.Close()
client := NewClient(&Config{
Server: ts.URL,
ClientID: "foo",
ClientSecret: "bar",
AccessToken: "zoo",
})
_, err := client.GetAccountPinnedStatuses(context.Background(), "123")
if err == nil {
t.Fatalf("should be fail: %v", err)
}
ss, err := client.GetAccountPinnedStatuses(context.Background(), "1234567")
if err != nil {
t.Fatalf("should not be fail: %v", err)
}
if ss[0].Content != "foo" {
t.Fatalf("want %q but %q", "foo", ss[0].Content)
}
if ss[1].Content != "bar" {
t.Fatalf("want %q but %q", "bar", ss[1].Content)
}
}
func TestGetAccountFollowers(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/api/v1/accounts/1234567/followers" {