@@ -45,7 +45,7 @@ class Api
4545 *
4646 * @var string
4747 */
48- private static $ binding_version = '1.2 .0 ' ;
48+ private static $ binding_version = '1.3 .0 ' ;
4949
5050 /**
5151 * User key (required for Rosette API).
@@ -96,13 +96,6 @@ class Api
9696 */
9797 private $ ms_between_retries ;
9898
99- /**
100- * request override - for testing
101- *
102- * @RosetteRequest
103- */
104- private $ mock_request ;
105-
10699 /**
107100 * internal options array
108101 * @var array
@@ -115,6 +108,11 @@ class Api
115108 */
116109 private $ customHeaders ;
117110
111+ /**
112+ * internal Request object
113+ * @var array
114+ */
115+ private $ request ;
118116
119117 /**
120118 * Create an L{API} object.
@@ -143,7 +141,7 @@ public function __construct($user_key, $service_url = 'https://api.rosette.com/
143141 $ this ->subUrl = null ;
144142 $ this ->max_retries = 5 ;
145143 $ this ->ms_between_retries = 500000 ;
146- $ this ->mock_request = null ;
144+ $ this ->request = new RosetteRequest () ;
147145 $ this ->options = array ();
148146 }
149147
@@ -154,7 +152,7 @@ public function __construct($user_key, $service_url = 'https://api.rosette.com/
154152 */
155153 public function setMockRequest ($ requestObject )
156154 {
157- $ this ->mock_request = $ requestObject ;
155+ $ this ->request = $ requestObject ;
158156 }
159157
160158 /**
@@ -368,6 +366,17 @@ public function clearCustomHeaders()
368366 }
369367
370368
369+ /**
370+ * Returns the max connections (concurrency)
371+ *
372+ * @return int
373+ */
374+ public function getMaxConnections ()
375+ {
376+ return $ this ->request ->getMaxConnections ();
377+ }
378+
379+
371380 /**
372381 * Replaces a header item with a new one
373382 */
@@ -448,25 +457,25 @@ private function callEndpoint($parameters, $subUrl)
448457 */
449458 private function makeRequest ($ url , $ headers , $ data , $ method )
450459 {
451- $ request = $ this ->mock_request != null ? $ this ->mock_request : new RosetteRequest ();
452460 for ($ retries = 0 ; $ retries < $ this ->max_retries ; $ retries ++) {
453- if ($ request ->makeRequest ($ url , $ headers , $ data , $ method ) === false ) {
454- throw new RosetteException ($ request ->getResponseError );
461+ if ($ this -> request ->makeRequest ($ url , $ headers , $ data , $ method ) === false ) {
462+ throw new RosetteException ($ this -> request ->getResponseError );
455463 } else {
456- $ this ->setResponseCode ($ request ->getResponseCode ());
464+ $ this ->setResponseCode ($ this -> request ->getResponseCode ());
457465 if ($ this ->getResponseCode () === 429 ) {
466+ print ('429 RETRY ' );
458467 usleep ($ this ->ms_between_retries );
459468 continue ;
460469 } elseif ($ this ->getResponseCode () !== 200 ) {
461- throw new RosetteException ($ request ->getResponse ()['message ' ], $ this ->getResponseCode ());
470+ throw new RosetteException ($ this -> request ->getResponse ()['message ' ], $ this ->getResponseCode ());
462471 }
463- return $ request ->getResponse ();
472+ return $ this -> request ->getResponse ();
464473 }
465474 }
466475 if ($ this ->getResponseCode () !== 200 ) {
467- throw new RosetteException ($ request ->getResponse ()['message ' ], $ this ->getResponseCode ());
476+ throw new RosetteException ($ this -> request ->getResponse ()['message ' ], $ this ->getResponseCode ());
468477 } else {
469- return $ request ->getResponse ();
478+ return $ this -> request ->getResponse ();
470479 }
471480 }
472481
@@ -607,24 +616,25 @@ public function morphology($params, $facet = null)
607616 return $ this ->callEndpoint ($ params , 'morphology/ ' . $ facet );
608617 }
609618
610- /* Calls the entities endpoint.
611- *
612- * @param $params
613- * @param $resolve_entities
614- *
615- * @return mixed
616- *
617- * @throws RosetteException
618- */
619- public function entities ($ params , $ resolve_entities = false )
620- {
619+ /**
620+ * Calls the entities endpoint.
621+ *
622+ * @param $params
623+ * @param $resolve_entities
624+ *
625+ * @return mixed
626+ *
627+ * @throws RosetteException
628+ */
629+ public function entities ($ params , $ resolve_entities = false )
630+ {
621631 if ($ resolve_entities == true ) {
622632 error_reporting (E_DEPRECATED );
623633 return $ this ->callEndpoint ($ params , 'entities/linked ' );
624634 } else {
625635 return $ this ->callEndpoint ($ params , 'entities ' );
626636 }
627- }
637+ }
628638
629639
630640 /**
@@ -696,4 +706,18 @@ public function relationships($params)
696706 {
697707 return $ this ->callEndpoint ($ params , 'relationships ' );
698708 }
709+
710+ /**
711+ * Calls the text-embedding endpoint.
712+ *
713+ * @param $params
714+ *
715+ * @return mixed
716+ *
717+ * @throws RosetteException
718+ */
719+ public function textEmbedding ($ params )
720+ {
721+ return $ this ->callEndpoint ($ params , 'text-embedding ' );
722+ }
699723}
0 commit comments