|
@@ -42,3 +42,20 @@ func GetUser(config APIConfig, username string) (User, error) {
|
|
|
|
|
|
return result.User, nil
|
|
|
}
|
|
|
+
|
|
|
+func getUserByID(config APIConfig, userID int) (User, error) {
|
|
|
+ url := fmt.Sprintf("%s/admin/users/%d.json", config.Endpoint, userID)
|
|
|
+
|
|
|
+ req, _ := newGetRequest(config, url)
|
|
|
+ client := getClient()
|
|
|
+ response, _ := client.Do(req)
|
|
|
+
|
|
|
+ var result *UserResponse
|
|
|
+ json.NewDecoder(response.Body).Decode(&result)
|
|
|
+
|
|
|
+ if result.ErrorType != "" {
|
|
|
+ return User{}, fmt.Errorf("Failed to get discourse user. Error: %s", strings.Join(result.Errors, "; "))
|
|
|
+ }
|
|
|
+
|
|
|
+ return result.User, nil
|
|
|
+}
|