mirror of
https://github.com/quentin-g-dev/afup.git
synced 2026-03-26 10:12:16 +01:00
53 lines
1.4 KiB
PHP
53 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace AppBundle\Slack;
|
|
|
|
use RuntimeException;
|
|
|
|
class UsersClient
|
|
{
|
|
const USER_LIST_API = '/users.list';
|
|
|
|
/**
|
|
* @var string
|
|
*/
|
|
private $token;
|
|
/**
|
|
* @var string
|
|
*/
|
|
private $apiBaseUrl;
|
|
|
|
/**
|
|
* @param string $token Token des API Slack
|
|
* @param string $apiBaseUrl URL de base des API Slack
|
|
*/
|
|
public function __construct($token, $apiBaseUrl)
|
|
{
|
|
$this->token = $token;
|
|
$this->apiBaseUrl = $apiBaseUrl;
|
|
}
|
|
|
|
/**
|
|
* Retourne une page d'utilisateur Slack
|
|
* @param string $cursor curseur pour obtenir la page suivante des utilisateurs Slack
|
|
* @return array
|
|
* @throws RuntimeException
|
|
*/
|
|
public function loadPage($cursor = '')
|
|
{
|
|
$return = file_get_contents(sprintf("%s%s?token=%s&limit=100&cursor=%s", $this->apiBaseUrl, self::USER_LIST_API, $this->token, $cursor));
|
|
if (false === $return) {
|
|
throw new RuntimeException("Erreur lors de l'appel à l'API slack");
|
|
}
|
|
$decodedContent = json_decode($return, true);
|
|
if (false === $decodedContent) {
|
|
throw new RuntimeException("Erreur lecture retour API slack");
|
|
}
|
|
if (false === $decodedContent["ok"]) {
|
|
throw new RuntimeException(sprintf("Erreur sur le retour de l'appel slack : %s",
|
|
$decodedContent['error']));
|
|
}
|
|
return $decodedContent;
|
|
}
|
|
}
|