Remove FromEnv option, a few todos
Signed-off-by: Vartan Benohanian <vartanbeno@gmail.com>
This commit is contained in:
parent
c4faa00b94
commit
a14cb3a3c8
7 changed files with 8 additions and 64 deletions
|
@ -326,7 +326,7 @@ func (s *AccountService) Friends(ctx context.Context) ([]Relationship, *Response
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
root := make([]rootRelationshipList, 2)
|
var root [2]rootRelationshipList
|
||||||
resp, err := s.client.Do(ctx, req, &root)
|
resp, err := s.client.Do(ctx, req, &root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, resp, err
|
return nil, resp, err
|
||||||
|
@ -362,7 +362,7 @@ func (s *AccountService) Messaging(ctx context.Context) ([]Relationship, []Relat
|
||||||
return nil, nil, nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
root := make([]rootRelationshipList, 2)
|
var root [2]rootRelationshipList
|
||||||
resp, err := s.client.Do(ctx, req, &root)
|
resp, err := s.client.Do(ctx, req, &root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, resp, err
|
return nil, nil, resp, err
|
||||||
|
@ -400,7 +400,6 @@ func (s *AccountService) AddTrusted(ctx context.Context, username string) (*Resp
|
||||||
form := url.Values{}
|
form := url.Values{}
|
||||||
form.Set("api_type", "json")
|
form.Set("api_type", "json")
|
||||||
form.Set("name", username)
|
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)
|
req, err := s.client.NewRequestWithForm(http.MethodPost, path, form)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -417,7 +416,6 @@ func (s *AccountService) RemoveTrusted(ctx context.Context, username string) (*R
|
||||||
|
|
||||||
form := url.Values{}
|
form := url.Values{}
|
||||||
form.Set("name", username)
|
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)
|
req, err := s.client.NewRequestWithForm(http.MethodPost, path, form)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -32,8 +32,7 @@ var expectedCommentSubmitOrEdit = &Comment{
|
||||||
Controversiality: 0,
|
Controversiality: 0,
|
||||||
|
|
||||||
Created: &Timestamp{time.Date(2020, 4, 29, 0, 9, 47, 0, time.UTC)},
|
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",
|
PostID: "t3_link1",
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.
|
// WithBaseURL sets the base URL for the client to make requests to.
|
||||||
func WithBaseURL(u string) Opt {
|
func WithBaseURL(u string) Opt {
|
||||||
return func(c *Client) error {
|
return func(c *Client) error {
|
||||||
|
|
|
@ -16,31 +16,6 @@ func TestWithHTTPClient(t *testing.T) {
|
||||||
require.NoError(t, err)
|
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) {
|
func TestWithBaseURL(t *testing.T) {
|
||||||
c, err := NewClient(&Credentials{}, WithBaseURL(":"))
|
c, err := NewClient(&Credentials{}, WithBaseURL(":"))
|
||||||
urlErr, ok := err.(*url.Error)
|
urlErr, ok := err.(*url.Error)
|
||||||
|
|
|
@ -119,6 +119,11 @@ func NewClient(creds *Credentials, opts ...Opt) (*Client, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
client := newClient()
|
client := newClient()
|
||||||
|
client.ID = creds.ID
|
||||||
|
client.Secret = creds.Secret
|
||||||
|
client.Username = creds.Username
|
||||||
|
client.Password = creds.Password
|
||||||
|
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
if err := opt(client); err != nil {
|
if err := opt(client); err != nil {
|
||||||
return nil, err
|
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)
|
oauthTransport := oauthTransport(client)
|
||||||
client.client.Transport = oauthTransport
|
client.client.Transport = oauthTransport
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,6 @@ type rootSubredditNames struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Relationship holds information about a relationship (friend/blocked).
|
// Relationship holds information about a relationship (friend/blocked).
|
||||||
// todo: there's also banned, wikibanned, etc.
|
|
||||||
type Relationship struct {
|
type Relationship struct {
|
||||||
ID string `json:"rel_id,omitempty"`
|
ID string `json:"rel_id,omitempty"`
|
||||||
User string `json:"name,omitempty"`
|
User string `json:"name,omitempty"`
|
||||||
|
|
|
@ -45,8 +45,3 @@ func (t *Timestamp) UnmarshalJSON(data []byte) (err error) {
|
||||||
func (t Timestamp) Equal(u Timestamp) bool {
|
func (t Timestamp) Equal(u Timestamp) bool {
|
||||||
return t.Time.Equal(u.Time)
|
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)
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue