diff --git a/CHANGELOG.md b/CHANGELOG.md index 3316cf5..1d8798b 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,16 +5,21 @@ All notable changes to `exonet-api-php` will be documented in this file. Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles. ## Unreleased -[Compare v2.0.0 - Unreleased](https://github.com/exonet/exonet-api-php/compare/v2.0.0...master) +[Compare v2.1.1 - Unreleased](https://github.com/exonet/exonet-api-php/compare/v2.1.1...master) + +## [v2.1.1](https://github.com/exonet/exonet-api-php/releases/tag/v2.1.1) - 2019-09-19 +[Compare v2.1.0 - v2.1.1](https://github.com/exonet/exonet-api-php/compare/v2.1.0...v2.1.1) +### Changed +- `DELETE` requests now return `true` when successful. If something went wrong, an exception is still thrown. ## [v2.1.0](https://github.com/exonet/exonet-api-php/releases/tag/v2.1.0) - 2019-09-06 -[Compare v2.1.0 - v2.0.0](https://github.com/exonet/backend/compare/v2.0.0...v2.1.0) +[Compare v2.1.0 - v2.0.0](https://github.com/exonet/exonet-api-php/compare/v2.0.0...v2.1.0) ### Added - Support for patching resources and relationships. - Exceptions thrown by the package are extended with the `status` as the exception code, the `code` as detailed code and an array containing the returned variables. ## [v2.0.0](https://github.com/exonet/exonet-api-php/releases/tag/v2.0.0) - 2019-07-02 -[Compare v2.0.0 - v1.0.0](https://github.com/exonet/backend/compare/v1.0.0...v2.0.0) +[Compare v2.0.0 - v1.0.0](https://github.com/exonet/exonet-api-php/compare/v1.0.0...v2.0.0) ## Breaking - The Client has been refactored to keep consistency between packages in different programming languages. See the updated documentation and examples. @@ -24,7 +29,7 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip - Making DELETE request to remove a resource. ## [v1.0.0](https://github.com/exonet/exonet-api-php/releases/tag/v1.0.0) - 2019-04-29 -[Compare v0.2.0 - v1.0.0](https://github.com/exonet/backend/compare/v0.2.0...v1.0.0) +[Compare v0.2.0 - v1.0.0](https://github.com/exonet/exonet-api-php/compare/v0.2.0...v1.0.0) ### Breaking - The public property `type` in the `ApiResource` class has been renamed to `resourceType` in order not to conflict with the DNS record resource, which has a `type` attribute. @@ -32,7 +37,7 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip - Two examples for DNS zones and records. ## [v0.2.0](https://github.com/exonet/exonet-api-php/releases/tag/v0.2.0) - 2018-07-09 -[Compare v0.1.0 - v0.2.0](https://github.com/exonet/backend/compare/v0.1.0...v0.2.0) +[Compare v0.1.0 - v0.2.0](https://github.com/exonet/exonet-api-php/compare/v0.1.0...v0.2.0) ### Added - Ready to use examples to get ticket details. - The ApiResourceSet now supports ArrayAccess. diff --git a/src/Connector.php b/src/Connector.php index aabb43c..89e50db 100644 --- a/src/Connector.php +++ b/src/Connector.php @@ -92,12 +92,13 @@ public function post(string $urlPath, array $data) } /** - * Convert the data to JSON and patch it to a URL. + * Convert the data to JSON and patch it to a URL. Will return 'true' when successful. If not successful an exception + * is thrown. * * @param string $urlPath The URL to patch to. * @param array $data An array with data to patch to the API. * - * @return bool True when the patch succeeded. + * @return true When the patch succeeded. */ public function patch(string $urlPath, array $data) : bool { @@ -117,12 +118,14 @@ public function patch(string $urlPath, array $data) : bool } /** - * Make a DELETE call to the API. + * Make a DELETE call to the API. Will return 'true' when successful. If not successful an exception is thrown. * * @param string $urlPath The url to make the DELETE request to. * @param array $data (Optional) The data to send along with the DELETE request. + * + * @return true When the delete was successful. */ - public function delete(string $urlPath, array $data = []) : void + public function delete(string $urlPath, array $data = []) : bool { $apiUrl = $this->apiClient()->getApiUrl().$urlPath; $this->apiClient()->log()->debug('Sending [DELETE] request', ['url' => $apiUrl]); @@ -135,6 +138,8 @@ public function delete(string $urlPath, array $data = []) : void ); self::httpClient()->send($request); + + return true; } /** diff --git a/src/Request.php b/src/Request.php index ee89cf8..54ffa40 100644 --- a/src/Request.php +++ b/src/Request.php @@ -87,12 +87,13 @@ public function post(array $payload, string $appendUrl = null) } /** - * Patch data to the API. + * Patch data to the API. Will return 'true' when successful. If not successful an exception + * is thrown. * * @param string $id The ID of the resource to patch. * @param array $payload The payload to post to the API. * - * @return bool True when succeeded. + * @return true When the patch succeeded. */ public function patch(string $id, array $payload) : bool { @@ -103,14 +104,16 @@ public function patch(string $id, array $payload) : bool } /** - * Delete a resource. + * Delete a resource. Will return 'true' when successful. If not successful an exception is thrown. * * @param string $id The ID of the resource to delete. * @param array $data (Optional) Data to send along with the request. + * + * @return true When the delete was successful. */ - public function delete(string $id, array $data = []) : void + public function delete(string $id, array $data = []) : bool { - $this->connector->delete( + return $this->connector->delete( trim($this->resource, '/').'/'.$id, $data ); diff --git a/src/Structures/ApiResource.php b/src/Structures/ApiResource.php index 604ed14..14af3e2 100644 --- a/src/Structures/ApiResource.php +++ b/src/Structures/ApiResource.php @@ -97,9 +97,10 @@ public function post() } /** - * Patch this resource to the API. For now this must be done in multiple calls if also relations are changed. + * Patch this resource to the API. For now this must be done in multiple calls if also relations are changed. If not + * successful an exception is thrown. * - * @return bool True when the patch has succeeded. + * @return true When the patch succeeded. */ public function patch() : bool { diff --git a/src/Structures/ApiResourceIdentifier.php b/src/Structures/ApiResourceIdentifier.php index 9e7cb13..7c19e2a 100644 --- a/src/Structures/ApiResourceIdentifier.php +++ b/src/Structures/ApiResourceIdentifier.php @@ -82,15 +82,15 @@ public function get() } /** - * Delete this resource from the API. + * Delete this resource from the API. Will return 'true' when successful. If not successful an exception is thrown. + * + * @return true When the delete was successful. */ - public function delete() : void + public function delete() : bool { // If there are no changed relationships, perform a 'normal' delete. if (empty($this->changedRelationships)) { - $this->request->delete($this->id()); - - return; + return $this->request->delete($this->id()); } // If there are changed relationships, transform them to JSON and send a DELETE to the relationship endpoint. @@ -106,6 +106,8 @@ public function delete() : void $this->request->delete($this->id().'/relationships/'.$relationship, ['data' => $relationData]); } + + return true; } /** diff --git a/tests/ConnectorTest.php b/tests/ConnectorTest.php index 9f94567..19f3327 100644 --- a/tests/ConnectorTest.php +++ b/tests/ConnectorTest.php @@ -176,8 +176,9 @@ public function testDelete() $payload = ['test' => 'demo']; - $connectorClass->delete('url', $payload); + $result = $connectorClass->delete('url', $payload); + $this->assertTrue($result); $this->assertCount(1, $apiCalls); $request = $apiCalls[0]['request']; diff --git a/tests/RequestTest.php b/tests/RequestTest.php index bbd872f..f26b0e7 100644 --- a/tests/RequestTest.php +++ b/tests/RequestTest.php @@ -68,10 +68,10 @@ public function testDeleteRequest() ->shouldReceive('delete') ->withArgs(['test/id999', []]) ->once() - ->andReturnNull(); + ->andReturnTrue(); $request = new Request('/test', $connectorMock); - $this->assertNull($request->delete('id999')); + $this->assertTrue($request->delete('id999')); } } diff --git a/tests/Structures/ApiResourceIdentifierTest.php b/tests/Structures/ApiResourceIdentifierTest.php index cb5c60d..51facf5 100644 --- a/tests/Structures/ApiResourceIdentifierTest.php +++ b/tests/Structures/ApiResourceIdentifierTest.php @@ -38,11 +38,11 @@ public function testDeleteResource() $requestMock->shouldReceive('delete') ->once() ->withArgs(['xV42']) - ->andReturnNull(); + ->andReturnTrue(); $resourceIdentifier = new ApiResourceIdentifier('unitTest', 'xV42', $requestMock); - $this->assertNull($resourceIdentifier->delete()); + $this->assertTrue($resourceIdentifier->delete()); } public function testDeleteRelation() @@ -51,17 +51,17 @@ public function testDeleteRelation() $requestMock->shouldReceive('delete') ->once() ->withArgs(['xV42/relationships/test', ['data' => ['type' => 'testRelation', 'id' => 'testId']]]) - ->andReturnNull(); + ->andReturnTrue(); $requestMock->shouldReceive('delete') ->once() ->withArgs(['xV42/relationships/test2', ['data' => [['type' => 'testRelation2', 'id' => 'testId2']]]]) - ->andReturnNull(); + ->andReturnTrue(); $resourceIdentifier = new ApiResourceIdentifier('unitTest', 'xV42', $requestMock); $resourceIdentifier->relationship('test', new ApiResourceIdentifier('testRelation', 'testId')); $resourceIdentifier->relationship('test2', [new ApiResourceIdentifier('testRelation2', 'testId2')]); - $this->assertNull($resourceIdentifier->delete()); + $this->assertTrue($resourceIdentifier->delete()); } }