Add methods to enable/disable contest mode for posts
Signed-off-by: Vartan Benohanian <vartanbeno@gmail.com>
This commit is contained in:
parent
930d294e70
commit
5ab24a1e32
3 changed files with 81 additions and 0 deletions
|
@ -12,6 +12,8 @@ import (
|
||||||
// This service holds functionality common to both posts and comments.
|
// This service holds functionality common to both posts and comments.
|
||||||
//
|
//
|
||||||
// Reddit API docs: https://www.reddit.com/dev/api/#section_links_and_comments
|
// Reddit API docs: https://www.reddit.com/dev/api/#section_links_and_comments
|
||||||
|
//
|
||||||
|
// todo: this is ugly, find a solution
|
||||||
type PostAndCommentService service
|
type PostAndCommentService service
|
||||||
|
|
||||||
type vote int
|
type vote int
|
||||||
|
|
35
post.go
35
post.go
|
@ -374,3 +374,38 @@ func (s *PostService) SetSuggestedSortLive(ctx context.Context, id string) (*Res
|
||||||
func (s *PostService) ClearSuggestedSort(ctx context.Context, id string) (*Response, error) {
|
func (s *PostService) ClearSuggestedSort(ctx context.Context, id string) (*Response, error) {
|
||||||
return s.setSuggestedSort(ctx, id, "")
|
return s.setSuggestedSort(ctx, id, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EnableContestMode enables contest mode for the post.
|
||||||
|
// Comments will be sorted randomly and regular users cannot see comment scores.
|
||||||
|
func (s *PostService) EnableContestMode(ctx context.Context, id string) (*Response, error) {
|
||||||
|
path := "api/set_contest_mode"
|
||||||
|
|
||||||
|
form := url.Values{}
|
||||||
|
form.Set("api_type", "json")
|
||||||
|
form.Set("id", id)
|
||||||
|
form.Set("state", "true")
|
||||||
|
|
||||||
|
req, err := s.client.NewRequestWithForm(http.MethodPost, path, form)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.client.Do(ctx, req, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
// DisableContestMode disables contest mode for the post.
|
||||||
|
func (s *PostService) DisableContestMode(ctx context.Context, id string) (*Response, error) {
|
||||||
|
path := "api/set_contest_mode"
|
||||||
|
|
||||||
|
form := url.Values{}
|
||||||
|
form.Set("api_type", "json")
|
||||||
|
form.Set("id", id)
|
||||||
|
form.Set("state", "false")
|
||||||
|
|
||||||
|
req, err := s.client.NewRequestWithForm(http.MethodPost, path, form)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.client.Do(ctx, req, nil)
|
||||||
|
}
|
||||||
|
|
44
post_test.go
44
post_test.go
|
@ -422,3 +422,47 @@ func TestPostService_ClearSuggestedSort(t *testing.T) {
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, http.StatusOK, res.StatusCode)
|
assert.Equal(t, http.StatusOK, res.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPostService_EnableContestMode(t *testing.T) {
|
||||||
|
setup()
|
||||||
|
defer teardown()
|
||||||
|
|
||||||
|
mux.HandleFunc("/api/set_contest_mode", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
assert.Equal(t, http.MethodPost, r.Method)
|
||||||
|
|
||||||
|
form := url.Values{}
|
||||||
|
form.Set("api_type", "json")
|
||||||
|
form.Set("id", "t3_test")
|
||||||
|
form.Set("state", "true")
|
||||||
|
|
||||||
|
err := r.ParseForm()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, form, r.PostForm)
|
||||||
|
})
|
||||||
|
|
||||||
|
res, err := client.Post.EnableContestMode(ctx, "t3_test")
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, http.StatusOK, res.StatusCode)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestPostService_DisableContestMode(t *testing.T) {
|
||||||
|
setup()
|
||||||
|
defer teardown()
|
||||||
|
|
||||||
|
mux.HandleFunc("/api/set_contest_mode", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
assert.Equal(t, http.MethodPost, r.Method)
|
||||||
|
|
||||||
|
form := url.Values{}
|
||||||
|
form.Set("api_type", "json")
|
||||||
|
form.Set("id", "t3_test")
|
||||||
|
form.Set("state", "false")
|
||||||
|
|
||||||
|
err := r.ParseForm()
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, form, r.PostForm)
|
||||||
|
})
|
||||||
|
|
||||||
|
res, err := client.Post.DisableContestMode(ctx, "t3_test")
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, http.StatusOK, res.StatusCode)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue