custom/plugins/OttEmarsysIntegration/src/Client/TpgOneClient.php line 14

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Ott\EmarsysIntegration\Client;
  3. use GuzzleHttp\Client;
  4. class TpgOneClient
  5. {
  6.     private const API_URL 'https://emarsys.taschen24.de/api/v1/';
  7.     public const MEDIA_URL 'https://emarsys.taschen24.de/media/';
  8.     private const ENDPOINT_DEPARTMENTS 'departments/de_DE';
  9.     private const ENDPOINT_SAVE 'save';
  10.     public function getDepartments(): array
  11.     {
  12.         $client = new Client();
  13.         $response $client->get(self::API_URL self::ENDPOINT_DEPARTMENTS);
  14.         if (200 !== $response->getStatusCode()) {
  15.             return [];
  16.         }
  17.         return json_decode($response->getBody()->getContents(), true);
  18.     }
  19.     public function save(array $data): bool
  20.     {
  21.         $client = new Client();
  22.         $response $client->post(self::API_URL self::ENDPOINT_SAVE, [
  23.             'json' => $data,
  24.         ]);
  25.         return 204 === $response->getStatusCode();
  26.     }
  27. }