summaryrefslogtreecommitdiff
path: root/grocy/user.go
diff options
context:
space:
mode:
Diffstat (limited to 'grocy/user.go')
-rw-r--r--grocy/user.go53
1 files changed, 53 insertions, 0 deletions
diff --git a/grocy/user.go b/grocy/user.go
new file mode 100644
index 0000000..58d3d08
--- /dev/null
+++ b/grocy/user.go
@@ -0,0 +1,53 @@
+package grocy
+
+import (
+ "context"
+ "fmt"
+ "net/http"
+)
+
+type (
+ User struct {
+ Id int `json:"id"`
+ Username string `json:"username"`
+ FirstName string `json:"first_name"`
+ LastName string `json:"last_name"`
+ RowCreated string `json:"row_created_timestamp"`
+ DisplayName string `json:"display_name"`
+ PictureFileName string `json:"picture_file_name"`
+ }
+)
+
+func (c *Client) GetUsers(ctx context.Context) ([]User, error) {
+ req, err := http.NewRequest("GET", fmt.Sprintf("%s/users", c.BaseUrl), nil)
+
+ if err != nil {
+ return nil, err
+ }
+ req.Header.Add("GROCY-API-KEY", c.apiKey)
+ req.WithContext(ctx)
+
+ var res []User
+ if err := c.sendRequest(req, &res); err != nil {
+ return nil, err
+ }
+
+ return res, nil
+}
+
+func (c *Client) GetUserFields(ctx context.Context, userId int) (map[string]string, error) {
+ req, err := http.NewRequest("GET", fmt.Sprintf("%s/userfields/users/%d", c.BaseUrl, userId), nil)
+
+ if err != nil {
+ return nil, err
+ }
+
+ req.WithContext(ctx)
+
+ var res map[string]string
+ if err := c.sendRequest(req, &res); err != nil {
+ return nil, err
+ }
+
+ return res, nil
+}