Add methods to report, un/ignore reports
Signed-off-by: Vartan Benohanian <vartanbeno@gmail.com>
This commit is contained in:
@@ -347,3 +347,24 @@ func TestCommentService_LoadMoreReplies(t *testing.T) {
|
|||||||
require.Len(t, comment.Replies.Comments, 2)
|
require.Len(t, comment.Replies.Comments, 2)
|
||||||
require.Len(t, comment.Replies.Comments[0].Replies.Comments, 1)
|
require.Len(t, comment.Replies.Comments[0].Replies.Comments, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCommentService_Report(t *testing.T) {
|
||||||
|
setup()
|
||||||
|
defer teardown()
|
||||||
|
|
||||||
|
mux.HandleFunc("/api/report", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
require.Equal(t, http.MethodPost, r.Method)
|
||||||
|
|
||||||
|
form := url.Values{}
|
||||||
|
form.Set("api_type", "json")
|
||||||
|
form.Set("thing_id", "t1_test")
|
||||||
|
form.Set("reason", "test reason")
|
||||||
|
|
||||||
|
err := r.ParseForm()
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, form, r.PostForm)
|
||||||
|
})
|
||||||
|
|
||||||
|
_, err := client.Comment.Report(ctx, "t1_test", "test reason")
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
|||||||
@@ -180,3 +180,33 @@ func (s *ModerationService) Edited(ctx context.Context, subreddit string, opts *
|
|||||||
|
|
||||||
return root.getPosts(), root.getComments(), resp, nil
|
return root.getPosts(), root.getComments(), resp, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IgnoreReports prevents reports on a post or comment from causing notifications.
|
||||||
|
func (s *ModerationService) IgnoreReports(ctx context.Context, id string) (*Response, error) {
|
||||||
|
path := "api/ignore_reports"
|
||||||
|
|
||||||
|
form := url.Values{}
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnignoreReports allows reports on a post or comment to cause notifications.
|
||||||
|
func (s *ModerationService) UnignoreReports(ctx context.Context, id string) (*Response, error) {
|
||||||
|
path := "api/unignore_reports"
|
||||||
|
|
||||||
|
form := url.Values{}
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|||||||
@@ -222,3 +222,41 @@ func TestModerationService_Edited(t *testing.T) {
|
|||||||
require.Equal(t, "t1_f0zsa37", comments.After)
|
require.Equal(t, "t1_f0zsa37", comments.After)
|
||||||
require.Equal(t, "", comments.Before)
|
require.Equal(t, "", comments.Before)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestModerationService_IgnoreReports(t *testing.T) {
|
||||||
|
setup()
|
||||||
|
defer teardown()
|
||||||
|
|
||||||
|
mux.HandleFunc("/api/ignore_reports", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
require.Equal(t, http.MethodPost, r.Method)
|
||||||
|
|
||||||
|
form := url.Values{}
|
||||||
|
form.Set("id", "t3_test")
|
||||||
|
|
||||||
|
err := r.ParseForm()
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, form, r.PostForm)
|
||||||
|
})
|
||||||
|
|
||||||
|
_, err := client.Moderation.IgnoreReports(ctx, "t3_test")
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestModerationService_UnignoreReports(t *testing.T) {
|
||||||
|
setup()
|
||||||
|
defer teardown()
|
||||||
|
|
||||||
|
mux.HandleFunc("/api/unignore_reports", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
require.Equal(t, http.MethodPost, r.Method)
|
||||||
|
|
||||||
|
form := url.Values{}
|
||||||
|
form.Set("id", "t3_test")
|
||||||
|
|
||||||
|
err := r.ParseForm()
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, form, r.PostForm)
|
||||||
|
})
|
||||||
|
|
||||||
|
_, err := client.Moderation.UnignoreReports(ctx, "t3_test")
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
|||||||
@@ -162,3 +162,21 @@ func (s *postAndCommentService) Downvote(ctx context.Context, id string) (*Respo
|
|||||||
func (s *postAndCommentService) RemoveVote(ctx context.Context, id string) (*Response, error) {
|
func (s *postAndCommentService) RemoveVote(ctx context.Context, id string) (*Response, error) {
|
||||||
return s.vote(ctx, id, novote)
|
return s.vote(ctx, id, novote)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Report reports a post or comment.
|
||||||
|
// The reason must not be longer than 100 characters.
|
||||||
|
func (s *postAndCommentService) Report(ctx context.Context, id string, reason string) (*Response, error) {
|
||||||
|
path := "api/report"
|
||||||
|
|
||||||
|
form := url.Values{}
|
||||||
|
form.Set("api_type", "json")
|
||||||
|
form.Set("thing_id", id)
|
||||||
|
form.Set("reason", reason)
|
||||||
|
|
||||||
|
req, err := s.client.NewRequestWithForm(http.MethodPost, path, form)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return s.client.Do(ctx, req, nil)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1152,3 +1152,24 @@ func TestPostService_MarkVisited(t *testing.T) {
|
|||||||
_, err = client.Post.MarkVisited(ctx, "t3_test1", "t3_test2", "t3_test3")
|
_, err = client.Post.MarkVisited(ctx, "t3_test1", "t3_test2", "t3_test3")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPostService_Report(t *testing.T) {
|
||||||
|
setup()
|
||||||
|
defer teardown()
|
||||||
|
|
||||||
|
mux.HandleFunc("/api/report", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
require.Equal(t, http.MethodPost, r.Method)
|
||||||
|
|
||||||
|
form := url.Values{}
|
||||||
|
form.Set("api_type", "json")
|
||||||
|
form.Set("thing_id", "t3_test")
|
||||||
|
form.Set("reason", "test reason")
|
||||||
|
|
||||||
|
err := r.ParseForm()
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, form, r.PostForm)
|
||||||
|
})
|
||||||
|
|
||||||
|
_, err := client.Post.Report(ctx, "t3_test", "test reason")
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user