| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- declare(strict_types=1);
- namespace App\Service\Mobyt;
- use App\Service\ApiRequestService;
- use JetBrains\PhpStorm\Pure;
- use Symfony\Contracts\HttpClient\HttpClientInterface;
- /**
- * Service d'appel à l'API Mobyt
- */
- class MobytService extends ApiRequestService
- {
- private string $userId;
- private string $sessionKey;
- #[Pure]
- function __construct(
- HttpClientInterface $mobyt_client
- )
- {
- parent::__construct($mobyt_client);
- }
- /**
- * Send a connexion request to mobyt and get the user id and session key from the response
- *
- * @param string $login
- * @param string $password
- * @return void
- */
- private function connect(string $login, string $password): void
- {
- $responseContent = $this->getContent('login', ['username' => $login, 'password' => $password]);
- list($this->userId, $this->sessionKey) = explode(';', $responseContent);
- }
- /**
- * Get a dolibarr society by its opentalent organization id
- *
- * @param int $organizationId
- * @param string $login
- * @param string $password
- * @return array
- */
- public function getUserStatus(int $organizationId, string $login, string $password): array {
- $this->connect($login, $password);
- return $this->getJsonContent(
- 'status',
- ['getMoney' => 'true', 'typeAliases' => 'true'],
- [
- 'headers' => [ 'user_key' => $this->userId, 'Session_key' => $this->sessionKey ]
- ]
- );
- }
- }
|