Skip to content

Commit 01d233b

Browse files
authored
Merge pull request #47 from carsso/master
Handle custom headers in a request and fix ovh-eu url
2 parents 1753296 + 234d0e3 commit 01d233b

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

src/Api.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class Api
5353
* @var array
5454
*/
5555
private $endpoints = [
56-
'ovh-eu' => 'https://api.ovh.com/1.0',
56+
'ovh-eu' => 'https://eu.api.ovh.com/1.0',
5757
'ovh-ca' => 'https://ca.api.ovh.com/1.0',
5858
'kimsufi-eu' => 'https://eu.api.kimsufi.com/1.0',
5959
'kimsufi-ca' => 'https://ca.api.kimsufi.com/1.0',
@@ -223,7 +223,7 @@ public function requestCredentials(
223223
* @return array
224224
* @throws \GuzzleHttp\Exception\ClientException if http request is an error
225225
*/
226-
private function rawCall($method, $path, $content = null, $is_authenticated = true)
226+
private function rawCall($method, $path, $content = null, $is_authenticated = true, $headers = null)
227227
{
228228
$url = $this->endpoint . $path;
229229
$request = new Request($method, $url);
@@ -262,10 +262,12 @@ private function rawCall($method, $path, $content = null, $is_authenticated = tr
262262
} else {
263263
$body = "";
264264
}
265-
$headers = [
266-
'Content-Type' => 'application/json; charset=utf-8',
267-
'X-Ovh-Application' => $this->application_key,
268-
];
265+
if(!is_array($headers))
266+
{
267+
$headers = [];
268+
}
269+
$headers['Content-Type'] = 'application/json; charset=utf-8';
270+
$headers['X-Ovh-Application'] = $this->application_key;
269271

270272
if ($is_authenticated) {
271273
if (!isset($this->time_delta)) {
@@ -309,10 +311,10 @@ private function decodeResponse(Response $response)
309311
* @return array
310312
* @throws \GuzzleHttp\Exception\ClientException if http request is an error
311313
*/
312-
public function get($path, $content = null)
314+
public function get($path, $content = null, $headers = null)
313315
{
314316
return $this->decodeResponse(
315-
$this->rawCall("GET", $path, $content)
317+
$this->rawCall("GET", $path, $content, true, $headers)
316318
);
317319
}
318320

@@ -325,10 +327,10 @@ public function get($path, $content = null)
325327
* @return array
326328
* @throws \GuzzleHttp\Exception\ClientException if http request is an error
327329
*/
328-
public function post($path, $content = null)
330+
public function post($path, $content = null, $headers = null)
329331
{
330332
return $this->decodeResponse(
331-
$this->rawCall("POST", $path, $content)
333+
$this->rawCall("POST", $path, $content, true, $headers)
332334
);
333335
}
334336

@@ -341,10 +343,10 @@ public function post($path, $content = null)
341343
* @return array
342344
* @throws \GuzzleHttp\Exception\ClientException if http request is an error
343345
*/
344-
public function put($path, $content)
346+
public function put($path, $content, $headers = null)
345347
{
346348
return $this->decodeResponse(
347-
$this->rawCall("PUT", $path, $content)
349+
$this->rawCall("PUT", $path, $content, true, $headers)
348350
);
349351
}
350352

@@ -357,10 +359,10 @@ public function put($path, $content)
357359
* @return array
358360
* @throws \GuzzleHttp\Exception\ClientException if http request is an error
359361
*/
360-
public function delete($path, $content = null)
362+
public function delete($path, $content = null, $headers = null)
361363
{
362364
return $this->decodeResponse(
363-
$this->rawCall("DELETE", $path, $content)
365+
$this->rawCall("DELETE", $path, $content, true, $headers)
364366
);
365367
}
366368

0 commit comments

Comments
 (0)