diff --git a/src/Client.php b/src/Client.php index 97d8ec4..d535514 100644 --- a/src/Client.php +++ b/src/Client.php @@ -3,12 +3,12 @@ namespace Attlaz; +use Attlaz\Endpoint\ConnectionEndpoint; use Attlaz\Endpoint\LogEndpoint; use Attlaz\Endpoint\StorageEndpoint; use Attlaz\Helper\TokenStorage; use Attlaz\Model\Config; use Attlaz\Model\Exception\RequestException; -use Attlaz\Model\LogEntry; use Attlaz\Model\Project; use Attlaz\Model\ProjectEnvironment; use Attlaz\Model\Task; @@ -33,6 +33,7 @@ class Client private StorageEndpoint $storageEndpoint; private LogEndpoint $logEndpoint; + private ConnectionEndpoint $connectionEndpoint; public function __construct(string $clientId, string $clientSecret, bool $storeToken = false) { @@ -463,29 +464,6 @@ public function getProjectEnvironments(string $projectId): array return $projectEnvironments; } - /** - * @param string $projectId - * @return array[] - * @throws RequestException - */ - public function getConnections(string $projectId): array - { - $uri = '/connections?projectId=' . $projectId; - - $request = $this->createRequest('GET', $uri); - -// $connections = []; - - $response = $this->sendRequest($request); - $rawConnections = $response['data']; -// foreach ($rawEnvironments as $rawEnvironment) { -// $projectEnvironments[] = $this->parseProjectEnvironment($rawEnvironment); -// } -// -// return $projectEnvironments; - - return $rawConnections; - } public function enableDebug() { @@ -501,8 +479,14 @@ public function getStorageEndpoint(): StorageEndpoint { return $this->storageEndpoint; } + public function getLogEndpoint(): LogEndpoint { return $this->logEndpoint; } + + public function getConnectionEndpoint(): ConnectionEndpoint + { + return $this->connectionEndpoint; + } } diff --git a/src/Endpoint/ConnectionEndpoint.php b/src/Endpoint/ConnectionEndpoint.php new file mode 100644 index 0000000..617e000 --- /dev/null +++ b/src/Endpoint/ConnectionEndpoint.php @@ -0,0 +1,41 @@ +client = $client; + } + + /** + * @param string $projectId + * @return array[] + * @throws RequestException + */ + public function getConnections(string $projectId): array + { + $uri = '/project/' . $projectId . '/connections'; + + $request = $this->client->createRequest('GET', $uri); + +// $connections = []; + + $response = $this->client->sendRequest($request); + $rawConnections = $response['data']; +// foreach ($rawEnvironments as $rawEnvironment) { +// $projectEnvironments[] = $this->parseProjectEnvironment($rawEnvironment); +// } +// +// return $projectEnvironments; + + return $rawConnections; + } +} diff --git a/src/Endpoint/LogEndpoint.php b/src/Endpoint/LogEndpoint.php index 451870f..49b081a 100644 --- a/src/Endpoint/LogEndpoint.php +++ b/src/Endpoint/LogEndpoint.php @@ -4,7 +4,9 @@ namespace Attlaz\Endpoint; use Attlaz\Client; -use Attlaz\Model\LogEntry; +use Attlaz\Model\Log\LogEntry; +use Attlaz\Model\Log\LogStream; +use Attlaz\Model\Log\LogStreamId; class LogEndpoint { @@ -19,7 +21,7 @@ public function saveLog(LogEntry $logEntry): LogEntry { $body = $logEntry; - $uri = '/logstreams/' . \base64_encode($logEntry->getLogStreamId()->getId()) . '/logs'; + $uri = '/logstreams/' . \base64_encode($logEntry->getLogStreamId()->__toString()) . '/logs'; $request = $this->client->createRequest('POST', $uri, $body); @@ -34,4 +36,36 @@ public function saveLog(LogEntry $logEntry): LogEntry } throw new \Exception('Unable to save log entry: invalid response'); } + + /** + * @param string $projectId + * @return LogStream[] + * @throws \Attlaz\Model\Exception\RequestException + */ + public function getLogStreams(string $projectId): array + { + + $uri = '/project/' . $projectId . '/logstreams'; + + $request = $this->client->createRequest('GET', $uri); + + $response = $this->client->sendRequest($request); + + + if (isset($response['data'])) { + + $result = []; + foreach ($response['data'] as $logStream) { + + $id = $logStream['id']; + if (\is_array($id)) { + $id = $id['id']; + } + $result[] = new LogStream(new LogStreamId($id), $logStream['name']); + } + + return $result; + } + throw new \Exception('Unable to get log streams: invalid response'); + } } diff --git a/src/Model/LogEntry.php b/src/Model/Log/LogEntry.php similarity index 91% rename from src/Model/LogEntry.php rename to src/Model/Log/LogEntry.php index bd8d178..c7cea20 100644 --- a/src/Model/LogEntry.php +++ b/src/Model/Log/LogEntry.php @@ -1,7 +1,7 @@ ['id' => $this->logStreamId->getId()], + 'logStream' => ['id' => $this->logStreamId->__toString()], 'date' => $this->date->format(\DateTime::RFC3339_EXTENDED), 'level' => $this->level, 'message' => $this->message, diff --git a/src/Model/Log/LogStream.php b/src/Model/Log/LogStream.php new file mode 100644 index 0000000..c1d83c9 --- /dev/null +++ b/src/Model/Log/LogStream.php @@ -0,0 +1,27 @@ +id = $id; + $this->name = $name; + } + + public function getId(): LogStreamId + { + return $this->id; + } + + public function getName(): string + { + return $this->name; + } + +} diff --git a/src/Model/LogStreamId.php b/src/Model/Log/LogStreamId.php similarity index 74% rename from src/Model/LogStreamId.php rename to src/Model/Log/LogStreamId.php index 3bb1177..6ca51ad 100644 --- a/src/Model/LogStreamId.php +++ b/src/Model/Log/LogStreamId.php @@ -1,7 +1,7 @@ id = $id; } - public function getId(): string + public function __toString(): string { return $this->id; }