Browse Source

new node creation function

dev
Cerys 3 weeks ago
parent
commit
1243d16376
  1. 24
      src/Core/DeegraphServer.php
  2. 12
      src/DataStructures/NewNodeDetails.php

24
src/Core/DeegraphServer.php

@ -5,6 +5,7 @@ namespace Darksparrow\DeegraphInteractions\Core;
use Auxilium\Exceptions\DatabaseConnectionException; use Auxilium\Exceptions\DatabaseConnectionException;
use Auxilium\Exceptions\DeegraphException; use Auxilium\Exceptions\DeegraphException;
use Darksparrow\DeegraphInteractions\DataStructures\DeegraphNodeDetails; use Darksparrow\DeegraphInteractions\DataStructures\DeegraphNodeDetails;
use Darksparrow\DeegraphInteractions\DataStructures\NewNodeDetails;
use Darksparrow\DeegraphInteractions\DataStructures\ServerInfo; use Darksparrow\DeegraphInteractions\DataStructures\ServerInfo;
use Darksparrow\DeegraphInteractions\DataStructures\UUID; use Darksparrow\DeegraphInteractions\DataStructures\UUID;
use Exception; use Exception;
@ -174,4 +175,27 @@ class DeegraphServer
); );
return new ServerInfo(response: $response); 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);
}
} }

12
src/DataStructures/NewNodeDetails.php

@ -0,0 +1,12 @@
<?php
namespace Darksparrow\DeegraphInteractions\DataStructures;
class NewNodeDetails
{
public UUID $ID;
public function __construct(array $serverResponse)
{
$this->ID = $serverResponse["@id"];
}
}
Loading…
Cancel
Save