Skip to content

Commit

Permalink
Merge branch 'release/1.7.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
Echron committed Mar 27, 2022
2 parents cb58f41 + 7e7fcb6 commit 7ff19c1
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 30 deletions.
32 changes: 8 additions & 24 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
{
Expand Down Expand Up @@ -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()
{
Expand All @@ -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;
}
}
41 changes: 41 additions & 0 deletions src/Endpoint/ConnectionEndpoint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);

namespace Attlaz\Endpoint;

use Attlaz\Client;
use Attlaz\Model\Exception\RequestException;

class ConnectionEndpoint
{
private Client $client;

public function __construct(Client $client)
{
$this->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;
}
}
38 changes: 36 additions & 2 deletions src/Endpoint/LogEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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);

Expand All @@ -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');
}
}
4 changes: 2 additions & 2 deletions src/Model/LogEntry.php → src/Model/Log/LogEntry.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
declare(strict_types=1);

namespace Attlaz\Model;
namespace Attlaz\Model\Log;

class LogEntry implements \JsonSerializable
{
Expand Down Expand Up @@ -34,7 +34,7 @@ public function getDate(): \DateTimeInterface
public function jsonSerialize(): array
{
return [
'logStream' => ['id' => $this->logStreamId->getId()],
'logStream' => ['id' => $this->logStreamId->__toString()],
'date' => $this->date->format(\DateTime::RFC3339_EXTENDED),
'level' => $this->level,
'message' => $this->message,
Expand Down
27 changes: 27 additions & 0 deletions src/Model/Log/LogStream.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);

namespace Attlaz\Model\Log;

class LogStream
{
private LogStreamId $id;
private string $name;

public function __construct(LogStreamId $id, string $name)
{
$this->id = $id;
$this->name = $name;
}

public function getId(): LogStreamId
{
return $this->id;
}

public function getName(): string
{
return $this->name;
}

}
4 changes: 2 additions & 2 deletions src/Model/LogStreamId.php → src/Model/Log/LogStreamId.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
declare(strict_types=1);

namespace Attlaz\Model;
namespace Attlaz\Model\Log;

class LogStreamId
{
Expand All @@ -13,7 +13,7 @@ public function __construct(string $id)
$this->id = $id;
}

public function getId(): string
public function __toString(): string
{
return $this->id;
}
Expand Down

0 comments on commit 7ff19c1

Please sign in to comment.