mirror of
https://github.com/ovh/php-ovh.git
synced 2023-11-05 03:20:26 +01:00
Merge pull request #36 from shulard/feature/invalid-direct-get
Hi @shulard, Thanks a lot for this contribution :) Merged
This commit is contained in:
commit
815b07ba22
51
src/Api.php
51
src/Api.php
@ -165,8 +165,13 @@ class Api
|
|||||||
private function calculateTimeDelta()
|
private function calculateTimeDelta()
|
||||||
{
|
{
|
||||||
if (!isset($this->time_delta)) {
|
if (!isset($this->time_delta)) {
|
||||||
$response = $this->http_client->get($this->endpoint . "/auth/time");
|
$response = $this->rawCall(
|
||||||
$serverTimestamp = (int)(String)$response->getBody();
|
'GET',
|
||||||
|
"/auth/time",
|
||||||
|
null,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
$serverTimestamp = (int)(string)$response->getBody();
|
||||||
$this->time_delta = $serverTimestamp - (int)\time();
|
$this->time_delta = $serverTimestamp - (int)\time();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,11 +197,13 @@ class Api
|
|||||||
$parameters->redirection = $redirection;
|
$parameters->redirection = $redirection;
|
||||||
|
|
||||||
//bypass authentication for this call
|
//bypass authentication for this call
|
||||||
$response = $this->rawCall(
|
$response = $this->decodeResponse(
|
||||||
'POST',
|
$this->rawCall(
|
||||||
'/auth/credential',
|
'POST',
|
||||||
$parameters,
|
'/auth/credential',
|
||||||
false
|
$parameters,
|
||||||
|
false
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->consumer_key = $response["consumerKey"];
|
$this->consumer_key = $response["consumerKey"];
|
||||||
@ -220,7 +227,6 @@ class Api
|
|||||||
{
|
{
|
||||||
$url = $this->endpoint . $path;
|
$url = $this->endpoint . $path;
|
||||||
$request = new Request($method, $url);
|
$request = new Request($method, $url);
|
||||||
|
|
||||||
if (isset($content) && $method == 'GET') {
|
if (isset($content) && $method == 'GET') {
|
||||||
|
|
||||||
$query_string = $request->getUri()->getQuery();
|
$query_string = $request->getUri()->getQuery();
|
||||||
@ -261,7 +267,6 @@ class Api
|
|||||||
} else {
|
} else {
|
||||||
$body = "";
|
$body = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
$headers = [
|
$headers = [
|
||||||
'Content-Type' => 'application/json; charset=utf-8',
|
'Content-Type' => 'application/json; charset=utf-8',
|
||||||
'X-Ovh-Application' => $this->application_key,
|
'X-Ovh-Application' => $this->application_key,
|
||||||
@ -285,8 +290,18 @@ class Api
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @var Response $response */
|
/** @var Response $response */
|
||||||
$response = $this->http_client->send($request, ['headers' => $headers]);
|
return $this->http_client->send($request, ['headers' => $headers]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decode a Response object body to an Array
|
||||||
|
*
|
||||||
|
* @param Response $response
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function decodeResponse(Response $response)
|
||||||
|
{
|
||||||
return json_decode($response->getBody(), true);
|
return json_decode($response->getBody(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,7 +316,9 @@ class Api
|
|||||||
*/
|
*/
|
||||||
public function get($path, $content = null)
|
public function get($path, $content = null)
|
||||||
{
|
{
|
||||||
return $this->rawCall("GET", $path, $content);
|
return $this->decodeResponse(
|
||||||
|
$this->rawCall("GET", $path, $content)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -315,7 +332,9 @@ class Api
|
|||||||
*/
|
*/
|
||||||
public function post($path, $content = null)
|
public function post($path, $content = null)
|
||||||
{
|
{
|
||||||
return $this->rawCall("POST", $path, $content);
|
return $this->decodeResponse(
|
||||||
|
$this->rawCall("POST", $path, $content)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -329,7 +348,9 @@ class Api
|
|||||||
*/
|
*/
|
||||||
public function put($path, $content)
|
public function put($path, $content)
|
||||||
{
|
{
|
||||||
return $this->rawCall("PUT", $path, $content);
|
return $this->decodeResponse(
|
||||||
|
$this->rawCall("PUT", $path, $content)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -343,7 +364,9 @@ class Api
|
|||||||
*/
|
*/
|
||||||
public function delete($path, $content = null)
|
public function delete($path, $content = null)
|
||||||
{
|
{
|
||||||
return $this->rawCall("DELETE", $path, $content);
|
return $this->decodeResponse(
|
||||||
|
$this->rawCall("DELETE", $path, $content)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user