1
0
mirror of https://github.com/ovh/php-ovh.git synced 2023-11-05 03:20:26 +01:00

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...
This commit is contained in:
Stéphane HULARD 2016-04-04 19:00:42 +02:00
parent 3203897e05
commit 3cfd9e4b30

View File

@ -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);
}
/**