/** * {@inheritdoc} */ public function flush() { if (0 === $this->queue->count()) { return 0; } $queue = clone $this->queue; $this->queue->clear(); try { $responses = $this->httpAdapter->sendRequests($queue->all()); } catch (MultiHttpAdapterException $e) { // Handle all networking errors: php-http only throws an exception // if no response is available. $collection = new ExceptionCollection(); foreach ($e->getExceptions() as $exception) { // php-http only throws an exception if no response is available if (!$exception->getResponse()) { // Assume networking error if no response was returned. $collection->add(ProxyUnreachableException::proxyUnreachable($exception)); } } foreach ($this->handleErrorResponses($e->getResponses()) as $exception) { $collection->add($exception); } throw $collection; } $exceptions = $this->handleErrorResponses($responses); if (count($exceptions) > 0) { throw new ExceptionCollection($exceptions); } return count($queue); }
/** * @param string $username * * @return \Github\Entities\User */ public function user($username) { $url = $this->base . '/users/' . $username; $response = $this->adapter->sendRequest(new Request('GET', $url)); $body = (string) $response->getBody(); return User::create(json_decode($body, true)); }
/** * {@inheritdoc} */ public function send($endpoint, $payload) { try { $response = $this->httpAdapter->post($endpoint, ['Content-Type' => 'text/xml; charset=UTF-8'], $payload); } catch (HttpAdapterException $e) { throw TransportError::createFromException($e); } if ($response->getStatusCode() !== 200) { throw HttpException::createFromResponse($response); } return (string) $response->getBody(); }