From b23b1b69f8c172a3ccce196166946775ea8b9b93 Mon Sep 17 00:00:00 2001 From: Vartan Benohanian Date: Thu, 6 Aug 2020 19:26:47 -0400 Subject: [PATCH] Update README.md, remove one of the flair methods Signed-off-by: Vartan Benohanian --- README.md | 9 +++++++-- flair.go | 28 +--------------------------- flair_test.go | 34 +--------------------------------- testdata/flair/flairs-v2.json | 30 ------------------------------ testdata/flair/flairs.json | 24 +++++++++++++++++------- 5 files changed, 26 insertions(+), 99 deletions(-) delete mode 100644 testdata/flair/flairs-v2.json diff --git a/README.md b/README.md index 322b0c1..b0fe6ef 100644 --- a/README.md +++ b/README.md @@ -62,10 +62,15 @@ if err != nil {
- Get a subreddit's top 5 posts of all time. + Get r/golang's top 5 posts of all time. ```go -result, _, err := client.Subreddit.Top(context.Background(), "golang", reddit.SetLimit(5), reddit.FromAllTime) +result, _, err := client.Subreddit.Top(context.Background(), "golang", &reddit.ListPostOptions{ + ListOptions: reddit.ListOptions{ + Limit: 5, + }, + Time: "all", +}) if err != nil { fmt.Printf("Something bad happened: %v\n", err) return err diff --git a/flair.go b/flair.go index 186d110..bae88d8 100644 --- a/flair.go +++ b/flair.go @@ -16,14 +16,6 @@ type FlairService struct { // Flair is a flair on Reddit type Flair struct { - ID string `json:"id,omitempty"` - Text string `json:"text,omitempty"` - Type string `json:"type,omitempty"` - CSS string `json:"css_class,omitempty"` -} - -// FlairV2 is a flair on Reddit -type FlairV2 struct { ID string `json:"id,omitempty"` Text string `json:"text,omitempty"` Type string `json:"type,omitempty"` @@ -33,7 +25,7 @@ type FlairV2 struct { // GetFromSubreddit returns the flairs from the subreddit func (s *FlairService) GetFromSubreddit(ctx context.Context, name string) ([]Flair, *Response, error) { - path := fmt.Sprintf("r/%s/api/user_flair", name) + path := fmt.Sprintf("r/%s/api/user_flair_v2", name) req, err := s.client.NewRequest(http.MethodGet, path, nil) if err != nil { @@ -48,21 +40,3 @@ func (s *FlairService) GetFromSubreddit(ctx context.Context, name string) ([]Fla return flairs, resp, nil } - -// GetFromSubredditV2 returns the flairs from the subreddit -func (s *FlairService) GetFromSubredditV2(ctx context.Context, name string) ([]FlairV2, *Response, error) { - path := fmt.Sprintf("r/%s/api/user_flair_v2", name) - - req, err := s.client.NewRequest(http.MethodGet, path, nil) - if err != nil { - return nil, nil, err - } - - var flairs []FlairV2 - resp, err := s.client.Do(ctx, req, &flairs) - if err != nil { - return nil, resp, err - } - - return flairs, resp, nil -} diff --git a/flair_test.go b/flair_test.go index 2a27e16..1dc623a 100644 --- a/flair_test.go +++ b/flair_test.go @@ -9,21 +9,6 @@ import ( ) var expectedFlairs = []Flair{ - { - ID: "b8a1c822-3feb-11e8-88e1-0e5f55d58ce0", - Text: "Beginner", - Type: "text", - CSS: "Beginner1", - }, - { - ID: "b8ea0fce-3feb-11e8-af7a-0e263a127cf8", - Text: "Beginner", - Type: "text", - CSS: "Beginner2", - }, -} - -var expectedFlairsV2 = []FlairV2{ { ID: "b8a1c822-3feb-11e8-88e1-0e5f55d58ce0", Text: "Beginner", @@ -47,7 +32,7 @@ func TestFlairService_GetFlairs(t *testing.T) { blob, err := readFileContents("testdata/flair/flairs.json") assert.NoError(t, err) - mux.HandleFunc("/r/subreddit/api/user_flair", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/r/subreddit/api/user_flair_v2", func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodGet, r.Method) fmt.Fprint(w, blob) }) @@ -56,20 +41,3 @@ func TestFlairService_GetFlairs(t *testing.T) { assert.NoError(t, err) assert.Equal(t, expectedFlairs, flairs) } - -func TestFlairService_GetFlairsV2(t *testing.T) { - setup() - defer teardown() - - blob, err := readFileContents("testdata/flair/flairs-v2.json") - assert.NoError(t, err) - - mux.HandleFunc("/r/subreddit/api/user_flair_v2", func(w http.ResponseWriter, r *http.Request) { - assert.Equal(t, http.MethodGet, r.Method) - fmt.Fprint(w, blob) - }) - - flairs, _, err := client.Flair.GetFromSubredditV2(ctx, "subreddit") - assert.NoError(t, err) - assert.Equal(t, expectedFlairsV2, flairs) -} diff --git a/testdata/flair/flairs-v2.json b/testdata/flair/flairs-v2.json deleted file mode 100644 index 7ceb03b..0000000 --- a/testdata/flair/flairs-v2.json +++ /dev/null @@ -1,30 +0,0 @@ -[ - { - "allowable_content": "all", - "text": "Beginner", - "text_color": "dark", - "mod_only": false, - "background_color": "", - "id": "b8a1c822-3feb-11e8-88e1-0e5f55d58ce0", - "css_class": "Beginner1", - "max_emojis": 10, - "richtext": [], - "text_editable": false, - "override_css": false, - "type": "text" - }, - { - "allowable_content": "all", - "text": "Moderator", - "text_color": "dark", - "mod_only": true, - "background_color": "", - "id": "b8ea0fce-3feb-11e8-af7a-0e263a127cf8", - "css_class": "Moderator1", - "max_emojis": 10, - "richtext": [], - "text_editable": false, - "override_css": false, - "type": "text" - } -] diff --git a/testdata/flair/flairs.json b/testdata/flair/flairs.json index ccf40ed..7ceb03b 100644 --- a/testdata/flair/flairs.json +++ b/testdata/flair/flairs.json @@ -1,20 +1,30 @@ [ { + "allowable_content": "all", "text": "Beginner", + "text_color": "dark", + "mod_only": false, + "background_color": "", + "id": "b8a1c822-3feb-11e8-88e1-0e5f55d58ce0", + "css_class": "Beginner1", + "max_emojis": 10, "richtext": [], "text_editable": false, "override_css": false, - "css_class": "Beginner1", - "type": "text", - "id": "b8a1c822-3feb-11e8-88e1-0e5f55d58ce0" + "type": "text" }, { - "text": "Beginner", + "allowable_content": "all", + "text": "Moderator", + "text_color": "dark", + "mod_only": true, + "background_color": "", + "id": "b8ea0fce-3feb-11e8-af7a-0e263a127cf8", + "css_class": "Moderator1", + "max_emojis": 10, "richtext": [], "text_editable": false, "override_css": false, - "css_class": "Beginner2", - "type": "text", - "id": "b8ea0fce-3feb-11e8-af7a-0e263a127cf8" + "type": "text" } ]