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;
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);
}
}

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 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"];
}
}

3
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);
}
}

3
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);
}
}

3
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);
}
}

3
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);
}
}

3
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);
}
}

3
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);
}
}

3
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);
}
}

Loading…
Cancel
Save