@@ -37,6 +37,7 @@ class Client
3737 const CAINFO = 'cainfo ' ;
3838 const CURLOPT = 'curloptions ' ;
3939 const PLACES_ENABLED = 'placesEnabled ' ;
40+ const FAILING_HOSTS_CACHE = 'failingHostsCache ' ;
4041
4142 /**
4243 * @var ClientContext
@@ -94,12 +95,18 @@ public function __construct($applicationID, $apiKey, $hostsArray = null, $option
9495 case self ::PLACES_ENABLED :
9596 $ this ->placesEnabled = (bool ) $ value ;
9697 break ;
98+ case self ::FAILING_HOSTS_CACHE :
99+ if (! $ value instanceof FailingHostsCache) {
100+ throw new \InvalidArgumentException ('failingHostsCache must be an instance of \AlgoliaSearch\FailingHostsCache. ' );
101+ }
102+ break ;
97103 default :
98104 throw new \Exception ('Unknown option: ' .$ option );
99105 }
100106 }
101107
102- $ this ->context = new ClientContext ($ applicationID , $ apiKey , $ hostsArray , $ this ->placesEnabled );
108+ $ failingHostsCache = isset ($ options [self ::FAILING_HOSTS_CACHE ]) ? $ options [self ::FAILING_HOSTS_CACHE ] : null ;
109+ $ this ->context = new ClientContext ($ applicationID , $ apiKey , $ hostsArray , $ this ->placesEnabled , $ failingHostsCache );
103110 }
104111
105112 /**
@@ -408,13 +415,13 @@ public function initIndex($indexName)
408415 }
409416
410417 /**
411- * List all existing user keys with their associated ACLs.
418+ * List all existing API keys with their associated ACLs.
412419 *
413420 * @return mixed
414421 *
415422 * @throws AlgoliaException
416423 */
417- public function listUserKeys ()
424+ public function listApiKeys ()
418425 {
419426 return $ this ->request (
420427 $ this ->context ,
@@ -429,13 +436,22 @@ public function listUserKeys()
429436 }
430437
431438 /**
432- * Get ACL of a user key.
439+ * @return mixed
440+ * @deprecated use listApiKeys instead
441+ */
442+ public function listUserKeys ()
443+ {
444+ return $ this ->listApiKeys ();
445+ }
446+
447+ /**
448+ * Get ACL of a API key.
433449 *
434450 * @param string $key
435451 *
436452 * @return mixed
437453 */
438- public function getUserKeyACL ($ key )
454+ public function getApiKey ($ key )
439455 {
440456 return $ this ->request (
441457 $ this ->context ,
@@ -450,13 +466,23 @@ public function getUserKeyACL($key)
450466 }
451467
452468 /**
453- * Delete an existing user key.
469+ * @param $key
470+ * @return mixed
471+ * @deprecated use getApiKey instead
472+ */
473+ public function getUserKeyACL ($ key )
474+ {
475+ return $ this ->getApiKey ($ key );
476+ }
477+
478+ /**
479+ * Delete an existing API key.
454480 *
455481 * @param string $key
456482 *
457483 * @return mixed
458484 */
459- public function deleteUserKey ($ key )
485+ public function deleteApiKey ($ key )
460486 {
461487 return $ this ->request (
462488 $ this ->context ,
@@ -471,7 +497,17 @@ public function deleteUserKey($key)
471497 }
472498
473499 /**
474- * Create a new user key.
500+ * @param $key
501+ * @return mixed
502+ * @deprecated use deleteApiKey instead
503+ */
504+ public function deleteUserKey ($ key )
505+ {
506+ return $ this ->deleteApiKey ($ key );
507+ }
508+
509+ /**
510+ * Create a new API key.
475511 *
476512 * @param array $obj can be two different parameters:
477513 * The list of parameters for this key. Defined by an array that
@@ -504,7 +540,7 @@ public function deleteUserKey($key)
504540 *
505541 * @throws AlgoliaException
506542 */
507- public function addUserKey ($ obj , $ validity = 0 , $ maxQueriesPerIPPerHour = 0 , $ maxHitsPerQuery = 0 , $ indexes = null )
543+ public function addApiKey ($ obj , $ validity = 0 , $ maxQueriesPerIPPerHour = 0 , $ maxHitsPerQuery = 0 , $ indexes = null )
508544 {
509545 if ($ obj !== array_values ($ obj )) { // is dict of value
510546 $ params = $ obj ;
@@ -537,7 +573,21 @@ public function addUserKey($obj, $validity = 0, $maxQueriesPerIPPerHour = 0, $ma
537573 }
538574
539575 /**
540- * Update a user key.
576+ * @param $obj
577+ * @param int $validity
578+ * @param int $maxQueriesPerIPPerHour
579+ * @param int $maxHitsPerQuery
580+ * @param null $indexes
581+ * @return mixed
582+ * @deprecated use addApiKey instead
583+ */
584+ public function addUserKey ($ obj , $ validity = 0 , $ maxQueriesPerIPPerHour = 0 , $ maxHitsPerQuery = 0 , $ indexes = null )
585+ {
586+ return $ this ->addApiKey ($ obj , $ validity , $ maxQueriesPerIPPerHour , $ maxHitsPerQuery , $ indexes );
587+ }
588+
589+ /**
590+ * Update an API key.
541591 *
542592 * @param string $key
543593 * @param array $obj can be two different parameters:
@@ -571,7 +621,7 @@ public function addUserKey($obj, $validity = 0, $maxQueriesPerIPPerHour = 0, $ma
571621 *
572622 * @throws AlgoliaException
573623 */
574- public function updateUserKey (
624+ public function updateApiKey (
575625 $ key ,
576626 $ obj ,
577627 $ validity = 0 ,
@@ -608,6 +658,27 @@ public function updateUserKey(
608658 );
609659 }
610660
661+ /**
662+ * @param $key
663+ * @param $obj
664+ * @param int $validity
665+ * @param int $maxQueriesPerIPPerHour
666+ * @param int $maxHitsPerQuery
667+ * @param null $indexes
668+ * @return mixed
669+ * @deprecated use updateApiKey instead
670+ */
671+ public function updateUserKey (
672+ $ key ,
673+ $ obj ,
674+ $ validity = 0 ,
675+ $ maxQueriesPerIPPerHour = 0 ,
676+ $ maxHitsPerQuery = 0 ,
677+ $ indexes = null
678+ ) {
679+ return $ this ->updateApiKey ($ key , $ obj , $ validity , $ maxQueriesPerIPPerHour , $ maxHitsPerQuery , $ indexes );
680+ }
681+
611682 /**
612683 * Send a batch request targeting multiple indices.
613684 *
@@ -918,7 +989,7 @@ public function doRequest(
918989 curl_close ($ curlHandle );
919990
920991 if (intval ($ http_status / 100 ) == 4 ) {
921- throw new AlgoliaException (isset ($ answer ['message ' ]) ? $ answer ['message ' ] : $ http_status . ' error ' );
992+ throw new AlgoliaException (isset ($ answer ['message ' ]) ? $ answer ['message ' ] : $ http_status. ' error ' );
922993 } elseif (intval ($ http_status / 100 ) != 2 ) {
923994 throw new \Exception ($ http_status .': ' .$ response );
924995 }
0 commit comments