From 234d0e3e51eda4c49b83fd14817f8e265d5208a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germain=20Carr=C3=A9?= Date: Fri, 1 Jul 2016 20:00:57 +0200 Subject: [PATCH] Adding headers option and changing OVH Europeean API url MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Germain Carré --- src/Api.php | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/Api.php b/src/Api.php index dbee282..dd7d10c 100644 --- a/src/Api.php +++ b/src/Api.php @@ -53,7 +53,7 @@ class Api * @var array */ 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', 'kimsufi-eu' => 'https://eu.api.kimsufi.com/1.0', 'kimsufi-ca' => 'https://ca.api.kimsufi.com/1.0', @@ -223,7 +223,7 @@ class Api * @return array * @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; $request = new Request($method, $url); @@ -262,10 +262,12 @@ class Api } else { $body = ""; } - $headers = [ - 'Content-Type' => 'application/json; charset=utf-8', - 'X-Ovh-Application' => $this->application_key, - ]; + if(!is_array($headers)) + { + $headers = []; + } + $headers['Content-Type'] = 'application/json; charset=utf-8'; + $headers['X-Ovh-Application'] = $this->application_key; if ($is_authenticated) { if (!isset($this->time_delta)) { @@ -309,10 +311,10 @@ class Api * @return array * @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( - $this->rawCall("GET", $path, $content) + $this->rawCall("GET", $path, $content, true, $headers) ); } @@ -325,10 +327,10 @@ class Api * @return array * @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( - $this->rawCall("POST", $path, $content) + $this->rawCall("POST", $path, $content, true, $headers) ); } @@ -341,10 +343,10 @@ class Api * @return array * @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( - $this->rawCall("PUT", $path, $content) + $this->rawCall("PUT", $path, $content, true, $headers) ); } @@ -357,10 +359,10 @@ class Api * @return array * @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( - $this->rawCall("DELETE", $path, $content) + $this->rawCall("DELETE", $path, $content, true, $headers) ); }