/** * @param Route $route * @return \Generator * @throws \Psr\Log\InvalidArgumentException * @throws \RuntimeException * @throws \OutOfBoundsException * @throws \InvalidArgumentException */ public function request(Route $route) : \Generator { $json = new JsonStream(); $request = $this->prepareRequest($this->gitter->token, $route); $this->logRequest($request, 'Blocking stream'); yield from $json->stream($this->client->send($request, $this->options)->getBody()); }
/** * @param Route $route * @return Observer * @throws \InvalidArgumentException */ public function request(Route $route) : Observer { $observer = new Observer(); $json = new JsonStream(); $request = $this->prepareRequest($this->gitter->token, $route); $this->logRequest($request, 'Non blocking stream'); /** @var Promise $promise */ $promise = $this->client->withOptions(['streaming' => true])->send($request); $promise->then(function (ResponseInterface $response) use($json, $observer) { $this->logResponse($response); /* @var $body ReadableStreamInterface */ $body = $response->getBody(); $body->on('data', function ($chunk) use($json, $observer) { $json->push($chunk, function ($object) use($observer) { $observer->fire($object); }); }); }); return $observer; }