Change doc comment, some very minor tweaks

Signed-off-by: Vartan Benohanian <vartanbeno@gmail.com>
This commit is contained in:
Vartan Benohanian 2020-08-21 15:31:15 -04:00
parent 8752bdd2d6
commit 407ee432a3
4 changed files with 17 additions and 11 deletions

View file

@ -11,7 +11,7 @@ import (
// GoldService handles communication with the gold
// related methods of the Reddit API.
//
// Reddit API docs: https://www.reddit.com/dev/api/#section_collections
// Reddit API docs: https://www.reddit.com/dev/api/#section_gold
type GoldService struct {
client *Client
}

View file

@ -16,19 +16,19 @@ type Opt func(*Client) error
// GO_REDDIT_CLIENT_USERNAME to set the client's username.
// GO_REDDIT_CLIENT_PASSWORD to set the client's password.
func FromEnv(c *Client) error {
if v, ok := os.LookupEnv("GO_REDDIT_CLIENT_ID"); ok {
if v := os.Getenv("GO_REDDIT_CLIENT_ID"); v != "" {
c.ID = v
}
if v, ok := os.LookupEnv("GO_REDDIT_CLIENT_SECRET"); ok {
if v := os.Getenv("GO_REDDIT_CLIENT_SECRET"); v != "" {
c.Secret = v
}
if v, ok := os.LookupEnv("GO_REDDIT_CLIENT_USERNAME"); ok {
if v := os.Getenv("GO_REDDIT_CLIENT_USERNAME"); v != "" {
c.Username = v
}
if v, ok := os.LookupEnv("GO_REDDIT_CLIENT_PASSWORD"); ok {
if v := os.Getenv("GO_REDDIT_CLIENT_PASSWORD"); v != "" {
c.Password = v
}

View file

@ -253,17 +253,13 @@ func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Res
if err != nil {
return nil, err
}
defer resp.Body.Close()
if c.onRequestCompleted != nil {
c.onRequestCompleted(req, resp)
}
response := newResponse(resp)
defer func() {
if rerr := response.Body.Close(); err == nil {
err = rerr
}
}()
err = CheckResponse(resp)
if err != nil {
@ -284,7 +280,7 @@ func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Res
}
}
return response, err
return response, nil
}
// id returns the client's Reddit ID.

View file

@ -91,6 +91,8 @@ func (s *SubredditService) getPosts(ctx context.Context, sort string, subreddit
// HotPosts returns the hottest posts from the specified subreddit.
// To search through multiple, separate the names with a plus (+), e.g. "golang+test".
// If none are defined, it returns the ones from your subscribed subreddits.
// To search through all, just specify "all".
// To search through all and filter out subreddits, provide "all-name1-name2".
// Note: when looking for hot posts in a subreddit, it will include the stickied
// posts (if any) PLUS posts from the limit parameter (25 by default).
func (s *SubredditService) HotPosts(ctx context.Context, subreddit string, opts *ListPostOptions) (*Posts, *Response, error) {
@ -100,6 +102,8 @@ func (s *SubredditService) HotPosts(ctx context.Context, subreddit string, opts
// NewPosts returns the newest posts from the specified subreddit.
// To search through multiple, separate the names with a plus (+), e.g. "golang+test".
// If none are defined, it returns the ones from your subscribed subreddits.
// To search through all, just specify "all".
// To search through all and filter out subreddits, provide "all-name1-name2".
func (s *SubredditService) NewPosts(ctx context.Context, subreddit string, opts *ListPostOptions) (*Posts, *Response, error) {
return s.getPosts(ctx, "new", subreddit, opts)
}
@ -107,6 +111,8 @@ func (s *SubredditService) NewPosts(ctx context.Context, subreddit string, opts
// RisingPosts returns the rising posts from the specified subreddit.
// To search through multiple, separate the names with a plus (+), e.g. "golang+test".
// If none are defined, it returns the ones from your subscribed subreddits.
// To search through all, just specify "all".
// To search through all and filter out subreddits, provide "all-name1-name2".
func (s *SubredditService) RisingPosts(ctx context.Context, subreddit string, opts *ListPostOptions) (*Posts, *Response, error) {
return s.getPosts(ctx, "rising", subreddit, opts)
}
@ -114,6 +120,8 @@ func (s *SubredditService) RisingPosts(ctx context.Context, subreddit string, op
// ControversialPosts returns the most controversial posts from the specified subreddit.
// To search through multiple, separate the names with a plus (+), e.g. "golang+test".
// If none are defined, it returns the ones from your subscribed subreddits.
// To search through all, just specify "all".
// To search through all and filter out subreddits, provide "all-name1-name2".
func (s *SubredditService) ControversialPosts(ctx context.Context, subreddit string, opts *ListPostOptions) (*Posts, *Response, error) {
return s.getPosts(ctx, "controversial", subreddit, opts)
}
@ -121,6 +129,8 @@ func (s *SubredditService) ControversialPosts(ctx context.Context, subreddit str
// TopPosts returns the top posts from the specified subreddit.
// To search through multiple, separate the names with a plus (+), e.g. "golang+test".
// If none are defined, it returns the ones from your subscribed subreddits.
// To search through all, just specify "all".
// To search through all and filter out subreddits, provide "all-name1-name2".
func (s *SubredditService) TopPosts(ctx context.Context, subreddit string, opts *ListPostOptions) (*Posts, *Response, error) {
return s.getPosts(ctx, "top", subreddit, opts)
}