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:
parent
d2c21616d0
commit
75455ff5f0
2
LICENSE
2
LICENSE
@ -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
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user