|
23 | 23 |
|
24 | 24 | namespace apigatewaycl\api_client; |
25 | 25 |
|
26 | | -use Psr\Http\Message\ResponseInterface; |
27 | 26 | use GuzzleHttp\Psr7\Utils; |
| 27 | +use Psr\Http\Message\ResponseInterface; |
28 | 28 |
|
29 | 29 | /** |
30 | 30 | * Cliente de la API de API Gateway. |
@@ -104,7 +104,7 @@ public function __construct(?string $token = null, ?string $url = null) |
104 | 104 |
|
105 | 105 | $this->api_version = $this->env('APIGATEWAY_API_VERSION') ?? $this->api_version; |
106 | 106 |
|
107 | | - if($this->api_version == 'v1'){ |
| 107 | + if ($this->api_version == 'v1') { |
108 | 108 | $this->api_url = 'https://legacy.apigateway.cl'; |
109 | 109 | $this->authorization = 'Bearer'; |
110 | 110 | } |
@@ -418,19 +418,13 @@ public function consume( |
418 | 418 | 'auth_cache' => (int)$auth_cache, |
419 | 419 | ]); |
420 | 420 |
|
421 | | - // Ejecutar consulta al SII. |
422 | | - try { |
423 | | - // echo $method; |
424 | | - // echo $this->last_url; |
425 | | - // echo $options; |
426 | | - // fwrite(STDERR, $method); |
427 | | - // fwrite(STDERR, $this->last_url); |
428 | | - // fwrite(STDERR, json_encode($options)); |
429 | | - $this->last_response = $client->request( |
430 | | - method: $method, |
431 | | - uri: $this->last_url, |
432 | | - options: $options |
433 | | - ); |
| 421 | + // Ejecutar consulta al SII. |
| 422 | + try { |
| 423 | + $this->last_response = $client->request( |
| 424 | + method: $method, |
| 425 | + uri: $this->last_url, |
| 426 | + options: $options |
| 427 | + ); |
434 | 428 | } catch (\GuzzleHttp\Exception\BadResponseException $e) { |
435 | 429 | // Obtener la respuesta de la llamada. |
436 | 430 | $this->last_response = $e->getResponse(); |
@@ -462,7 +456,7 @@ public function consume( |
462 | 456 |
|
463 | 457 | $response_body = (string) $this->last_response->getBody(); |
464 | 458 | $data = json_decode($response_body, true); |
465 | | - if(json_last_error() === JSON_ERROR_NONE && isset($data['data'])){ |
| 459 | + if (json_last_error() === JSON_ERROR_NONE && isset($data['data'])) { |
466 | 460 | $data = $data['data']; |
467 | 461 | $response_data = Utils::streamFor(json_encode($data)); |
468 | 462 | $this->last_response = $this->last_response->withBody($response_data); |
@@ -578,13 +572,13 @@ private function forceUrlParams(string $url, array $params): string |
578 | 572 | (isset($parsedUrl['host']) ? "{$parsedUrl['host']}" : '') . |
579 | 573 | (isset($parsedUrl['port']) ? ":{$parsedUrl['port']}" : '') . |
580 | 574 | (isset($parsedUrl['path']) ? "{$parsedUrl['path']}" : '') . |
581 | | - (isset($parsedUrl['query']) ? "?{$parsedUrl['query']}" : '') . |
| 575 | + ($parsedUrl['query'] !== '' ? "?{$parsedUrl['query']}" : '') . |
582 | 576 | (isset($parsedUrl['fragment']) ? "#{$parsedUrl['fragment']}" : '') |
583 | 577 | ; |
584 | 578 | } |
| 579 | + |
585 | 580 | public function getApiVersion(): string |
586 | 581 | { |
587 | 582 | return $this->api_version; |
588 | 583 | } |
589 | | - |
590 | 584 | } |
0 commit comments