Skip to content

Commit ae93946

Browse files
committed
CodemashLog.
1 parent bc14ac1 commit ae93946

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

src/CodemashLog.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace Codemash;
4+
5+
use Codemash\Exceptions\RequestValidationException;
6+
use Codemash\Params\CodemashLogParams;
7+
use GuzzleHttp\Exception\GuzzleException;
8+
9+
class CodemashLog
10+
{
11+
private CodemashClient $client;
12+
private string $uriPrefix = 'v2/';
13+
14+
public function __construct(CodemashClient $client)
15+
{
16+
$this->client = $client;
17+
}
18+
19+
/**
20+
* @throws GuzzleException
21+
* @throws RequestValidationException
22+
*/
23+
public function create(array $params): string
24+
{
25+
$params = CodemashLogParams::prepCreateParams($params);
26+
27+
$response = $this->client->request('POST', $this->uriPrefix . 'logs', [
28+
'headers' => [
29+
'Accept' => 'application/json',
30+
'Content-Type' => 'application/json',
31+
],
32+
'body' => toJson($params),
33+
]);
34+
35+
return $response['result'];
36+
}
37+
}

src/Params/CodemashLogParams.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Codemash\Params;
4+
5+
use Codemash\Exceptions\RequestValidationException;
6+
7+
class CodemashLogParams
8+
{
9+
/**
10+
* @throws RequestValidationException
11+
*/
12+
public static function prepCreateParams(array $params): array
13+
{
14+
$required = ['message'];
15+
16+
validateRequiredRequestParams($required, $params);
17+
18+
return [
19+
'message' => $params['message'],
20+
'items' => $params['items'] ?? null,
21+
'level' => $params['level'] ?? null,
22+
];
23+
}
24+
}

0 commit comments

Comments
 (0)