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

Adding headers option and changing OVH Europeean API url

Signed-off-by: Germain Carré <germain@carsso.com>
This commit is contained in:
Germain Carré 2016-07-01 20:00:57 +02:00
parent c3c860ee71
commit 234d0e3e51

View File

@ -53,7 +53,7 @@ class Api
* @var array * @var array
*/ */
private $endpoints = [ private $endpoints = [
'ovh-eu' => 'https://api.ovh.com/1.0', 'ovh-eu' => 'https://eu.api.ovh.com/1.0',
'ovh-ca' => 'https://ca.api.ovh.com/1.0', 'ovh-ca' => 'https://ca.api.ovh.com/1.0',
'kimsufi-eu' => 'https://eu.api.kimsufi.com/1.0', 'kimsufi-eu' => 'https://eu.api.kimsufi.com/1.0',
'kimsufi-ca' => 'https://ca.api.kimsufi.com/1.0', 'kimsufi-ca' => 'https://ca.api.kimsufi.com/1.0',
@ -223,7 +223,7 @@ class Api
* @return array * @return array
* @throws \GuzzleHttp\Exception\ClientException if http request is an error * @throws \GuzzleHttp\Exception\ClientException if http request is an error
*/ */
private function rawCall($method, $path, $content = null, $is_authenticated = true) private function rawCall($method, $path, $content = null, $is_authenticated = true, $headers = null)
{ {
$url = $this->endpoint . $path; $url = $this->endpoint . $path;
$request = new Request($method, $url); $request = new Request($method, $url);
@ -262,10 +262,12 @@ class Api
} else { } else {
$body = ""; $body = "";
} }
$headers = [ if(!is_array($headers))
'Content-Type' => 'application/json; charset=utf-8', {
'X-Ovh-Application' => $this->application_key, $headers = [];
]; }
$headers['Content-Type'] = 'application/json; charset=utf-8';
$headers['X-Ovh-Application'] = $this->application_key;
if ($is_authenticated) { if ($is_authenticated) {
if (!isset($this->time_delta)) { if (!isset($this->time_delta)) {
@ -309,10 +311,10 @@ class Api
* @return array * @return array
* @throws \GuzzleHttp\Exception\ClientException if http request is an error * @throws \GuzzleHttp\Exception\ClientException if http request is an error
*/ */
public function get($path, $content = null) public function get($path, $content = null, $headers = null)
{ {
return $this->decodeResponse( return $this->decodeResponse(
$this->rawCall("GET", $path, $content) $this->rawCall("GET", $path, $content, true, $headers)
); );
} }
@ -325,10 +327,10 @@ class Api
* @return array * @return array
* @throws \GuzzleHttp\Exception\ClientException if http request is an error * @throws \GuzzleHttp\Exception\ClientException if http request is an error
*/ */
public function post($path, $content = null) public function post($path, $content = null, $headers = null)
{ {
return $this->decodeResponse( return $this->decodeResponse(
$this->rawCall("POST", $path, $content) $this->rawCall("POST", $path, $content, true, $headers)
); );
} }
@ -341,10 +343,10 @@ class Api
* @return array * @return array
* @throws \GuzzleHttp\Exception\ClientException if http request is an error * @throws \GuzzleHttp\Exception\ClientException if http request is an error
*/ */
public function put($path, $content) public function put($path, $content, $headers = null)
{ {
return $this->decodeResponse( return $this->decodeResponse(
$this->rawCall("PUT", $path, $content) $this->rawCall("PUT", $path, $content, true, $headers)
); );
} }
@ -357,10 +359,10 @@ class Api
* @return array * @return array
* @throws \GuzzleHttp\Exception\ClientException if http request is an error * @throws \GuzzleHttp\Exception\ClientException if http request is an error
*/ */
public function delete($path, $content = null) public function delete($path, $content = null, $headers = null)
{ {
return $this->decodeResponse( return $this->decodeResponse(
$this->rawCall("DELETE", $path, $content) $this->rawCall("DELETE", $path, $content, true, $headers)
); );
} }