@@ -38,64 +38,18 @@ class Client implements ClientAwareInterface, APIClient
3838 use ClientAwareTrait;
3939
4040 /**
41- * @var APIResource
41+ * @var APIResource|null
4242 */
43- protected $ accountAPI ;
43+ protected ? APIResource $ accountAPI ;
4444
45- /**
46- * @var APIResource
47- */
48- protected $ secretsAPI ;
49-
50- public function __construct (?APIResource $ accountAPI = null , ?APIResource $ secretsAPI = null )
45+ public function __construct (?APIResource $ accountAPI = null )
5146 {
5247 $ this ->accountAPI = $ accountAPI ;
53- $ this ->secretsAPI = $ secretsAPI ;
54- }
55-
56- /**
57- * Shim to handle older instantiations of this class
58- *
59- * @deprecated Will remove in v3
60- */
61- public function getAccountAPI (): APIResource
62- {
63- if (is_null ($ this ->accountAPI )) {
64- $ api = new APIResource ();
65- $ api ->setClient ($ this ->getClient ())
66- ->setBaseUrl ($ this ->getClient ()->getRestUrl ())
67- ->setIsHAL (false )
68- ->setBaseUri ('/account ' )
69- ->setCollectionName ('' );
70- $ this ->accountAPI = $ api ;
71- }
72-
73- return clone $ this ->accountAPI ;
7448 }
7549
7650 public function getAPIResource (): APIResource
7751 {
78- return $ this ->getAccountAPI ();
79- }
80-
81- /**
82- * Shim to handle older instantiations of this class
83- *
84- * @deprecated Will remove in v3
85- */
86- public function getSecretsAPI (): APIResource
87- {
88- if (is_null ($ this ->secretsAPI )) {
89- $ api = new APIResource ();
90- $ api ->setClient ($ this ->getClient ())
91- ->setBaseUrl ($ this ->getClient ()->getApiUrl ())
92- ->setIsHAL (false )
93- ->setBaseUri ('/accounts ' )
94- ->setCollectionName ('' );
95- $ this ->secretsAPI = $ api ;
96- }
97-
98- return clone $ this ->secretsAPI ;
52+ return $ this ->accountAPI ;
9953 }
10054
10155 /**
@@ -105,7 +59,7 @@ public function getSecretsAPI(): APIResource
10559 */
10660 public function getPrefixPricing ($ prefix ): array
10761 {
108- $ api = $ this ->getAccountAPI ();
62+ $ api = $ this ->getAPIResource ();
10963 $ api ->setBaseUri ('/account/get-prefix-pricing/outbound ' );
11064 $ api ->setCollectionName ('prices ' );
11165
@@ -171,7 +125,7 @@ public function getVoicePrice(string $country): VoicePrice
171125 */
172126 protected function makePricingRequest ($ country , $ pricingType ): array
173127 {
174- $ api = $ this ->getAccountAPI ();
128+ $ api = $ this ->getAPIResource ();
175129 $ api ->setBaseUri ('/account/get-pricing/outbound/ ' . $ pricingType );
176130 $ results = $ api ->search (new KeyValueFilter (['country ' => $ country ]));
177131 $ data = $ results ->getPageData ();
@@ -194,7 +148,7 @@ protected function makePricingRequest($country, $pricingType): array
194148 */
195149 public function getBalance (): Balance
196150 {
197- $ data = $ this ->getAccountAPI ()->get ('get-balance ' , [], ['accept ' => 'application/json ' ]);
151+ $ data = $ this ->getAPIResource ()->get ('get-balance ' , [], ['accept ' => 'application/json ' ]);
198152
199153 if (is_null ($ data )) {
200154 throw new ClientException \Server ('No results found ' );
@@ -209,7 +163,8 @@ public function getBalance(): Balance
209163 */
210164 public function topUp ($ trx ): void
211165 {
212- $ api = $ this ->getAccountAPI ();
166+ $ api = $ this ->getAPIResource ();
167+ // @TODO why is this re-setting the base URL
213168 $ api ->setBaseUri ('/account/top-up ' );
214169 $ api ->submit (['trx ' => $ trx ]);
215170 }
@@ -223,7 +178,7 @@ public function topUp($trx): void
223178 */
224179 public function getConfig (): Config
225180 {
226- $ api = $ this ->getAccountAPI ();
181+ $ api = $ this ->getAPIResource ();
227182 $ api ->setBaseUri ('/account/settings ' );
228183 $ body = $ api ->submit ();
229184
@@ -262,7 +217,7 @@ public function updateConfig(array $options): Config
262217 $ params ['drCallBackUrl ' ] = $ options ['dr_callback_url ' ];
263218 }
264219
265- $ api = $ this ->getAccountAPI ();
220+ $ api = $ this ->getAPIResource ();
266221 $ api ->setBaseUri ('/account/settings ' );
267222
268223 $ rawBody = $ api ->submit ($ params );
@@ -281,89 +236,4 @@ public function updateConfig(array $options): Config
281236 $ body ['max-calls-per-second ' ]
282237 );
283238 }
284-
285- /**
286- * @deprecated use the Vonage\Secrets\Client::list method
287- *
288- * @throws ClientExceptionInterface
289- * @throws ClientException\Exception
290- * @throws InvalidResponseException
291- */
292- public function listSecrets (string $ apiKey ): SecretCollection
293- {
294- trigger_error ('Vonage\Account\Client::listSecrets is deprecated, please use the Vonage\Secrets\Client::list method ' , E_USER_DEPRECATED );
295- $ api = $ this ->getSecretsAPI ();
296-
297- $ data = $ api ->get ($ apiKey . '/secrets ' );
298- return new SecretCollection ($ data ['_embedded ' ]['secrets ' ], $ data ['_links ' ]);
299- }
300-
301- /**
302- * @deprecated use the Vonage\Secrets\Client::get method
303- *
304- * @throws ClientExceptionInterface
305- * @throws ClientException\Exception
306- * @throws InvalidResponseException
307- */
308- public function getSecret (string $ apiKey , string $ secretId ): Secret
309- {
310- trigger_error ('Vonage\Account\Client::getSecret is deprecated, please use the Vonage\Secrets\Client::get method ' , E_USER_DEPRECATED );
311- $ api = $ this ->getSecretsAPI ();
312-
313- $ data = $ api ->get ($ apiKey . '/secrets/ ' . $ secretId );
314- return new Secret ($ data );
315- }
316-
317- /**
318- * Create a new account secret
319- *
320- * @deprecated use the Vonage\Secrets\Client::create method
321- *
322- * @throws ClientExceptionInterface
323- * @throws ClientRequestException
324- * @throws ClientException\Exception
325- * @throws InvalidResponseException
326- * @throws ClientValidationException
327- */
328- public function createSecret (string $ apiKey , string $ newSecret ): Secret
329- {
330- trigger_error ('Vonage\Account\Client::createSecret is deprecated, please use the Vonage\Secrets\Client::create method ' , E_USER_DEPRECATED );
331- $ api = $ this ->getSecretsAPI ();
332- $ api ->setBaseUri ('/accounts/ ' . $ apiKey . '/secrets ' );
333-
334- try {
335- $ response = $ api ->create (['secret ' => $ newSecret ]);
336- } catch (ClientRequestException $ e ) {
337- // @deprecated Throw a Validation exception to preserve old behavior
338- // This will change to a general Request exception in the future
339- $ rawResponse = json_decode (@$ e ->getResponse ()->getBody ()->getContents (), true );
340-
341- if (array_key_exists ('invalid_parameters ' , $ rawResponse )) {
342- throw new ClientValidationException (
343- $ e ->getMessage (),
344- $ e ->getCode (),
345- null ,
346- $ rawResponse ['invalid_parameters ' ]
347- );
348- }
349-
350- throw $ e ;
351- }
352-
353- return new Secret ($ response );
354- }
355-
356- /**
357- * @deprecated use the Vonage\Secrets\Client::revoke method
358- *
359- * @throws ClientExceptionInterface
360- * @throws ClientException\Exception
361- */
362- public function deleteSecret (string $ apiKey , string $ secretId ): void
363- {
364- trigger_error ('Vonage\Account\Client::deleteSecret is deprecated, please use the Vonage\Secrets\Client::revoke method ' , E_USER_DEPRECATED );
365- $ api = $ this ->getSecretsAPI ();
366- $ api ->setBaseUri ('/accounts/ ' . $ apiKey . '/secrets ' );
367- $ api ->delete ($ secretId );
368- }
369239}
0 commit comments