@@ -497,7 +497,7 @@ func addCommentToTree(pc *PostAndComments, comment *Comment) {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *PostService) random(ctx context.Context, subreddits ...string) (*Post, []*Comment, *Response, error) {
|
||||
func (s *PostService) random(ctx context.Context, subreddits ...string) (*PostAndComments, *Response, error) {
|
||||
path := "random"
|
||||
if len(subreddits) > 0 {
|
||||
path = fmt.Sprintf("r/%s/random", strings.Join(subreddits, "+"))
|
||||
@@ -505,30 +505,30 @@ func (s *PostService) random(ctx context.Context, subreddits ...string) (*Post,
|
||||
|
||||
req, err := s.client.NewRequest(http.MethodGet, path, nil)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
root := new(PostAndComments)
|
||||
resp, err := s.client.Do(ctx, req, root)
|
||||
if err != nil {
|
||||
return nil, nil, resp, err
|
||||
return nil, resp, err
|
||||
}
|
||||
|
||||
return root.Post, root.Comments, resp, nil
|
||||
return root, resp, nil
|
||||
}
|
||||
|
||||
// RandomFromSubreddits returns a random post and its comments from the subreddits.
|
||||
// If no subreddits are provided, Reddit runs the query against your subscriptions.
|
||||
func (s *PostService) RandomFromSubreddits(ctx context.Context, subreddits ...string) (*Post, []*Comment, *Response, error) {
|
||||
func (s *PostService) RandomFromSubreddits(ctx context.Context, subreddits ...string) (*PostAndComments, *Response, error) {
|
||||
return s.random(ctx, subreddits...)
|
||||
}
|
||||
|
||||
// Random returns a random post and its comments from all of Reddit.
|
||||
func (s *PostService) Random(ctx context.Context) (*Post, []*Comment, *Response, error) {
|
||||
func (s *PostService) Random(ctx context.Context) (*PostAndComments, *Response, error) {
|
||||
return s.random(ctx, "all")
|
||||
}
|
||||
|
||||
// RandomFromSubscriptions returns a random post and its comments from your subscriptions.
|
||||
func (s *PostService) RandomFromSubscriptions(ctx context.Context) (*Post, []*Comment, *Response, error) {
|
||||
func (s *PostService) RandomFromSubscriptions(ctx context.Context) (*PostAndComments, *Response, error) {
|
||||
return s.random(ctx)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user