Get new and popular users

Signed-off-by: Vartan Benohanian <vartanbeno@gmail.com>
This commit is contained in:
Vartan Benohanian
2020-08-01 16:31:57 -04:00
parent dad9def22c
commit 94f27f9e04
3 changed files with 310 additions and 0 deletions
+38
View File
@@ -515,3 +515,41 @@ func (s *UserService) TrophiesOf(ctx context.Context, username string) ([]Trophy
return trophies, resp, nil
}
// Popular gets the user subreddits with the most activity.
func (s *UserService) Popular(ctx context.Context, opts ...SearchOptionSetter) (*Subreddits, *Response, error) {
form := newSearchOptions(opts...)
path := addQuery("users/popular", form)
req, err := s.client.NewRequest(http.MethodGet, path, nil)
if err != nil {
return nil, nil, err
}
root := new(rootListing)
resp, err := s.client.Do(ctx, req, root)
if err != nil {
return nil, resp, err
}
return root.getSubreddits(), resp, nil
}
// New gets the most recently created user subreddits.
func (s *UserService) New(ctx context.Context, opts ...SearchOptionSetter) (*Subreddits, *Response, error) {
form := newSearchOptions(opts...)
path := addQuery("users/new", form)
req, err := s.client.NewRequest(http.MethodGet, path, nil)
if err != nil {
return nil, nil, err
}
root := new(rootListing)
resp, err := s.client.Do(ctx, req, root)
if err != nil {
return nil, resp, err
}
return root.getSubreddits(), resp, nil
}