Skip to content

Commit

Permalink
Merge pull request #57 from simonbronner/move-to-user-id-api-endpoint
Browse files Browse the repository at this point in the history
Moved to use the new /api/admin/user/id/<user_ID> endpoint - available in 1.0.184
  • Loading branch information
pasha-codefresh committed Jul 21, 2021
2 parents aaab4ef + 4bfea96 commit 4df8740
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions client/user.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package client

import (
"errors"
"fmt"
"log"
)
Expand Down Expand Up @@ -234,18 +233,27 @@ func (client *Client) GetAllUsers() (*[]User, error) {

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

users, err := client.GetAllUsers()
opts := RequestOptions{
Path: fmt.Sprintf("/admin/user/id/%s", userId),
Method: "GET",
}

resp, err := client.RequestAPI(&opts)

if err != nil {
return nil, err
}

for _, user := range *users {
if user.ID == userId {
return &user, nil
}
var user User

err = DecodeResponseInto(resp, &user)

if err != nil {
return nil, err
}

return nil, errors.New(fmt.Sprintf("[ERROR] User with ID %s wasn't found.", userId))
return &user, nil

}

func (client *Client) DeleteUser(userName string) error {
Expand Down

0 comments on commit 4df8740

Please sign in to comment.