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

Merge pull request #142 from deathiop/204

feat: handle 204 / empty bodies
This commit is contained in:
Adrien Barreau 2023-10-20 17:21:31 +02:00 committed by GitHub
commit a5241f8411
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,5 @@
<?php <?php
# Copyright (c) 2013-2017, OVH SAS. # Copyright (c) 2013-2023, OVH SAS.
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # 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')); $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 <?php
# Copyright (c) 2013-2017, OVH SAS. # Copyright (c) 2013-2023, OVH SAS.
# All rights reserved. # All rights reserved.
# #
# Redistribution and use in source and binary forms, with or without # Redistribution and use in source and binary forms, with or without