diff --git a/reddit/account.go b/reddit/account.go index 92a6c0a..7595195 100644 --- a/reddit/account.go +++ b/reddit/account.go @@ -326,7 +326,7 @@ func (s *AccountService) Friends(ctx context.Context) ([]Relationship, *Response return nil, nil, err } - root := make([]rootRelationshipList, 2) + var root [2]rootRelationshipList resp, err := s.client.Do(ctx, req, &root) if err != nil { return nil, resp, err @@ -362,7 +362,7 @@ func (s *AccountService) Messaging(ctx context.Context) ([]Relationship, []Relat return nil, nil, nil, err } - root := make([]rootRelationshipList, 2) + var root [2]rootRelationshipList resp, err := s.client.Do(ctx, req, &root) if err != nil { return nil, nil, resp, err @@ -400,7 +400,6 @@ func (s *AccountService) AddTrusted(ctx context.Context, username string) (*Resp form := url.Values{} form.Set("api_type", "json") form.Set("name", username) - // todo: you can also do this with the user id. form.Set("id", id). should we? or is this enough? req, err := s.client.NewRequestWithForm(http.MethodPost, path, form) if err != nil { @@ -417,7 +416,6 @@ func (s *AccountService) RemoveTrusted(ctx context.Context, username string) (*R form := url.Values{} form.Set("name", username) - // todo: you can also do this with the user id. form.Set("id", id). should we? or is this enough? req, err := s.client.NewRequestWithForm(http.MethodPost, path, form) if err != nil { diff --git a/reddit/comment_test.go b/reddit/comment_test.go index cb987e0..ae1f0f3 100644 --- a/reddit/comment_test.go +++ b/reddit/comment_test.go @@ -32,8 +32,7 @@ var expectedCommentSubmitOrEdit = &Comment{ Controversiality: 0, Created: &Timestamp{time.Date(2020, 4, 29, 0, 9, 47, 0, time.UTC)}, - // todo: this should just be nil - Edited: &Timestamp{time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC)}, + Edited: &Timestamp{time.Date(1, 1, 1, 0, 0, 0, 0, time.UTC)}, PostID: "t3_link1", } diff --git a/reddit/reddit-options.go b/reddit/reddit-options.go index 4986131..7ace2c3 100644 --- a/reddit/reddit-options.go +++ b/reddit/reddit-options.go @@ -20,28 +20,6 @@ func WithHTTPClient(httpClient *http.Client) Opt { } } -// FromEnv configures the client with values from environment variables. -// Supported environment variables: -// GO_REDDIT_CLIENT_ID to set the client's id. -// GO_REDDIT_CLIENT_SECRET to set the client's secret. -// 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 := os.Getenv("GO_REDDIT_CLIENT_ID"); v != "" { -// c.ID = v -// } -// if v := os.Getenv("GO_REDDIT_CLIENT_SECRET"); v != "" { -// c.Secret = v -// } -// if v := os.Getenv("GO_REDDIT_CLIENT_USERNAME"); v != "" { -// c.Username = v -// } -// if v := os.Getenv("GO_REDDIT_CLIENT_PASSWORD"); v != "" { -// c.Password = v -// } -// return nil -// } - // WithBaseURL sets the base URL for the client to make requests to. func WithBaseURL(u string) Opt { return func(c *Client) error { diff --git a/reddit/reddit-options_test.go b/reddit/reddit-options_test.go index 15ca5bf..31b0248 100644 --- a/reddit/reddit-options_test.go +++ b/reddit/reddit-options_test.go @@ -16,31 +16,6 @@ func TestWithHTTPClient(t *testing.T) { require.NoError(t, err) } -// func TestFromEnv(t *testing.T) { -// os.Setenv("GO_REDDIT_CLIENT_ID", "id1") -// defer os.Unsetenv("GO_REDDIT_CLIENT_ID") - -// os.Setenv("GO_REDDIT_CLIENT_SECRET", "secret1") -// defer os.Unsetenv("GO_REDDIT_CLIENT_SECRET") - -// os.Setenv("GO_REDDIT_CLIENT_USERNAME", "username1") -// defer os.Unsetenv("GO_REDDIT_CLIENT_USERNAME") - -// os.Setenv("GO_REDDIT_CLIENT_PASSWORD", "password1") -// defer os.Unsetenv("GO_REDDIT_CLIENT_PASSWORD") - -// c, err := NewClient(&Credentials{}, FromEnv) -// require.NoError(t, err) - -// type values struct { -// id, secret, username, password string -// } - -// expect := values{"id1", "secret1", "username1", "password1"} -// actual := values{c.ID, c.Secret, c.Username, c.Password} -// require.Equal(t, expect, actual) -// } - func TestWithBaseURL(t *testing.T) { c, err := NewClient(&Credentials{}, WithBaseURL(":")) urlErr, ok := err.(*url.Error) diff --git a/reddit/reddit.go b/reddit/reddit.go index 37eb8d7..044eb63 100644 --- a/reddit/reddit.go +++ b/reddit/reddit.go @@ -119,6 +119,11 @@ func NewClient(creds *Credentials, opts ...Opt) (*Client, error) { } client := newClient() + client.ID = creds.ID + client.Secret = creds.Secret + client.Username = creds.Username + client.Password = creds.Password + for _, opt := range opts { if err := opt(client); err != nil { return nil, err @@ -156,11 +161,6 @@ func NewClient(creds *Credentials, opts ...Opt) (*Client, error) { } } - client.ID = creds.ID - client.Secret = creds.Secret - client.Username = creds.Username - client.Password = creds.Password - oauthTransport := oauthTransport(client) client.client.Transport = oauthTransport diff --git a/reddit/subreddit.go b/reddit/subreddit.go index 70f9e79..f97e634 100644 --- a/reddit/subreddit.go +++ b/reddit/subreddit.go @@ -27,7 +27,6 @@ type rootSubredditNames struct { } // Relationship holds information about a relationship (friend/blocked). -// todo: there's also banned, wikibanned, etc. type Relationship struct { ID string `json:"rel_id,omitempty"` User string `json:"name,omitempty"` diff --git a/reddit/timestamp.go b/reddit/timestamp.go index 0ee4f12..7f90cb4 100644 --- a/reddit/timestamp.go +++ b/reddit/timestamp.go @@ -45,8 +45,3 @@ func (t *Timestamp) UnmarshalJSON(data []byte) (err error) { func (t Timestamp) Equal(u Timestamp) bool { return t.Time.Equal(u.Time) } - -// Before reports whether u is before t based on time.Before -func (t Timestamp) Before(u Timestamp) bool { - return t.Time.Before(u.Time) -}