WIP: Create More struct, to be used to load more comments

Signed-off-by: Vartan Benohanian <vartanbeno@gmail.com>
This commit is contained in:
Vartan Benohanian
2020-07-17 17:04:28 -04:00
parent 5ab24a1e32
commit c85bb5485f
7 changed files with 130 additions and 63 deletions
+8 -8
View File
@@ -116,12 +116,12 @@ func (s *SubredditService) GetModerated(ctx context.Context, opts *ListOptions)
}
// GetSticky1 returns the first stickied post on a subreddit (if it exists).
func (s *SubredditService) GetSticky1(ctx context.Context, name string) (*PostAndComments, *Response, error) {
func (s *SubredditService) GetSticky1(ctx context.Context, name string) (*Post, []Comment, *Response, error) {
return s.getSticky(ctx, name, 1)
}
// GetSticky2 returns the second stickied post on a subreddit (if it exists).
func (s *SubredditService) GetSticky2(ctx context.Context, name string) (*PostAndComments, *Response, error) {
func (s *SubredditService) GetSticky2(ctx context.Context, name string) (*Post, []Comment, *Response, error) {
return s.getSticky(ctx, name, 2)
}
@@ -240,7 +240,7 @@ func (s *SubredditService) getSubreddits(ctx context.Context, path string, opts
// getSticky returns one of the 2 stickied posts of the subreddit (if they exist).
// Num should be equal to 1 or 2, depending on which one you want.
func (s *SubredditService) getSticky(ctx context.Context, subreddit string, num int) (*PostAndComments, *Response, error) {
func (s *SubredditService) getSticky(ctx context.Context, subreddit string, num int) (*Post, []Comment, *Response, error) {
type query struct {
Num int `url:"num"`
}
@@ -248,21 +248,21 @@ func (s *SubredditService) getSticky(ctx context.Context, subreddit string, num
path := fmt.Sprintf("r/%s/about/sticky", subreddit)
path, err := addOptions(path, query{num})
if err != nil {
return nil, nil, err
return nil, nil, nil, err
}
req, err := s.client.NewRequest(http.MethodGet, path, nil)
if err != nil {
return nil, nil, err
return nil, nil, nil, err
}
root := new(PostAndComments)
root := new(postAndComments)
resp, err := s.client.Do(ctx, req, root)
if err != nil {
return nil, resp, err
return nil, nil, resp, err
}
return root, resp, nil
return root.Post, root.Comments, resp, nil
}
// PostFinder finds posts from the specified subreddits.