11<?php
22
3- namespace Devloops \ Typesence ;
3+ namespace Typesence ;
44
5- use Devloops \Typesence \Lib \Node ;
6- use GuzzleHttp \Exception \GuzzleException ;
7- use Devloops \Typesence \Lib \Configuration ;
5+ use \Typesence \Lib \Node ;
6+ use \Typesence \Lib \Configuration ;
87use GuzzleHttp \Exception \ClientException ;
98use GuzzleHttp \Exception \RequestException ;
10- use Devloops \Typesence \Exceptions \ServerError ;
11- use Devloops \Typesence \Exceptions \ObjectNotFound ;
12- use Devloops \Typesence \Exceptions \RequestMalformed ;
13- use Devloops \Typesence \Exceptions \HTTPStatus0Error ;
14- use Devloops \Typesence \Exceptions \ServiceUnavailable ;
15- use Devloops \Typesence \Exceptions \RequestUnauthorized ;
16- use Devloops \Typesence \Exceptions \ObjectAlreadyExists ;
17- use Devloops \Typesence \Exceptions \ObjectUnprocessable ;
18- use Devloops \Typesence \Exceptions \TypesenseClientError ;
9+ use \Typesence \Exceptions \ServerError ;
10+ use \Typesence \Exceptions \ObjectNotFound ;
11+ use \Typesence \Exceptions \RequestMalformed ;
12+ use \Typesence \Exceptions \HTTPStatus0Error ;
13+ use \Typesence \Exceptions \ServiceUnavailable ;
14+ use \Typesence \Exceptions \RequestUnauthorized ;
15+ use \Typesence \Exceptions \ObjectAlreadyExists ;
16+ use \Typesence \Exceptions \ObjectUnprocessable ;
17+ use \Typesence \Exceptions \TypesenseClientError ;
1918
2019/**
2120 * Class ApiCall
2221 *
23- * @package Devloops \Typesence
22+ * @package \Typesence
2423 * @date 4/5/20
2524 * @author Abdullah Al-Faqeir <abdullah@devloops.net>
2625 */
@@ -35,17 +34,17 @@ class ApiCall
3534 private $ client ;
3635
3736 /**
38- * @var \Devloops\ Typesence\Lib\Configuration
37+ * @var \Typesence\Lib\Configuration
3938 */
4039 private $ config ;
4140
4241 /**
43- * @var array|\Devloops\ Typesence\Lib\Node[]
42+ * @var array|\Typesence\Lib\Node[]
4443 */
4544 private static $ nodes ;
4645
4746 /**
48- * @var \Devloops\ Typesence\Lib\Node
47+ * @var \Typesence\Lib\Node
4948 */
5049 private static $ nearestNode ;
5150
@@ -57,7 +56,7 @@ class ApiCall
5756 /**
5857 * ApiCall constructor.
5958 *
60- * @param \Devloops\ Typesence\Lib\Configuration $config
59+ * @param \Typesence\Lib\Configuration $config
6160 */
6261 public function __construct (Configuration $ config )
6362 {
@@ -75,11 +74,11 @@ public function __construct(Configuration $config)
7574 private function initializeNodes (): void
7675 {
7776 if (self ::$ nearestNode !== null ) {
78- $ this ->setNodeHealthcheck (self ::$ nearestNode , true );
77+ $ this ->setNodeHealthCheck (self ::$ nearestNode , true );
7978 }
8079
8180 foreach (self ::$ nodes as &$ node ) {
82- $ this ->setNodeHealthcheck ($ node , true );
81+ $ this ->setNodeHealthCheck ($ node , true );
8382 }
8483 }
8584
@@ -89,7 +88,7 @@ private function initializeNodes(): void
8988 * @param bool $asJson
9089 *
9190 * @return string|array
92- * @throws \Devloops\ Typesence\Exceptions\TypesenseClientError
91+ * @throws \Typesence\Exceptions\TypesenseClientError
9392 * @throws \Exception|\GuzzleHttp\Exception\GuzzleException
9493 */
9594 public function get (string $ endPoint , array $ params , bool $ asJson = true )
@@ -106,7 +105,7 @@ public function get(string $endPoint, array $params, bool $asJson = true)
106105 * @param bool $asJson
107106 *
108107 * @return array|string
109- * @throws \Devloops\ Typesence\Exceptions\TypesenseClientError
108+ * @throws \Typesence\Exceptions\TypesenseClientError
110109 * @throws \GuzzleHttp\Exception\GuzzleException
111110 */
112111 public function post (string $ endPoint , $ body , bool $ asJson = true ): array
@@ -121,7 +120,7 @@ public function post(string $endPoint, $body, bool $asJson = true): array
121120 * @param array $body
122121 *
123122 * @return array
124- * @throws \Devloops\ Typesence\Exceptions\TypesenseClientError|\GuzzleHttp\Exception\GuzzleException
123+ * @throws \Typesence\Exceptions\TypesenseClientError|\GuzzleHttp\Exception\GuzzleException
125124 */
126125 public function put (string $ endPoint , array $ body ): array
127126 {
@@ -134,7 +133,7 @@ public function put(string $endPoint, array $body): array
134133 * @param string $endPoint
135134 *
136135 * @return array
137- * @throws \Devloops\ Typesence\Exceptions\TypesenseClientError|\GuzzleHttp\Exception\GuzzleException
136+ * @throws \Typesence\Exceptions\TypesenseClientError|\GuzzleHttp\Exception\GuzzleException
138137 */
139138 public function delete (string $ endPoint ): array
140139 {
@@ -150,7 +149,7 @@ public function delete(string $endPoint): array
150149 * @param array $options
151150 *
152151 * @return string|array
153- * @throws \Devloops\ Typesence\Exceptions\TypesenseClientError|\GuzzleHttp\Exception\GuzzleException
152+ * @throws \Typesence\Exceptions\TypesenseClientError|\GuzzleHttp\Exception\GuzzleException
154153 * @throws \Exception
155154 */
156155 private function makeRequest (string $ method , string $ endPoint , bool $ asJson , array $ options )
@@ -178,7 +177,7 @@ private function makeRequest(string $method, string $endPoint, bool $asJson, arr
178177
179178 $ statusCode = $ response ->getStatusCode ();
180179 if (0 < $ statusCode && $ statusCode < 500 ) {
181- $ this ->setNodeHealthcheck ($ node , true );
180+ $ this ->setNodeHealthCheck ($ node , true );
182181 }
183182
184183 if (!(200 <= $ statusCode && $ statusCode < 300 )) {
@@ -196,20 +195,20 @@ private function makeRequest(string $method, string $endPoint, bool $asJson, arr
196195 ->getStatusCode () === 408 ) {
197196 continue ;
198197 }
199- $ this ->setNodeHealthcheck ($ node , false );
198+ $ this ->setNodeHealthCheck ($ node , false );
200199 throw $ this ->getException ($ exception ->getResponse ()
201200 ->getStatusCode ())
202201 ->setMessage ($ exception ->getMessage ());
203202 } catch (RequestException $ exception ) {
204- $ this ->setNodeHealthcheck ($ node , false );
203+ $ this ->setNodeHealthCheck ($ node , false );
205204 throw $ this ->getException ($ exception ->getResponse ()
206205 ->getStatusCode ())
207206 ->setMessage ($ exception ->getMessage ());
208207 } catch (TypesenseClientError $ exception ) {
209- $ this ->setNodeHealthcheck ($ node , false );
208+ $ this ->setNodeHealthCheck ($ node , false );
210209 throw $ exception ;
211210 } catch (\Exception $ exception ) {
212- $ this ->setNodeHealthcheck ($ node , false );
211+ $ this ->setNodeHealthCheck ($ node , false );
213212 $ last_exception = $ exception ;
214213 sleep ($ this ->config ->getRetryIntervalSeconds ());
215214 }
@@ -234,14 +233,14 @@ private function getRequestOptions(): array
234233 }
235234
236235 /**
237- * @param \Devloops\ Typesence\Lib\Node $node
236+ * @param \Typesence\Lib\Node $node
238237 *
239238 * @return bool
240239 */
241240 private function nodeDueForHealthCheck (Node $ node ): bool
242241 {
243242 $ currentTimestamp = time ();
244- $ checkNode = ($ currentTimestamp - $ node ->getLastAccessTs ()) > $ this ->config ->getHealthcheckIntervalSeconds ();
243+ $ checkNode = ($ currentTimestamp - $ node ->getLastAccessTs ()) > $ this ->config ->getHealthCheckIntervalSeconds ();
245244 if ($ checkNode ) {
246245 //
247246 }
@@ -250,10 +249,10 @@ private function nodeDueForHealthCheck(Node $node): bool
250249 }
251250
252251 /**
253- * @param \Devloops\ Typesence\Lib\Node $node
252+ * @param \Typesence\Lib\Node $node
254253 * @param bool $isHealthy
255254 */
256- public function setNodeHealthcheck (Node $ node , bool $ isHealthy ): void
255+ public function setNodeHealthCheck (Node $ node , bool $ isHealthy ): void
257256 {
258257 $ node ->setHealthy ($ isHealthy );
259258 $ node ->setLastAccessTs (time ());
@@ -263,7 +262,7 @@ public function setNodeHealthcheck(Node $node, bool $isHealthy): void
263262 * Returns a healthy host from the pool in a round-robin fashion
264263 * Might return an unhealthy host periodically to check for recovery.
265264 *
266- * @return \Devloops\ Typesence\Lib\Node
265+ * @return \Typesence\Lib\Node
267266 */
268267 public function getNode (): Lib \Node
269268 {
@@ -292,7 +291,7 @@ public function getNode(): Lib\Node
292291 /**
293292 * @param int $httpCode
294293 *
295- * @return \Devloops\ Typesence\Exceptions\TypesenseClientError
294+ * @return \Typesence\Exceptions\TypesenseClientError
296295 */
297296 public function getException (int $ httpCode ): TypesenseClientError
298297 {
0 commit comments