From a580c4a42c5f54195b77139f94fcf9489327099f Mon Sep 17 00:00:00 2001 From: Christopher Vagnetoft Date: Thu, 24 Apr 2025 15:38:16 +0200 Subject: [PATCH] Group management methods --- composer.json | 3 ++- src/SlotDbClient.php | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 212c640..f06624c 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,8 @@ } ], "require": { - "psr/http-client": "^1.0" + "psr/http-client": "^1.0", + "psr/http-message": "^2.0" }, "require-dev": { "guzzlehttp/guzzle": "^7.9", diff --git a/src/SlotDbClient.php b/src/SlotDbClient.php index 43a9796..e5dcc48 100644 --- a/src/SlotDbClient.php +++ b/src/SlotDbClient.php @@ -162,10 +162,23 @@ class SlotDbClient return $data; } - public function updateGroup(string $groupId, array $props): array + public function createGroup(string $groupId, array $props): array + { + $res = $this->post("/groups", $props); + $data = json_decode($res->getBody(), true); + if (is_array($data) && isset($data['error'])) { + throw new GroupException($data['error']); + } + return $data; + } + + public function updateGroup(string $groupId, array $props): bool { $res = $this->post("/group/{$groupId}", $props); $data = json_decode($res->getBody(), true); + if (is_array($data) && isset($data['error'])) { + throw new GroupException($data['error']); + } return $data; } @@ -196,3 +209,6 @@ class SlotDbClient } } + +class GroupException extends \RuntimeException +{} \ No newline at end of file