We need to be able to retrieve all pages of Groups data via the Discourse API (https://docs.discourse.org). We're using Guzzle 6, and it would seem to be possible to use the promises system that is part of Guzzle's ServiceClient class to retrieve all pages asynchronously, but there's nothing in the docs to suggest exactly how that's done (https://github.com/guzzle/command/blob/master/README.md). Here's (roughly) what we're doing now.
use GuzzleHttp\Command\Guzzle\GuzzleClient;
use GuzzleHttp\Command\Guzzle\Description;
use Webbj74\JSDL\Loader\ServiceDescriptionLoader;
/**
* @return GuzzleClient|null
*/
public function getClient()
{
$config = [
'base_uri' => 'https://connect.mycompany.org',
'api_key' => 'XYZ',
'api_username' => 'system',
];
$client = new Client($config);
$this->serviceDescription = $this->loadServiceDescription();
if (! empty($this->serviceDescription)) {
$this->client = new GuzzleClient($client, $this->serviceDescription);
return $this->client;
}
return null;
}
/**
* @return Description|null
*/
protected function loadServiceDescription()
{
$loader = new ServiceDescriptionLoader();
try {
$serviceDescription = new Description($loader->load($path = self::SERVICE_JSON));
return $serviceDescription;
} catch (\Exception $e) {
$errorMessage = $e->getMessage();
Logger::log('Error: ' . $errorMessage, 'ERROR', true);
}
return null;
}
The service description includes this:
{
"operations": {
"Groups": {
"extends": "discourse.base",
"httpMethod": "GET",
"uri": "/groups.json"
}
}
Any guidance would be deeply appreciated.