src/Service/CallApiService.php line 18

  1. <?php
  2. namespace App\Service;
  3. use Symfony\Component\HttpFoundation\Request;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Contracts\HttpClient\HttpClientInterface;
  6. class CallApiService
  7. {
  8.     private $client;
  9.     public function __construct(HttpClientInterface $client)
  10.     {
  11.         $this->client $client;
  12.     }
  13.     public function callApi($page): ?array
  14.     {
  15.         $range "0-9";
  16.         if ($page != null) {
  17.             $max $page;
  18.             $min $max 9;
  19.             $range $min '-' $max;
  20.         }
  21.         $token $this->client->request(
  22.             'POST',
  23.             'https://entreprise.pole-emploi.fr/connexion/oauth2/access_token?realm=%2Fpartenaire',
  24.             [
  25.                 'headers' =>
  26.                 [
  27.                     'Content-Type' => 'application/x-www-form-urlencoded'
  28.                 ],
  29.                 'body' =>
  30.                 [
  31.                     'client_id' => 'PAR_forumindustriebourges_9ee63d8fe636d39dcccd61e7a0bdd1ba8533c68d53fc0ec77b89035bd135569e',
  32.                     'client_secret' => '9bdd37f789dd7ddd36cfc2c5b9f58131beb9241dfc6cc49ac61d38b774626815',
  33.                     'grant_type' => 'client_credentials',
  34.                     'scope' => 'api_offresdemploiv2 o2dsoffre'
  35.                 ]
  36.             ]
  37.         );
  38.         $contentjson_decode($token->getContent(), true);
  39.         $access_token $content['access_token'];
  40.         $response $this->client->request(
  41.             'GET',
  42.             'https://api.pole-emploi.io/partenaire/offresdemploi/v2/offres/search',
  43.             [
  44.                 'headers' =>
  45.                 [
  46.                     'Authorization' => 'Bearer ' $access_token,
  47.                 ],
  48.                 'query' => [
  49.                     'range' => $range,
  50.                     'grandDomaine' => 'H,I,N',
  51.                     'departement' => '18',
  52.                     'sort' => '1',
  53.                 ]
  54.             ]
  55.         );
  56.         $data json_decode($response->getContent(), true);
  57.         return $data;
  58.     }
  59.     public function searchKeyword($motcle,$page)
  60.     {
  61.         $range "0-9";
  62.         if ($page != null) {
  63.             $max $page;
  64.             $min $max 9;
  65.             $range $min '-' $max;
  66.         }
  67.         $motcle str_replace('+'','$motcle);
  68.         // Effectuer la requête à l'API de Pôle emploi
  69.         $token $this->client->request(
  70.             'POST',
  71.             'https://entreprise.pole-emploi.fr/connexion/oauth2/access_token?realm=%2Fpartenaire',
  72.             [
  73.                 'headers' =>
  74.                 [
  75.                     'Content-Type' => 'application/x-www-form-urlencoded'
  76.                 ],
  77.                 'body' =>
  78.                 [
  79.                     'client_id' => 'PAR_forumindustriebourges_9ee63d8fe636d39dcccd61e7a0bdd1ba8533c68d53fc0ec77b89035bd135569e',
  80.                     'client_secret' => '9bdd37f789dd7ddd36cfc2c5b9f58131beb9241dfc6cc49ac61d38b774626815',
  81.                     'grant_type' => 'client_credentials',
  82.                     'scope' => 'api_offresdemploiv2 o2dsoffre'
  83.                 ]
  84.             ]
  85.         );
  86.         $contentjson_decode($token->getContent(), true);
  87.         $access_token $content['access_token'];
  88.         $response $this->client->request(
  89.             'GET',
  90.             'https://api.pole-emploi.io/partenaire/offresdemploi/v2/offres/search',
  91.             [
  92.                 'headers' =>
  93.                 [
  94.                     'Authorization' => 'Bearer ' $access_token,
  95.                 ],
  96.                 'query' => [
  97.                     'range' => $range,
  98.                     'grandDomaine' => 'H,I,N',
  99.                     'departement' => '18',
  100.                     'motsCles' => $motcle
  101.                 ]
  102.             ]
  103.         );
  104.         $data json_decode($response->getContent(), true);
  105.         return $data;
  106.     }
  107. }