@@ -35,26 +35,11 @@ class Client
3535 */
3636 protected $ apiSecret ;
3737
38- /**
39- * @var string
40- */
41- protected $ location ;
42-
4338 /**
4439 * @var string
4540 */
4641 protected $ authToken ;
4742
48- /**
49- * @var string
50- */
51- public $ apiVersion ;
52-
53- /**
54- * @var float
55- */
56- public $ timeout ;
57-
5843 /**
5944 * @var array
6045 */
@@ -66,19 +51,25 @@ class Client
6651 protected $ httpRequestHeaders = [];
6752
6853 /**
69- * @var HandlerStack
54+ * @var GuzzleClient
7055 */
71- private $ handler ;
56+ private $ client ;
7257
7358 /**
7459 * @param string $apiKey
7560 * @param string $apiSecret
76- * @param string $apiVersion
77- * @param string $location
61+ * @param string $apiVersion @deprecated will be removed in the next version
62+ * @param string $location @deprecated will be removed in the next version
7863 * @param float $timeout
7964 */
80- public function __construct ($ apiKey , $ apiSecret , $ apiVersion =' v1.0 ' , $ location =' us-east ' , $ timeout =null )
65+ public function __construct ($ apiKey , $ apiSecret , $ apiVersion =null , $ location =null , $ timeout =null )
8166 {
67+ if ($ apiVersion !== null || $ location !== null ) {
68+ $ warn = "\$apiVersion and \$location parameters are deprecated and will be removed in a future version. " ;
69+ $ warn .= "Please provide null to suppress this warning. " ;
70+ trigger_error ($ warn , E_USER_NOTICE );
71+ }
72+
8273 $ this ->apiKey = $ apiKey ?? getenv ("STREAM_KEY " );
8374 $ this ->apiSecret = $ apiSecret ?? getenv ("STREAM_SECRET " );
8475
@@ -87,17 +78,20 @@ public function __construct($apiKey, $apiSecret, $apiVersion='v1.0', $location='
8778 }
8879
8980 if ($ timeout != null ) {
90- $ this -> timeout = $ timeout ;
81+ $ timeout = $ timeout ;
9182 } elseif (getenv ("STREAM_CHAT_TIMEOUT " )) {
92- $ this -> timeout = floatval (getenv ("STREAM_CHAT_TIMEOUT " ));
83+ $ timeout = floatval (getenv ("STREAM_CHAT_TIMEOUT " ));
9384 } else {
94- $ this -> timeout = 3.0 ;
85+ $ timeout = 3.0 ;
9586 }
9687
97- $ this ->apiVersion = $ apiVersion ;
98- $ this ->location = $ location ;
9988 $ this ->authToken = JWT ::encode (["server " =>"true " ], $ this ->apiSecret , 'HS256 ' );
100- $ this ->handler = HandlerStack::create ();
89+ $ this ->client = new GuzzleClient ([
90+ 'base_uri ' => $ this ->getBaseUrl (),
91+ 'timeout ' => $ timeout ,
92+ 'handler ' => HandlerStack::create (),
93+ 'headers ' => ['Accept-Encoding ' => 'gzip ' ],
94+ ]);
10195 }
10296
10397 /** Sets the location for the URL. Deprecated, and will be removed in a future version.
@@ -144,17 +138,12 @@ public function buildRequestUrl($uri)
144138 return "{$ baseUrl }/ {$ uri }" ;
145139 }
146140
147- /**
148- * @return \GuzzleHttp\Client
141+ /** Sets the underlying HTTP client. Make sure you set a base_uri.
142+ * @param \GuzzleHttp\Client $client
149143 */
150- public function getHttpClient ( )
144+ public function setHttpClient ( $ client )
151145 {
152- return new GuzzleClient ([
153- 'base_uri ' => $ this ->getBaseUrl (),
154- 'timeout ' => $ this ->timeout ,
155- 'handler ' => $ this ->handler ,
156- 'headers ' => ['Accept-Encoding ' => 'gzip ' ],
157- ]);
146+ $ this ->client = $ client ;
158147 }
159148
160149 /** Sets a Guzzle HTTP option that add to the request. See `\GuzzleHttp\RequestOptions`.
@@ -193,7 +182,6 @@ protected function getHttpRequestHeaders()
193182 public function makeHttpRequest ($ uri , $ method , $ data = [], $ queryParams = [], $ multipart = [])
194183 {
195184 $ queryParams ['api_key ' ] = $ this ->apiKey ;
196- $ client = $ this ->getHttpClient ();
197185 $ headers = $ this ->getHttpRequestHeaders ();
198186
199187 $ uri = (new Uri ($ this ->buildRequestUrl ($ uri )))
@@ -214,7 +202,7 @@ public function makeHttpRequest($uri, $method, $data = [], $queryParams = [], $m
214202 $ options ['headers ' ] = $ headers ;
215203
216204 try {
217- $ response = $ client ->request ($ method , $ uri , $ options );
205+ $ response = $ this -> client ->request ($ method , $ uri , $ options );
218206 } catch (ClientException $ e ) {
219207 $ response = $ e ->getResponse ();
220208 $ msg = $ response ->getBody ()->getContents ();
0 commit comments