Add user info endpoint

Signed-off-by: Vartan Benohanian <vartanbeno@gmail.com>
This commit is contained in:
Vartan Benohanian
2020-06-27 00:47:51 -04:00
parent 10214b7eb6
commit 7e3fdfca89
3 changed files with 204 additions and 0 deletions
+19
View File
@@ -8,6 +8,7 @@ import (
// AccountService handles communication with the account
// related methods of the Reddit API.
type AccountService interface {
Info(ctx context.Context) (*User, *Response, error)
Karma(ctx context.Context) ([]SubredditKarma, *Response, error)
Settings(ctx context.Context) (*Settings, *Response, error)
UpdateSettings(ctx context.Context, settings *Settings) (*Settings, *Response, error)
@@ -216,6 +217,24 @@ type Settings struct {
EnableVideoAutoplay *bool `json:"video_autoplay,omitempty"`
}
// Info returns some general information about your account.
func (s *AccountServiceOp) Info(ctx context.Context) (*User, *Response, error) {
path := "api/v1/me"
req, err := s.client.NewRequest(http.MethodGet, path, nil)
if err != nil {
return nil, nil, err
}
root := new(User)
resp, err := s.client.Do(ctx, req, root)
if err != nil {
return nil, resp, err
}
return root, resp, nil
}
// Karma returns a breakdown of your karma per subreddit.
func (s *AccountServiceOp) Karma(ctx context.Context) ([]SubredditKarma, *Response, error) {
path := "api/v1/me/karma"