Update README.md, remove one of the flair methods

Signed-off-by: Vartan Benohanian <vartanbeno@gmail.com>
This commit is contained in:
Vartan Benohanian 2020-08-06 19:26:47 -04:00
parent 11d1e2d5e0
commit b23b1b69f8
5 changed files with 26 additions and 99 deletions

View File

@ -62,10 +62,15 @@ if err != nil {
</details>
<details>
<summary>Get a subreddit's top 5 posts of all time.</summary>
<summary>Get r/golang's top 5 posts of all time.</summary>
```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

View File

@ -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
}

View File

@ -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)
}

View File

@ -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"
}
]

View File

@ -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"
}
]