From bac86a4e701bfbf8eba08eca5fd610aecd9096f2 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Thu, 17 Jul 2025 14:37:08 +0200 Subject: [PATCH] try #7646 @1 --- src/Api.php | 62 ++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 52 insertions(+), 10 deletions(-) diff --git a/src/Api.php b/src/Api.php index 9041238..f2c853f 100644 --- a/src/Api.php +++ b/src/Api.php @@ -1,30 +1,34 @@ client = new Client(); - $response = $this->client->request('POST', self::AUTH_URL, - ['body' => $this->_authRequest($siret, $name, $firstname, $password, $service), 'headers' => ['Content-Type' => 'application/xml', 'User-Agent' => self::USER_AGENT]] - ); - dddd($response); + $this->token = cache()->remember('dsn_' . $siret, 7200, function () use ($siret, $name, $firstname, $password, $service) { + $response = $this->_request('POST', self::AUTH_URL, + ['body' => $this->_authRequest($siret, $name, $firstname, $password, $service), 'headers' => ['Content-Type' => 'application/xml', 'User-Agent' => self::USER_AGENT]] + ); + return $response->getBody()->getContents(); + }); } protected function _authRequest($siret, $name, $firstname, $password, $service = 25) @@ -37,4 +41,42 @@ class Api ' . $service . ' '; } + + public function listSubmissions($timestamp = '') + { + return $this->_json($this->_request('GET', self::SUBMISSIONS_LIST_URL . $timestamp)); + } + + public function getFeedbacks($id) + { + return $this->_json($this->_request('GET', self::FEEDBACKS_LIST_URL . '/' . $id)); + } + + /** + * @param $method + * @param $uri + * @param $options + * @return \Psr\Http\Message\ResponseInterface|void + * @throws \GuzzleHttp\Exception\GuzzleException + */ + protected function _request($method, $uri, $options = []) + { + if (!isset($options['headers'])) { + $options['headers'] = []; + } + $options['headers']['User-Agent'] = self::USER_AGENT; + if ($this->token) { + $options['headers']['Authorization'] = 'DSNLogin jeton=' . $this->token; + } + try { + return $this->client->request($method, $uri, $options); + } catch (\GuzzleHttp\Exception\ClientException $e) { + dd($e); + } + } + + protected function _json($response) + { + return json_decode($response->getBody()->getContents()); + } } \ No newline at end of file -- 2.39.5