File tree Expand file tree Collapse file tree 2 files changed +61
-0
lines changed Expand file tree Collapse file tree 2 files changed +61
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments