0

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.

mpemburn
  • 2,776
  • 1
  • 35
  • 41
  • I am a bit confused why you have to use Guzzle commands to make requests. Could you elaborate? – ncla Feb 08 '19 at 12:10
  • Do you mean, as opposed to using curl? There are a lot of things in Guzzle that I'd have to hand code if not. I'm pretty committed to Guzzle at this point. What did you have in mind? – mpemburn Feb 08 '19 at 18:54
  • No. I think you are using the wrong package for Guzzle. You are suppose to use 'GuzzleHttp\Client' for Client, not 'GuzzleHttp\Command\Guzzle\GuzzleClient' from here https://github.com/guzzle/guzzle/ I am not too sure, but that's how you usually make requests. – ncla Feb 08 '19 at 19:58
  • Thanks—I'll give that a look. – mpemburn Feb 11 '19 at 18:56

0 Answers0