@@ -30,9 +30,10 @@ public function __construct(Config $config, ?ClientInterface $httpClient = null)
3030
3131 $ this ->httpClient = $ httpClient ?? new GuzzleClient ([
3232 'base_uri ' => $ config ->getBasePath (),
33- 'timeout ' => 30 ,
34- 'connect_timeout ' => 10 ,
33+ 'timeout ' => $ config -> getTimeout () ,
34+ 'connect_timeout ' => $ config -> getConnectTimeout () ,
3535 'http_errors ' => false ,
36+ 'verify ' => $ config ->getVerifySSL (),
3637 ]);
3738
3839 $ this ->defaultHeaders = [
@@ -79,11 +80,22 @@ public function makeRequest(
7980 $ pathWithQuery .= '? ' . http_build_query ($ queryParams );
8081 }
8182
82- $ token = $ this ->generateToken ($ method , $ pathWithQuery , $ requestBody );
83+ if ($ endpointPath !== null ) {
84+ $ url = $ endpointPath ;
85+ if (!empty ($ queryParams )) {
86+ $ url .= '? ' . http_build_query ($ queryParams );
87+ }
88+ } else {
89+ $ url = $ this ->config ->getBasePath () . $ pathWithQuery ;
90+ }
91+
92+ $ tokenPath = $ endpointPath !== null
93+ ? parse_url ($ endpointPath , PHP_URL_PATH ) . (parse_url ($ endpointPath , PHP_URL_QUERY ) ? '? ' . parse_url ($ endpointPath , PHP_URL_QUERY ) : '' )
94+ : $ pathWithQuery ;
95+
96+ $ token = $ this ->generateToken ($ method , $ tokenPath , $ requestBody );
8397 $ headers ['Authorization ' ] = 'Bearer ' . $ token ;
8498
85- $ url = $ this ->config ->getBasePath () . $ pathWithQuery ;
86-
8799 $ requestPayload = null ;
88100 if ($ requestBody !== null ) {
89101 $ requestPayload = is_string ($ requestBody ) ? $ requestBody : json_encode ($ requestBody );
@@ -118,31 +130,6 @@ public function getConfig(): Config
118130 return $ this ->config ;
119131 }
120132
121- public function buildAcceptHeader (array $ accept ): ?string
122- {
123- if (empty ($ accept )) {
124- return null ;
125- }
126-
127- if (in_array ('application/json ' , $ accept , true )) {
128- return 'application/json ' ;
129- }
130-
131- return implode (', ' , $ accept );
132- }
133-
134- public function buildContentTypeHeader (array $ contentTypes ): string
135- {
136- if (empty ($ contentTypes )) {
137- return 'application/json ' ;
138- }
139-
140- if (in_array ('application/json ' , $ contentTypes , true )) {
141- return 'application/json ' ;
142- }
143-
144- return $ contentTypes [0 ];
145- }
146133
147134 /**
148135 * Generate JWT for api auth
@@ -236,74 +223,4 @@ private function handleApiError(int $statusCode, string $body, array $headers):
236223 }
237224 }
238225
239- public static function sanitizeForSerialization ($ data )
240- {
241- if (is_scalar ($ data ) || null === $ data ) {
242- return $ data ;
243- }
244-
245- if ($ data instanceof \DateTime) {
246- return $ data ->format (\DateTime::ATOM );
247- }
248-
249- if (is_array ($ data )) {
250- foreach ($ data as $ property => $ value ) {
251- $ data [$ property ] = self ::sanitizeForSerialization ($ value );
252- }
253- return $ data ;
254- }
255-
256- if (is_object ($ data )) {
257- $ values = [];
258- if ($ data instanceof \JsonSerializable) {
259- $ values = $ data ->jsonSerialize ();
260- } else {
261- $ values = (array ) $ data ;
262- }
263- foreach ($ values as $ property => $ value ) {
264- $ values [$ property ] = self ::sanitizeForSerialization ($ value );
265- }
266- return $ values ;
267- }
268-
269- return (string ) $ data ;
270- }
271-
272- public static function processFormData (array $ formData , array $ files = []): array
273- {
274- $ processedData = [];
275-
276- foreach ($ formData as $ name => $ value ) {
277- if (is_array ($ value )) {
278- foreach ($ value as $ item ) {
279- $ processedData [] = [
280- 'name ' => $ name . '[] ' ,
281- 'contents ' => $ item
282- ];
283- }
284- } else {
285- $ processedData [] = [
286- 'name ' => $ name ,
287- 'contents ' => $ value
288- ];
289- }
290- }
291-
292- foreach ($ files as $ name => $ file ) {
293- if (is_array ($ file )) {
294- $ processedData [] = [
295- 'name ' => $ name ,
296- 'contents ' => $ file ['contents ' ] ?? '' ,
297- 'filename ' => $ file ['filename ' ] ?? $ name
298- ];
299- } else {
300- $ processedData [] = [
301- 'name ' => $ name ,
302- 'contents ' => $ file
303- ];
304- }
305- }
306-
307- return $ processedData ;
308- }
309226}
0 commit comments