Skip to content

Commit 4df8740

Browse files
Merge pull request #57 from simonbronner/move-to-user-id-api-endpoint
Moved to use the new /api/admin/user/id/<user_ID> endpoint - available in 1.0.184
2 parents aaab4ef + 4bfea96 commit 4df8740

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

client/user.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package client
22

33
import (
4-
"errors"
54
"fmt"
65
"log"
76
)
@@ -234,18 +233,27 @@ func (client *Client) GetAllUsers() (*[]User, error) {
234233

235234
func (client *Client) GetUserByID(userId string) (*User, error) {
236235

237-
users, err := client.GetAllUsers()
236+
opts := RequestOptions{
237+
Path: fmt.Sprintf("/admin/user/id/%s", userId),
238+
Method: "GET",
239+
}
240+
241+
resp, err := client.RequestAPI(&opts)
242+
238243
if err != nil {
239244
return nil, err
240245
}
241246

242-
for _, user := range *users {
243-
if user.ID == userId {
244-
return &user, nil
245-
}
247+
var user User
248+
249+
err = DecodeResponseInto(resp, &user)
250+
251+
if err != nil {
252+
return nil, err
246253
}
247254

248-
return nil, errors.New(fmt.Sprintf("[ERROR] User with ID %s wasn't found.", userId))
255+
return &user, nil
256+
249257
}
250258

251259
func (client *Client) DeleteUser(userName string) error {

0 commit comments

Comments
 (0)