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

feat: handle 204 / empty bodies

Signed-off-by: Adrien Barreau <adrien.barreau@ovhcloud.com>
This commit is contained in:
Adrien Barreau 2023-10-20 15:06:15 +00:00
parent d2c21616d0
commit 75455ff5f0
8 changed files with 36 additions and 8 deletions

View File

@ -1,4 +1,4 @@
Copyright (c) 2013-2017, OVH SAS.
Copyright (c) 2013-2023, OVH SAS.
All rights reserved.
Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
<?php
# Copyright (c) 2013-2017, OVH SAS.
# Copyright (c) 2013-2023, OVH SAS.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@ -329,6 +329,9 @@ class Api
*/
private function decodeResponse(Response $response)
{
if ($response->getStatusCode() === 204 || $response->getBody()->getSize() === 0) {
return null;
}
return json_decode($response->getBody(), true, 512, JSON_THROW_ON_ERROR);
}

View File

@ -1,5 +1,5 @@
<?php
# Copyright (c) 2013-2017, OVH SAS.
# Copyright (c) 2013-2023, OVH SAS.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
<?php
# Copyright (c) 2013-2017, OVH SAS.
# Copyright (c) 2013-2023, OVH SAS.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
<?php
# Copyright (c) 2013-2017, OVH SAS.
# Copyright (c) 2013-2023, OVH SAS.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
<?php
# Copyright (c) 2013-2017, OVH SAS.
# Copyright (c) 2013-2023, OVH SAS.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without

View File

@ -1,5 +1,5 @@
<?php
# Copyright (c) 2013-2017, OVH SAS.
# Copyright (c) 2013-2023, OVH SAS.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@ -462,4 +462,29 @@ class ApiTest extends TestCase
$this->assertSame($test['sig'], $req->getHeaderLine('X-Ovh-Signature'));
}
}
public function testEmptyResponseBody()
{
$client = new MockClient(
// GET /auth/time
new Response(200, [], MOCK_TIME),
// POST /domain/zone/nonexisting.ovh/refresh
new Response(204, [], ''),
);
$api = new Api(MOCK_APPLICATION_KEY, MOCK_APPLICATION_SECRET, 'ovh-eu', MOCK_CONSUMER_KEY, $client);
$response = $api->post('/domain/zone/nonexisting.ovh/refresh');
$this->assertSame(null, $response);
$calls = $client->calls;
$this->assertCount(2, $calls);
$req = $calls[0]['request'];
$this->assertSame('GET', $req->getMethod());
$this->assertSame('https://eu.api.ovh.com/1.0/auth/time', $req->getUri()->__toString());
$req = $calls[1]['request'];
$this->assertSame('POST', $req->getMethod());
$this->assertSame('https://eu.api.ovh.com/1.0/domain/zone/nonexisting.ovh/refresh', $req->getUri()->__toString());
}
}

View File

@ -1,5 +1,5 @@
<?php
# Copyright (c) 2013-2017, OVH SAS.
# Copyright (c) 2013-2023, OVH SAS.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without