Create getThing method to remove duplicate code

Signed-off-by: Vartan Benohanian <vartanbeno@gmail.com>
This commit is contained in:
Vartan Benohanian
2020-09-18 11:27:42 -04:00
parent 1eb75d163c
commit e01896137a
7 changed files with 65 additions and 160 deletions
+4 -19
View File
@@ -61,18 +61,11 @@ type Trophy struct {
// Get returns information about the user.
func (s *UserService) Get(ctx context.Context, username string) (*User, *Response, error) {
path := fmt.Sprintf("user/%s/about", username)
req, err := s.client.NewRequest(http.MethodGet, path, nil)
if err != nil {
return nil, nil, err
}
root := new(thing)
resp, err := s.client.Do(ctx, req, root)
t, resp, err := s.client.getThing(ctx, path, nil)
if err != nil {
return nil, resp, err
}
user, _ := root.User()
user, _ := t.User()
return user, resp, nil
}
@@ -380,19 +373,11 @@ func (s *UserService) Trophies(ctx context.Context) ([]*Trophy, *Response, error
// TrophiesOf returns a list of the specified user's trophies.
func (s *UserService) TrophiesOf(ctx context.Context, username string) ([]*Trophy, *Response, error) {
path := fmt.Sprintf("api/v1/user/%s/trophies", username)
req, err := s.client.NewRequest(http.MethodGet, path, nil)
if err != nil {
return nil, nil, err
}
root := new(thing)
resp, err := s.client.Do(ctx, req, root)
t, resp, err := s.client.getThing(ctx, path, nil)
if err != nil {
return nil, resp, err
}
trophies, _ := root.TrophyList()
trophies, _ := t.TrophyList()
return trophies, resp, nil
}