Change doc comment, some very minor tweaks
Signed-off-by: Vartan Benohanian <vartanbeno@gmail.com>
This commit is contained in:
parent
8752bdd2d6
commit
407ee432a3
4 changed files with 17 additions and 11 deletions
|
@ -11,7 +11,7 @@ import (
|
||||||
// GoldService handles communication with the gold
|
// GoldService handles communication with the gold
|
||||||
// related methods of the Reddit API.
|
// 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 {
|
type GoldService struct {
|
||||||
client *Client
|
client *Client
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,19 +16,19 @@ type Opt func(*Client) error
|
||||||
// GO_REDDIT_CLIENT_USERNAME to set the client's username.
|
// GO_REDDIT_CLIENT_USERNAME to set the client's username.
|
||||||
// GO_REDDIT_CLIENT_PASSWORD to set the client's password.
|
// GO_REDDIT_CLIENT_PASSWORD to set the client's password.
|
||||||
func FromEnv(c *Client) error {
|
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
|
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
|
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
|
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
|
c.Password = v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -253,17 +253,13 @@ func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Res
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
if c.onRequestCompleted != nil {
|
if c.onRequestCompleted != nil {
|
||||||
c.onRequestCompleted(req, resp)
|
c.onRequestCompleted(req, resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
response := newResponse(resp)
|
response := newResponse(resp)
|
||||||
defer func() {
|
|
||||||
if rerr := response.Body.Close(); err == nil {
|
|
||||||
err = rerr
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
err = CheckResponse(resp)
|
err = CheckResponse(resp)
|
||||||
if err != nil {
|
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.
|
// id returns the client's Reddit ID.
|
||||||
|
|
|
@ -91,6 +91,8 @@ func (s *SubredditService) getPosts(ctx context.Context, sort string, subreddit
|
||||||
// HotPosts returns the hottest posts from the specified subreddit.
|
// HotPosts returns the hottest posts from the specified subreddit.
|
||||||
// To search through multiple, separate the names with a plus (+), e.g. "golang+test".
|
// 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.
|
// 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
|
// 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).
|
// 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) {
|
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.
|
// NewPosts returns the newest posts from the specified subreddit.
|
||||||
// To search through multiple, separate the names with a plus (+), e.g. "golang+test".
|
// 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.
|
// 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) {
|
func (s *SubredditService) NewPosts(ctx context.Context, subreddit string, opts *ListPostOptions) (*Posts, *Response, error) {
|
||||||
return s.getPosts(ctx, "new", subreddit, opts)
|
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.
|
// RisingPosts returns the rising posts from the specified subreddit.
|
||||||
// To search through multiple, separate the names with a plus (+), e.g. "golang+test".
|
// 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.
|
// 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) {
|
func (s *SubredditService) RisingPosts(ctx context.Context, subreddit string, opts *ListPostOptions) (*Posts, *Response, error) {
|
||||||
return s.getPosts(ctx, "rising", subreddit, opts)
|
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.
|
// ControversialPosts returns the most controversial posts from the specified subreddit.
|
||||||
// To search through multiple, separate the names with a plus (+), e.g. "golang+test".
|
// 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.
|
// 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) {
|
func (s *SubredditService) ControversialPosts(ctx context.Context, subreddit string, opts *ListPostOptions) (*Posts, *Response, error) {
|
||||||
return s.getPosts(ctx, "controversial", subreddit, opts)
|
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.
|
// TopPosts returns the top posts from the specified subreddit.
|
||||||
// To search through multiple, separate the names with a plus (+), e.g. "golang+test".
|
// 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.
|
// 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) {
|
func (s *SubredditService) TopPosts(ctx context.Context, subreddit string, opts *ListPostOptions) (*Posts, *Response, error) {
|
||||||
return s.getPosts(ctx, "top", subreddit, opts)
|
return s.getPosts(ctx, "top", subreddit, opts)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue