send() public method

public send ( Psr\Http\Message\RequestInterface $request, array $options = [] )
$request Psr\Http\Message\RequestInterface
$options array
Example #1
0
 /**
  * @return array
  */
 public function doRequest() : array
 {
     $this->generateRequestOptions();
     $this->authenticator->authenticate($this);
     $request = $this->httpClient->createRequest($this->method, $this->getUrl(), $this->requestOptions);
     return $this->httpClient->send($request)->json();
 }
Example #2
0
 /**
  * Get the result of the http request.
  *
  * @return Response
  */
 protected function getResponse()
 {
     if ($this->response === null) {
         $this->response = $this->client->send($this->request);
     }
     return $this->response;
 }
Example #3
0
 /**
  * Method to handle the Subscribe Request to the Hub
  */
 public function subscribe()
 {
     // Start empty $hubUrl variable
     $hubUrl = '';
     // Check if the Hub URL finishes with a / or not to be able to create the correct subscribe URL
     if (preg_match("/\\/\$/", $this->current_options['hub_url'])) {
         $hubUrl = $this->current_options['hub_url'] . 'subscribe';
     } else {
         $hubUrl = $this->current_options['hub_url'] . '/subscribe';
     }
     // Json Data needed to send to the Hub for Subscription
     $subscribeJson = json_encode(array("callbackUrl" => esc_url($this->callbackUrl), "topicId" => esc_url($this->current_options['topic_url'])), JSON_UNESCAPED_SLASHES);
     $subscribeRequest = $this->guzzleClient->createRequest('POST', $hubUrl);
     $subscribeRequest->setHeader('Content-Type', 'application/json');
     $subscribeRequest->setBody(Stream::factory($subscribeJson));
     $subscribeResponse = $this->guzzleClient->send($subscribeRequest);
     // Check if Response is 200, 202 or 204 and add a log message otherwise log error message
     if (in_array($subscribeResponse->getStatusCode(), array(200, 202, 204))) {
         HubLogger::log('Your Subscription request is being processed. Check back later to see if you are fully Subscribed', $subscribeResponse->getStatusCode());
         return true;
     } else {
         HubLogger::error('Error issuing Subscribe request to the Hub. Please make sure all your details are correct', $subscribeResponse->getStatusCode());
         return false;
     }
 }
Example #4
0
 /**
  * @param \DonePM\ConsoleClient\Http\Commands\Command $command
  *
  * @return mixed|\Psr\Http\Message\ResponseInterface
  */
 public function send(Command $command)
 {
     if ($command instanceof NeedsToken) {
         $command->token($this->token);
     }
     return $this->client->send($command->request());
 }
Example #5
0
 /**
  * @param string $method
  * @param string $uri
  * @param array  $options
  *
  * @return ResponseInterface
  */
 public function request($method, $uri, array $options = [])
 {
     $this->lazyLoadGuzzle();
     $this->lastRequest = $this->guzzle->createRequest($method, $uri, $options);
     $response = $this->guzzle->send($this->lastRequest);
     return $response;
 }
Example #6
0
 /**
  * @param string $path
  * @param array $queryParams
  *
  * @return \StdClass
  *
  * @throws RequestException
  */
 private function get($path, array $queryParams = array())
 {
     $url = self::BASE_URI . $path;
     $request = $this->createHttpRequest('GET', $url, $queryParams);
     $response = $this->httpClient->send($request);
     return $this->parseResponse($response);
 }
 /**
  * @param  Request  $request
  * @return Response
  */
 public function request(Request $request)
 {
     $guzzleRequest = $this->prepareRequest($request);
     /** @var GuzzleResponse $guzzleResponse */
     $guzzleResponse = $this->client->send($guzzleRequest);
     return new Response($guzzleResponse->getProtocolVersion(), (int) $guzzleResponse->getStatusCode(), $guzzleResponse->getReasonPhrase(), HeaderConverter::convertComplexAssociativeToFlatAssociative($guzzleResponse->getHeaders()), (string) $guzzleResponse->getBody());
 }
Example #8
0
 /**
  * Send the request and return the response.
  *
  * @param  Request $request
  * @param  string  $url
  * @return Response
  */
 public function send(Request $request, $url)
 {
     $guzzleRequest = $this->convertRequest($request);
     $guzzleRequest->setUrl($url);
     $guzzleResponse = $this->client->send($guzzleRequest);
     return $this->convertResponse($guzzleResponse);
 }
 /**
  * @param Request $request
  *
  * @dataProvider nonCachableRequestProvider
  */
 public function testItIsNotStupid(Request $request)
 {
     $this->client->send($request);
     // Will not be cached
     $response = $this->client->send($request);
     // Will not come from cache
     $this->assertEquals(CacheMiddleware::HEADER_CACHE_MISS, $response->getHeaderLine(CacheMiddleware::HEADER_CACHE_INFO));
 }
 protected function sendGuzzleRequest($http_verb = 'GET', $url, $data = null)
 {
     if (date(time()) >= Session::get('oauth_token_expiry')) {
         $this->refreshAccessToken();
     }
     $request = $this->client->createRequest($http_verb, $url, ['json' => $data, 'headers' => ['Authorization' => 'Bearer ' . Session::get('access_token')]]);
     return $this->client->send($request)->json();
 }
Example #11
0
File: Rev.php Project: unl/rev_api
 /**
  * Send a request and convert any BadResponseExceptions to a RequestException
  * 
  * @param \GuzzleHttp\Psr7\Request $request
  * @return \Psr\Http\Message\ResponseInterface
  * @throws Exception\RequestException
  */
 protected function sendRequest(Request $request)
 {
     try {
         return $this->http_client->send($request);
     } catch (ClientException $e) {
         throw new Exception\RequestException($e);
     }
 }
Example #12
0
 public function execute($method, $uri, $data)
 {
     $request = $this->guzzleClient->createRequest($method, $uri, $data);
     /** @var ResponseInterface $response */
     /** @noinspection PhpVoidFunctionResultUsedInspection */
     $response = $this->guzzleClient->send($request);
     return new Response($response);
 }
 /**
  * Broadcast the given event.
  *
  * @param  array $channels
  * @param  string $event
  * @param  array $payload
  * @return void
  */
 public function broadcast(array $channels, $event, array $payload = array())
 {
     foreach ($channels as $channel) {
         $payload = ['text' => array_merge(['eventtype' => $event], $payload)];
         $request = $this->client->createRequest('POST', '/pub?id=' . $channel, ['json' => $payload]);
         $response = $this->client->send($request);
     }
 }
Example #14
0
 /**
  * @inheritDoc
  *
  * @param RequestInterface $request request
  *
  * @return ResponseInterface
  */
 public function send(RequestInterface $request)
 {
     $options = array('curl' => []);
     foreach ($this->curlOptions as $option => $value) {
         $options['curl'][constant('CURLOPT_' . strtoupper($option))] = $value;
     }
     $options['verify'] = __DIR__ . '/../../Resources/cert/cacert.pem';
     return $this->client->send($request, $options);
 }
Example #15
0
 /**
  * @param \Psr\Http\Message\RequestInterface $request
  * @param array $options
  *
  * @throws \Spryker\Zed\Payolution\Business\Exception\ApiHttpRequestException
  *
  * @return string
  */
 protected function send($request, array $options = [])
 {
     try {
         $response = $this->client->send($request, $options);
     } catch (RequestException $requestException) {
         throw new ApiHttpRequestException($requestException->getMessage());
     }
     return $response->getBody();
 }
 /**
  * @param $topic string
  * @param $args array|null
  * @param $kwargs array|null
  * @return array JSON decoded response
  * @throws \Exception
  */
 public function publish($topic, array $args = NULL, array $kwargs = NULL)
 {
     $request = $this->client->createRequest('POST', NULL, array('body' => $this->prepareBody($topic, $args, $kwargs), 'query' => $this->prepareQuery()));
     try {
         $response = $this->client->send($request);
     } catch (\Exception $e) {
         throw $e;
     }
     return $response->json();
 }
 /**
  * @param RequestInterface  $request
  * @param ResponseInspector $inspector
  *
  * @return ResponseInterface
  *
  * @internal
  */
 public function send(RequestInterface $request, ResponseInspector $inspector) : ResponseInterface
 {
     try {
         $response = $this->httpClient->send($request);
     } catch (TransferException $e) {
         $this->handleTransferException($e);
     }
     $inspector->inspect($response);
     return $response;
 }
Example #18
0
 /**
  * A simple wrapper for calling any valid service.
  *
  * This function accepts strings so that it is flexible enough to handle
  * new APIs released by CCB without requiring code updates.
  *
  * @param string $httpMethod  Either "GET" or "POST"
  * @param string $serviceName
  * @param array  $args
  *
  * @return SimpleXMLElement
  */
 public function srv($httpMethod, $serviceName, array $args = [])
 {
     $url = "https://{$this->church}.ccbchurch.com/api.php";
     if (!isset($args['query'])) {
         $args['query'] = [];
     }
     $args['query']['srv'] = $serviceName;
     $request = $this->client->createRequest($httpMethod, $url, $args);
     return $this->client->send($request)->xml();
 }
Example #19
0
 /**
  * Get a players statistics from the hiscores API feed
  *
  * @return \Burthorpe\Runescape\RS3\Stats\Repository|bool
  *
  * @throws \Burthorpe\Exception\UnknownPlayerException
  */
 public function stats($rsn)
 {
     $request = new Request('GET', sprintf($this->endpoints['hiscores'], $rsn));
     try {
         $response = $this->guzzle->send($request);
     } catch (RequestException $e) {
         throw new UnknownPlayerException($rsn);
     }
     return StatsRepository::factory($response->getBody());
 }
 /**
  * @param $topic string
  * @param $args array|null
  * @param $kwargs array|null
  * @return array JSON decoded response
  * @throws \Exception
  */
 public function publish($topic, array $args = null, array $kwargs = null)
 {
     $jsonBody = $this->prepareBody($topic, $args, $kwargs);
     $request = $this->client->createRequest('POST', null, array('body' => $jsonBody, 'query' => $this->prepareSignature($jsonBody)));
     try {
         $response = $this->client->send($request);
     } catch (\Exception $e) {
         throw new PublishRequestException($e->getMessage(), 500, $e);
     }
     return $response->json();
 }
 /**
  * {@inheritdoc}
  */
 public function execute(HttpRequestInterface $request)
 {
     $guzzleRequest = $this->guzzleClient->createRequest($request->getMethod(), $request->getUrl(), ['query' => $request->getParams(), 'headers' => $request->getHeaders()]);
     try {
         $clientResponse = $this->guzzleClient->send($guzzleRequest);
     } catch (RequestException $e) {
         // Re-throw guzzle exception as our own
         throw new HttpTransportException("Guzzle exception", 0, $e);
     }
     return (new HttpResponse())->setBody($clientResponse->getBody())->setHeaders($clientResponse->getHeaders());
 }
 protected function getResponse($request)
 {
     if (is_array($request)) {
         return $this->getResponses($request);
     }
     try {
         $response = $this->client->send($request);
     } catch (ClientException $ex) {
         throw new BadRequestException($ex->getResponse()->json()['text']);
     }
     return $response;
 }
Example #23
0
 /**
  * Wraps HTTP call into a good mould
  *
  * @param  string $method
  * @param  string $endpoint
  * @param  array $data
  * @return Horntell\Http\Response
  * @throws Horntell\Errors\*
  */
 public function send($method, $endpoint, $data = [])
 {
     try {
         $request = $this->client->createRequest($method, $endpoint, ['body' => json_encode($data)]);
         return new Response($this->client->send($request));
     } catch (GuzzleExceptions\RequestException $e) {
         // pass the exception to a helper method,
         // which will figure our what kind of
         // exception to throw
         return $this->handleError($e);
     }
 }
 /**
  * @param string $method
  * @param string $url
  * @param array $headers
  * @param string $body
  * @return ResponseInterface
  */
 public function request($method, $url, $headers, $body)
 {
     $request = new GuzzleHttp\Psr7\Request($method, $url, $headers, $body);
     foreach ($this->onRequest as $callback) {
         call_user_func($callback, $request);
     }
     $response = $this->client->send($request);
     foreach ($this->onResponse as $callback) {
         call_user_func($callback, $response);
     }
     return $response;
 }
 /**
  * @param RequestableInterface $apiRequest
  *
  * @return bool|\GuzzleHttp\Message\ResponseInterface
  */
 public function send(RequestableInterface $apiRequest)
 {
     $request = $this->guzzleClient->createRequest($apiRequest->getMethod(), $apiRequest->getUrl(), $apiRequest->getOptions());
     try {
         return $this->guzzleClient->send($request);
     } catch (ClientException $e) {
         if (null !== $this->logger) {
             $this->logger->alert($e->getMessage());
         }
         return false;
     }
 }
Example #26
0
 /**
  * {@inheritdoc}
  */
 protected function getResponse()
 {
     if ($this->response === null) {
         try {
             $this->response = $this->client->send($this->request);
         } catch (\Exception $exception) {
             $this->error = $exception->getMessage();
             $this->response = false;
         }
     }
     return $this->response;
 }
Example #27
0
 /**
  * @param RequestInterface $request
  * @return ApiResponse
  * @throws Exception
  */
 protected function loadResponse(RequestInterface $request)
 {
     //TODO Is it needed?
     if (stristr($request->getHeaderLine('Content-Type'), 'multipart/form-data')) {
         $request = $request->withHeader('Expect', '');
     }
     //TODO Is it needed?
     if ($request->getBody()->isSeekable()) {
         $request->getBody()->rewind();
     }
     $response = $this->_guzzle->send($request);
     return new ApiResponse($request, $response);
 }
Example #28
0
 /**
  * Download new ownCloud package
  * @param Feed $feed
  * @param Callable $onProgress
  * @throws \UnexpectedValueException
  */
 public function getOwncloud(Feed $feed, callable $onProgress)
 {
     if ($feed->isValid()) {
         $downloadPath = $this->getBaseDownloadPath($feed);
         if (!is_writable(dirname($downloadPath))) {
             throw new \Exception(dirname($downloadPath) . ' is not writable.');
         }
         $url = $feed->getUrl();
         $request = $this->httpClient->createRequest('GET', $url, ['save_to' => $downloadPath, 'timeout' => 600]);
         $request->getEmitter()->on('progress', $onProgress);
         $response = $this->httpClient->send($request);
         $this->validateResponse($response);
     }
 }
Example #29
0
 /**
  * Call method
  * @param string $method
  * @param array $data
  * @return mixed
  */
 public function call($method, $data = null)
 {
     $headers = [];
     if ($data) {
         $headers['Content-Type'] = 'multipart/form-data';
     }
     $request = $this->client->createRequest('post', $this->url . $method, ['headers' => [], 'body' => $data]);
     $response = $this->client->send($request);
     $results = $response->json();
     if (!$results['ok']) {
         throw new Exception($results['description'], $results['error_code']);
     }
     return $results['result'];
 }
Example #30
0
 /**
  * Make the request to Premailer
  * @param  array  $params
  * @return \ScottRobertson\Premailer\Response
  */
 private function request(array $params = array())
 {
     $request = $this->client->createRequest('POST', $this->url);
     $body = $request->getBody();
     foreach ($params as $key => $value) {
         $body->setField($key, $value);
     }
     try {
         $response = $this->client->send($request);
     } catch (\Exception $e) {
         throw new \ScottRobertson\Premailer\Exception\Request($e->getMessage());
     }
     return new Response($response->json(), $this->client);
 }