Add distinguishing methods
Signed-off-by: Vartan Benohanian <vartanbeno@gmail.com>
This commit is contained in:
parent
078b172e81
commit
8458fb4c98
2 changed files with 118 additions and 0 deletions
|
@ -438,3 +438,57 @@ func (s *ModerationService) deleteRelationship(ctx context.Context, subreddit, u
|
|||
|
||||
return s.client.Do(ctx, req, nil)
|
||||
}
|
||||
|
||||
// Distinguish your post or comment via its full ID, adding a moderator tag to it.
|
||||
// todo: add how=admin and how=special? They require special privileges.
|
||||
func (s *ModerationService) Distinguish(ctx context.Context, id string) (*Response, error) {
|
||||
path := "api/distinguish"
|
||||
|
||||
form := url.Values{}
|
||||
form.Set("api_type", "json")
|
||||
form.Set("how", "yes")
|
||||
form.Set("id", id)
|
||||
|
||||
req, err := s.client.NewRequestWithForm(http.MethodPost, path, form)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return s.client.Do(ctx, req, nil)
|
||||
}
|
||||
|
||||
// DistinguishAndSticky your comment via its full ID, adding a moderator tag to it
|
||||
// and stickying the comment at the top of the thread.
|
||||
func (s *ModerationService) DistinguishAndSticky(ctx context.Context, id string) (*Response, error) {
|
||||
path := "api/distinguish"
|
||||
|
||||
form := url.Values{}
|
||||
form.Set("api_type", "json")
|
||||
form.Set("how", "yes")
|
||||
form.Set("sticky", "true")
|
||||
form.Set("id", id)
|
||||
|
||||
req, err := s.client.NewRequestWithForm(http.MethodPost, path, form)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return s.client.Do(ctx, req, nil)
|
||||
}
|
||||
|
||||
// Undistinguish your post or comment via its full ID, removing the moderator tag from it.
|
||||
func (s *ModerationService) Undistinguish(ctx context.Context, id string) (*Response, error) {
|
||||
path := "api/distinguish"
|
||||
|
||||
form := url.Values{}
|
||||
form.Set("api_type", "json")
|
||||
form.Set("how", "no")
|
||||
form.Set("id", id)
|
||||
|
||||
req, err := s.client.NewRequestWithForm(http.MethodPost, path, form)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return s.client.Do(ctx, req, nil)
|
||||
}
|
||||
|
|
|
@ -666,3 +666,67 @@ func TestModerationService_UnapproveUserWiki(t *testing.T) {
|
|||
_, err := client.Moderation.UnapproveUserWiki(ctx, "testsubreddit", "testuser")
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestModerationService_Distinguish(t *testing.T) {
|
||||
client, mux, teardown := setup()
|
||||
defer teardown()
|
||||
|
||||
mux.HandleFunc("/api/distinguish", func(w http.ResponseWriter, r *http.Request) {
|
||||
require.Equal(t, http.MethodPost, r.Method)
|
||||
|
||||
form := url.Values{}
|
||||
form.Set("api_type", "json")
|
||||
form.Set("how", "yes")
|
||||
form.Set("id", "t1_123")
|
||||
|
||||
err := r.ParseForm()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, form, r.PostForm)
|
||||
})
|
||||
|
||||
_, err := client.Moderation.Distinguish(ctx, "t1_123")
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestModerationService_DistinguishAndSticky(t *testing.T) {
|
||||
client, mux, teardown := setup()
|
||||
defer teardown()
|
||||
|
||||
mux.HandleFunc("/api/distinguish", func(w http.ResponseWriter, r *http.Request) {
|
||||
require.Equal(t, http.MethodPost, r.Method)
|
||||
|
||||
form := url.Values{}
|
||||
form.Set("api_type", "json")
|
||||
form.Set("how", "yes")
|
||||
form.Set("sticky", "true")
|
||||
form.Set("id", "t1_123")
|
||||
|
||||
err := r.ParseForm()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, form, r.PostForm)
|
||||
})
|
||||
|
||||
_, err := client.Moderation.DistinguishAndSticky(ctx, "t1_123")
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestModerationService_Undistinguish(t *testing.T) {
|
||||
client, mux, teardown := setup()
|
||||
defer teardown()
|
||||
|
||||
mux.HandleFunc("/api/distinguish", func(w http.ResponseWriter, r *http.Request) {
|
||||
require.Equal(t, http.MethodPost, r.Method)
|
||||
|
||||
form := url.Values{}
|
||||
form.Set("api_type", "json")
|
||||
form.Set("how", "no")
|
||||
form.Set("id", "t1_123")
|
||||
|
||||
err := r.ParseForm()
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, form, r.PostForm)
|
||||
})
|
||||
|
||||
_, err := client.Moderation.Undistinguish(ctx, "t1_123")
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue