From 8bb0a0f85f7db1943a9bf50d18d639d5cae0de52 Mon Sep 17 00:00:00 2001 From: 178inaba <178inaba@users.noreply.github.com> Date: Sat, 29 Apr 2017 00:36:13 +0900 Subject: [PATCH 1/2] Add GetTimelineMedia --- status.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/status.go b/status.go index 4c28b33..dbbed03 100644 --- a/status.go +++ b/status.go @@ -187,6 +187,23 @@ func (c *Client) GetTimelineHashtag(ctx context.Context, tag string, isLocal boo return statuses, nil } +// GetTimelineMedia return statuses from media timeline. +// NOTE: This is an experimental feature of pawoo.net. +func (c *Client) GetTimelineMedia(ctx context.Context, isLocal bool) ([]*Status, error) { + params := url.Values{} + params.Set("media", "t") + 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 +} + // PostStatus post the toot. func (c *Client) PostStatus(ctx context.Context, toot *Toot) (*Status, error) { params := url.Values{} From 47292cbca3d682cac0fd0fe9e9e3a52f17e4815f Mon Sep 17 00:00:00 2001 From: 178inaba <178inaba@users.noreply.github.com> Date: Sat, 29 Apr 2017 00:43:53 +0900 Subject: [PATCH 2/2] Add TestGetTimelineMedia --- status_test.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/status_test.go b/status_test.go index bfc4a41..bc4eed6 100644 --- a/status_test.go +++ b/status_test.go @@ -393,6 +393,42 @@ func TestGetTimelineHashtag(t *testing.T) { } } +func TestGetTimelineMedia(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.StatusNotFound), http.StatusNotFound) + return + } + fmt.Fprintln(w, `[{"content": "zzz"},{"content": "yyy"}]`) + return + })) + defer ts.Close() + + client := NewClient(&Config{ + Server: ts.URL, + ClientID: "foo", + ClientSecret: "bar", + AccessToken: "zoo", + }) + _, err := client.GetTimelineMedia(context.Background(), false) + if err == nil { + t.Fatalf("should be fail: %v", err) + } + tags, err := client.GetTimelineMedia(context.Background(), true) + 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 TestDeleteStatus(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.URL.Path != "/api/v1/statuses/1234567" {