Browse Source

can now get a raw node

dev
Cerys 3 weeks ago
parent
commit
80022987c9
  1. 19
      src/Core/DeegraphServer.php
  2. 52
      src/DataStructures/DeegraphNodeDetails.php
  3. 14
      src/DataStructures/ServerInfo.php
  4. 3
      src/QueryBuilder/DeleteQuery/DeleteQuery.php
  5. 3
      src/QueryBuilder/DirectoryQuery/DirectoryQuery.php
  6. 3
      src/QueryBuilder/LinkQuery/LinkQuery.php
  7. 3
      src/QueryBuilder/PermissionsQuery/PermissionQuery.php
  8. 3
      src/QueryBuilder/ReferencesQuery/ReferencesQuery.php
  9. 3
      src/QueryBuilder/SelectQuery/SelectQuery.php
  10. 3
      src/QueryBuilder/UnlinkQuery/UnlinkQuery.php

19
src/Core/DeegraphServer.php

@ -2,7 +2,9 @@
namespace Darksparrow\DeegraphInteractions\Core; namespace Darksparrow\DeegraphInteractions\Core;
use Darksparrow\DeegraphInteractions\DataStructures\DeegraphNodeDetails;
use Darksparrow\DeegraphInteractions\DataStructures\ServerInfo; use Darksparrow\DeegraphInteractions\DataStructures\ServerInfo;
use Darksparrow\DeegraphInteractions\DataStructures\UUID;
class DeegraphServer class DeegraphServer
{ {
@ -36,10 +38,10 @@ class DeegraphServer
public function ServerInfo(): ServerInfo public function ServerInfo(): ServerInfo
{ {
$response = $this->RunRawRequest(endpoint: "/api/v1/@server_info"); $response = $this->RunRawRequest(endpoint: "/api/v1/@server_info");
return ServerInfo::FromAPIResponse(response: $response); return new ServerInfo(response: $response);
} }
public function RunRawRequest(string $endpoint, string $method = "GET", string $body = null): string public function RunRawRequest(string $endpoint, string $method = "GET", string $body = null): array
{ {
$ch = curl_init("https://{$this->ServerDomain}:{$this->Port}{$endpoint}"); $ch = curl_init("https://{$this->ServerDomain}:{$this->Port}{$endpoint}");
curl_setopt($ch, CURLOPT_HTTPHEADER, [ curl_setopt($ch, CURLOPT_HTTPHEADER, [
@ -74,6 +76,17 @@ class DeegraphServer
curl_close($ch); curl_close($ch);
return $result; $temp = json_decode($result, true);
return $temp;
}
public function GetRawNode(UUID $nodeID): DeegraphNodeDetails
{
$response = $this->RunRawRequest(
endpoint: "/api/v1/{$nodeID}",
method: "GET",
body: null,
);
return new DeegraphNodeDetails($response);
} }
} }

52
src/DataStructures/DeegraphNodeDetails.php

@ -0,0 +1,52 @@
<?php
namespace Darksparrow\DeegraphInteractions\DataStructures;
use DateTime;
class DeegraphNodeDetails
{
public string $ID;
public DateTime $CreatedAt;
public string $CreatorID;
public array $OtherProperties;
public function __construct(array $nodeDetails)
{
$this->ID = $nodeDetails["@id"];
$this->CreatedAt = new DateTime($nodeDetails["@created"]);
$this->CreatorID = $nodeDetails["@creator"];
foreach($nodeDetails as $key=>$value) {
switch($key)
{
case "@id":
$this->ID = $value;
break;
case "@created":
$this->CreatedAt = new DateTime($value);
break;
case "@creator":
$this->CreatorID = $value;
break;
default:
$this->OtherProperties[$key] = $value;
break;
}
}
}
public function AsJSON(): string
{
$builder = [
"@id" => $this->ID,
"@created" => $this->CreatedAt->format(format: 'Y-m-d\TH:i:s.v\Z'),
"@creator" => $this->CreatorID,
];
foreach($this->OtherProperties as $key=>$value) {
$builder[$key] = $value;
}
return json_encode($builder);
}
}

14
src/DataStructures/ServerInfo.php

@ -8,16 +8,10 @@ class ServerInfo
public string $InstanceFQDN; public string $InstanceFQDN;
public array $PublicKeys; public array $PublicKeys;
public static function FromAPIResponse(string $response): ServerInfo public function __construct(array $response)
{ {
$temp = json_decode($response, true); $this->InstanceID = $response["@instance_id"];
$this->InstanceFQDN = $response["@instance_fqdn"];
$builder = new ServerInfo(); $this->PublicKeys = $response["@public_keys"];
$builder->InstanceID = $temp["@instance_id"];
$builder->InstanceFQDN = $temp["@instance_fqdn"];
$builder->PublicKeys = $temp["@public_keys"];
return $builder;
} }
} }

3
src/QueryBuilder/DeleteQuery/DeleteQuery.php

@ -25,7 +25,6 @@ class DeleteQuery
method: "POST", method: "POST",
body: $this->QueryString body: $this->QueryString
); );
$temp = json_decode($response, true); return new DeleteQueryResponse($response);
return new DeleteQueryResponse($temp);
} }
} }

3
src/QueryBuilder/DirectoryQuery/DirectoryQuery.php

@ -24,7 +24,6 @@ final class DirectoryQuery
method: "POST", method: "POST",
body: $this->QueryString body: $this->QueryString
); );
$temp = json_decode($response, true); return new DirectoryQueryResponse($response);
return new DirectoryQueryResponse($temp);
} }
} }

3
src/QueryBuilder/LinkQuery/LinkQuery.php

@ -25,7 +25,6 @@ class LinkQuery
method: "POST", method: "POST",
body: $this->QueryString body: $this->QueryString
); );
$temp = json_decode($response, true); return new LinkQueryResponse($response);
return new LinkQueryResponse($temp);
} }
} }

3
src/QueryBuilder/PermissionsQuery/PermissionQuery.php

@ -24,7 +24,6 @@ final class PermissionQuery
method: "POST", method: "POST",
body: $this->QueryString body: $this->QueryString
); );
$temp = json_decode($response, true); return new PermissionQueryResponse($response);
return new PermissionQueryResponse($temp);
} }
} }

3
src/QueryBuilder/ReferencesQuery/ReferencesQuery.php

@ -24,7 +24,6 @@ final class ReferencesQuery
method: "POST", method: "POST",
body: $this->QueryString body: $this->QueryString
); );
$temp = json_decode($response, true); return new ReferencesQueryResponse($response);
return new ReferencesQueryResponse($temp);
} }
} }

3
src/QueryBuilder/SelectQuery/SelectQuery.php

@ -24,7 +24,6 @@ class SelectQuery
method: "POST", method: "POST",
body: $this->QueryString body: $this->QueryString
); );
$temp = json_decode($response, true); return new SelectQueryResponse($response);
return new SelectQueryResponse($temp);
} }
} }

3
src/QueryBuilder/UnlinkQuery/UnlinkQuery.php

@ -25,7 +25,6 @@ class UnlinkQuery
method: "POST", method: "POST",
body: $this->QueryString body: $this->QueryString
); );
$temp = json_decode($response, true); return new UnlinkQueryResponse($response);
return new UnlinkQueryResponse($temp);
} }
} }

Loading…
Cancel
Save