11<?php
22
3+ declare (strict_types=1 );
4+
35namespace Slvler \Cuttly ;
46
57use Illuminate \Contracts \Container \Container ;
6-
8+ use InvalidArgumentException ;
9+ use Slvler \Cuttly \Exceptions \MissingApiKey ;
710
811class Cuttly extends CuttlyApiWrapper
912{
1013 public array $ data ;
1114
1215 public function __construct (Container $ app )
1316 {
14- parent ::__construct (
15- [
16- 'base_uri ' => $ app ['config ' ]->get ('cuttly.base_uri ' )
17- ]
18- );
17+ $ apiKey = $ app ['config ' ]->get ('cuttly.api_key ' );
18+
19+ if (empty ($ apiKey ) || ! isset ($ apiKey )) {
20+ throw MissingApiKey::create ();
21+ }
22+
23+ $ baseURL = $ app ['config ' ]->get ('cuttly.api_key ' );
24+
25+ if (empty ($ baseURL ) || ! isset ($ baseURL )) {
26+ throw new InvalidArgumentException ('Invalid Cuttly API base URL. ' );
27+ }
1928
20- $ this -> key = $ app [ ' config ' ]-> get ( ' cuttly.api_key ' );
29+ parent :: __construct ( $ baseURL );
2130
31+ $ this ->key = $ apiKey ;
2232 }
2333
2434 public function short (array $ data ): string
@@ -28,8 +38,9 @@ public function short(array $data): string
2838 $ this ->data ['short ' ] = urlencode ($ data ['short ' ]);
2939 $ sendData = http_build_query ($ this ->data );
3040
31- $ response = $ this ->getHttpClient ()->request ('GET ' ,'? ' .$ sendData );
32- $ value = new HttpResponse ($ response );
41+ $ response = $ this ->getHttpClient ()->request ('GET ' , '? ' .$ sendData );
42+ $ value = new HttpResponse ($ response );
43+
3344 return $ value ->getBody ();
3445 }
3546
@@ -40,22 +51,22 @@ public function edit(array $data): string
4051 $ this ->data ['edit ' ] = $ data ['edit ' ];
4152 $ sendData = http_build_query ($ this ->data );
4253
43- $ response = $ this ->getHttpClient ()->request ('GET ' ,'? ' .$ sendData );
44- $ value = new HttpResponse ($ response );
54+ $ response = $ this ->getHttpClient ()->request ('GET ' , '? ' .$ sendData );
55+ $ value = new HttpResponse ($ response );
56+
4557 return $ value ->getBody ();
4658 }
4759
48-
4960 public function stats (array $ data ): string
5061 {
5162 $ this ->data = $ data ;
5263 $ this ->data ['key ' ] = $ this ->key ;
5364 $ this ->data ['stats ' ] = $ data ['stats ' ];
5465 $ sendData = http_build_query ($ this ->data );
5566
56- $ response = $ this ->getHttpClient ()->request ('GET ' ,'? ' .$ sendData );
57- $ value = new HttpResponse ($ response );
67+ $ response = $ this ->getHttpClient ()->request ('GET ' , '? ' .$ sendData );
68+ $ value = new HttpResponse ($ response );
69+
5870 return $ value ->getBody ();
5971 }
60-
6172}
0 commit comments