From 9f6492185b2e14fe8d1e53f8a1d01715039f29a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20HULARD?= Date: Mon, 4 Apr 2016 19:06:37 +0200 Subject: [PATCH] Create a central method to send the Request All the calls go through that method, it'll allow extensibility. --- src/Api.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Api.php b/src/Api.php index 8ac13db..111a06d 100644 --- a/src/Api.php +++ b/src/Api.php @@ -30,6 +30,8 @@ namespace Ovh; +use Psr\Http\Message\RequestInterface; +use Psr\Http\Message\ResponseInterface; use GuzzleHttp\Psr7\Uri; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Response; @@ -276,15 +278,13 @@ class Api } } - $request = new Request( + /** @var ResponseInterface $response */ + return $this->sendRequest(new Request( $method, $uri, $headers, $body - ); - - /** @var Response $response */ - return $this->getHttpClient()->sendRequest($request); + )); } /** @@ -378,4 +378,14 @@ class Api { return $this->http_client; } + + /** + * Send the Request through the HttpClient + * @param RequestInterface $request + * @return ResponseInterface + */ + private function sendRequest(RequestInterface $request) + { + return $this->getHttpClient()->sendRequest($request); + } }