diff --git a/src/Core/DeegraphServer.php b/src/Core/DeegraphServer.php index de67d25..1e4339b 100644 --- a/src/Core/DeegraphServer.php +++ b/src/Core/DeegraphServer.php @@ -2,7 +2,9 @@ namespace Darksparrow\DeegraphInteractions\Core; +use Darksparrow\DeegraphInteractions\DataStructures\DeegraphNodeDetails; use Darksparrow\DeegraphInteractions\DataStructures\ServerInfo; +use Darksparrow\DeegraphInteractions\DataStructures\UUID; class DeegraphServer { @@ -36,10 +38,10 @@ class DeegraphServer public function ServerInfo(): ServerInfo { $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}"); curl_setopt($ch, CURLOPT_HTTPHEADER, [ @@ -74,6 +76,17 @@ class DeegraphServer 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); } } diff --git a/src/DataStructures/DeegraphNodeDetails.php b/src/DataStructures/DeegraphNodeDetails.php new file mode 100644 index 0000000..e24092a --- /dev/null +++ b/src/DataStructures/DeegraphNodeDetails.php @@ -0,0 +1,52 @@ +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); + } +} diff --git a/src/DataStructures/ServerInfo.php b/src/DataStructures/ServerInfo.php index 668475d..fd0eddf 100755 --- a/src/DataStructures/ServerInfo.php +++ b/src/DataStructures/ServerInfo.php @@ -8,16 +8,10 @@ class ServerInfo public string $InstanceFQDN; public array $PublicKeys; - public static function FromAPIResponse(string $response): ServerInfo + public function __construct(array $response) { - $temp = json_decode($response, true); - - $builder = new ServerInfo(); - - $builder->InstanceID = $temp["@instance_id"]; - $builder->InstanceFQDN = $temp["@instance_fqdn"]; - $builder->PublicKeys = $temp["@public_keys"]; - - return $builder; + $this->InstanceID = $response["@instance_id"]; + $this->InstanceFQDN = $response["@instance_fqdn"]; + $this->PublicKeys = $response["@public_keys"]; } } diff --git a/src/QueryBuilder/DeleteQuery/DeleteQuery.php b/src/QueryBuilder/DeleteQuery/DeleteQuery.php index 701d9de..a7bdc50 100644 --- a/src/QueryBuilder/DeleteQuery/DeleteQuery.php +++ b/src/QueryBuilder/DeleteQuery/DeleteQuery.php @@ -25,7 +25,6 @@ class DeleteQuery method: "POST", body: $this->QueryString ); - $temp = json_decode($response, true); - return new DeleteQueryResponse($temp); + return new DeleteQueryResponse($response); } } diff --git a/src/QueryBuilder/DirectoryQuery/DirectoryQuery.php b/src/QueryBuilder/DirectoryQuery/DirectoryQuery.php index 4f20190..e05266c 100644 --- a/src/QueryBuilder/DirectoryQuery/DirectoryQuery.php +++ b/src/QueryBuilder/DirectoryQuery/DirectoryQuery.php @@ -24,7 +24,6 @@ final class DirectoryQuery method: "POST", body: $this->QueryString ); - $temp = json_decode($response, true); - return new DirectoryQueryResponse($temp); + return new DirectoryQueryResponse($response); } } diff --git a/src/QueryBuilder/LinkQuery/LinkQuery.php b/src/QueryBuilder/LinkQuery/LinkQuery.php index a86cc9d..9450ab8 100644 --- a/src/QueryBuilder/LinkQuery/LinkQuery.php +++ b/src/QueryBuilder/LinkQuery/LinkQuery.php @@ -25,7 +25,6 @@ class LinkQuery method: "POST", body: $this->QueryString ); - $temp = json_decode($response, true); - return new LinkQueryResponse($temp); + return new LinkQueryResponse($response); } } \ No newline at end of file diff --git a/src/QueryBuilder/PermissionsQuery/PermissionQuery.php b/src/QueryBuilder/PermissionsQuery/PermissionQuery.php index 1a1ec89..25a54fc 100644 --- a/src/QueryBuilder/PermissionsQuery/PermissionQuery.php +++ b/src/QueryBuilder/PermissionsQuery/PermissionQuery.php @@ -24,7 +24,6 @@ final class PermissionQuery method: "POST", body: $this->QueryString ); - $temp = json_decode($response, true); - return new PermissionQueryResponse($temp); + return new PermissionQueryResponse($response); } } diff --git a/src/QueryBuilder/ReferencesQuery/ReferencesQuery.php b/src/QueryBuilder/ReferencesQuery/ReferencesQuery.php index 07f8ad6..cc7986a 100644 --- a/src/QueryBuilder/ReferencesQuery/ReferencesQuery.php +++ b/src/QueryBuilder/ReferencesQuery/ReferencesQuery.php @@ -24,7 +24,6 @@ final class ReferencesQuery method: "POST", body: $this->QueryString ); - $temp = json_decode($response, true); - return new ReferencesQueryResponse($temp); + return new ReferencesQueryResponse($response); } } diff --git a/src/QueryBuilder/SelectQuery/SelectQuery.php b/src/QueryBuilder/SelectQuery/SelectQuery.php index 7914d13..f15c2fb 100644 --- a/src/QueryBuilder/SelectQuery/SelectQuery.php +++ b/src/QueryBuilder/SelectQuery/SelectQuery.php @@ -24,7 +24,6 @@ class SelectQuery method: "POST", body: $this->QueryString ); - $temp = json_decode($response, true); - return new SelectQueryResponse($temp); + return new SelectQueryResponse($response); } } diff --git a/src/QueryBuilder/UnlinkQuery/UnlinkQuery.php b/src/QueryBuilder/UnlinkQuery/UnlinkQuery.php index 4fd10e2..837d44e 100644 --- a/src/QueryBuilder/UnlinkQuery/UnlinkQuery.php +++ b/src/QueryBuilder/UnlinkQuery/UnlinkQuery.php @@ -25,7 +25,6 @@ class UnlinkQuery method: "POST", body: $this->QueryString ); - $temp = json_decode($response, true); - return new UnlinkQueryResponse($temp); + return new UnlinkQueryResponse($response); } }