add GetTimelineHashtagMultiple
parent
e86f463667
commit
ad3aa348dd
32
status.go
32
status.go
|
@ -103,6 +103,12 @@ type Media struct {
|
|||
Focus string
|
||||
}
|
||||
|
||||
type TagData struct {
|
||||
Any []string
|
||||
All []string
|
||||
None []string
|
||||
}
|
||||
|
||||
func (m *Media) bodyAndContentType() (io.Reader, string, error) {
|
||||
var buf bytes.Buffer
|
||||
mw := multipart.NewWriter(&buf)
|
||||
|
@ -350,6 +356,32 @@ func (c *Client) GetTimelineHashtag(ctx context.Context, tag string, isLocal boo
|
|||
return statuses, nil
|
||||
}
|
||||
|
||||
// GetTimelineHashtag return statuses from tagged timeline.
|
||||
func (c *Client) GetTimelineHashtagMultiple(ctx context.Context, tag string, isLocal bool, td *TagData, pg *Pagination) ([]*Status, error) {
|
||||
params := url.Values{}
|
||||
if isLocal {
|
||||
params.Set("local", "t")
|
||||
}
|
||||
if td != nil {
|
||||
for _, v := range td.Any {
|
||||
params.Add("any[]", v)
|
||||
}
|
||||
for _, v := range td.All {
|
||||
params.Add("all[]", v)
|
||||
}
|
||||
for _, v := range td.None {
|
||||
params.Add("none[]", v)
|
||||
}
|
||||
}
|
||||
|
||||
var statuses []*Status
|
||||
err := c.doAPI(ctx, http.MethodGet, fmt.Sprintf("/api/v1/timelines/tag/%s", url.PathEscape(tag)), params, &statuses, pg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return statuses, nil
|
||||
}
|
||||
|
||||
// GetTimelineList return statuses from a list timeline.
|
||||
func (c *Client) GetTimelineList(ctx context.Context, id ID, pg *Pagination) ([]*Status, error) {
|
||||
var statuses []*Status
|
||||
|
|
|
@ -581,6 +581,53 @@ func TestGetTimelineDirect(t *testing.T) {
|
|||
}
|
||||
|
||||
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" {
|
||||
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
if r.FormValue("any[]") != "aaa" {
|
||||
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if r.FormValue("all[]") != "bbb" {
|
||||
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if r.FormValue("none[]") != "ccc" {
|
||||
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
fmt.Fprintln(w, `[{"content": "zzz"},{"content": "yyy"}]`)
|
||||
}))
|
||||
defer ts.Close()
|
||||
|
||||
client := NewClient(&Config{
|
||||
Server: ts.URL,
|
||||
ClientID: "foo",
|
||||
ClientSecret: "bar",
|
||||
AccessToken: "zoo",
|
||||
})
|
||||
_, err := client.GetTimelineHashtagMultiple(context.Background(), "notfound", false, &TagData{}, nil)
|
||||
if err == nil {
|
||||
t.Fatalf("should be fail: %v", err)
|
||||
}
|
||||
tags, err := client.GetTimelineHashtagMultiple(context.Background(), "zzz", true, &TagData{Any: []string{"aaa"}, All: []string{"bbb"}, None: []string{"ccc"}}, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("should not be fail: %v", err)
|
||||
}
|
||||
if len(tags) != 2 {
|
||||
t.Fatalf("should have %q entries but %q", "2", len(tags))
|
||||
}
|
||||
if tags[0].Content != "zzz" {
|
||||
t.Fatalf("want %q but %q", "zzz", tags[0].Content)
|
||||
}
|
||||
if tags[1].Content != "yyy" {
|
||||
t.Fatalf("want %q but %q", "zzz", tags[1].Content)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetTimelineHashtagMultiple(t *testing.T) {
|
||||
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != "/api/v1/timelines/tag/zzz" {
|
||||
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
|
||||
|
|
Loading…
Reference in New Issue