From 3cfd9e4b3040ae483b5131738d274ee0589d2331 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20HULARD?= Date: Mon, 4 Apr 2016 19:00:42 +0200 Subject: [PATCH] Update `rawCall` request creation logic All the data are computed before `Request` creation. It allow to perform a simple `new Request` with all the analysis result. Headers are set with authentication, URI is cleaned... --- src/Api.php | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/Api.php b/src/Api.php index fa5c8f5..8ac13db 100644 --- a/src/Api.php +++ b/src/Api.php @@ -221,9 +221,11 @@ class Api private function rawCall($method, $path, $content = null, $is_authenticated = true, $headers = null) { $url = $this->endpoint . $path; - $request = new Request($method, $url); + $uri = new Uri($url); + $body = null; + if (isset($content) && $method == 'GET') { - $query_string = $request->getUri()->getQuery(); + $query_string = $uri->getQuery(); $query = array(); if (!empty($query_string)) { @@ -246,16 +248,9 @@ class Api } $query = \GuzzleHttp\Psr7\build_query($query); - - $url = $request->getUri()->withQuery($query); - $request = $request->withUri($url); - $body = ""; + $uri = $uri->withQuery($query); } elseif (isset($content)) { $body = json_encode($content); - - $request->getBody()->write($body); - } else { - $body = ""; } if(!is_array($headers)) { @@ -281,8 +276,15 @@ class Api } } + $request = new Request( + $method, + $uri, + $headers, + $body + ); + /** @var Response $response */ - return $this->http_client->send($request, ['headers' => $headers]); + return $this->getHttpClient()->sendRequest($request); } /**