From 1243d16376a3d0ac8e308546f5b546124d920d1e Mon Sep 17 00:00:00 2001 From: Cerys Date: Tue, 3 Dec 2024 23:34:42 +0000 Subject: [PATCH] new node creation function --- src/Core/DeegraphServer.php | 24 ++++++++++++++++++++++++ src/DataStructures/NewNodeDetails.php | 12 ++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/DataStructures/NewNodeDetails.php diff --git a/src/Core/DeegraphServer.php b/src/Core/DeegraphServer.php index 5ba9623..cd83b10 100644 --- a/src/Core/DeegraphServer.php +++ b/src/Core/DeegraphServer.php @@ -5,6 +5,7 @@ namespace Darksparrow\DeegraphInteractions\Core; use Auxilium\Exceptions\DatabaseConnectionException; use Auxilium\Exceptions\DeegraphException; use Darksparrow\DeegraphInteractions\DataStructures\DeegraphNodeDetails; +use Darksparrow\DeegraphInteractions\DataStructures\NewNodeDetails; use Darksparrow\DeegraphInteractions\DataStructures\ServerInfo; use Darksparrow\DeegraphInteractions\DataStructures\UUID; use Exception; @@ -174,4 +175,27 @@ class DeegraphServer ); return new ServerInfo(response: $response); } + + + public function CreatedNewNode( + UUID $actorID, + string $dataURL, + ?string $schema = null, + ?UUID $creator = null + ): NewNodeDetails + { + $body = [ + "@data" => $dataURL, + ]; + if($schema != null) + $body["@schema"] = $schema; + + $response = $this->RunRawRequest( + actorID: $actorID, + endpoint: "/api/v1/@new", + method: "PUT", + body: json_encode($body), + ); + return new NewNodeDetails(serverResponse: $response); + } } diff --git a/src/DataStructures/NewNodeDetails.php b/src/DataStructures/NewNodeDetails.php new file mode 100644 index 0000000..81d6378 --- /dev/null +++ b/src/DataStructures/NewNodeDetails.php @@ -0,0 +1,12 @@ +ID = $serverResponse["@id"]; + } +}