Merge pull request #44 from 178inaba/public_timeline
Add GetTimelinePublic
This commit is contained in:
commit
d0fb60d3ec
17
status.go
17
status.go
|
@ -5,8 +5,8 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Status is struct to hold status.
|
||||
|
@ -157,6 +157,21 @@ func (c *Client) GetTimelineHome(ctx context.Context) ([]*Status, error) {
|
|||
return statuses, nil
|
||||
}
|
||||
|
||||
// GetTimelinePublic return statuses from public timeline.
|
||||
func (c *Client) GetTimelinePublic(ctx context.Context, isLocal bool) ([]*Status, error) {
|
||||
params := url.Values{}
|
||||
if isLocal {
|
||||
params.Set("local", "t")
|
||||
}
|
||||
|
||||
var statuses []*Status
|
||||
err := c.doAPI(ctx, http.MethodGet, "/api/v1/timelines/public", params, &statuses, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return statuses, nil
|
||||
}
|
||||
|
||||
// GetTimelineHashtag return statuses from tagged timeline.
|
||||
func (c *Client) GetTimelineHashtag(ctx context.Context, tag string) ([]*Status, error) {
|
||||
var statuses []*Status
|
||||
|
|
|
@ -327,6 +327,36 @@ func TestUnfavourite(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestGetTimelinePublic(t *testing.T) {
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Query().Get("local") == "" {
|
||||
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
fmt.Fprintln(w, `[{"content": "foo"}, {"content": "bar"}]`)
|
||||
}))
|
||||
defer ts.Close()
|
||||
|
||||
client := NewClient(&Config{Server: ts.URL})
|
||||
_, err := client.GetTimelinePublic(context.Background(), false)
|
||||
if err == nil {
|
||||
t.Fatalf("should be fail: %v", err)
|
||||
}
|
||||
tl, err := client.GetTimelinePublic(context.Background(), true)
|
||||
if err != nil {
|
||||
t.Fatalf("should not be fail: %v", err)
|
||||
}
|
||||
if len(tl) != 2 {
|
||||
t.Fatalf("result should be two: %d", len(tl))
|
||||
}
|
||||
if tl[0].Content != "foo" {
|
||||
t.Fatalf("want %q but %q", "foo", tl[0].Content)
|
||||
}
|
||||
if tl[1].Content != "bar" {
|
||||
t.Fatalf("want %q but %q", "bar", tl[1].Content)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetTimelineHashtag(t *testing.T) {
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/api/v1/timelines/tag/zzz" {
|
||||
|
|
Loading…
Reference in New Issue
Block a user